Make menu to state machine

This commit is contained in:
Vladislav Khorev committed 2026-03-06 21:52:00 +03:00
1 parent ac551122d9
commit 4af20c65e6
14 files changed
+480 -335

No files matched your search

+7 -12
View File
@@ -150,7 +150,6 @@ namespace ZL
Environment::shipState.nickname = nickname;
Environment::shipState.shipType = shipType;
if (Environment::shipState.shipType == 1)
{
menuManager.uiManager.findButton("shootButton")->state = ButtonState::Disabled;
@@ -171,14 +170,12 @@ namespace ZL
networkClient->Connect("", 0);
lastTickCount = 0;
spaceGameStarted = 1;
};
menuManager.onMultiplayerPressed = [this](const std::string& nickname, int shipType) {
Environment::shipState.nickname = nickname;
Environment::shipState.shipType = shipType;
#ifdef EMSCRIPTEN
networkClient = std::make_unique<WebSocketClientEmscripten>();
networkClient->Connect("localhost", 8081);
@@ -186,7 +183,7 @@ namespace ZL
networkClient = std::make_unique<WebSocketClient>(taskManager.getIOContext());
networkClient->Connect("localhost", 8081);
#endif
if (networkClient) {
std::string joinMsg = std::string("JOIN:") + nickname + ":" + std::to_string(shipType);
networkClient->Send(joinMsg);
@@ -195,12 +192,10 @@ namespace ZL
space.boxCoordsArr.clear();
space.boxRenderArr.clear();
//space.boxLabels.clear();
space.boxAlive.clear();
space.serverBoxesApplied = false;
lastTickCount = 0;
spaceGameStarted = 1;
};
@@ -252,7 +247,7 @@ namespace ZL
else
{
if (spaceGameStarted) {
if (menuManager.shouldRenderSpace()) {
space.drawScene();
}
else
@@ -336,7 +331,7 @@ namespace ZL
//throw std::runtime_error("Synchronization is lost");
}
if (spaceGameStarted) {
if (menuManager.shouldRenderSpace()) {
space.processTickCount(newTickCount, delta);
}
menuManager.uiManager.update(static_cast<float>(delta));
@@ -503,7 +498,7 @@ namespace ZL
}
mainThreadHandler.processMainThreadTasks();
if (spaceGameStarted) {
if (menuManager.shouldRenderSpace()) {
space.update();
}
}
@@ -529,7 +524,7 @@ namespace ZL
}();
if (!menuManager.uiManager.isUiInteraction()) {
if (spaceGameStarted) {
if (menuManager.shouldRenderSpace()) {
space.handleDown(mx, my);
}
}
@@ -544,7 +539,7 @@ namespace ZL
menuManager.uiManager.onMouseUp(uiX, uiY);
if (!menuManager.uiManager.isUiInteraction()) {
if (spaceGameStarted) {
if (menuManager.shouldRenderSpace()) {
space.handleUp(mx, my);
}
}
@@ -559,7 +554,7 @@ namespace ZL
menuManager.uiManager.onMouseMove(uiX, uiY);
if (!menuManager.uiManager.isUiInteraction()) {
if (spaceGameStarted) {
if (menuManager.shouldRenderSpace()) {
space.handleMotion(mx, my);
}
}