Working on inventory
This commit is contained in:
1 parent
dda9f34277
commit
90c57932ec
16 files changed
+617
-399
No files matched your search
+67
-17
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user