mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 17:43:52 +00:00
refactor: move kClassMasks, kRaceMasks, kSocketTypes to shared ui_colors.hpp
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.
This commit is contained in:
parent
cd29c6d50b
commit
92d8262f96
3 changed files with 32 additions and 72 deletions
|
|
@ -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) ----
|
// ---- WoW class colors (Blizzard canonical) ----
|
||||||
inline ImVec4 getClassColor(uint8_t classId) {
|
inline ImVec4 getClassColor(uint8_t classId) {
|
||||||
switch (classId) {
|
switch (classId) {
|
||||||
|
|
|
||||||
|
|
@ -1502,12 +1502,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) {
|
||||||
// Gem sockets (WotLK only — socketColor != 0 means socket present)
|
// Gem sockets (WotLK only — socketColor != 0 means socket present)
|
||||||
// socketColor bitmask: 1=Meta, 2=Red, 4=Yellow, 8=Blue
|
// socketColor bitmask: 1=Meta, 2=Red, 4=Yellow, 8=Blue
|
||||||
{
|
{
|
||||||
static const struct { uint32_t mask; const char* label; ImVec4 col; } kSocketTypes[] = {
|
const auto& kSocketTypes = ui::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 } },
|
|
||||||
};
|
|
||||||
bool hasSocket = false;
|
bool hasSocket = false;
|
||||||
for (int s = 0; s < 3; ++s) {
|
for (int s = 0; s < 3; ++s) {
|
||||||
if (info->socketColor[s] == 0) continue;
|
if (info->socketColor[s] == 0) continue;
|
||||||
|
|
@ -1707,18 +1702,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) {
|
||||||
}
|
}
|
||||||
// Class restriction (e.g. "Classes: Paladin, Warrior")
|
// Class restriction (e.g. "Classes: Paladin, Warrior")
|
||||||
if (info->allowableClass != 0) {
|
if (info->allowableClass != 0) {
|
||||||
static const struct { uint32_t mask; const char* name; } kClasses[] = {
|
const auto& kClasses = ui::kClassMasks;
|
||||||
{ 1, "Warrior" },
|
|
||||||
{ 2, "Paladin" },
|
|
||||||
{ 4, "Hunter" },
|
|
||||||
{ 8, "Rogue" },
|
|
||||||
{ 16, "Priest" },
|
|
||||||
{ 32, "Death Knight" },
|
|
||||||
{ 64, "Shaman" },
|
|
||||||
{ 128, "Mage" },
|
|
||||||
{ 256, "Warlock" },
|
|
||||||
{ 1024, "Druid" },
|
|
||||||
};
|
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
for (const auto& kc : kClasses)
|
for (const auto& kc : kClasses)
|
||||||
if (info->allowableClass & kc.mask) ++matchCount;
|
if (info->allowableClass & kc.mask) ++matchCount;
|
||||||
|
|
@ -1740,18 +1724,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) {
|
||||||
}
|
}
|
||||||
// Race restriction (e.g. "Races: Night Elf, Human")
|
// Race restriction (e.g. "Races: Night Elf, Human")
|
||||||
if (info->allowableRace != 0) {
|
if (info->allowableRace != 0) {
|
||||||
static const struct { uint32_t mask; const char* name; } kRaces[] = {
|
const auto& kRaces = ui::kRaceMasks;
|
||||||
{ 1, "Human" },
|
|
||||||
{ 2, "Orc" },
|
|
||||||
{ 4, "Dwarf" },
|
|
||||||
{ 8, "Night Elf" },
|
|
||||||
{ 16, "Undead" },
|
|
||||||
{ 32, "Tauren" },
|
|
||||||
{ 64, "Gnome" },
|
|
||||||
{ 128, "Troll" },
|
|
||||||
{ 512, "Blood Elf" },
|
|
||||||
{ 1024, "Draenei" },
|
|
||||||
};
|
|
||||||
constexpr uint32_t kAllPlayable = 1|2|4|8|16|32|64|128|512|1024;
|
constexpr uint32_t kAllPlayable = 1|2|4|8|16|32|64|128|512|1024;
|
||||||
if ((info->allowableRace & kAllPlayable) != kAllPlayable) {
|
if ((info->allowableRace & kAllPlayable) != kAllPlayable) {
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,7 @@ constexpr const char* kResistNames[6] = {
|
||||||
"Frost Resistance", "Shadow Resistance", "Arcane Resistance"
|
"Frost Resistance", "Shadow Resistance", "Arcane Resistance"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Socket type definitions (shared across tooltip renderers)
|
// Socket types from shared ui_colors.hpp (ui::kSocketTypes)
|
||||||
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 } },
|
|
||||||
};
|
|
||||||
|
|
||||||
const game::ItemSlot* findComparableEquipped(const game::Inventory& inventory, uint8_t inventoryType) {
|
const game::ItemSlot* findComparableEquipped(const game::Inventory& inventory, uint8_t inventoryType) {
|
||||||
using ES = game::EquipSlot;
|
using ES = game::EquipSlot;
|
||||||
|
|
@ -2849,11 +2842,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I
|
||||||
}
|
}
|
||||||
// Class restriction
|
// Class restriction
|
||||||
if (qInfo->allowableClass != 0) {
|
if (qInfo->allowableClass != 0) {
|
||||||
static const struct { uint32_t mask; const char* name; } kClassesB[] = {
|
const auto& kClassesB = ui::kClassMasks;
|
||||||
{ 1,"Warrior" },{ 2,"Paladin" },{ 4,"Hunter" },{ 8,"Rogue" },
|
|
||||||
{ 16,"Priest" },{ 32,"Death Knight" },{ 64,"Shaman" },
|
|
||||||
{ 128,"Mage" },{ 256,"Warlock" },{ 1024,"Druid" },
|
|
||||||
};
|
|
||||||
int mc = 0;
|
int mc = 0;
|
||||||
for (const auto& kc : kClassesB) if (qInfo->allowableClass & kc.mask) ++mc;
|
for (const auto& kc : kClassesB) if (qInfo->allowableClass & kc.mask) ++mc;
|
||||||
if (mc > 0 && mc < 10) {
|
if (mc > 0 && mc < 10) {
|
||||||
|
|
@ -2872,11 +2861,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I
|
||||||
}
|
}
|
||||||
// Race restriction
|
// Race restriction
|
||||||
if (qInfo->allowableRace != 0) {
|
if (qInfo->allowableRace != 0) {
|
||||||
static const struct { uint32_t mask; const char* name; } kRacesB[] = {
|
const auto& kRacesB = ui::kRaceMasks;
|
||||||
{ 1,"Human" },{ 2,"Orc" },{ 4,"Dwarf" },{ 8,"Night Elf" },
|
|
||||||
{ 16,"Undead" },{ 32,"Tauren" },{ 64,"Gnome" },{ 128,"Troll" },
|
|
||||||
{ 512,"Blood Elf" },{ 1024,"Draenei" },
|
|
||||||
};
|
|
||||||
constexpr uint32_t kAll = 1|2|4|8|16|32|64|128|512|1024;
|
constexpr uint32_t kAll = 1|2|4|8|16|32|64|128|512|1024;
|
||||||
if ((qInfo->allowableRace & kAll) != kAll) {
|
if ((qInfo->allowableRace & kAll) != kAll) {
|
||||||
int mc = 0;
|
int mc = 0;
|
||||||
|
|
@ -3377,18 +3362,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemQueryResponseData& info,
|
||||||
|
|
||||||
// Class restriction (e.g. "Classes: Paladin, Warrior")
|
// Class restriction (e.g. "Classes: Paladin, Warrior")
|
||||||
if (info.allowableClass != 0) {
|
if (info.allowableClass != 0) {
|
||||||
static const struct { uint32_t mask; const char* name; } kClasses[] = {
|
const auto& kClasses = ui::kClassMasks;
|
||||||
{ 1, "Warrior" },
|
|
||||||
{ 2, "Paladin" },
|
|
||||||
{ 4, "Hunter" },
|
|
||||||
{ 8, "Rogue" },
|
|
||||||
{ 16, "Priest" },
|
|
||||||
{ 32, "Death Knight" },
|
|
||||||
{ 64, "Shaman" },
|
|
||||||
{ 128, "Mage" },
|
|
||||||
{ 256, "Warlock" },
|
|
||||||
{ 1024, "Druid" },
|
|
||||||
};
|
|
||||||
// Count matching classes
|
// Count matching classes
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
for (const auto& kc : kClasses)
|
for (const auto& kc : kClasses)
|
||||||
|
|
@ -3417,18 +3391,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemQueryResponseData& info,
|
||||||
|
|
||||||
// Race restriction (e.g. "Races: Night Elf, Human")
|
// Race restriction (e.g. "Races: Night Elf, Human")
|
||||||
if (info.allowableRace != 0) {
|
if (info.allowableRace != 0) {
|
||||||
static const struct { uint32_t mask; const char* name; } kRaces[] = {
|
const auto& kRaces = ui::kRaceMasks;
|
||||||
{ 1, "Human" },
|
|
||||||
{ 2, "Orc" },
|
|
||||||
{ 4, "Dwarf" },
|
|
||||||
{ 8, "Night Elf" },
|
|
||||||
{ 16, "Undead" },
|
|
||||||
{ 32, "Tauren" },
|
|
||||||
{ 64, "Gnome" },
|
|
||||||
{ 128, "Troll" },
|
|
||||||
{ 512, "Blood Elf" },
|
|
||||||
{ 1024, "Draenei" },
|
|
||||||
};
|
|
||||||
constexpr uint32_t kAllPlayable = 1|2|4|8|16|32|64|128|512|1024;
|
constexpr uint32_t kAllPlayable = 1|2|4|8|16|32|64|128|512|1024;
|
||||||
// Only show if not all playable races are allowed
|
// Only show if not all playable races are allowed
|
||||||
if ((info.allowableRace & kAllPlayable) != kAllPlayable) {
|
if ((info.allowableRace & kAllPlayable) != kAllPlayable) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue