Fixing inventory and HUD screen

This commit is contained in:
Vladislav Khorev committed 2026-05-31 21:11:58 +03:00
1 parent 03681bedaf
commit 5f7e66f765
8 files changed
+294 -7

No files matched your search

+102 -7
View File
@@ -81,6 +81,8 @@ namespace ZL {
hudStep5aRoot = loadUiFromFile("resources/w/ui/hud_step5a.json", renderer, zipFile);
hudStep5bRoot = loadUiFromFile("resources/w/ui/hud_step5b.json", renderer, zipFile);
hudStep5abRoot = loadUiFromFile("resources/w/ui/hud_step5ab.json", renderer, zipFile);
hudUniExtRoot = loadUiFromFile("resources/w/ui/hud_uni_ext.json", renderer, zipFile);
hudUniIntRoot = loadUiFromFile("resources/w/ui/hud_uni_int.json", renderer, zipFile);
phoneChatListRoot = loadUiFromFile("resources/w/ui/screen_phone_chat_list.json", renderer, zipFile);
phoneChat1Root = loadUiFromFile("resources/w/ui/screen_phone_chat1.json", renderer, zipFile);
phoneChat2Root = loadUiFromFile("resources/w/ui/screen_phone_chat2.json", renderer, zipFile);
@@ -123,12 +125,6 @@ namespace ZL {
uiManager.setButtonCallback("inventoryExitButton", [this](const std::string&) {
closeInventory();
});
/*
uiManager.pushMenuFromSavedRoot(inventoryRoot);
uiManager.setTextButtonCallback("close_inventory_button", [this](const std::string&) {
closeInventory();
});
const auto& items = inventory->getItems();
std::string itemText;
@@ -139,11 +135,74 @@ namespace ZL {
itemText = "Inventory (" + std::to_string(items.size()) + " items)\n\n";
for (size_t i = 0; i < items.size(); ++i) {
itemText += std::to_string(i + 1) + ". " + items[i].name + "\n";
const int maxSlots = 7;
for (int i = 0; i < maxSlots; ++i) {
const std::string btnName = "item" + std::to_string(i + 1) + "Button";
if (i < static_cast<int>(items.size())) {
uiManager.setNodeVisible(btnName, true);
auto btn = uiManager.findButton(btnName);
if (btn) {
auto tex = renderer.textureManager.LoadFromPng(items[i].icon, zipFile_, true);
btn->texNormal = btn->texHover = btn->texPressed = tex;
}
uiManager.setButtonCallback(btnName, [this, i](const std::string&) {
selectInventoryItem(i);
});
}
else {
uiManager.setNodeVisible(btnName, false);
}
}
inventorySelectedIndex_ = -1;
if (!items.empty()) {
selectInventoryItem(0);
}
}
}
uiManager.setText("inventory_items_text", itemText);*/
}
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, zipFile_, 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, zipFile_, 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, zipFile_, true);
}
uiManager.setText("selectedText", item.name);
uiManager.setText("selectedDescription", item.description);
}
void MenuManager::closeInventory() {
state = GameState::Gameplay;
uiManager.popMenu();
@@ -267,6 +326,11 @@ namespace ZL {
openPhoneScreen();
});
}
if (uiManager.findButton("inventoryButton")) {
uiManager.setButtonCallback("inventoryButton", [this](const std::string&) {
openInventory();
});
}
if (uiManager.findButton("journalButton")) {
uiManager.setButtonCallback("journalButton", [this](const std::string&) {
openQuestJournal();
@@ -274,6 +338,37 @@ namespace ZL {
}
if (tutorialPhoneScreenOpened) uiManager.setNodeVisible("hint6a", false);
if (tutorialJournalScreenOpened) uiManager.setNodeVisible("hint6b", false);
if (tutorialPhoneScreenOpened && tutorialJournalScreenOpened) {
tutorialStep = TutorialStep::Step6;
}
}
void MenuManager::setupGameplayHudCallbacks() {
uiManager.setButtonCallback("phoneButton", [this](const std::string&) {
openPhoneScreen();
});
uiManager.setButtonCallback("inventoryButton", [this](const std::string&) {
openInventory();
});
uiManager.setButtonCallback("journalButton", [this](const std::string&) {
openQuestJournal();
});
}
void MenuManager::onLocationChanged(const std::string& locationName) {
if (state != GameState::Gameplay) return;
if (locationName == "uni_exterior") {
uiManager.replaceRoot(hudUniExtRoot);
setupGameplayHudCallbacks();
} else if (locationName == "uni_interior") {
uiManager.replaceRoot(hudUniIntRoot);
setupGameplayHudCallbacks();
} else {
// Returning to dorm: reuse step5ab, suppress already-completed hints
uiManager.replaceRoot(hudStep5abRoot);
setupStep5Callbacks();
}
}
void MenuManager::advanceTutorialStep() {