Working on game state

This commit is contained in:
Vladislav Khorev committed 2026-06-19 18:39:10 +03:00
1 parent b01e970554
commit 2807d82d51
12 files changed
+501 -445

No files matched your search

+162 -190
View File
@@ -91,9 +91,9 @@ namespace ZL {
}
}
MenuManager::MenuManager(Renderer& iRenderer, std::unordered_map<std::string, int>& globalInts) :
MenuManager::MenuManager(Renderer& iRenderer, GameState& gameState) :
renderer(iRenderer),
globalInts(globalInts)
gameState_(gameState)
{
}
@@ -118,7 +118,7 @@ namespace ZL {
hudUniIntFullRoot = loadUiFromFile("resources/w/ui/hud_uni_int_full.json", renderer, zipFile);
hudUniIntDarkFullRoot = loadUiFromFile("resources/w/ui/hud_uni_int_dark_full.json", renderer, zipFile);
hudUniExtDarkRoot = loadUiFromFile("resources/w/ui/hud_uni_ext_dark.json", renderer, zipFile);
hudCutsceneRoot_ = loadUiFromFile("resources/w/ui/hud_cutscene.json", renderer, zipFile);
hudTopHintRoot_ = loadUiFromFile("resources/w/ui/hud_top_hint01.json", renderer, zipFile);
@@ -147,30 +147,25 @@ namespace ZL {
texItemSelected_ = renderer.textureManager.LoadFromPng("resources/w/ui/img/journal/ButtonBkg001.png", zipFile, true);
texItemTransparent_ = renderer.textureManager.LoadFromPng("resources/w/ui/img/journal/ButtonBkgTransparent001.png", zipFile, true);
questJournal.loadFromFile("resources/quests/quests.json", zipFile);
gameState_.questJournal.loadFromFile("resources/quests/quests.json", zipFile);
renderer.textureManager.LoadFromPng("resources/w/ui/img/toast/quest_new001.png", zipFile, true);
renderer.textureManager.LoadFromPng("resources/w/ui/img/toast/quest_completed001.png", zipFile, true);
renderer.textureManager.LoadFromPng("resources/w/ui/img/toast/quest_failed001.png", zipFile, true);
questJournal.onQuestUnlocked = [this](const std::string& id) {
const Quest::QuestState* q = questJournal.findQuest(id);
gameState_.questJournal.onQuestUnlocked = [this](const std::string& id) {
const Quest::QuestState* q = gameState_.questJournal.findQuest(id);
if (q) showToast("resources/w/ui/img/toast/quest_new001.png", q->definition.title);
};
questJournal.onQuestCompleted = [this](const std::string& id) {
const Quest::QuestState* q = questJournal.findQuest(id);
gameState_.questJournal.onQuestCompleted = [this](const std::string& id) {
const Quest::QuestState* q = gameState_.questJournal.findQuest(id);
if (q) showToast("resources/w/ui/img/toast/quest_completed001.png", q->definition.title);
};
questJournal.onQuestFailed = [this](const std::string& id) {
const Quest::QuestState* q = questJournal.findQuest(id);
gameState_.questJournal.onQuestFailed = [this](const std::string& id) {
const Quest::QuestState* q = gameState_.questJournal.findQuest(id);
if (q) showToast("resources/w/ui/img/toast/quest_failed001.png", q->definition.title);
};
/*
questJournal.onObjectiveCompleted = [this](const std::string& id, const std::string&) {
const Quest::QuestState* q = questJournal.findQuest(id);
if (q) showToast("resources/w/ui/img/toast/objective_completed001.png", q->definition.title);
};*/
const std::string imgDir = "resources/w/ui/img/phone/";
texBubbleInCenter_ = renderer.textureManager.LoadFromPng(imgDir + "bubble_in_center.png", zipFile, true);
@@ -188,30 +183,20 @@ namespace ZL {
}
void MenuManager::enterGameplay() {
if (state == GameState::MainMenu && startGameFunc) startGameFunc();
state = GameState::Gameplay;
if (uiState_ == GameUiState::MainMenu && startGameFunc) startGameFunc();
uiState_ = GameUiState::Gameplay;
uiManager.replaceRoot(hudRoot);
topUiManager.replaceRoot(hudTopHintRoot_);
applyCurrentHealthBar();
/*
uiManager.setTextButtonCallback("inventory_button", [this](const std::string&) {
openInventory();
});
uiManager.setTextButtonCallback("quest_journal_button", [this](const std::string&) {
openQuestJournal();
});*/
uiManager.setButtonCallback("inventoryButton", [this](const std::string&) {
openInventory();
});
//openInventory()
}
void MenuManager::showMainMenu() {
state = GameState::MainMenu;
uiState_ = GameUiState::MainMenu;
uiManager.replaceRoot(mainMenuRoot);
uiManager.setTextButtonCallback("menuStartButton", [this](const std::string&) {
@@ -239,7 +224,7 @@ namespace ZL {
}
void MenuManager::openInventory() {
state = GameState::Inventory;
uiState_ = GameUiState::Inventory;
uiManager.pushMenuFromSavedRoot(newInventoryRoot);
uiManager.setButtonCallback("inventoryExitButton", [this](const std::string&) {
closeInventory();
@@ -284,54 +269,54 @@ namespace ZL {
}
}
void MenuManager::selectInventoryItem(int index) {
const auto& items = inventory->getItems();
if (index < 0 || index >= static_cast<int>(items.size())) return;
void MenuManager::selectInventoryItem(int index) {
const auto& items = inventory->getItems();
if (index < 0 || index >= static_cast<int>(items.size())) return;
// Revert previously selected button to its regular icon
if (inventorySelectedIndex_ >= 0 && inventorySelectedIndex_ < static_cast<int>(items.size())) {
const std::string prevBtnName = "item" + std::to_string(inventorySelectedIndex_ + 1) + "Button";
auto prevBtn = uiManager.findButton(prevBtnName);
if (prevBtn) {
auto tex = renderer.textureManager.LoadFromPng(items[inventorySelectedIndex_].icon, CONST_ZIP_FILE, true);
prevBtn->texNormal = prevBtn->texHover = prevBtn->texPressed = tex;
}
}
inventorySelectedIndex_ = index;
const auto& item = items[index];
// Highlight newly selected button with its selected icon
const std::string btnName = "item" + std::to_string(index + 1) + "Button";
auto btn = uiManager.findButton(btnName);
if (btn) {
const std::string& selPath = item.selectedIcon.empty() ? item.icon : item.selectedIcon;
auto tex = renderer.textureManager.LoadFromPng(selPath, CONST_ZIP_FILE, true);
btn->texNormal = btn->texHover = btn->texPressed = tex;
}
// Update the large selected picture on the right panel
auto img = uiManager.findStaticImage("selectedItemPic");
if (img) {
const std::string& path = item.selectedIcon.empty() ? item.icon : item.selectedIcon;
img->texture = renderer.textureManager.LoadFromPng(path, CONST_ZIP_FILE, true);
}
uiManager.setText("selectedText", item.name);
uiManager.setText("selectedDescription", item.description);
// Revert previously selected button to its regular icon
if (inventorySelectedIndex_ >= 0 && inventorySelectedIndex_ < static_cast<int>(items.size())) {
const std::string prevBtnName = "item" + std::to_string(inventorySelectedIndex_ + 1) + "Button";
auto prevBtn = uiManager.findButton(prevBtnName);
if (prevBtn) {
auto tex = renderer.textureManager.LoadFromPng(items[inventorySelectedIndex_].icon, CONST_ZIP_FILE, true);
prevBtn->texNormal = prevBtn->texHover = prevBtn->texPressed = tex;
}
}
inventorySelectedIndex_ = index;
const auto& item = items[index];
// Highlight newly selected button with its selected icon
const std::string btnName = "item" + std::to_string(index + 1) + "Button";
auto btn = uiManager.findButton(btnName);
if (btn) {
const std::string& selPath = item.selectedIcon.empty() ? item.icon : item.selectedIcon;
auto tex = renderer.textureManager.LoadFromPng(selPath, CONST_ZIP_FILE, true);
btn->texNormal = btn->texHover = btn->texPressed = tex;
}
// Update the large selected picture on the right panel
auto img = uiManager.findStaticImage("selectedItemPic");
if (img) {
const std::string& path = item.selectedIcon.empty() ? item.icon : item.selectedIcon;
img->texture = renderer.textureManager.LoadFromPng(path, CONST_ZIP_FILE, true);
}
uiManager.setText("selectedText", item.name);
uiManager.setText("selectedDescription", item.description);
}
void MenuManager::closeInventory() {
state = GameState::Gameplay;
uiState_ = GameUiState::Gameplay;
uiManager.popMenu();
uiManager.updateAllLayouts();
}
void MenuManager::openQuestJournal() {
state = GameState::QuestJournal;
tutorialJournalScreenOpened = true;
uiState_ = GameUiState::QuestJournal;
gameState_.tutorialJournalScreenOpened = true;
uiManager.setNodeVisible("hint6b", false);
uiManager.setNodeVisible("hint6barrow", false);
uiManager.pushMenuFromSavedRoot(questJournalRoot);
@@ -358,7 +343,7 @@ namespace ZL {
}
void MenuManager::closeQuestJournal() {
state = GameState::Gameplay;
uiState_ = GameUiState::Gameplay;
selectedQuestIndex = -1;
visibleQuestIds.clear();
uiManager.popMenu();
@@ -367,11 +352,11 @@ namespace ZL {
void MenuManager::toggleQuestJournal() {
std::cout << "[quest] toggleQuestJournal: " << (isQuestJournalOpen() ? "closing" : "opening") << std::endl;
if (state == GameState::QuestJournal) {
if (uiState_ == GameUiState::QuestJournal) {
closeQuestJournal();
}
else {
if (state == GameState::Inventory) {
if (uiState_ == GameUiState::Inventory) {
closeInventory();
}
openQuestJournal();
@@ -379,23 +364,17 @@ namespace ZL {
}
void MenuManager::openPhoneScreen() {
state = GameState::PhoneScreen;
uiState_ = GameUiState::PhoneScreen;
//uiManager.setNodeVisible("hint6a", false);
//uiManager.setNodeVisible("hint6aarrow", false);
//tutorialPhoneScreenOpened = true;
if (tutorialNeedOpenTaxiScreen && (tutorialPhoneChatScreenOpened == false))
if (gameState_.tutorialNeedOpenTaxiScreen && (gameState_.tutorialPhoneChatScreenOpened == false))
{
uiManager.pushMenuFromSavedRoot(phoneMainHintABRoot);
}
else if (tutorialNeedOpenTaxiScreen)
else if (gameState_.tutorialNeedOpenTaxiScreen)
{
uiManager.pushMenuFromSavedRoot(phoneMainHintBRoot);
}
else if (tutorialPhoneChatScreenOpened == false)
else if (gameState_.tutorialPhoneChatScreenOpened == false)
{
uiManager.pushMenuFromSavedRoot(phoneMainHintARoot);
}
@@ -403,7 +382,7 @@ namespace ZL {
{
uiManager.pushMenuFromSavedRoot(phoneMainRoot);
}
uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) {
closePhoneEntirely();
});
@@ -420,9 +399,9 @@ namespace ZL {
openPhoneTaxi();
});
if (isNight)
if (gameState_.isNight)
{
if (isDawn)
if (gameState_.isDawn)
{
uiManager.setNodeVisible("phoneTimeDay", false);
uiManager.setNodeVisible("phoneTimeNight", false);
@@ -445,7 +424,7 @@ namespace ZL {
void MenuManager::openPhoneMessenger() {
if (tutorialPhoneChatScreenOpened)
if (gameState_.tutorialPhoneChatScreenOpened)
{
uiManager.pushMenuFromSavedRoot(phoneChatListRoot);
}
@@ -453,7 +432,6 @@ namespace ZL {
{
uiManager.pushMenuFromSavedRoot(phoneChatListHintRoot);
}
//uiManager.pushMenuFromSavedRoot(phoneChatListRoot);
refreshChatUnreadIndicators();
uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) {
@@ -461,15 +439,15 @@ namespace ZL {
});
uiManager.setButtonCallback("phoneMain", [this](const std::string&) {});
uiManager.setTextButtonCallback("chat1button", [this](const std::string&) {
chatUnread_[0] = false;
gameState_.chatUnread[0] = false;
openPhoneChatFromList(0, phoneChat1Root);
});
uiManager.setTextButtonCallback("chat2button", [this](const std::string&) {
chatUnread_[1] = false;
gameState_.chatUnread[1] = false;
openPhoneChatFromList(1, phoneChat2Root);
});
uiManager.setTextButtonCallback("chat3button", [this](const std::string&) {
chatUnread_[2] = false;
gameState_.chatUnread[2] = false;
openPhoneChatFromList(2, phoneChat3Root);
});
}
@@ -478,30 +456,30 @@ namespace ZL {
static const char* kUnreadNodes[3] = { "chat1Unread", "chat2Unread", "chat3Unread" };
static const char* kMsgNodes[3] = { "chat1msg", "chat2msg", "chat3msg" };
for (int i = 0; i < 3; ++i) {
uiManager.setNodeVisible(kUnreadNodes[i], chatUnread_[i]);
if (!chatPreviewMsg_[i].empty())
uiManager.setText(kMsgNodes[i], chatPreviewMsg_[i]);
uiManager.setNodeVisible(kUnreadNodes[i], gameState_.chatUnread[i]);
if (!gameState_.chatPreviewMsg[i].empty())
uiManager.setText(kMsgNodes[i], gameState_.chatPreviewMsg[i]);
}
}
void MenuManager::setChatUnread(int chatIndex, bool unread, const std::string& previewMsg) {
if (chatIndex < 0 || chatIndex > 2) return;
chatUnread_[chatIndex] = unread;
gameState_.chatUnread[chatIndex] = unread;
if (!previewMsg.empty()) {
chatPreviewMsg_[chatIndex] = trimChatPreview(previewMsg);
} else if (!unread && !chatHistory_[chatIndex].empty()) {
chatPreviewMsg_[chatIndex] = trimChatPreview(chatHistory_[chatIndex].back().text);
gameState_.chatPreviewMsg[chatIndex] = trimChatPreview(previewMsg);
} else if (!unread && !gameState_.chatHistory[chatIndex].empty()) {
gameState_.chatPreviewMsg[chatIndex] = trimChatPreview(gameState_.chatHistory[chatIndex].back().text);
}
}
void MenuManager::spendMoney(int amount) {
money_ -= amount;
gameState_.money -= amount;
}
void MenuManager::openPhoneBank() {
uiManager.pushMenuFromSavedRoot(phoneBankRoot);
uiManager.setText("balanceText", formatMoney(money_));
uiManager.setText("balanceText", formatMoney(gameState_.money));
uiManager.setButtonCallback("phoneExitButton", [this](const std::string&) {
closePhoneEntirely();
@@ -525,13 +503,13 @@ namespace ZL {
uiManager.setButtonCallback("videoSkip", [this](const std::string&) {
closePhoneEntirely();
if (isNight)
if (gameState_.isNight)
{
startDialogueFunc("dialog_video002");
}
else
{
auto day = globalInts["day"];
auto day = gameState_.globalInts["day"];
if (day == 0)
{
startDialogueFunc("dialog_video003");
@@ -545,10 +523,10 @@ namespace ZL {
}
void MenuManager::openPhoneTaxi() {
if (currentLocationName_ == "uni_interior") {
if (gameState_.currentLocationName == "uni_interior") {
closePhoneEntirely();
if (startDialogueFunc) startDialogueFunc("dialog_taxi003");
} else if (currentLocationName_ == "uni_exterior") {
} else if (gameState_.currentLocationName == "uni_exterior") {
openPhoneMapScreen(phoneMapUniRoot);
} else {
openPhoneMapScreen(phoneMapDormRoot);
@@ -566,13 +544,13 @@ namespace ZL {
uiManager.updateAllLayouts();
});
uiManager.setButtonCallback("mapGo", [this](const std::string&) {
tutorialNeedOpenTaxiScreen = false;
gameState_.tutorialNeedOpenTaxiScreen = false;
if (callTaxiFunc)
{
callTaxiFunc();
}
money_ -= 500;
gameState_.money -= 500;
closePhoneEntirely();
if (startDialogueFunc) startDialogueFunc("dialog_taxi002");
});
@@ -581,7 +559,7 @@ namespace ZL {
void MenuManager::openPhoneChatFromList(int chatIndex, std::shared_ptr<UiNode> chatRoot) {
activeChatIndex_ = chatIndex;
phoneChatVisibleBubbles_.clear();
tutorialPhoneChatScreenOpened = true;
gameState_.tutorialPhoneChatScreenOpened = true;
uiManager.pushMenuFromSavedRoot(chatRoot);
rebuildChatBubblesFromHistory(chatIndex);
@@ -601,15 +579,15 @@ namespace ZL {
void MenuManager::returnToPhoneChatList() {
if (activeChatIndex_ >= 0 && activeChatIndex_ <= 2
&& !chatHistory_[activeChatIndex_].empty()) {
chatPreviewMsg_[activeChatIndex_] =
trimChatPreview(chatHistory_[activeChatIndex_].back().text);
&& !gameState_.chatHistory[activeChatIndex_].empty()) {
gameState_.chatPreviewMsg[activeChatIndex_] =
trimChatPreview(gameState_.chatHistory[activeChatIndex_].back().text);
}
activeChatIndex_ = -1;
phoneChatVisibleBubbles_.clear();
uiManager.popMenu();
uiManager.updateAllLayouts();
if (tutorialPhoneChatScreenOpened)
if (gameState_.tutorialPhoneChatScreenOpened)
{
uiManager.setNodeVisible("hint_m002", false);
}
@@ -623,18 +601,18 @@ namespace ZL {
void MenuManager::closePhoneEntirely() {
if (activeChatIndex_ >= 0 && activeChatIndex_ <= 2
&& !chatHistory_[activeChatIndex_].empty()) {
chatPreviewMsg_[activeChatIndex_] =
trimChatPreview(chatHistory_[activeChatIndex_].back().text);
&& !gameState_.chatHistory[activeChatIndex_].empty()) {
gameState_.chatPreviewMsg[activeChatIndex_] =
trimChatPreview(gameState_.chatHistory[activeChatIndex_].back().text);
}
activeChatIndex_ = -1;
state = GameState::Gameplay;
uiState_ = GameUiState::Gameplay;
phoneChatVisibleBubbles_.clear();
const int depth = uiManager.menuStackSize();
for (int i = 0; i < depth; ++i) uiManager.popMenu();
uiManager.updateAllLayouts();
if (tutorialNeedOpenTaxiScreen)
if (gameState_.tutorialNeedOpenTaxiScreen)
{
uiManager.setNodeVisible("hint7", true);
uiManager.setNodeVisible("hint7arrow", true);
@@ -647,7 +625,7 @@ namespace ZL {
uiManager.setNodeVisible("hint7", false);
uiManager.setNodeVisible("hint7arrow", false);
if (tutorialPhoneChatScreenOpened)
if (gameState_.tutorialPhoneChatScreenOpened)
{
uiManager.setNodeVisible("hint6a", false);
uiManager.setNodeVisible("hint6aarrow", false);
@@ -658,10 +636,6 @@ namespace ZL {
uiManager.setNodeVisible("hint6aarrow", true);
}
}
}
void MenuManager::closePhoneScreenFromChat() {
@@ -675,15 +649,14 @@ namespace ZL {
void MenuManager::tutorialShowTaxiHint()
{
std::cout << "tutorialShowTaxiHint" << std::endl;
tutorialNeedOpenTaxiScreen = true;
if (state == GameState::Gameplay)
gameState_.tutorialNeedOpenTaxiScreen = true;
if (uiState_ == GameUiState::Gameplay)
{
uiManager.setNodeVisible("hint6a", false);
uiManager.setNodeVisible("hint6aarrow", false);
uiManager.setNodeVisible("hint7", true);
uiManager.setNodeVisible("hint7arrow", true);
}
}
@@ -706,7 +679,7 @@ namespace ZL {
openQuestJournal();
});
}
if (tutorialNeedOpenTaxiScreen)
if (gameState_.tutorialNeedOpenTaxiScreen)
{
uiManager.setNodeVisible("hint6a", false);
uiManager.setNodeVisible("hint6aarrow", false);
@@ -720,17 +693,17 @@ namespace ZL {
uiManager.setNodeVisible("hint7arrow", false);
}
if (tutorialPhoneChatScreenOpened) {
if (gameState_.tutorialPhoneChatScreenOpened) {
uiManager.setNodeVisible("hint6a", false);
uiManager.setNodeVisible("hint6aarrow", false);
}
if (tutorialJournalScreenOpened)
if (gameState_.tutorialJournalScreenOpened)
{
uiManager.setNodeVisible("hint6b", false);
uiManager.setNodeVisible("hint6barrow", false);
}
if (tutorialPhoneChatScreenOpened && tutorialJournalScreenOpened) {
tutorialStep = TutorialStep::Step6;
if (gameState_.tutorialPhoneChatScreenOpened && gameState_.tutorialJournalScreenOpened) {
gameState_.tutorialStep = TutorialStep::Step6;
}
}
@@ -748,11 +721,11 @@ namespace ZL {
}
void MenuManager::onLocationChanged(const std::string& locationName) {
if (state != GameState::Gameplay) return;
currentLocationName_ = locationName;
if (uiState_ != GameUiState::Gameplay) return;
gameState_.currentLocationName = locationName;
if (locationName == "uni_exterior") {
uiManager.replaceRoot(currentIsDarklands_ ? hudUniExtDarkRoot : hudUniExtRoot);
uiManager.replaceRoot(gameState_.isDarklands ? hudUniExtDarkRoot : hudUniExtRoot);
applyCurrentHealthBar();
setupGameplayHudCallbacks();
} else if (locationName == "uni_interior") {
@@ -768,22 +741,22 @@ namespace ZL {
void MenuManager::advanceTutorialStep() {
std::shared_ptr<UiNode> nextRoot;
switch (tutorialStep) {
switch (gameState_.tutorialStep) {
case TutorialStep::Step0:
tutorialStep = TutorialStep::Step1;
gameState_.tutorialStep = TutorialStep::Step1;
nextRoot = hudStep1Root;
topUiManager.replaceRoot(nullptr);
break;
case TutorialStep::Step1:
tutorialStep = TutorialStep::Step2;
gameState_.tutorialStep = TutorialStep::Step2;
nextRoot = hudStep2Root;
break;
case TutorialStep::Step2:
tutorialStep = TutorialStep::Step3;
gameState_.tutorialStep = TutorialStep::Step3;
nextRoot = hudStep3Root;
break;
case TutorialStep::Step3:
tutorialStep = TutorialStep::Step4;
gameState_.tutorialStep = TutorialStep::Step4;
nextRoot = hudStep4Root;
if (tutorialUnlockInteractiveObjectsFunc)
{
@@ -795,7 +768,7 @@ namespace ZL {
return; // Step4/Step5 transitions are driven by onItemPickedUp
}
if (state == GameState::Gameplay && nextRoot) {
if (uiState_ == GameUiState::Gameplay && nextRoot) {
uiManager.replaceRoot(nextRoot);
applyCurrentHealthBar();
@@ -806,41 +779,41 @@ namespace ZL {
}
void MenuManager::onItemPickedUp(const std::string& itemId) {
if (itemId == "note_spell" && uniIntTutorialState_ == UniIntTutorialState::Step10) {
uniIntTutorialState_ = UniIntTutorialState::Step11;
if (currentLocationName_ == "uni_interior" && state == GameState::Gameplay)
if (itemId == "note_spell" && gameState_.uniIntTutorialState == UniIntTutorialState::Step10) {
gameState_.uniIntTutorialState = UniIntTutorialState::Step11;
if (gameState_.currentLocationName == "uni_interior" && uiState_ == GameUiState::Gameplay)
applyUniIntHud();
}
if (tutorialStep != TutorialStep::Step4 && tutorialStep != TutorialStep::Step5) {
if (gameState_.tutorialStep != TutorialStep::Step4 && gameState_.tutorialStep != TutorialStep::Step5) {
return;
}
// Dorm tutorial HUD logic must not run in other locations.
// currentLocationName_ is empty only before the first teleport (still in dorm).
if (!currentLocationName_.empty() && currentLocationName_ != "location_dorm") {
// currentLocationName is empty only before the first teleport (still in dorm).
if (!gameState_.currentLocationName.empty() && gameState_.currentLocationName != "location_dorm") {
return;
}
if (itemId == "phone") tutorialPhonePickedUp = true;
if (itemId == "journal") tutorialJournalPickedUp = true;
if (itemId == "phone") gameState_.tutorialPhonePickedUp = true;
if (itemId == "journal") gameState_.tutorialJournalPickedUp = true;
if (tutorialStep == TutorialStep::Step4) {
tutorialStep = TutorialStep::Step5;
if (gameState_.tutorialStep == TutorialStep::Step4) {
gameState_.tutorialStep = TutorialStep::Step5;
}
refreshItemPickupHud();
}
void MenuManager::refreshItemPickupHud() {
if (state != GameState::Gameplay) return;
if (uiState_ != GameUiState::Gameplay) return;
std::shared_ptr<UiNode> nextRoot;
if (tutorialPhonePickedUp && tutorialJournalPickedUp) {
if (gameState_.tutorialPhonePickedUp && gameState_.tutorialJournalPickedUp) {
nextRoot = hudStep5abRoot;
} else if (tutorialPhonePickedUp) {
} else if (gameState_.tutorialPhonePickedUp) {
nextRoot = hudStep5aRoot;
} else if (tutorialJournalPickedUp) {
} else if (gameState_.tutorialJournalPickedUp) {
nextRoot = hudStep5bRoot;
}
@@ -854,7 +827,7 @@ namespace ZL {
void MenuManager::refreshQuestJournalUi() {
visibleQuestIds.clear();
auto quests = questJournal.getVisibleQuests();
auto quests = gameState_.questJournal.getVisibleQuests();
std::sort(quests.begin(), quests.end(), [](const Quest::QuestState* a, const Quest::QuestState* b) {
const int pa = questStatusPriority(a->status);
@@ -920,7 +893,7 @@ namespace ZL {
}
selectedQuestIndex = index;
Quest::QuestState* quest = questJournal.findQuest(visibleQuestIds[index]);
Quest::QuestState* quest = gameState_.questJournal.findQuest(visibleQuestIds[index]);
if (!quest) {
return;
}
@@ -1007,7 +980,7 @@ namespace ZL {
phoneChatVisibleBubbles_.clear();
if (chatIndex < 0 || chatIndex > 2) return;
for (const auto& msg : chatHistory_[chatIndex]) {
for (const auto& msg : gameState_.chatHistory[chatIndex]) {
const bool inc = msg.incoming;
const std::string nodeName = uiManager.addChatBubble(
"chatMessagesContainer", msg.text, inc,
@@ -1028,13 +1001,13 @@ namespace ZL {
void MenuManager::onChatBubbleReady(const std::string& text, bool incoming) {
if (activeChatIndex_ < 0) return;
auto& history = chatHistory_[activeChatIndex_];
auto& history = gameState_.chatHistory[activeChatIndex_];
if (static_cast<int>(history.size()) >= 5) {
history.erase(history.begin());
}
history.push_back({ text, incoming });
if (state != GameState::PhoneScreen) return;
if (uiState_ != GameUiState::PhoneScreen) return;
const std::string nodeName = uiManager.addChatBubble(
"chatMessagesContainer", text, incoming,
@@ -1060,15 +1033,14 @@ namespace ZL {
void MenuManager::setDarklandsMode(bool enabled)
{
std::cout << "MenuManager::setDarklandsMode called" << std::endl;
currentIsDarklands_ = enabled;
if (currentLocationName_ == "uni_interior") {
if (enabled && uniIntTutorialState_ == UniIntTutorialState::Step11) {
uniIntTutorialState_ = UniIntTutorialState::DarklandsActive;
if (gameState_.currentLocationName == "uni_interior") {
if (enabled && gameState_.uniIntTutorialState == UniIntTutorialState::Step11) {
gameState_.uniIntTutorialState = UniIntTutorialState::DarklandsActive;
}
applyUniIntHud();
} else if (currentLocationName_ == "uni_exterior") {
if (state == GameState::Gameplay) {
} else if (gameState_.currentLocationName == "uni_exterior") {
if (uiState_ == GameUiState::Gameplay) {
uiManager.replaceRoot(enabled ? hudUniExtDarkRoot : hudUniExtRoot);
applyCurrentHealthBar();
setupGameplayHudCallbacks();
@@ -1081,31 +1053,31 @@ namespace ZL {
void MenuManager::applyUniIntHud()
{
if (state != GameState::Gameplay) return;
if (uiState_ != GameUiState::Gameplay) return;
std::shared_ptr<UiNode> root;
if (currentIsDarklands_) {
switch (uniIntTutorialState_) {
if (gameState_.isDarklands) {
switch (gameState_.uniIntTutorialState) {
case UniIntTutorialState::DarklandsStep13: root = hudUniIntStep13Root; break;
case UniIntTutorialState::DarklandsFull: root = hudUniIntDarkFullRoot; break;
default: root = hudUniIntStep12Root; break;
}
} else {
switch (uniIntTutorialState_) {
case UniIntTutorialState::Step10: root = hudUniIntStep10Root; break;
case UniIntTutorialState::Step11: root = hudUniIntStep11Root; break;
default: root = hudUniIntFullRoot; break;
switch (gameState_.uniIntTutorialState) {
case UniIntTutorialState::Step10: root = hudUniIntStep10Root; break;
case UniIntTutorialState::Step11: root = hudUniIntStep11Root; break;
default: root = hudUniIntFullRoot; break;
}
}
uiManager.replaceRoot(root);
applyCurrentHealthBar();
setupGameplayHudCallbacks(); // already calls hideAllToastWidgets + applyToastsToUi
setupGameplayHudCallbacks();
}
void MenuManager::onPlayerStartedWalking()
{
if (currentLocationName_ == "uni_interior"
&& currentIsDarklands_
&& uniIntTutorialState_ == UniIntTutorialState::DarklandsActive) {
if (gameState_.currentLocationName == "uni_interior"
&& gameState_.isDarklands
&& gameState_.uniIntTutorialState == UniIntTutorialState::DarklandsActive) {
uiManager.setNodeVisible("hint_darklands003", false);
uiManager.setNodeVisible("hint_darklands003_arrow", false);
}
@@ -1113,24 +1085,24 @@ namespace ZL {
void MenuManager::advanceUniIntDarklandsHud()
{
if (uniIntTutorialState_ != UniIntTutorialState::DarklandsActive) return;
uniIntTutorialState_ = UniIntTutorialState::DarklandsStep13;
if (currentLocationName_ == "uni_interior" && currentIsDarklands_ && state == GameState::Gameplay)
if (gameState_.uniIntTutorialState != UniIntTutorialState::DarklandsActive) return;
gameState_.uniIntTutorialState = UniIntTutorialState::DarklandsStep13;
if (gameState_.currentLocationName == "uni_interior" && gameState_.isDarklands && uiState_ == GameUiState::Gameplay)
applyUniIntHud();
}
void MenuManager::onEnemyKilledInUniInterior()
{
if (uniIntTutorialState_ != UniIntTutorialState::DarklandsActive
&& uniIntTutorialState_ != UniIntTutorialState::DarklandsStep13) return;
uniIntTutorialState_ = UniIntTutorialState::DarklandsFull;
if (currentLocationName_ == "uni_interior" && currentIsDarklands_ && state == GameState::Gameplay)
if (gameState_.uniIntTutorialState != UniIntTutorialState::DarklandsActive
&& gameState_.uniIntTutorialState != UniIntTutorialState::DarklandsStep13) return;
gameState_.uniIntTutorialState = UniIntTutorialState::DarklandsFull;
if (gameState_.currentLocationName == "uni_interior" && gameState_.isDarklands && uiState_ == GameUiState::Gameplay)
applyUniIntHud();
}
void MenuManager::updateHealthBar(float hp, float maxHp) {
currentPlayerHp_ = hp;
currentPlayerMaxHp_ = maxHp;
gameState_.playerHp = hp;
gameState_.playerMaxHp = maxHp;
applyCurrentHealthBar();
}
@@ -1145,22 +1117,22 @@ namespace ZL {
void MenuManager::onCutsceneFinished() {
cutsceneHudActive_ = false;
topUiManager.replaceRoot(nullptr);
if (state == GameState::Gameplay)
onLocationChanged(currentLocationName_);
if (uiState_ == GameUiState::Gameplay)
onLocationChanged(gameState_.currentLocationName);
}
void MenuManager::applyCurrentHealthBar() {
std::cout << "MenuManager::applyCurrentHealthBar called step 1" << std::endl;
std::cout << "currentPlayerMaxHp_ is " << currentPlayerMaxHp_ << std::endl;
if (currentPlayerMaxHp_ <= 0.f) return;
std::cout << "currentPlayerMaxHp_ is " << gameState_.playerMaxHp << std::endl;
if (gameState_.playerMaxHp <= 0.f) return;
std::cout << "MenuManager::applyCurrentHealthBar called step 2" << std::endl;
std::cout << "currentPlayerHp_ is " << currentPlayerHp_ << std::endl;
std::cout << "currentPlayerHp_ is " << gameState_.playerHp << std::endl;
const float fraction = std::clamp(currentPlayerHp_ / currentPlayerMaxHp_, 0.f, 1.f);
const float fraction = std::clamp(gameState_.playerHp / gameState_.playerMaxHp, 0.f, 1.f);
uiManager.setSliderValue("healthBarFill", fraction);
std::string hpText = std::to_string(static_cast<int>(currentPlayerHp_)) + "/" +
std::to_string(static_cast<int>(currentPlayerMaxHp_));
std::string hpText = std::to_string(static_cast<int>(gameState_.playerHp)) + "/" +
std::to_string(static_cast<int>(gameState_.playerMaxHp));
if (hpText.size() < 7) hpText.insert(0, 7 - hpText.size(), ' ');
uiManager.setText("healthValue", hpText);
}