177 lines
4.3 KiB
C++
177 lines
4.3 KiB
C++
#include "ui_main.h"
|
|
|
|
UIMain::UIMain()
|
|
{
|
|
{
|
|
gcSprite spr = g_factory->CreateSpriteDefault();
|
|
spr->SetColor(createColor(0x0f0f0fff), 0);
|
|
spr->SetColor(createColor(0x000000ff), 1);
|
|
spr->SetColor(createColor(0x0f0f0fff), 2);
|
|
spr->SetColor(createColor(0x2f2f2fff), 3);
|
|
UI::Sprite* ui_spr = UI::Sprite::Create(
|
|
spr, UI::Sprite::AutoSize::PANEL, UI::Sprite::FillMode::STRETCH);
|
|
GetPanelRoot()->SetOrderMode(UI::Panel::FORCE);
|
|
GetPanelRoot()->SetOrder(Z_DEFAULT_BG);
|
|
GetPanelRoot()->Add(ui_spr);
|
|
_sprBg = ui_spr;
|
|
}
|
|
|
|
_panel = CreatePanel("root");
|
|
_panel->SetAutoRun(false);
|
|
_panel->SetPosScale({ 0.5f, 0.1f });
|
|
_panel->SetLocator("main");
|
|
|
|
{
|
|
UI::Text* txt = g_ui->CreateText("title");
|
|
txt->SetString("dl库测试程序v0.1");
|
|
_panel->Add(txt);
|
|
}
|
|
_panel->AddCpt(createComponents());
|
|
_panel->AddCpt(createComponents());
|
|
|
|
std::array menu = {
|
|
"gfx", "sprite", "actor", "text", "gui", "audio", "crypto", "game"
|
|
};
|
|
for (auto& iter : menu)
|
|
{
|
|
UI::ButtonSprite* btn = g_ui->CreateButtonSpriteDefault();
|
|
btn->SetElementData(Align::CC);
|
|
btn->GetCpt()->SetName(iter);
|
|
btn->SetMode(UI::ButtonMode::RADIO);
|
|
btn->SetString(iter);
|
|
_panel->Add(btn);
|
|
}
|
|
|
|
{
|
|
// 二维码
|
|
Image* img = QR::EncodeString("https://gitee.com/lveyou/dl");
|
|
g_factory->RegisterSprite("qr", 0, img);
|
|
delete img;
|
|
|
|
gcSprite spr = g_factory->CreateSprite("qr");
|
|
UI::Sprite* ui_spr = UI::Sprite::Create(spr,
|
|
UI::Sprite::AutoSize::NONE,
|
|
UI::Sprite::FillMode::STATIC);
|
|
ui_spr->SetElementData(Align::CC);
|
|
ui_spr->SetEDOrderOffset(-1);
|
|
_panel->Add(ui_spr);
|
|
}
|
|
/*g_as->ExcuteFunction("mod管理器", "UI::Panel@ initUI(string)",
|
|
_panelMod, std::string{ "dddddddddd" });*/
|
|
int x = 3;
|
|
}
|
|
|
|
void UIMain::Update()
|
|
{
|
|
if (g_input->KeyDown(KeyCode::R))
|
|
g_system->Exit();
|
|
|
|
if (_selectName.empty())
|
|
{// 主界面
|
|
_panel->Update();
|
|
}
|
|
else
|
|
{// 子界面
|
|
_uiInfo._panelInfo->Update();
|
|
|
|
if (_uiInfo._btnBack->IsClick())
|
|
{
|
|
_panel->SetSelect(-1);
|
|
}
|
|
}
|
|
|
|
// 切换
|
|
std::string name = _panel->GetSelectName();
|
|
if (_selectName != name)
|
|
{
|
|
_selectName = name;
|
|
_change_scene();
|
|
}
|
|
}
|
|
|
|
void UIMain::Render()
|
|
{
|
|
}
|
|
|
|
void UIMain::_change_scene()
|
|
{
|
|
_sprBg->SetVisible(true);
|
|
if (_selectName.empty())
|
|
{
|
|
g_scene->Del("child");
|
|
}
|
|
else if (_selectName == "gfx")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Graphics 基础绘图");
|
|
_uiInfo._txtInfo->SetString("基本几何图形绘制");
|
|
g_scene->Add("child", new UIGfx);
|
|
}
|
|
else if (_selectName == "sprite")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Sprite 2d绘图");
|
|
_uiInfo._txtInfo->SetString("2d图形绘制");
|
|
g_scene->Add("child", new UISprite);
|
|
}
|
|
else if (_selectName == "actor")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Actor 3d绘图");
|
|
_uiInfo._txtInfo->SetString("3d图形绘制 按tab操作相机\n双击切换模型,空格键停止动画");
|
|
g_scene->Add("child", new UIActor);
|
|
_sprBg->SetVisible(false);
|
|
}
|
|
else if (_selectName == "text")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Text 文本绘制");
|
|
_uiInfo._txtInfo->SetString("文本绘制");
|
|
g_scene->Add("child", new UIText);
|
|
}
|
|
else if (_selectName == "gui")
|
|
{
|
|
_uiInfo._txtTitle->SetString("GUI 图像用户界面");
|
|
_uiInfo._txtInfo->SetString("GUI展示");
|
|
g_scene->Add("child", new UIGui);
|
|
}
|
|
else if (_selectName == "audio")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Audio 音频系统");
|
|
_uiInfo._txtInfo->SetString("音频系统 点左键播放");
|
|
g_scene->Add("child", new UIAudio);
|
|
}
|
|
else if (_selectName == "crypto")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Crypto 加密算法");
|
|
_uiInfo._txtInfo->SetString("加密算法");
|
|
g_scene->Add("child", new UICrypto);
|
|
}
|
|
else if (_selectName == "game")
|
|
{
|
|
_uiInfo._txtTitle->SetString("Game 游戏示例");
|
|
_uiInfo._txtInfo->SetString("游戏示例");
|
|
g_scene->Add("child", new UIGame);
|
|
}
|
|
}
|
|
|
|
UIMain::UIInfo::UIInfo()
|
|
{
|
|
_panelInfo = g_ui->CreatePanel();
|
|
_panelInfo->SetAutoRun(false);
|
|
_panelInfo->SetPosScale({ 0.0f, 0.0f });
|
|
_panelInfo->SetPosPixel({ 100, 50 });
|
|
_panelInfo->SetLocator("main_info");
|
|
|
|
//_panelInfo->AddCpt(createComponents());
|
|
|
|
_txtTitle = g_ui->CreateText("t_normal");
|
|
//_txtTitle->SetElementData(Align::LT);
|
|
_panelInfo->Add(_txtTitle);
|
|
|
|
_txtInfo = g_ui->CreateText("c_normal");
|
|
_panelInfo->Add(_txtInfo);
|
|
|
|
_panelInfo->AddCpt(createComponents());
|
|
|
|
_btnBack = g_ui->CreateButtonSpriteDefault();
|
|
_btnBack->SetString("返回");
|
|
_panelInfo->Add(_btnBack);
|
|
}
|