diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index 614d4c913..37487edd0 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -113,30 +113,25 @@ SlotView::SlotView(GUI& gui, SlotLayout layout) setColor(glm::vec4(0, 0, 0, 0.2f)); setTooltipDelay(0.0f); } -// TODO: Refactor -static std::wstring get_caption_string( - const ItemStack& stack, const ItemDef& item -) { - dv::value* caption = stack.getField("caption"); - if (caption != nullptr) { - return util::pascal_case( - langs::get(util::str2wstr_utf8(caption->asString())) - ); - } else { - return util::pascal_case(langs::get(util::str2wstr_utf8(item.caption))); - } -} -// TODO: Refactor -static std::wstring get_description_string( - const ItemStack& stack, const ItemDef& item -) { - dv::value* description = stack.getField("description"); - if (description != nullptr) { - return langs::get(util::str2wstr_utf8(description->asString())); - } else { - return langs::get(util::str2wstr_utf8(item.description)); - } +// May not work correctly, requires review +static std::wstring get_item_field_string( + const ItemStack& stack, + const std::string& field_name, + const std::string& fallback_value +) { + dv::value* field = stack.getField(field_name); + const std::string& target_str = (field != nullptr) ? field->asString() : fallback_value; + + return langs::get(util::str2wstr_utf8(target_str)); +} + +static std::wstring get_caption_string(const ItemStack& stack, const ItemDef& item) { + return util::pascal_case(get_item_field_string(stack, "caption", item.caption)); +} +// pascal_case is omitted for descriptions to preserve standard text formatting and readability +static std::wstring get_description_string(const ItemStack& stack, const ItemDef& item) { + return get_item_field_string(stack, "description", item.description); } static bool is_same_tooltip(const ItemStack& stack, const ItemStack& cache) { diff --git a/src/graphics/ui/gui_xml.cpp b/src/graphics/ui/gui_xml.cpp index 41a603cea..dba18d0b9 100644 --- a/src/graphics/ui/gui_xml.cpp +++ b/src/graphics/ui/gui_xml.cpp @@ -38,6 +38,8 @@ static Align align_from_string(std::string_view str, Align def) { return def; } +static constexpr glm::vec4 INVENTORY_VIEW_BACKGROUND_COLOR = glm::vec4(0.122f, 0.122f, 0.122f, 0.878f); + static Gravity gravity_from_string(const std::string& str) { static const std::unordered_map gravity_names { {"top-left", Gravity::TOP_LEFT}, @@ -860,7 +862,8 @@ static std::shared_ptr read_inventory( UiXmlReader& reader, const xml::xmlelement& element ) { auto view = std::make_shared(reader.getGUI()); - view->setColor(glm::vec4(0.122f, 0.122f, 0.122f, 0.878f)); // TODO: fixme +// view->setColor(glm::vec4(0.122f, 0.122f, 0.122f, 0.878f)); + view->setColor(INVENTORY_VIEW_BACKGROUND_COLOR); // fixed variant (magic color -> constant) reader.addIgnore("slot"); reader.addIgnore("slots-grid"); reader.readUINode(reader, element, *view);