mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-05 00:33:51 +00:00
refactor: extract getInventorySlotName and renderBindingType into shared UI utils
Add getInventorySlotName() and renderBindingType() to ui_colors.hpp, replacing 3 copies of the 26-case slot name switch (2 inventory_screen + 1 game_screen) and 2 copies of the binding type switch. Removes ~80 lines of duplicate tooltip code.
This commit is contained in:
parent
97b44bf833
commit
7484ce6c2d
3 changed files with 50 additions and 100 deletions
|
|
@ -60,4 +60,49 @@ inline void renderCoinsFromCopper(uint64_t copper) {
|
|||
static_cast<uint32_t>(copper % 100));
|
||||
}
|
||||
|
||||
// ---- Inventory slot name from WoW inventory type ----
|
||||
inline const char* getInventorySlotName(uint32_t inventoryType) {
|
||||
switch (inventoryType) {
|
||||
case 1: return "Head";
|
||||
case 2: return "Neck";
|
||||
case 3: return "Shoulder";
|
||||
case 4: return "Shirt";
|
||||
case 5: return "Chest";
|
||||
case 6: return "Waist";
|
||||
case 7: return "Legs";
|
||||
case 8: return "Feet";
|
||||
case 9: return "Wrist";
|
||||
case 10: return "Hands";
|
||||
case 11: return "Finger";
|
||||
case 12: return "Trinket";
|
||||
case 13: return "One-Hand";
|
||||
case 14: return "Shield";
|
||||
case 15: return "Ranged";
|
||||
case 16: return "Back";
|
||||
case 17: return "Two-Hand";
|
||||
case 18: return "Bag";
|
||||
case 19: return "Tabard";
|
||||
case 20: return "Robe";
|
||||
case 21: return "Main Hand";
|
||||
case 22: return "Off Hand";
|
||||
case 23: return "Held In Off-hand";
|
||||
case 25: return "Thrown";
|
||||
case 26: return "Ranged";
|
||||
case 28: return "Relic";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Binding type display ----
|
||||
inline void renderBindingType(uint32_t bindType) {
|
||||
constexpr ImVec4 kBindColor = {1.0f, 0.82f, 0.0f, 1.0f};
|
||||
switch (bindType) {
|
||||
case 1: ImGui::TextColored(kBindColor, "Binds when picked up"); break;
|
||||
case 2: ImGui::TextColored(kBindColor, "Binds when equipped"); break;
|
||||
case 3: ImGui::TextColored(kBindColor, "Binds when used"); break;
|
||||
case 4: ImGui::TextColored(kBindColor, "Quest Item"); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wowee::ui
|
||||
|
|
|
|||
|
|
@ -1396,34 +1396,7 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) {
|
|||
|
||||
// Slot type
|
||||
if (info->inventoryType > 0) {
|
||||
const char* slotName = "";
|
||||
switch (info->inventoryType) {
|
||||
case 1: slotName = "Head"; break;
|
||||
case 2: slotName = "Neck"; break;
|
||||
case 3: slotName = "Shoulder"; break;
|
||||
case 4: slotName = "Shirt"; break;
|
||||
case 5: slotName = "Chest"; break;
|
||||
case 6: slotName = "Waist"; break;
|
||||
case 7: slotName = "Legs"; break;
|
||||
case 8: slotName = "Feet"; break;
|
||||
case 9: slotName = "Wrist"; break;
|
||||
case 10: slotName = "Hands"; break;
|
||||
case 11: slotName = "Finger"; break;
|
||||
case 12: slotName = "Trinket"; break;
|
||||
case 13: slotName = "One-Hand"; break;
|
||||
case 14: slotName = "Shield"; break;
|
||||
case 15: slotName = "Ranged"; break;
|
||||
case 16: slotName = "Back"; break;
|
||||
case 17: slotName = "Two-Hand"; break;
|
||||
case 18: slotName = "Bag"; break;
|
||||
case 19: slotName = "Tabard"; break;
|
||||
case 20: slotName = "Robe"; break;
|
||||
case 21: slotName = "Main Hand"; break;
|
||||
case 22: slotName = "Off Hand"; break;
|
||||
case 23: slotName = "Held In Off-hand"; break;
|
||||
case 25: slotName = "Thrown"; break;
|
||||
case 26: slotName = "Ranged"; break;
|
||||
}
|
||||
const char* slotName = ui::getInventorySlotName(info->inventoryType);
|
||||
if (slotName[0]) {
|
||||
if (!info->subclassName.empty())
|
||||
ImGui::TextColored(ui::colors::kLightGray, "%s %s", slotName, info->subclassName.c_str());
|
||||
|
|
|
|||
|
|
@ -2562,13 +2562,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I
|
|||
}
|
||||
|
||||
// Binding type
|
||||
switch (item.bindType) {
|
||||
case 1: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Binds when picked up"); break;
|
||||
case 2: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Binds when equipped"); break;
|
||||
case 3: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Binds when used"); break;
|
||||
case 4: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Quest Item"); break;
|
||||
default: break;
|
||||
}
|
||||
ui::renderBindingType(item.bindType);
|
||||
|
||||
if (item.itemId == 6948 && gameHandler_) {
|
||||
uint32_t mapId = 0;
|
||||
|
|
@ -2600,35 +2594,7 @@ void InventoryScreen::renderItemTooltip(const game::ItemDef& item, const game::I
|
|||
|
||||
// Slot type
|
||||
if (item.inventoryType > 0) {
|
||||
const char* slotName = "";
|
||||
switch (item.inventoryType) {
|
||||
case 1: slotName = "Head"; break;
|
||||
case 2: slotName = "Neck"; break;
|
||||
case 3: slotName = "Shoulder"; break;
|
||||
case 4: slotName = "Shirt"; break;
|
||||
case 5: slotName = "Chest"; break;
|
||||
case 6: slotName = "Waist"; break;
|
||||
case 7: slotName = "Legs"; break;
|
||||
case 8: slotName = "Feet"; break;
|
||||
case 9: slotName = "Wrist"; break;
|
||||
case 10: slotName = "Hands"; break;
|
||||
case 11: slotName = "Finger"; break;
|
||||
case 12: slotName = "Trinket"; break;
|
||||
case 13: slotName = "One-Hand"; break;
|
||||
case 14: slotName = "Shield"; break;
|
||||
case 15: slotName = "Ranged"; break;
|
||||
case 16: slotName = "Back"; break;
|
||||
case 17: slotName = "Two-Hand"; break;
|
||||
case 18: slotName = "Bag"; break;
|
||||
case 19: slotName = "Tabard"; break;
|
||||
case 20: slotName = "Robe"; break;
|
||||
case 21: slotName = "Main Hand"; break;
|
||||
case 22: slotName = "Off Hand"; break;
|
||||
case 23: slotName = "Held In Off-hand"; break;
|
||||
case 25: slotName = "Thrown"; break;
|
||||
case 26: slotName = "Ranged"; break;
|
||||
default: slotName = ""; break;
|
||||
}
|
||||
const char* slotName = ui::getInventorySlotName(item.inventoryType);
|
||||
if (slotName[0]) {
|
||||
if (!item.subclassName.empty()) {
|
||||
ImGui::TextColored(ui::colors::kLightGray, "%s %s", slotName, item.subclassName.c_str());
|
||||
|
|
@ -3240,45 +3206,11 @@ void InventoryScreen::renderItemTooltip(const game::ItemQueryResponseData& info,
|
|||
}
|
||||
|
||||
// Binding type
|
||||
switch (info.bindType) {
|
||||
case 1: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Binds when picked up"); break;
|
||||
case 2: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Binds when equipped"); break;
|
||||
case 3: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Binds when used"); break;
|
||||
case 4: ImGui::TextColored(ImVec4(1.0f, 0.82f, 0.0f, 1.0f), "Quest Item"); break;
|
||||
default: break;
|
||||
}
|
||||
ui::renderBindingType(info.bindType);
|
||||
|
||||
// Slot / subclass
|
||||
if (info.inventoryType > 0) {
|
||||
const char* slotName = "";
|
||||
switch (info.inventoryType) {
|
||||
case 1: slotName = "Head"; break;
|
||||
case 2: slotName = "Neck"; break;
|
||||
case 3: slotName = "Shoulder"; break;
|
||||
case 4: slotName = "Shirt"; break;
|
||||
case 5: slotName = "Chest"; break;
|
||||
case 6: slotName = "Waist"; break;
|
||||
case 7: slotName = "Legs"; break;
|
||||
case 8: slotName = "Feet"; break;
|
||||
case 9: slotName = "Wrist"; break;
|
||||
case 10: slotName = "Hands"; break;
|
||||
case 11: slotName = "Finger"; break;
|
||||
case 12: slotName = "Trinket"; break;
|
||||
case 13: slotName = "One-Hand"; break;
|
||||
case 14: slotName = "Shield"; break;
|
||||
case 15: slotName = "Ranged"; break;
|
||||
case 16: slotName = "Back"; break;
|
||||
case 17: slotName = "Two-Hand"; break;
|
||||
case 18: slotName = "Bag"; break;
|
||||
case 19: slotName = "Tabard"; break;
|
||||
case 20: slotName = "Robe"; break;
|
||||
case 21: slotName = "Main Hand"; break;
|
||||
case 22: slotName = "Off Hand"; break;
|
||||
case 23: slotName = "Held In Off-hand"; break;
|
||||
case 25: slotName = "Thrown"; break;
|
||||
case 26: slotName = "Ranged"; break;
|
||||
default: break;
|
||||
}
|
||||
const char* slotName = ui::getInventorySlotName(info.inventoryType);
|
||||
if (slotName[0]) {
|
||||
if (!info.subclassName.empty())
|
||||
ImGui::TextColored(ui::colors::kLightGray, "%s %s", slotName, info.subclassName.c_str());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue