Working on save-load system and UI

This commit is contained in:
Vladislav Khorev committed 2026-06-20 21:41:07 +03:00
1 parent 901142385d
commit d7db0faea3
29 files changed
+708 -180

No files matched your search

+98 -2
View File
@@ -1,4 +1,5 @@
#include "MenuManager.h"
#include "Game.h"
#include "render/TextRenderer.h"
#include <iostream>
#include <algorithm>
@@ -186,11 +187,15 @@ namespace ZL {
showMainMenu();
}
void MenuManager::enterGameplay() {
if (uiState_ == GameUiState::MainMenu && startGameFunc) startGameFunc();
void MenuManager::enterGameplay(bool isFromLoad) {
if (!isFromLoad && uiState_ == GameUiState::MainMenu && startGameFunc) startGameFunc();
uiState_ = GameUiState::Gameplay;
uiManager.replaceRoot(hudRoot);
topUiManager.replaceRoot(hudTopHintRoot_);
if (isFromLoad) {
uiManager.clearMenuStack();
topUiManager.clearMenuStack();
}
applyCurrentHealthBar();
@@ -202,10 +207,53 @@ namespace ZL {
showModalMenuScreen();
});
}
if (isFromLoad)
applyHudForCurrentState();
}
void MenuManager::applyHudForCurrentState() {
// Clear the step-0 dialogue hint unless we're actually at step 0.
if (gameState_.tutorialStep != TutorialStep::Step0)
topUiManager.replaceRoot(nullptr);
const std::string& loc = gameState_.currentLocationName;
// Non-dorm locations: reuse the existing location-change logic.
if (loc == "uni_exterior" || loc == "uni_interior") {
onLocationChanged(loc);
return;
}
// Dorm (or pre-first-teleport): select HUD root by tutorial step.
std::shared_ptr<UiNode> nextRoot;
switch (gameState_.tutorialStep) {
case TutorialStep::Step0: nextRoot = hudRoot; break;
case TutorialStep::Step1: nextRoot = hudStep1Root; break;
case TutorialStep::Step2: nextRoot = hudStep2Root; break;
case TutorialStep::Step3: nextRoot = hudStep3Root; break;
case TutorialStep::Step4: nextRoot = hudStep4Root; break;
default: break; // Step5/6 handled below
}
if (nextRoot) {
uiManager.replaceRoot(nextRoot);
applyCurrentHealthBar();
uiManager.setButtonCallback("inventoryButton", [this](const std::string&) { openInventory(); });
if (uiManager.findButton("settingsButton"))
uiManager.setButtonCallback("settingsButton", [this](const std::string&) { showModalMenuScreen(); });
} else {
// Step5 or Step6: pick the right variant and apply hint visibility.
refreshItemPickupHud();
}
}
void MenuManager::showMainMenu() {
if (onResetGame) onResetGame();
uiState_ = GameUiState::MainMenu;
uiManager.clearMenuStack();
topUiManager.replaceRoot(nullptr);
topUiManager.clearMenuStack();
uiManager.replaceRoot(mainMenuRoot);
uiManager.setTextButtonCallback("menuStartButton", [this](const std::string&) {
@@ -254,6 +302,24 @@ namespace ZL {
uiManager.popMenu();
uiManager.updateAllLayouts();
});
static const char* kSlotButtons[4] = {
"loadSlot1Button", "loadSlot2Button", "loadSlot3Button", "loadSlot4Button"
};
for (int i = 0; i < 4; ++i) {
int slot = i + 1;
if (getSlotInfoFunc) {
SaveSlotInfo info = getSlotInfoFunc(slot);
std::string label = info.empty
? "Empty"
: info.locationName + "\n" + info.savedAt;
uiManager.setTextButtonText(kSlotButtons[i], label);
}
uiManager.setTextButtonCallback(kSlotButtons[i], [this, slot](const std::string&) {
if (onLoadGame) onLoadGame(slot);
enterGameplay(true);
});
}
}
void MenuManager::showSaveGameScreen()
@@ -263,6 +329,31 @@ namespace ZL {
uiManager.popMenu();
uiManager.updateAllLayouts();
});
static const char* kSlotButtons[4] = {
"saveSlot1Button", "saveSlot2Button", "saveSlot3Button", "saveSlot4Button"
};
for (int i = 0; i < 4; ++i) {
int slot = i + 1;
const char* buttonName = kSlotButtons[i];
if (getSlotInfoFunc) {
SaveSlotInfo info = getSlotInfoFunc(slot);
std::string label = info.empty
? "Empty"
: info.locationName + "\n" + info.savedAt;
uiManager.setTextButtonText(buttonName, label);
}
uiManager.setTextButtonCallback(buttonName, [this, slot, buttonName](const std::string&) {
if (onSaveGame) onSaveGame(slot);
if (getSlotInfoFunc) {
SaveSlotInfo info = getSlotInfoFunc(slot);
std::string label = info.empty
? "Empty"
: info.locationName + "\n" + info.savedAt;
uiManager.setTextButtonText(buttonName, label);
}
});
}
}
void MenuManager::openInventory() {
@@ -711,6 +802,11 @@ namespace ZL {
uiManager.setButtonCallback("menuSettingsButton", [this](const std::string&) {
showSettingsScreen();
});
uiManager.setButtonCallback("menuExitButton", [this](const std::string&) {
uiManager.popMenu();
showMainMenu();
});
}
void MenuManager::tutorialShowTaxiHint()