WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
ItemBrowserPanel.cpp
Go to the documentation of this file.
1#include "ItemBrowserPanel.h"
2
3#include <cassert>
4
5#include "imgui.h"
6#include "imgui_stdlib.h"
7#include "database.h"
8
9#include <format>
10
12{
13
14namespace
15{
16
17ImVec4 getQualityColor(int quality)
18{
19 switch (quality)
20 {
21 case 0: return ImVec4(0.616f, 0.616f, 0.616f, 1.0f); // Poor (gray)
22 case 1: return ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // Common (white)
23 case 2: return ImVec4(0.118f, 1.0f, 0.0f, 1.0f); // Uncommon (green)
24 case 3: return ImVec4(0.0f, 0.439f, 0.867f, 1.0f); // Rare (blue)
25 case 4: return ImVec4(0.639f, 0.208f, 0.933f, 1.0f); // Epic (purple)
26 case 5: return ImVec4(1.0f, 0.502f, 0.0f, 1.0f); // Legendary (orange)
27 case 6:
28 case 7: return ImVec4(0.898f, 0.8f, 0.502f, 1.0f); // Artifact/Heirloom (gold)
29 default: return ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
30 }
31}
32
33} // anonymous namespace
34
35void draw(DrawContext& ctx)
36{
37 assert(ctx.items && "DrawContext::items must not be null");
38 assert(ctx.itemBrowseFiltered && "DrawContext::itemBrowseFiltered must not be null");
39 assert(ctx.itemBrowseSearchBuf && "DrawContext::itemBrowseSearchBuf must not be null");
40
41 if (!ctx.isWoWLoaded || !ctx.isDBReady)
42 {
43 ImGui::TextDisabled("Game not loaded.");
44 return;
45 }
46
47 ImGui::Text("Search:");
48 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 60.0f);
49 if (ImGui::InputText("##itemBrowseSearch", ctx.itemBrowseSearchBuf,
50 ImGuiInputTextFlags_EnterReturnsTrue))
51 {
53 }
54 ImGui::SameLine();
55 if (ImGui::Button("Apply##itembrowse", ImVec2(-1, 0)))
56 {
58 }
59
62
63 if (ctx.itemBrowseFiltered)
64 ImGui::Text("%d items", static_cast<int>(ctx.itemBrowseFiltered->size()));
65 ImGui::Separator();
66
67 ImGui::BeginChild("##ItemBrowseList", ImVec2(0, 0), ImGuiChildFlags_None);
68 if (ctx.itemBrowseFiltered && ctx.items)
69 {
70 ImGuiListClipper clipper;
71 clipper.Begin(static_cast<int>(ctx.itemBrowseFiltered->size()));
72 while (clipper.Step())
73 {
74 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
75 {
76 const auto& item = ctx.items->items[(*ctx.itemBrowseFiltered)[i]];
77 ImGui::PushID(static_cast<int>((*ctx.itemBrowseFiltered)[i]));
78 ImVec4 qcol = getQualityColor(item.quality);
79 ImGui::PushStyleColor(ImGuiCol_Text, qcol);
80 std::string label = std::format("{} ({})", item.name, item.id);
81 if (ImGui::Selectable(label.c_str()))
82 {
83 if (ctx.loadItemModel)
84 ctx.loadItemModel(static_cast<unsigned int>(item.id));
85 }
86 ImGui::PopStyleColor();
87 ImGui::PopID();
88 }
89 }
90 }
91 ImGui::EndChild();
92}
93
94} // namespace ItemBrowserPanel
std::vector< ItemRecord > items
Definition database.h:45
ImGui panel for browsing and loading item models.
void draw(DrawContext &ctx)
Per-frame context for the item browser panel.
std::function< void()> rebuildItemBrowseFilter
std::function< void(unsigned int)> loadItemModel
std::vector< size_t > * itemBrowseFiltered