* fixed variant (magic color -> constant) in gui_xml.cpp

* refactored code in InventoryView.cpp
This commit is contained in:
benjaminkalb 2026-06-05 00:26:49 +03:00
parent 34cc778f0d
commit ed7d0594ff
2 changed files with 22 additions and 24 deletions

View file

@ -116,30 +116,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) {

View file

@ -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<std::string, Gravity> gravity_names {
{"top-left", Gravity::TOP_LEFT},
@ -851,7 +853,8 @@ static std::shared_ptr<UINode> read_inventory(
UiXmlReader& reader, const xml::xmlelement& element
) {
auto view = std::make_shared<InventoryView>(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);