From 2d2faebd1065216fe409944211835f0051fa1be0 Mon Sep 17 00:00:00 2001 From: Mark Suckerberg Date: Tue, 30 Dec 2025 17:44:12 -0600 Subject: [PATCH 1/2] tweaks inventory screen display --- src/state.cpp | 5 +- src/window/inventory.cpp | 153 +++++++++++++++++++++++++++------------ src/window/inventory.h | 16 ++-- src/window/main_menu.cpp | 9 ++- src/window/play.cpp | 4 +- 5 files changed, 130 insertions(+), 57 deletions(-) diff --git a/src/state.cpp b/src/state.cpp index 1a847e8..40d7168 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -123,8 +123,7 @@ namespace game ((Item::SPAWN_Y_MAX - Item::SPAWN_Y_MIN) * math::random()) + Item::SPAWN_Y_MIN); items.emplace_back(&resources.anm2s[anm2::ITEMS], position, type); - inventory.values[type]--; - if (inventory.values[type] == 0) inventory.values.erase(type); + inventory.adjust_item(type, -1); type = Item::NONE; inventory.isQueued = false; } @@ -159,7 +158,7 @@ namespace game { if (Item::queuedReturnItem->state == Item::DEFAULT) { - inventory.values[item.type]++; + inventory.adjust_item(item.type); resources.sound_play(audio::RETURN); } else diff --git a/src/window/inventory.cpp b/src/window/inventory.cpp index 3d9ddd6..05b0f37 100644 --- a/src/window/inventory.cpp +++ b/src/window/inventory.cpp @@ -9,6 +9,31 @@ using namespace glm; namespace game::window { + Inventory::Inventory() + { + count = 0; + + for (auto& [type, quantity] : values) + { + count += quantity; + } + } + + void Inventory::adjust_item(Item::Type type, int quantity) + { + values[type] += quantity; + count += quantity; + } + + void Inventory::set_item(Item::Type type, int value) + { + count -= values[type]; + values[type] = value; + count += value; + } + + int Inventory::get_item(Item::Type type) { return values.contains(type) ? values[type] : 0; } + void Inventory::update(Resources& resources, Character& character, GameData& gameData) { auto& texture = resources.anm2s[anm2::ITEMS].content.spritesheets.at(0).texture; @@ -18,9 +43,11 @@ namespace game::window auto cursorPos = ImGui::GetCursorPos(); auto cursorStartX = ImGui::GetCursorPosX(); - for (auto& [type, quantity] : values) + for (int index = 0; index < Item::ITEM_COUNT; index++) { - if (quantity == 0) continue; + if (index == Item::INVALID) continue; + + auto type = (Item::Type)index; auto columns = (int)(texture.size.x / ITEM_SIZE.x); auto crop = vec2(type % columns, type / columns) * ITEM_SIZE; @@ -30,13 +57,84 @@ namespace game::window ImGui::PushID(type); ImGui::SetCursorPos(cursorPos); auto cursorScreenPos = ImGui::GetCursorScreenPos(); - if (ImGui::ImageButton("##Image Button", texture.id, IMAGE_SIZE, imgui::to_imvec2(uvMin), - imgui::to_imvec2(uvMax))) - { - queuedItemType = type; - isQueued = true; - resources.sound_play(audio::SUMMON); + auto quantity = 0; + auto seen = values.contains(type); + + if (seen) + { + quantity = values[type]; + + ImGui::BeginDisabled(quantity < 1); + if (ImGui::ImageButton("##Image Button", texture.id, IMAGE_SIZE, imgui::to_imvec2(uvMin), + imgui::to_imvec2(uvMax)) && + quantity > 0) + { + queuedItemType = type; + isQueued = true; + + resources.sound_play(audio::SUMMON); + } + ImGui::EndDisabled(); + + if (ImGui::BeginItemTooltip()) + { + auto& category = Item::CATEGORIES[type]; + auto& rarity = Item::RARITIES[type]; + auto& flavor = Item::FLAVORS[type]; + auto& calories = Item::CALORIES[type]; + auto& digestionRateBonus = Item::DIGESTION_RATE_BONUSES[type]; + auto& eatSpeedBonus = Item::EAT_SPEED_BONUSES[type]; + + ImGui::Text("%s (x%i)", Item::NAMES[type], quantity); + + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(imgui::to_imvec4(GRAY))); + ImGui::Text("-- %s (%s) --", Item::CATEGORY_NAMES[category], Item::RARITY_NAMES[rarity]); + if (category == Item::FOOD) + { + ImGui::Separator(); + if (flavor != Item::FLAVORLESS) ImGui::Text("Flavor: %s", Item::FLAVOR_NAMES[flavor]); + if (calories != 0) ImGui::Text("%0.0f kcal", calories); + if (digestionRateBonus > 0) + ImGui::Text("Digestion Rate Bonus: +%0.2f%% / sec", digestionRateBonus * 60.0f); + else if (digestionRateBonus < 0) + ImGui::Text("Digestion Rate Penalty: %0.2f%% / sec", digestionRateBonus * 60.0f); + if (eatSpeedBonus > 0) ImGui::Text("Eat Speed Bonus: +%0.2fx ", eatSpeedBonus); + } + ImGui::Separator(); + ImGui::TextUnformatted(Item::DESCRIPTIONS[type]); + ImGui::PopStyleColor(); + ImGui::EndTooltip(); + } + + ImGui::PushFont(resources.font.get(), Font::BIG); + auto text = std::format("x{}", quantity); + auto textPos = ImVec2(cursorScreenPos.x + IMAGE_SIZE.x - ImGui::CalcTextSize(text.c_str()).x, + cursorScreenPos.y + IMAGE_SIZE.y - ImGui::GetTextLineHeight()); + ImGui::GetWindowDrawList()->AddText(textPos, ImGui::GetColorU32(ImGui::GetStyleColorVec4(ImGuiCol_Text)), + text.c_str()); + ImGui::PopFont(); + } + else + { + ImGui::BeginDisabled(true); + ImGui::ImageButton("##Image Button", texture.id, IMAGE_SIZE, imgui::to_imvec2(uvMin), imgui::to_imvec2(uvMax), + ImVec4(0, 0, 0, 0), ImVec4(0, 0, 0, 1)); + ImGui::EndDisabled(); + + if (ImGui::BeginItemTooltip()) + { + ImGui::TextUnformatted("??? (x0)"); + + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(imgui::to_imvec4(GRAY))); + ImGui::TextUnformatted("-- ??? (\?\?\?) --"); + + ImGui::Separator(); + ImGui::TextUnformatted("???"); + + ImGui::PopStyleColor(); + ImGui::EndTooltip(); + } } auto increment = ImGui::GetItemRectSize().x + ImGui::GetStyle().ItemSpacing.x; @@ -48,47 +146,10 @@ namespace game::window cursorPos.y += increment; } - if (ImGui::BeginItemTooltip()) - { - auto& category = Item::CATEGORIES[type]; - auto& rarity = Item::RARITIES[type]; - auto& flavor = Item::FLAVORS[type]; - auto& calories = Item::CALORIES[type]; - auto& digestionRateBonus = Item::DIGESTION_RATE_BONUSES[type]; - auto& eatSpeedBonus = Item::EAT_SPEED_BONUSES[type]; - - ImGui::Text("%s (x%i)", Item::NAMES[type], quantity); - - ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(imgui::to_imvec4(GRAY))); - ImGui::Text("-- %s (%s) --", Item::CATEGORY_NAMES[category], Item::RARITY_NAMES[rarity]); - if (category == Item::FOOD) - { - ImGui::Separator(); - if (flavor != Item::FLAVORLESS) ImGui::Text("Flavor: %s", Item::FLAVOR_NAMES[flavor]); - if (calories != 0) ImGui::Text("%0.0f kcal", calories); - if (digestionRateBonus > 0) - ImGui::Text("Digestion Rate Bonus: +%0.2f%% / sec", digestionRateBonus * 60.0f); - else if (digestionRateBonus < 0) - ImGui::Text("Digestion Rate Penalty: %0.2f%% / sec", digestionRateBonus * 60.0f); - if (eatSpeedBonus > 0) ImGui::Text("Eat Speed Bonus: +%0.2fx ", eatSpeedBonus); - } - ImGui::Separator(); - ImGui::TextUnformatted(Item::DESCRIPTIONS[type]); - ImGui::PopStyleColor(); - ImGui::EndTooltip(); - } ImGui::PopID(); - - ImGui::PushFont(resources.font.get(), Font::BIG); - auto text = std::format("x{}", quantity); - auto textPos = ImVec2(cursorScreenPos.x + IMAGE_SIZE.x - ImGui::CalcTextSize(text.c_str()).x, - cursorScreenPos.y + IMAGE_SIZE.y - ImGui::GetTextLineHeight()); - ImGui::GetWindowDrawList()->AddText(textPos, ImGui::GetColorU32(ImGui::GetStyleColorVec4(ImGuiCol_Text)), - text.c_str()); - ImGui::PopFont(); } - if (values.empty()) ImGui::Text("Check the \"Play\" tab to earn rewards!"); + if (count == 0) ImGui::Text("Check the \"Play\" tab to earn rewards!"); ImGui::PopStyleVar(); } diff --git a/src/window/inventory.h b/src/window/inventory.h index 547c8a3..40c8510 100644 --- a/src/window/inventory.h +++ b/src/window/inventory.h @@ -11,20 +11,26 @@ namespace game::window { class Inventory { - public: - static constexpr auto ITEM_SIZE = glm::vec2(48, 48); - static constexpr auto IMAGE_SIZE = ImVec2(48, 48); - static constexpr auto BUTTON_ROUNDING = 32.0f; - + private: std::map values = {{Item::POKE_PUFF_BASIC_SWEET, 1}, {Item::POKE_PUFF_BASIC_CITRUS, 1}, {Item::POKE_PUFF_BASIC_MINT, 1}, {Item::POKE_PUFF_BASIC_MOCHA, 1}, {Item::POKE_PUFF_BASIC_SPICE, 1}}; + public: + static constexpr auto ITEM_SIZE = glm::vec2(48, 48); + static constexpr auto IMAGE_SIZE = ImVec2(48, 48); + static constexpr auto BUTTON_ROUNDING = 32.0f; + int count; + bool isQueued{}; Item::Type queuedItemType{}; + Inventory(); void update(Resources&, Character&, GameData&); + void adjust_item(Item::Type, int = 1); + void set_item(Item::Type, int); + int get_item(Item::Type); }; } diff --git a/src/window/main_menu.cpp b/src/window/main_menu.cpp index 6627317..0ef4d5b 100644 --- a/src/window/main_menu.cpp +++ b/src/window/main_menu.cpp @@ -117,7 +117,14 @@ namespace game::window { if (i == Item::INVALID) continue; ImGui::PushID(i); - ImGui::DragInt(Item::NAMES[i], &inventory.values[(Item::Type)i], 0.1f, 0, 999); + + //TODO: Probably a cleaner way to do this, maybe + int value = inventory.get_item((Item::Type)i); + if (ImGui::DragInt(Item::NAMES[i], &value, 0.1f, 0, 999)) + { + inventory.set_item((Item::Type)i, value); + } + ImGui::PopID(); } ImGui::PopItemWidth(); diff --git a/src/window/play.cpp b/src/window/play.cpp index 9109833..91e8e97 100644 --- a/src/window/play.cpp +++ b/src/window/play.cpp @@ -203,7 +203,7 @@ namespace game::window resources.sound_play(audio::HIGH_SCORE_BIG); isHighScoreBigAchieved = true; - inventory.values[Item::POKE_PUFF_SUPREME_HONOR]++; + inventory.adjust_item(Item::POKE_PUFF_SUPREME_HONOR); auto toastItemPosition = ImVec2(math::random_in_range(barMax.x + ITEM_SIZE.x, barMax.x + (size.x * 0.5f) - ITEM_SIZE.x), @@ -265,7 +265,7 @@ namespace game::window resources.sound_play(audio::FALL); resources.sound_play(RARITY_SOUNDS.at(rarity)); - inventory.values[rewardType]++; + inventory.adjust_item(rewardType); auto toastItemPosition = ImVec2(math::random_in_range(barMax.x + ITEM_SIZE.x, barMax.x + (size.x * 0.5f) - ITEM_SIZE.x), From 0f4ba92de5e83c8a4910f9c956b6c62beefb2048 Mon Sep 17 00:00:00 2001 From: Mark Suckerberg Date: Tue, 30 Dec 2025 17:53:57 -0600 Subject: [PATCH 2/2] Adjusts to also hide impossible item silhouettes --- src/window/inventory.cpp | 7 ++++--- src/window/main_menu.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/window/inventory.cpp b/src/window/inventory.cpp index 05b0f37..f0ddfbe 100644 --- a/src/window/inventory.cpp +++ b/src/window/inventory.cpp @@ -45,9 +45,11 @@ namespace game::window for (int index = 0; index < Item::ITEM_COUNT; index++) { - if (index == Item::INVALID) continue; - auto type = (Item::Type)index; + auto seen = values.contains(type); + + //Hide invalid items and impossible-to-obtain items when not seen. + if (!seen && (Item::CATEGORIES[type] == Item::INVALID || Item::RARITIES[type] == Item::IMPOSSIBLE)) continue; auto columns = (int)(texture.size.x / ITEM_SIZE.x); auto crop = vec2(type % columns, type / columns) * ITEM_SIZE; @@ -59,7 +61,6 @@ namespace game::window auto cursorScreenPos = ImGui::GetCursorScreenPos(); auto quantity = 0; - auto seen = values.contains(type); if (seen) { diff --git a/src/window/main_menu.cpp b/src/window/main_menu.cpp index 0ef4d5b..b19119c 100644 --- a/src/window/main_menu.cpp +++ b/src/window/main_menu.cpp @@ -115,7 +115,7 @@ namespace game::window ImGui::PushItemWidth(100); for (int i = 0; i < Item::ITEM_COUNT; i++) { - if (i == Item::INVALID) continue; + if (Item::CATEGORIES[i] == Item::INVALID) continue; ImGui::PushID(i); //TODO: Probably a cleaner way to do this, maybe