#include "item_display.hpp" #include "../../resource/font.hpp" #include "../../util/color.hpp" #include "../../util/imgui.hpp" #include namespace game::state::play { constexpr auto ZERO_FLOAT = 0.0f; void item_header_draw(const resource::xml::Schema::ItemEntry& item) { ImGui::PushFont(ImGui::GetFont(), resource::Font::HEADER_2); ImGui::TextWrapped("%s", item.name.c_str()); ImGui::PopFont(); } void item_summary_draw(Entity& character, resource::xml::Schema& schema, const resource::xml::Schema::ItemEntry& item) { using Strings = resource::xml::Strings; auto& strings = character.data.strings; auto isCategory = item.categoryID >= 0 && item.categoryID < (int)schema.categories.size(); auto isRarity = item.rarityID >= 0 && item.rarityID < (int)schema.rarities.size(); auto isFlavor = item.flavorID >= 0 && item.flavorID < (int)schema.flavors.size(); ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(util::imgui::to_imvec4(util::color::GRAY))); if (isCategory && isRarity) ImGui::TextWrapped("-- %s (%s) --", schema.categories[item.categoryID].name.c_str(), schema.rarities[item.rarityID].name.c_str()); else if (isCategory) ImGui::TextWrapped("-- %s --", schema.categories[item.categoryID].name.c_str()); if (item.isFlavor && isFlavor) ImGui::TextWrapped(strings.get(Strings::InventoryFlavorFormat).c_str(), schema.flavors[item.flavorID].name.c_str()); if (item.isCalories) ImGui::TextWrapped(strings.get(Strings::InventoryCaloriesFormat).c_str(), item.calories); if (item.isCapacityBonus) ImGui::TextWrapped(strings.get(Strings::InventoryCapacityBonusFormat).c_str(), item.capacityBonus); if (item.isDigestionBonus) { if (item.digestionBonus > ZERO_FLOAT) ImGui::TextWrapped(strings.get(Strings::InventoryDigestionRateBonusFormat).c_str(), item.digestionBonus * Entity::UPDATE_RATE); else if (item.digestionBonus < ZERO_FLOAT) ImGui::TextWrapped(strings.get(Strings::InventoryDigestionRatePenaltyFormat).c_str(), item.digestionBonus * Entity::UPDATE_RATE); } ImGui::PopStyleColor(); } void item_tooltip_draw(Entity& character, resource::xml::Schema& schema, const resource::xml::Schema::ItemEntry& item) { ImGui::PushTextWrapPos(ImGui::GetFontSize() * ITEM_TOOLTIP_WRAP_FONT_MULTIPLIER); item_header_draw(item); ImGui::Separator(); item_summary_draw(character, schema, item); ImGui::Separator(); ImGui::TextWrapped("%s", item.description.c_str()); ImGui::PopTextWrapPos(); } }