From 92d8262f96dfae8599c50c2ccd9becfd215e8f3d Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 27 Mar 2026 14:35:16 -0700 Subject: [PATCH] refactor: move kClassMasks, kRaceMasks, kSocketTypes to shared ui_colors.hpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deduplicate class/race bitmask arrays (3 copies each → 1 shared) and socket type definitions (3 copies → 1 shared). Eliminates ~80 lines of repeated struct definitions across game_screen.cpp and inventory_screen.cpp. --- include/ui/ui_colors.hpp | 24 +++++++++++++++++++ src/ui/game_screen.cpp | 33 +++----------------------- src/ui/inventory_screen.cpp | 47 ++++--------------------------------- 3 files changed, 32 insertions(+), 72 deletions(-) diff --git a/include/ui/ui_colors.hpp b/include/ui/ui_colors.hpp index 8acebf79..ac945f69 100644 --- a/include/ui/ui_colors.hpp +++ b/include/ui/ui_colors.hpp @@ -137,6 +137,30 @@ inline void renderBindingType(uint32_t bindType) { } } +// ---- Socket type display (gem sockets) ---- +struct SocketTypeDef { uint32_t mask; const char* label; ImVec4 col; }; +inline constexpr SocketTypeDef kSocketTypes[] = { + { 1, "Meta Socket", { 0.7f, 0.7f, 0.9f, 1.0f } }, + { 2, "Red Socket", { 1.0f, 0.3f, 0.3f, 1.0f } }, + { 4, "Yellow Socket", { 1.0f, 0.9f, 0.3f, 1.0f } }, + { 8, "Blue Socket", { 0.3f, 0.6f, 1.0f, 1.0f } }, +}; + +// ---- Class/race bitmask lookup (for allowableClass/allowableRace display) ---- +struct ClassMaskEntry { uint32_t mask; const char* name; }; +inline constexpr ClassMaskEntry kClassMasks[] = { + {1,"Warrior"}, {2,"Paladin"}, {4,"Hunter"}, {8,"Rogue"}, + {16,"Priest"}, {32,"Death Knight"}, {64,"Shaman"}, + {128,"Mage"}, {256,"Warlock"}, {1024,"Druid"}, +}; + +struct RaceMaskEntry { uint32_t mask; const char* name; }; +inline constexpr RaceMaskEntry kRaceMasks[] = { + {1,"Human"}, {2,"Orc"}, {4,"Dwarf"}, {8,"Night Elf"}, + {16,"Undead"}, {32,"Tauren"}, {64,"Gnome"}, {128,"Troll"}, + {512,"Blood Elf"}, {1024,"Draenei"}, +}; + // ---- WoW class colors (Blizzard canonical) ---- inline ImVec4 getClassColor(uint8_t classId) { switch (classId) { diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 39189156..7660f665 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -1502,12 +1502,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { // Gem sockets (WotLK only — socketColor != 0 means socket present) // socketColor bitmask: 1=Meta, 2=Red, 4=Yellow, 8=Blue { - static const struct { uint32_t mask; const char* label; ImVec4 col; } kSocketTypes[] = { - { 1, "Meta Socket", { 0.7f, 0.7f, 0.9f, 1.0f } }, - { 2, "Red Socket", { 1.0f, 0.3f, 0.3f, 1.0f } }, - { 4, "Yellow Socket", { 1.0f, 0.9f, 0.3f, 1.0f } }, - { 8, "Blue Socket", { 0.3f, 0.6f, 1.0f, 1.0f } }, - }; + const auto& kSocketTypes = ui::kSocketTypes; bool hasSocket = false; for (int s = 0; s < 3; ++s) { if (info->socketColor[s] == 0) continue; @@ -1707,18 +1702,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { } // Class restriction (e.g. "Classes: Paladin, Warrior") if (info->allowableClass != 0) { - static const struct { uint32_t mask; const char* name; } kClasses[] = { - { 1, "Warrior" }, - { 2, "Paladin" }, - { 4, "Hunter" }, - { 8, "Rogue" }, - { 16, "Priest" }, - { 32, "Death Knight" }, - { 64, "Shaman" }, - { 128, "Mage" }, - { 256, "Warlock" }, - { 1024, "Druid" }, - }; + const auto& kClasses = ui::kClassMasks; int matchCount = 0; for (const auto& kc : kClasses) if (info->allowableClass & kc.mask) ++matchCount; @@ -1740,18 +1724,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) { } // Race restriction (e.g. "Races: Night Elf, Human") if (info->allowableRace != 0) { - static const struct { uint32_t mask; const char* name; } kRaces[] = { - { 1, "Human" }, - { 2, "Orc" }, - { 4, "Dwarf" }, - { 8, "Night Elf" }, - { 16, "Undead" }, - { 32, "Tauren" }, - { 64, "Gnome" }, - { 128, "Troll" }, - { 512, "Blood Elf" }, - { 1024, "Draenei" }, - }; + const auto& kRaces = ui::kRaceMasks; constexpr uint32_t kAllPlayable = 1|2|4|8|16|32|64|128|512|1024; if ((info->allowableRace & kAllPlayable) != kAllPlayable) { int matchCount = 0; diff --git a/src/ui/inventory_screen.cpp b/src/ui/inventory_screen.cpp index 66f1ac03..e86f8e3f 100644 --- a/src/ui/inventory_screen.cpp +++ b/src/ui/inventory_screen.cpp @@ -38,14 +38,7 @@ constexpr const char* kResistNames[6] = { "Frost Resistance", "Shadow Resistance", "Arcane Resistance" }; -// Socket type definitions (shared across tooltip renderers) -struct SocketTypeDef { uint32_t mask; const char* label; ImVec4 col; }; -constexpr SocketTypeDef kSocketTypes[] = { - { 1, "Meta Socket", { 0.7f, 0.7f, 0.9f, 1.0f } }, - { 2, "Red Socket", { 1.0f, 0.3f, 0.3f, 1.0f } }, - { 4, "Yellow Socket", { 1.0f, 0.9f, 0.3f, 1.0f } }, - { 8, "Blue Socket", { 0.3f, 0.6f, 1.0f, 1.0f } }, -}; +// Socket types from shared ui_colors.hpp (ui::kSocketTypes) const game::ItemSlot* findComparableEquipped(const game::Inventory& inventory, uint8_t inventoryType) { using ES = game::EquipSlot; @@ -2849,11 +2842,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I } // Class restriction if (qInfo->allowableClass != 0) { - static const struct { uint32_t mask; const char* name; } kClassesB[] = { - { 1,"Warrior" },{ 2,"Paladin" },{ 4,"Hunter" },{ 8,"Rogue" }, - { 16,"Priest" },{ 32,"Death Knight" },{ 64,"Shaman" }, - { 128,"Mage" },{ 256,"Warlock" },{ 1024,"Druid" }, - }; + const auto& kClassesB = ui::kClassMasks; int mc = 0; for (const auto& kc : kClassesB) if (qInfo->allowableClass & kc.mask) ++mc; if (mc > 0 && mc < 10) { @@ -2872,11 +2861,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I } // Race restriction if (qInfo->allowableRace != 0) { - static const struct { uint32_t mask; const char* name; } kRacesB[] = { - { 1,"Human" },{ 2,"Orc" },{ 4,"Dwarf" },{ 8,"Night Elf" }, - { 16,"Undead" },{ 32,"Tauren" },{ 64,"Gnome" },{ 128,"Troll" }, - { 512,"Blood Elf" },{ 1024,"Draenei" }, - }; + const auto& kRacesB = ui::kRaceMasks; constexpr uint32_t kAll = 1|2|4|8|16|32|64|128|512|1024; if ((qInfo->allowableRace & kAll) != kAll) { int mc = 0; @@ -3377,18 +3362,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemQueryResponseData& info, // Class restriction (e.g. "Classes: Paladin, Warrior") if (info.allowableClass != 0) { - static const struct { uint32_t mask; const char* name; } kClasses[] = { - { 1, "Warrior" }, - { 2, "Paladin" }, - { 4, "Hunter" }, - { 8, "Rogue" }, - { 16, "Priest" }, - { 32, "Death Knight" }, - { 64, "Shaman" }, - { 128, "Mage" }, - { 256, "Warlock" }, - { 1024, "Druid" }, - }; + const auto& kClasses = ui::kClassMasks; // Count matching classes int matchCount = 0; for (const auto& kc : kClasses) @@ -3417,18 +3391,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemQueryResponseData& info, // Race restriction (e.g. "Races: Night Elf, Human") if (info.allowableRace != 0) { - static const struct { uint32_t mask; const char* name; } kRaces[] = { - { 1, "Human" }, - { 2, "Orc" }, - { 4, "Dwarf" }, - { 8, "Night Elf" }, - { 16, "Undead" }, - { 32, "Tauren" }, - { 64, "Gnome" }, - { 128, "Troll" }, - { 512, "Blood Elf" }, - { 1024, "Draenei" }, - }; + const auto& kRaces = ui::kRaceMasks; constexpr uint32_t kAllPlayable = 1|2|4|8|16|32|64|128|512|1024; // Only show if not all playable races are allowed if ((info.allowableRace & kAllPlayable) != kAllPlayable) {