Some clean up
This commit is contained in:
1 parent
6149182f02
commit
fb7b42ddf9
20 files changed
+122
-984110
No files matched your search
+36
-38
@@ -33,8 +33,9 @@ namespace ZL {
|
||||
void MenuManager::setup(Inventory& inv, const std::string& zipFile) {
|
||||
inventory = &inv;
|
||||
|
||||
ingameRoot = loadUiFromFile("resources/config2/ui_inventory.json", renderer, zipFile);
|
||||
questJournalRoot = loadUiFromFile("resources/config2/ui_quest_journal.json", renderer, zipFile);
|
||||
hudRoot = loadUiFromFile("resources/config2/hud.json", renderer, zipFile);
|
||||
inventoryRoot = loadUiFromFile("resources/config2/ui_inventory.json", renderer, zipFile);
|
||||
questJournalRoot = loadUiFromFile("resources/config2/ui_quest_journal.json", renderer, zipFile);
|
||||
|
||||
questJournal.loadFromFile("resources/quests/quests.json", zipFile);
|
||||
|
||||
@@ -43,37 +44,10 @@ namespace ZL {
|
||||
|
||||
void MenuManager::enterGameplay() {
|
||||
state = GameState::Gameplay;
|
||||
uiManager.replaceRoot(ingameRoot);
|
||||
|
||||
uiManager.setNodeVisible("inventory_items_panel", false);
|
||||
uiManager.setNodeVisible("close_inventory_button", false);
|
||||
inventoryOpen = false;
|
||||
uiManager.replaceRoot(hudRoot);
|
||||
|
||||
uiManager.setTextButtonCallback("inventory_button", [this](const std::string&) {
|
||||
std::cout << "[UI] Inventory button clicked" << std::endl;
|
||||
uiManager.setNodeVisible("inventory_items_panel", true);
|
||||
uiManager.setNodeVisible("close_inventory_button", true);
|
||||
inventoryOpen = true;
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
uiManager.setText("inventory_items_text", itemText);
|
||||
});
|
||||
|
||||
uiManager.setTextButtonCallback("close_inventory_button", [this](const std::string&) {
|
||||
std::cout << "[UI] Close button clicked" << std::endl;
|
||||
uiManager.setNodeVisible("inventory_items_panel", false);
|
||||
uiManager.setNodeVisible("close_inventory_button", false);
|
||||
inventoryOpen = false;
|
||||
openInventory();
|
||||
});
|
||||
|
||||
uiManager.setTextButtonCallback("quest_journal_button", [this](const std::string&) {
|
||||
@@ -81,13 +55,34 @@ namespace ZL {
|
||||
});
|
||||
}
|
||||
|
||||
void MenuManager::openQuestJournal() {
|
||||
if (inventoryOpen) {
|
||||
uiManager.setNodeVisible("inventory_items_panel", false);
|
||||
uiManager.setNodeVisible("close_inventory_button", false);
|
||||
inventoryOpen = false;
|
||||
}
|
||||
void MenuManager::openInventory() {
|
||||
state = GameState::Inventory;
|
||||
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";
|
||||
}
|
||||
}
|
||||
uiManager.setText("inventory_items_text", itemText);
|
||||
}
|
||||
|
||||
void MenuManager::closeInventory() {
|
||||
state = GameState::Gameplay;
|
||||
uiManager.popMenu();
|
||||
}
|
||||
|
||||
void MenuManager::openQuestJournal() {
|
||||
state = GameState::QuestJournal;
|
||||
uiManager.pushMenuFromSavedRoot(questJournalRoot);
|
||||
|
||||
@@ -117,10 +112,13 @@ namespace ZL {
|
||||
|
||||
void MenuManager::toggleQuestJournal() {
|
||||
std::cout << "[quest] toggleQuestJournal: " << (isQuestJournalOpen() ? "closing" : "opening") << std::endl;
|
||||
if (isQuestJournalOpen()) {
|
||||
if (state == GameState::QuestJournal) {
|
||||
closeQuestJournal();
|
||||
}
|
||||
else {
|
||||
if (state == GameState::Inventory) {
|
||||
closeInventory();
|
||||
}
|
||||
openQuestJournal();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -15,6 +15,7 @@ namespace ZL {
|
||||
|
||||
enum class GameState {
|
||||
Gameplay,
|
||||
Inventory,
|
||||
QuestJournal
|
||||
};
|
||||
|
||||
@@ -26,9 +27,15 @@ namespace ZL {
|
||||
MenuManager(Renderer& iRenderer);
|
||||
|
||||
void setup(Inventory& inv, const std::string& zipFile);
|
||||
|
||||
void openInventory();
|
||||
void closeInventory();
|
||||
|
||||
void openQuestJournal();
|
||||
void closeQuestJournal();
|
||||
void toggleQuestJournal();
|
||||
|
||||
bool isInventoryOpen() const { return state == GameState::Inventory; }
|
||||
bool isQuestJournalOpen() const { return state == GameState::QuestJournal; }
|
||||
|
||||
protected:
|
||||
@@ -42,10 +49,10 @@ namespace ZL {
|
||||
GameState state = GameState::Gameplay;
|
||||
Inventory* inventory = nullptr;
|
||||
|
||||
std::shared_ptr<UiNode> ingameRoot;
|
||||
std::shared_ptr<UiNode> hudRoot;
|
||||
std::shared_ptr<UiNode> inventoryRoot;
|
||||
std::shared_ptr<UiNode> questJournalRoot;
|
||||
|
||||
bool inventoryOpen = false;
|
||||
int selectedQuestIndex = -1;
|
||||
std::vector<std::string> visibleQuestIds;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user