From 4981d162c524558192efb56b51e9f06e2f84abb2 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 27 Mar 2026 14:40:44 -0700 Subject: [PATCH] refactor: deduplicate item-set DBC key arrays, widen totem timer buffer - Move itemKeys/spellKeys/thrKeys to shared kItemSetItemKeys/ kItemSetSpellKeys/kItemSetThresholdKeys in ui_colors.hpp, removing 5 identical local definitions across game_screen and inventory_screen - Widen totem timer snprintf buffer from 8 to 16 bytes (defensive) - Promote kStatTooltips to constexpr --- include/ui/ui_colors.hpp | 14 ++++++++++++++ src/ui/game_screen.cpp | 8 ++++---- src/ui/inventory_screen.cpp | 29 +++++++---------------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/include/ui/ui_colors.hpp b/include/ui/ui_colors.hpp index ac945f69..2f9c7744 100644 --- a/include/ui/ui_colors.hpp +++ b/include/ui/ui_colors.hpp @@ -137,6 +137,20 @@ inline void renderBindingType(uint32_t bindType) { } } +// ---- DBC item-set spell field keys ---- +inline constexpr const char* kItemSetItemKeys[10] = { + "Item0","Item1","Item2","Item3","Item4", + "Item5","Item6","Item7","Item8","Item9" +}; +inline constexpr const char* kItemSetSpellKeys[10] = { + "Spell0","Spell1","Spell2","Spell3","Spell4", + "Spell5","Spell6","Spell7","Spell8","Spell9" +}; +inline constexpr const char* kItemSetThresholdKeys[10] = { + "Threshold0","Threshold1","Threshold2","Threshold3","Threshold4", + "Threshold5","Threshold6","Threshold7","Threshold8","Threshold9" +}; + // ---- Socket type display (gem sockets) ---- struct SocketTypeDef { uint32_t mask; const char* label; ImVec4 col; }; inline constexpr SocketTypeDef kSocketTypes[] = { diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 7660f665..1473902c 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -1562,9 +1562,9 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { return layout ? (*layout)[k] : def; }; uint32_t idF = lf("ID", 0), nameF = lf("Name", 1); - static const char* itemKeys[10] = {"Item0","Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9"}; - static const char* spellKeys[10] = {"Spell0","Spell1","Spell2","Spell3","Spell4","Spell5","Spell6","Spell7","Spell8","Spell9"}; - static const char* thrKeys[10] = {"Threshold0","Threshold1","Threshold2","Threshold3","Threshold4","Threshold5","Threshold6","Threshold7","Threshold8","Threshold9"}; + const auto& itemKeys = ui::kItemSetItemKeys; + const auto& spellKeys = ui::kItemSetSpellKeys; + const auto& thrKeys = ui::kItemSetThresholdKeys; for (uint32_t r = 0; r < dbc->getRecordCount(); ++r) { uint32_t id = dbc->getUInt32(r, idF); if (!id) continue; @@ -3577,7 +3577,7 @@ void GameScreen::renderPlayerFrame(game::GameHandler& gameHandler) { tdl->AddRectFilled(ImVec2(x0, y0), ImVec2(fillX, y1), ImGui::ColorConvertFloat4ToU32(kTotemColors[i]), 2.0f); // Remaining seconds label - char secBuf[8]; + char secBuf[16]; snprintf(secBuf, sizeof(secBuf), "%.0f", rem / 1000.0f); ImVec2 tsz = ImGui::CalcTextSize(secBuf); float lx = x0 + (slotW - tsz.x) * 0.5f; diff --git a/src/ui/inventory_screen.cpp b/src/ui/inventory_screen.cpp index e86f8e3f..4a74207f 100644 --- a/src/ui/inventory_screen.cpp +++ b/src/ui/inventory_screen.cpp @@ -1838,7 +1838,7 @@ void InventoryScreen::renderStatsPanel(game::Inventory& inventory, uint32_t play ImVec4 gold(1.0f, 0.84f, 0.0f, 1.0f); ImVec4 gray(0.6f, 0.6f, 0.6f, 1.0f); - static const char* kStatTooltips[5] = { + static constexpr const char* kStatTooltips[5] = { "Increases your melee attack power by 2.\nIncreases your block value.", "Increases your Armor.\nIncreases ranged attack power by 2.\nIncreases your chance to dodge attacks and score critical strikes.", "Increases Health by 10 per point.", @@ -2942,15 +2942,9 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I return layout ? (*layout)[k] : def; }; uint32_t idF = lf("ID", 0), nameF = lf("Name", 1); - static const char* itemKeys[10] = { - "Item0","Item1","Item2","Item3","Item4", - "Item5","Item6","Item7","Item8","Item9" }; - static const char* spellKeys[10] = { - "Spell0","Spell1","Spell2","Spell3","Spell4", - "Spell5","Spell6","Spell7","Spell8","Spell9" }; - static const char* thrKeys[10] = { - "Threshold0","Threshold1","Threshold2","Threshold3","Threshold4", - "Threshold5","Threshold6","Threshold7","Threshold8","Threshold9" }; + const auto& itemKeys = ui::kItemSetItemKeys; + const auto& spellKeys = ui::kItemSetSpellKeys; + const auto& thrKeys = ui::kItemSetThresholdKeys; uint32_t itemFB[10], spellFB[10], thrFB[10]; for (int i = 0; i < 10; ++i) { itemFB[i] = 18+i; spellFB[i] = 28+i; thrFB[i] = 38+i; @@ -3519,18 +3513,9 @@ void InventoryScreen::renderItemTooltip(const game::ItemQueryResponseData& info, return layout ? (*layout)[k] : def; }; uint32_t idF = lf("ID", 0), nameF = lf("Name", 1); - static const char* itemKeys[10] = { - "Item0","Item1","Item2","Item3","Item4", - "Item5","Item6","Item7","Item8","Item9" - }; - static const char* spellKeys[10] = { - "Spell0","Spell1","Spell2","Spell3","Spell4", - "Spell5","Spell6","Spell7","Spell8","Spell9" - }; - static const char* thrKeys[10] = { - "Threshold0","Threshold1","Threshold2","Threshold3","Threshold4", - "Threshold5","Threshold6","Threshold7","Threshold8","Threshold9" - }; + const auto& itemKeys = ui::kItemSetItemKeys; + const auto& spellKeys = ui::kItemSetSpellKeys; + const auto& thrKeys = ui::kItemSetThresholdKeys; uint32_t itemFallback[10], spellFallback[10], thrFallback[10]; for (int i = 0; i < 10; ++i) { itemFallback[i] = 18 + i;