WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
ItemSetsPanel.cpp
Go to the documentation of this file.
1#include "ItemSetsPanel.h"
2
3#include <cassert>
4
5#include "imgui.h"
6#include "imgui_stdlib.h"
7
8#include <format>
9
11{
12
13void draw(DrawContext& ctx)
14{
15 assert(ctx.itemSets && "DrawContext::itemSets must not be null");
16 assert(ctx.itemSetSearchBuf && "DrawContext::itemSetSearchBuf must not be null");
17 assert(ctx.itemSetFiltered && "DrawContext::itemSetFiltered must not be null");
18 assert(ctx.startOutfitSearchBuf && "DrawContext::startOutfitSearchBuf must not be null");
19 assert(ctx.startOutfitFiltered && "DrawContext::startOutfitFiltered must not be null");
20
21 WoWModel* cModel = ctx.getLoadedModel ? ctx.getLoadedModel() : nullptr;
22 if (!cModel || !ctx.isChar)
23 {
24 ImGui::TextDisabled("Load a character model first.");
25 return;
26 }
27
28 // ---- Item Sets ----
29 if (ctx.buildItemSets)
30 ctx.buildItemSets(); // lazy init on first frame
31
32 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 60.0f);
33 if (ImGui::InputText("##itemSetSearch", ctx.itemSetSearchBuf,
34 ImGuiInputTextFlags_EnterReturnsTrue))
35 {
36 if (ctx.itemSetFilterDirty) *ctx.itemSetFilterDirty = true;
37 }
38 ImGui::SameLine();
39 if (ImGui::Button("Apply##itemset", ImVec2(-1, 0)))
40 {
41 if (ctx.itemSetFilterDirty) *ctx.itemSetFilterDirty = true;
42 }
43
46
47 if (ctx.itemSetFiltered)
48 ImGui::Text("%d sets", static_cast<int>(ctx.itemSetFiltered->size()));
49 ImGui::Separator();
50
51 ImGui::BeginChild("##ItemSetList", ImVec2(0, 200), ImGuiChildFlags_Borders);
52 if (ctx.itemSetFiltered && ctx.itemSets)
53 {
54 ImGuiListClipper clipper;
55 clipper.Begin(static_cast<int>(ctx.itemSetFiltered->size()));
56 while (clipper.Step())
57 {
58 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
59 {
60 const auto& setEntry = (*ctx.itemSets)[(*ctx.itemSetFiltered)[i]];
61 ImGui::PushID(setEntry.id);
62 std::string label = std::format("{} (ID:{})", setEntry.name, setEntry.id);
63 if (ImGui::Selectable(label.c_str()))
64 {
65 if (ctx.applyItemSet)
66 ctx.applyItemSet(cModel, setEntry.id);
67 }
68 ImGui::PopID();
69 }
70 }
71 }
72 ImGui::EndChild();
73
74 // ---- Start Outfits ----
75 ImGui::SeparatorText("Start Outfits");
76
78 ctx.buildStartOutfits(cModel);
79
80 if (ctx.startOutfits && ctx.startOutfits->empty())
81 {
82 ImGui::TextDisabled("No start outfits available for this race/sex.");
83 return;
84 }
85
86 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 60.0f);
87 if (ImGui::InputText("##startOutfitSearch", ctx.startOutfitSearchBuf,
88 ImGuiInputTextFlags_EnterReturnsTrue))
89 {
91 }
92 ImGui::SameLine();
93 if (ImGui::Button("Apply##startoutfit", ImVec2(-1, 0)))
94 {
96 }
97
100
101 if (ctx.startOutfitFiltered)
102 ImGui::Text("%d classes", static_cast<int>(ctx.startOutfitFiltered->size()));
103 ImGui::Separator();
104
105 ImGui::BeginChild("##StartOutfitList", ImVec2(0, 150), ImGuiChildFlags_Borders);
106 if (ctx.startOutfitFiltered && ctx.startOutfits)
107 {
108 ImGuiListClipper clipper;
109 clipper.Begin(static_cast<int>(ctx.startOutfitFiltered->size()));
110 while (clipper.Step())
111 {
112 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
113 {
114 const auto& entry = (*ctx.startOutfits)[(*ctx.startOutfitFiltered)[i]];
115 ImGui::PushID(entry.id);
116 std::string label = std::format("{} (ID:{})", entry.name, entry.id);
117 if (ImGui::Selectable(label.c_str()))
118 {
119 if (ctx.applyStartOutfit)
120 ctx.applyStartOutfit(cModel, entry.id);
121 }
122 ImGui::PopID();
123 }
124 }
125 }
126 ImGui::EndChild();
127}
128
129} // namespace ItemSetsPanel
Core WoW .m2 model: geometry, animation, textures, and character data.
Definition WoWModel.h:50
ImGui panel for applying pre-defined item sets and start outfits.
void draw(DrawContext &ctx)
Per-frame context for the item sets panel.
std::function< void(WoWModel *, int)> applyStartOutfit
std::function< void()> rebuildItemSetFilter
std::vector< size_t > * startOutfitFiltered
std::function< void(WoWModel *, int)> applyItemSet
std::vector< ItemSetEntry > * itemSets
std::function< void(WoWModel *)> buildStartOutfits
std::vector< size_t > * itemSetFiltered
std::function< WoWModel *()> getLoadedModel
std::vector< StartOutfitEntry > * startOutfits
std::string * startOutfitSearchBuf
std::function< void()> buildItemSets
std::function< void()> rebuildStartOutfitFilter