Working on inventory

This commit is contained in:
Vladislav Khorev committed 2026-05-28 17:16:10 +03:00
1 parent dda9f34277
commit 90c57932ec
16 files changed
+617 -399

No files matched your search

+2
View File
@@ -519,6 +519,7 @@ namespace ZL
renderer.shaderManager.PushShader(defaultShaderName);
renderer.RenderUniform1i(textureUniformName, 0);
renderer.RenderUniform1f("uAlpha", 1.0);
float width = Environment::projectionWidth;
float height = Environment::projectionHeight;
@@ -749,6 +750,7 @@ namespace ZL
case SDLK_l:
//x = x - 1;
//std::cout << "current x: " << x << std::endl;
std::cout << "Azimuth: " << currentLocation->cameraAzimuth << std::endl;
std::cout << "Inclination: " << currentLocation->cameraInclination << std::endl;
break;
+67 -17
View File
@@ -32,6 +32,7 @@ namespace ZL {
void MenuManager::setup(Inventory& inv, const std::string& zipFile) {
inventory = &inv;
zipFile_ = zipFile;
//hudRoot = loadUiFromFile("resources/config2/hud.json", renderer, zipFile);
hudRoot = loadUiFromFile("resources/w/ui/hud_step0.json", renderer, zipFile);
@@ -44,7 +45,6 @@ namespace ZL {
hudStep5abRoot = loadUiFromFile("resources/w/ui/hud_step5ab.json", renderer, zipFile);
phoneScreenRoot = loadUiFromFile("resources/w/ui/screen_phone.json", renderer, zipFile);
journalScreenRoot= loadUiFromFile("resources/w/ui/screen_journal.json", renderer, zipFile);
inventoryRoot = loadUiFromFile("resources/config2/ui_inventory.json", renderer, zipFile);
newInventoryRoot = loadUiFromFile("resources/w/ui/screen_inventory.json", renderer, zipFile);
questJournalRoot = loadUiFromFile("resources/config2/ui_quest_journal.json", renderer, zipFile);
@@ -76,26 +76,71 @@ namespace ZL {
uiManager.pushMenuFromSavedRoot(newInventoryRoot);
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;
if (items.empty()) {
itemText = "Inventory (Empty)";
}
else {
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);
}
}
uiManager.setText("inventory_items_text", itemText);*/
inventorySelectedIndex_ = -1;
if (!items.empty()) {
selectInventoryItem(0);
}
}
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() {
@@ -180,6 +225,11 @@ namespace ZL {
// and hides any hints that have already been completed.
// Called after every replaceRoot during step 5.
void MenuManager::setupStep5Callbacks() {
if (uiManager.findButton("inventoryButton")) {
uiManager.setButtonCallback("inventoryButton", [this](const std::string&) {
openInventory();
});
}
if (uiManager.findButton("phoneButton")) {
uiManager.setButtonCallback("phoneButton", [this](const std::string&) {
openPhoneScreen();
+3 -1
View File
@@ -66,11 +66,14 @@ namespace ZL {
void enterGameplay();
void refreshQuestJournalUi();
void selectQuestByIndex(int index);
void selectInventoryItem(int index);
void refreshItemPickupHud();
void setupStep5Callbacks();
GameState state = GameState::Gameplay;
Inventory* inventory = nullptr;
std::string zipFile_;
int inventorySelectedIndex_ = -1;
bool tutorialPhonePickedUp = false;
bool tutorialJournalPickedUp = false;
@@ -87,7 +90,6 @@ namespace ZL {
std::shared_ptr<UiNode> hudStep5abRoot;
std::shared_ptr<UiNode> phoneScreenRoot;
std::shared_ptr<UiNode> journalScreenRoot;
std::shared_ptr<UiNode> inventoryRoot;
std::shared_ptr<UiNode> newInventoryRoot;
std::shared_ptr<UiNode> questJournalRoot;
+1
View File
@@ -11,6 +11,7 @@ namespace ZL {
std::string name;
std::string description;
std::string icon;
std::string selectedIcon;
Item() = default;
Item(const std::string& _id, const std::string& _name, const std::string& _desc, const std::string& _icon)
+1
View File
@@ -54,6 +54,7 @@ void ItemRegistry::loadFromJson(const std::string& jsonPath, const std::string&
entry.value("description", ""),
entry.value("icon", "")
);
item.selectedIcon = entry.value("selectedIcon", "");
items_[id] = std::move(item);
}