Minor fixing
This commit is contained in:
1 parent
4af20c65e6
commit
41f370f2ee
4 files changed
+86
-9
No files matched your search
+55
-9
@@ -10,11 +10,13 @@ namespace ZL {
|
||||
|
||||
void MenuManager::setupMenu()
|
||||
{
|
||||
mainMenuRoot = loadUiFromFile("resources/config/main_menu.json", renderer, CONST_ZIP_FILE);
|
||||
shipSelectionRoot = loadUiFromFile("resources/config/ship_selection_menu.json", renderer, CONST_ZIP_FILE);
|
||||
gameplayRoot = loadUiFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE);
|
||||
gameOverRoot = loadUiFromFile("resources/config/game_over.json", renderer, CONST_ZIP_FILE);
|
||||
connectionLostRoot = loadUiFromFile("resources/config/connection_lost.json", renderer, CONST_ZIP_FILE);
|
||||
mainMenuRoot = loadUiFromFile("resources/config/main_menu.json", renderer, CONST_ZIP_FILE);
|
||||
shipSelectionRoot = loadUiFromFile("resources/config/ship_selection_menu.json", renderer, CONST_ZIP_FILE);
|
||||
connectingRoot = loadUiFromFile("resources/config/connecting.json", renderer, CONST_ZIP_FILE);
|
||||
connectionFailedRoot= loadUiFromFile("resources/config/connection_failed.json", renderer, CONST_ZIP_FILE);
|
||||
gameplayRoot = loadUiFromFile("resources/config/ui.json", renderer, CONST_ZIP_FILE);
|
||||
gameOverRoot = loadUiFromFile("resources/config/game_over.json", renderer, CONST_ZIP_FILE);
|
||||
connectionLostRoot = loadUiFromFile("resources/config/connection_lost.json", renderer, CONST_ZIP_FILE);
|
||||
|
||||
enterMainMenu();
|
||||
}
|
||||
@@ -78,14 +80,18 @@ namespace ZL {
|
||||
uiManager.setButtonCallback("spaceshipButton", [this](const std::string&) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = "Player";
|
||||
enterGameplay();
|
||||
pendingMultiNick = nick;
|
||||
pendingMultiShipType = 0;
|
||||
enterConnecting();
|
||||
if (onMultiplayerPressed) onMultiplayerPressed(nick, 0);
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("cargoshipButton", [this](const std::string&) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = "Player";
|
||||
enterGameplay();
|
||||
pendingMultiNick = nick;
|
||||
pendingMultiShipType = 1;
|
||||
enterConnecting();
|
||||
if (onMultiplayerPressed) onMultiplayerPressed(nick, 1);
|
||||
});
|
||||
|
||||
@@ -94,6 +100,32 @@ namespace ZL {
|
||||
});
|
||||
}
|
||||
|
||||
// ── State: Connecting ────────────────────────────────────────────────────
|
||||
|
||||
void MenuManager::enterConnecting()
|
||||
{
|
||||
state = GameState::Connecting;
|
||||
uiManager.replaceRoot(connectingRoot);
|
||||
// No interactive elements — just a static "Connecting..." image
|
||||
}
|
||||
|
||||
// ── State: ConnectionFailed ───────────────────────────────────────────────
|
||||
|
||||
void MenuManager::enterConnectionFailed()
|
||||
{
|
||||
state = GameState::ConnectionFailed;
|
||||
uiManager.replaceRoot(connectionFailedRoot);
|
||||
|
||||
uiManager.setButtonCallback("connectionFailedReconnectButton", [this](const std::string&) {
|
||||
enterConnecting();
|
||||
if (onMultiplayerPressed) onMultiplayerPressed(pendingMultiNick, pendingMultiShipType);
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("connectionFailedGoBack", [this](const std::string&) {
|
||||
enterMainMenu();
|
||||
});
|
||||
}
|
||||
|
||||
// ── State: Gameplay ──────────────────────────────────────────────────────
|
||||
|
||||
void MenuManager::enterGameplay()
|
||||
@@ -148,7 +180,7 @@ namespace ZL {
|
||||
enterGameplay();
|
||||
});
|
||||
uiManager.setButtonCallback("gameOverExitButton", [this](const std::string&) {
|
||||
Environment::exitGameLoop = true;
|
||||
enterMainMenu();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,12 +195,26 @@ namespace ZL {
|
||||
// TODO: reconnect logic
|
||||
});
|
||||
uiManager.setButtonCallback("exitServerButton", [this](const std::string&) {
|
||||
Environment::exitGameLoop = true;
|
||||
enterMainMenu();
|
||||
});
|
||||
}
|
||||
|
||||
// ── Public event API ──────────────────────────────────────────────────────
|
||||
|
||||
void MenuManager::notifyConnected()
|
||||
{
|
||||
if (state == GameState::Connecting) {
|
||||
enterGameplay();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuManager::notifyConnectionFailed()
|
||||
{
|
||||
if (state == GameState::Connecting) {
|
||||
enterConnectionFailed();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuManager::showGameOver(int score)
|
||||
{
|
||||
if (state == GameState::Gameplay) {
|
||||
|
||||
Reference in new issue
Block a user