181 lines
4.4 KiB
C++
181 lines
4.4 KiB
C++
#include "ui_game.h"
|
|
|
|
UIGame::UIGame()
|
|
{
|
|
_coor = Coor::Create();
|
|
g_gfx->SetCoor(_coor);
|
|
uint32_t v =Crypto::HashCrc32(CreateBufferView("lveyou"));
|
|
auto x = Crypto::HashMd5(CreateBufferView("lveyou"));
|
|
std::string str = to_string_hex(CreateBufferView(x));
|
|
|
|
_panel = g_ui->CreatePanel();
|
|
_panel->SetPosScale({ 0.0f, 0.0f });
|
|
_panel->SetPosPixel(POS_CONTENT);
|
|
_panel->SetAutoRun(false);
|
|
|
|
UI::Panel* panel_menu = g_ui->CreatePanel();
|
|
panel_menu->SetLocator(createLocatorX(128, 1));
|
|
panel_menu->SetPosPixel({ 400, 0 });
|
|
g_ui->SetPanelParent(panel_menu, _panel);
|
|
{
|
|
UI::ButtonSprite* btn = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn->SetMode(UI::ButtonMode::RADIO);
|
|
btn->SetString("1");
|
|
UI::ButtonSprite* btn1 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn1->SetMode(UI::ButtonMode::RADIO);
|
|
btn1->SetString("2");
|
|
UI::ButtonSprite* btn2 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn2->SetMode(UI::ButtonMode::RADIO);
|
|
btn2->SetString("3");
|
|
UI::ButtonSprite* btn3 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn3->SetMode(UI::ButtonMode::RADIO);
|
|
btn3->SetString("4");
|
|
UI::ButtonSprite* btn4 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn4->SetMode(UI::ButtonMode::RADIO);
|
|
btn4->SetString("5");
|
|
UI::ButtonSprite* btn5 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn5->SetMode(UI::ButtonMode::RADIO);
|
|
btn5->SetString("6");
|
|
UI::ButtonSprite* btn6 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn6->SetMode(UI::ButtonMode::RADIO);
|
|
btn6->SetString("7");
|
|
UI::ButtonSprite* btn7 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn7->SetMode(UI::ButtonMode::RADIO);
|
|
btn7->SetString("8");
|
|
UI::ButtonSprite* btn8 = g_ui->CreateButtonSpriteDefault(
|
|
UI::Manager::ButtonStyle::LONG);
|
|
btn8->SetMode(UI::ButtonMode::RADIO);
|
|
btn8->SetString("9");
|
|
panel_menu->Add(btn);
|
|
panel_menu->Add(btn1);
|
|
panel_menu->Add(btn2);
|
|
panel_menu->Add(btn3);
|
|
panel_menu->Add(btn4);
|
|
panel_menu->Add(btn5);
|
|
panel_menu->Add(btn6);
|
|
panel_menu->Add(btn7);
|
|
panel_menu->Add(btn8);
|
|
}
|
|
_panelMenu = panel_menu;
|
|
|
|
_create_list();
|
|
}
|
|
|
|
void UIGame::Update()
|
|
{
|
|
_panel->Update();
|
|
std::size_t i = _panelMenu->GetSelectIndex();
|
|
_cur_value = i + 1;
|
|
}
|
|
|
|
void UIGame::Render()
|
|
{
|
|
_coor->SetScale(g_ui->GetScale());
|
|
_coor->SetPosition({ 20.0, 20.0 });
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
float cur = 60 * i;
|
|
g_gfx->Line2D({0 , cur }, { 540, cur });
|
|
}
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
float cur = 60 * i;
|
|
g_gfx->Line2D({ cur, 0 }, { cur, 540 });
|
|
}
|
|
if (g_input->KeyDown(MouseCode::LEFT))
|
|
{
|
|
Position pos = _coor->WorldToThis(toPosition(g_input->GetCursorPosition()));
|
|
int x = pos[0] / 60.0;
|
|
int y = pos[1] / 60.0;
|
|
for (size_t i = 0; i < _vecNum.size(); ++i)
|
|
{
|
|
if (_vecNum[i].x == x && _vecNum[i].y == y && _check_click({x, y}, _cur_value))
|
|
{
|
|
_vecNum[i].data = _cur_value;
|
|
_vecNum[i].txt->SetString(std::to_string(_cur_value));
|
|
_vecNum[i].txt->SetPositionAlign({ (float)x * 60 + 30, (float)y * 60 + 30 }, Align::CC);
|
|
}
|
|
}
|
|
}
|
|
for (size_t i = 0; i < _vecNum.size(); ++i)
|
|
{
|
|
_vecNum[i].txt->Render();
|
|
}
|
|
}
|
|
|
|
bool UIGame::_check_click(Point pt, int value)
|
|
{
|
|
int start = 9 * pt[1];
|
|
bool is = false;
|
|
for (int i = start; i < start + 9; ++i)
|
|
{
|
|
if (_vecNum[i].data == value)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
for (int i = pt[0]; i < 81; i = i + 9)
|
|
{
|
|
if (_vecNum[i].data == value)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
int start_new = pt[0] / 3 * 3 + 9 * (pt[1] / 3 * 3);
|
|
for (int i = start_new; i < start_new + 9 * 2 + 3;)
|
|
{
|
|
if (_vecNum[i].data == value)
|
|
{
|
|
return false;
|
|
}
|
|
if (i == start_new + 2 || i == start_new + 9 * 1 + 2)
|
|
{
|
|
i = i + 7;
|
|
}
|
|
else
|
|
++i;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void UIGame::_create_list()
|
|
{
|
|
for (int i = 0; i < 81; ++i)
|
|
{
|
|
numNode num;
|
|
num.data = -1;
|
|
num.x = i % 9;
|
|
num.y = i / 9;
|
|
num.txt = g_factory->CreateTextDefault();
|
|
num.txt->GetCoor()->SetParent(_coor);
|
|
num.txt->SetFontSize(20);
|
|
_vecNum.push_back(num);
|
|
}
|
|
auto fun = [&](std::vector<numNode>& vec)
|
|
{
|
|
for (size_t x = 0; x < vec.size(); ++x)
|
|
{
|
|
bool can = false;
|
|
while (!can)
|
|
{
|
|
int ret = Random::Int(1, 9);
|
|
if (_check_click({ vec[x].x, vec[x].y }, ret))
|
|
{
|
|
_vecNum[x].data = ret;
|
|
can = true;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
fun(_vecNum);
|
|
}
|