From a784a68c44768ca28d83c795811c63c96f2e3466 Mon Sep 17 00:00:00 2001 From: GHOST11111100 Date: Sat, 26 Jul 2025 22:02:53 +0300 Subject: [PATCH 1/5] refactor tooltip handling in SlotView to improve caption and description retrieval --- src/graphics/ui/elements/InventoryView.cpp | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index a02a49da..38361857 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -119,25 +119,37 @@ SlotView::SlotView(GUI& gui, SlotLayout layout) void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) { itemid_t itemid = stack.getItemId(); - if (itemid == cache.stack.getItemId()) { + dv::value* caption = stack.getField("caption"); + dv::value* description = stack.getField("description"); + if ( + itemid == cache.stack.getItemId() && + caption == cache.stack.getField("caption") && + description == cache.stack.getField("description") + ) { return; } if (itemid) { - dv::value* caption = stack.getField("caption"); - dv::value* description = stack.getField("description"); std::wstring captionText; std::wstring descriptionText; if (description != nullptr) { - descriptionText = util::pascal_case( langs::get( util::str2wstr_utf8( description->asString() ) ) ); + descriptionText = util::pascal_case( + langs::get(util::str2wstr_utf8(description->asString())) + ); } else { - descriptionText = util::pascal_case( langs::get( util::str2wstr_utf8( item.description ) ) ); + descriptionText = util::pascal_case( + langs::get(util::str2wstr_utf8(item.description)) + ); } if (caption != nullptr) { - captionText = util::pascal_case( langs::get( util::str2wstr_utf8( caption->asString() ) ) ); + captionText = util::pascal_case( + langs::get(util::str2wstr_utf8(caption->asString())) + ); } else { - captionText = util::pascal_case( langs::get( util::str2wstr_utf8( item.caption ) ) ); + captionText = util::pascal_case( + langs::get(util::str2wstr_utf8(item.caption)) + ); } tooltip = captionText + L"\n" + descriptionText; From 7893338b6773ff33009482448a499d69626d82cf Mon Sep 17 00:00:00 2001 From: GHOST11111100 Date: Sun, 27 Jul 2025 00:29:23 +0300 Subject: [PATCH 2/5] fix: update tooltip handling to display caption only when description is empty --- src/graphics/ui/elements/InventoryView.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index 38361857..2b7dc270 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -152,7 +152,11 @@ void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) { ); } - tooltip = captionText + L"\n" + descriptionText; + if (descriptionText.length() > 0) { + tooltip = captionText + L"\n" + descriptionText; + } else { + tooltip = captionText; + } } else { tooltip.clear(); } From d489dab013439f4379f1b3001bff93626d0b6279 Mon Sep 17 00:00:00 2001 From: GHOST11111100 Date: Sun, 27 Jul 2025 00:51:42 +0300 Subject: [PATCH 3/5] refactor: streamline tooltip handling by separating caption and description retrieval --- src/graphics/ui/elements/InventoryView.cpp | 63 +++++++++++----------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index 2b7dc270..be58dd50 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -116,46 +116,43 @@ SlotView::SlotView(GUI& gui, SlotLayout layout) setColor(glm::vec4(0, 0, 0, 0.2f)); setTooltipDelay(0.0f); } +// TODO: Refactor +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 +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)); + } +} void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) { itemid_t itemid = stack.getItemId(); - dv::value* caption = stack.getField("caption"); - dv::value* description = stack.getField("description"); - if ( - itemid == cache.stack.getItemId() && - caption == cache.stack.getField("caption") && - description == cache.stack.getField("description") - ) { + std::wstring caption = get_caption_string(stack, item); + std::wstring cached_caption = get_caption_string(cache.stack, item); + std::wstring description = get_description_string(stack, item); + std::wstring cached_description = get_description_string(cache.stack, item); + + if (itemid == cache.stack.getItemId() && cached_caption == caption && cached_description == description) { return; } if (itemid) { - std::wstring captionText; - std::wstring descriptionText; - - if (description != nullptr) { - descriptionText = util::pascal_case( - langs::get(util::str2wstr_utf8(description->asString())) - ); + if (description.length() > 0) { + tooltip = caption + L"\n" + description; } else { - descriptionText = util::pascal_case( - langs::get(util::str2wstr_utf8(item.description)) - ); - } - - if (caption != nullptr) { - captionText = util::pascal_case( - langs::get(util::str2wstr_utf8(caption->asString())) - ); - } else { - captionText = util::pascal_case( - langs::get(util::str2wstr_utf8(item.caption)) - ); - } - - if (descriptionText.length() > 0) { - tooltip = captionText + L"\n" + descriptionText; - } else { - tooltip = captionText; + tooltip = caption; } } else { tooltip.clear(); From 1e270d4adbbf4ec6bb6e314f15120d8ff224a364 Mon Sep 17 00:00:00 2001 From: GHOST11111100 Date: Sun, 27 Jul 2025 02:26:05 +0300 Subject: [PATCH 4/5] refactor: enhance tooltip handling by making caption and description retrieval static --- src/graphics/ui/elements/InventoryView.cpp | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index be58dd50..563d36a7 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -117,18 +117,24 @@ SlotView::SlotView(GUI& gui, SlotLayout layout) setTooltipDelay(0.0f); } // TODO: Refactor -std::wstring get_caption_string(const ItemStack& stack, const ItemDef& item) { +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))); + return util::pascal_case( + langs::get(util::str2wstr_utf8(item.caption)) + ); } } // TODO: Refactor -std::wstring get_description_string(const ItemStack& stack, const ItemDef& item) { +static std::wstring get_description_string( + const ItemStack& stack, const ItemDef& item +) { dv::value* description = stack.getField("description"); if (description != nullptr) { @@ -138,17 +144,33 @@ std::wstring get_description_string(const ItemStack& stack, const ItemDef& item) } } +static bool is_same_tooltip(const ItemStack& stack, const ItemStack& cache) { + if (stack.getItemId() != cache.getItemId()) { + return false; + } + auto caption = stack.getField("caption"); + auto cCaption = cache.getField("caption"); + auto description = stack.getField("description"); + auto cDescription = cache.getField("description"); + + if (((caption != nullptr) != (description != nullptr)) || + ((description != nullptr) != (cDescription != nullptr))) { + return false; + } + return (caption ? caption->asString() == cCaption->asString() : true) && + (description ? description->asString() == cDescription->asString() + : true); +} + void SlotView::refreshTooltip(const ItemStack& stack, const ItemDef& item) { itemid_t itemid = stack.getItemId(); - std::wstring caption = get_caption_string(stack, item); - std::wstring cached_caption = get_caption_string(cache.stack, item); - std::wstring description = get_description_string(stack, item); - std::wstring cached_description = get_description_string(cache.stack, item); - if (itemid == cache.stack.getItemId() && cached_caption == caption && cached_description == description) { + if (is_same_tooltip(stack, cache.stack)) { return; } if (itemid) { + std::wstring caption = get_caption_string(stack, item); + std::wstring description = get_description_string(stack, item); if (description.length() > 0) { tooltip = caption + L"\n" + description; } else { From 310dc9ebb239c10c455eb85a81ceccfd776bc000 Mon Sep 17 00:00:00 2001 From: GHOST11111100 Date: Sun, 27 Jul 2025 14:48:41 +0300 Subject: [PATCH 5/5] fix: correct tooltip comparison logic and streamline stack setting in SlotView --- src/graphics/ui/elements/InventoryView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/ui/elements/InventoryView.cpp b/src/graphics/ui/elements/InventoryView.cpp index 563d36a7..6aadd3c4 100644 --- a/src/graphics/ui/elements/InventoryView.cpp +++ b/src/graphics/ui/elements/InventoryView.cpp @@ -153,7 +153,7 @@ static bool is_same_tooltip(const ItemStack& stack, const ItemStack& cache) { auto description = stack.getField("description"); auto cDescription = cache.getField("description"); - if (((caption != nullptr) != (description != nullptr)) || + if (((caption != nullptr) != (cCaption != nullptr)) || ((description != nullptr) != (cDescription != nullptr))) { return false; } @@ -250,7 +250,7 @@ void SlotView::draw(const DrawContext& pctx, const Assets& assets) { cache.countStr = std::to_wstring(stack.getCount()); } refreshTooltip(stack, item); - cache.stack.set(ItemStack(stack.getItemId(), stack.getCount())); + cache.stack.set(stack); glm::vec4 tint(1, 1, 1, isEnabled() ? 1 : 0.5f); glm::vec2 pos = calcPos();