Portrait mode for inventory screen
This commit is contained in:
1 parent
1b172460e0
commit
bdad5fa107
6 files changed
+375
-36
No files matched your search
+85
-36
@@ -159,6 +159,8 @@ namespace ZL {
|
||||
|
||||
modalMenuRoot = loadUiFromFile("resources/w/ui/screen_modal_menu.json", renderer, zipFile);
|
||||
newInventoryRoot = loadUiFromFile("resources/w/ui/screen_inventory.json", renderer, zipFile);
|
||||
portraitInventoryListRoot = loadUiFromFile("resources/w/ui/portrait_screen_inventory.json", renderer, zipFile);
|
||||
portraitInventoryItemRoot = loadUiFromFile("resources/w/ui/portrait_screen_inventory_item.json", renderer, zipFile);
|
||||
questJournalRoot = loadUiFromFile("resources/w/ui/screen_journal.json", renderer, zipFile);
|
||||
portraitQuestJournalListRoot = loadUiFromFile("resources/w/ui/portrait_screen_journal.json", renderer, zipFile);
|
||||
portraitQuestJournalItemRoot = loadUiFromFile("resources/w/ui/portrait_screen_journal_item.json", renderer, zipFile);
|
||||
@@ -444,54 +446,49 @@ namespace ZL {
|
||||
|
||||
void MenuManager::openInventory() {
|
||||
uiState_ = GameUiState::Inventory;
|
||||
uiManager.pushMenuFromSavedRoot(newInventoryRoot);
|
||||
inventoryMenuStackDepth_ = 1;
|
||||
|
||||
const bool portrait = isPortraitMode();
|
||||
uiManager.pushMenuFromSavedRoot(portrait ? portraitInventoryListRoot : newInventoryRoot);
|
||||
|
||||
uiManager.setButtonCallback("inventoryExitButton", [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 = 9;
|
||||
|
||||
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, CONST_ZIP_FILE, 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);
|
||||
const int maxSlots = 9;
|
||||
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, CONST_ZIP_FILE, 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 (!portrait && !items.empty()) {
|
||||
selectInventoryItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MenuManager::selectInventoryItem(int index) {
|
||||
const auto& items = inventory->getItems();
|
||||
if (index < 0 || index >= static_cast<int>(items.size())) return;
|
||||
|
||||
if (isPortraitMode() && inventoryMenuStackDepth_ == 1) {
|
||||
openPortraitInventoryItem(index);
|
||||
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";
|
||||
@@ -528,7 +525,8 @@ namespace ZL {
|
||||
|
||||
void MenuManager::closeInventory() {
|
||||
uiState_ = GameUiState::Gameplay;
|
||||
uiManager.popMenu();
|
||||
for (int i = 0; i < inventoryMenuStackDepth_; ++i) uiManager.popMenu();
|
||||
inventoryMenuStackDepth_ = 0;
|
||||
uiManager.updateAllLayouts();
|
||||
}
|
||||
|
||||
@@ -1290,6 +1288,34 @@ namespace ZL {
|
||||
refreshQuestJournalUi();
|
||||
}
|
||||
|
||||
void MenuManager::openPortraitInventoryItem(int index) {
|
||||
const auto& items = inventory->getItems();
|
||||
inventorySelectedIndex_ = index;
|
||||
inventoryMenuStackDepth_ = 2;
|
||||
uiManager.pushMenuFromSavedRoot(portraitInventoryItemRoot);
|
||||
|
||||
uiManager.setButtonCallback("inventoryExitButton", [this](const std::string&) {
|
||||
closePortraitInventoryItem();
|
||||
});
|
||||
|
||||
const auto& item = items[index];
|
||||
|
||||
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);
|
||||
uiManager.updateAllLayouts();
|
||||
}
|
||||
|
||||
void MenuManager::closePortraitInventoryItem() {
|
||||
inventoryMenuStackDepth_ = 1;
|
||||
uiManager.popMenu();
|
||||
uiManager.updateAllLayouts();
|
||||
}
|
||||
|
||||
void MenuManager::openPortraitQuestJournalItem(int index) {
|
||||
selectedQuestIndex = index;
|
||||
journalMenuStackDepth_ = 2;
|
||||
@@ -1770,6 +1796,29 @@ namespace ZL {
|
||||
}
|
||||
|
||||
void MenuManager::onOrientationChanged() {
|
||||
if (uiState_ == GameUiState::Inventory) {
|
||||
const int savedIndex = inventorySelectedIndex_;
|
||||
const bool wasOnItemDetail = (inventoryMenuStackDepth_ == 2);
|
||||
|
||||
for (int i = 0; i < inventoryMenuStackDepth_; ++i) uiManager.popMenu();
|
||||
inventoryMenuStackDepth_ = 0;
|
||||
uiState_ = GameUiState::Gameplay;
|
||||
inventorySelectedIndex_ = -1;
|
||||
|
||||
openInventory();
|
||||
|
||||
const int itemCount = static_cast<int>(inventory->getItems().size());
|
||||
if (isPortraitMode() && wasOnItemDetail &&
|
||||
savedIndex >= 0 && savedIndex < itemCount) {
|
||||
selectInventoryItem(savedIndex);
|
||||
} else if (!isPortraitMode() && savedIndex > 0 && savedIndex < itemCount) {
|
||||
selectInventoryItem(savedIndex);
|
||||
}
|
||||
|
||||
uiManager.updateAllLayouts();
|
||||
return;
|
||||
}
|
||||
|
||||
if (uiState_ == GameUiState::QuestJournal) {
|
||||
const int savedQuestIndex = selectedQuestIndex;
|
||||
const bool wasOnItemDetail = (journalMenuStackDepth_ == 2);
|
||||
|
||||
Reference in new issue
Block a user