WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
MountsPanel.cpp
Go to the documentation of this file.
1#include "MountsPanel.h"
2
3#include <cassert>
4
5#include "imgui.h"
6#include "imgui_stdlib.h"
7
8#include <format>
9
10namespace MountsPanel
11{
12
13void draw(DrawContext& ctx)
14{
15 assert(ctx.mountList && "DrawContext::mountList must not be null");
16 assert(ctx.mountFiltered && "DrawContext::mountFiltered must not be null");
17 assert(ctx.mountSearchBuf && "DrawContext::mountSearchBuf must not be null");
18 assert(ctx.mountTab && "DrawContext::mountTab must not be null");
19
20 WoWModel* cModel = ctx.getLoadedModel ? ctx.getLoadedModel() : nullptr;
21 if (cModel && ctx.isChar)
22 {
23 if (ctx.buildMountList)
24 ctx.buildMountList(); // lazy init on first frame
25
26 if (ctx.isMounted)
27 {
28 ImGui::TextColored(ImVec4(0.4f, 1.0f, 0.4f, 1.0f), "Mounted");
29 if (ImGui::Button("Dismount", ImVec2(-1, 0)))
30 {
31 if (ctx.dismountCharacter)
33 }
34 }
35 else
36 {
37 if (ImGui::BeginTabBar("##MountTabs"))
38 {
39 int prevTab = ctx.mountTab ? *ctx.mountTab : 0;
40
41 if (ImGui::BeginTabItem("Player Mounts"))
42 {
43 if (ctx.mountTab) *ctx.mountTab = 0;
44 ImGui::EndTabItem();
45 }
46 if (ImGui::BeginTabItem("Creature Models"))
47 {
48 if (ctx.mountTab) *ctx.mountTab = 1;
49 ImGui::EndTabItem();
50 }
51 ImGui::EndTabBar();
52
53 if (ctx.mountTab && *ctx.mountTab != prevTab)
54 {
55 if (ctx.mountFilterDirty) *ctx.mountFilterDirty = true;
56 if (ctx.mountSearchBuf) ctx.mountSearchBuf->clear();
57 }
58 }
59
60 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 60.0f);
61 if (ImGui::InputText("##mountSearch", ctx.mountSearchBuf,
62 ImGuiInputTextFlags_EnterReturnsTrue))
63 {
64 if (ctx.mountFilterDirty) *ctx.mountFilterDirty = true;
65 }
66 ImGui::SameLine();
67 if (ImGui::Button("Apply##mount", ImVec2(-1, 0)))
68 {
69 if (ctx.mountFilterDirty) *ctx.mountFilterDirty = true;
70 }
71
74
75 if (ctx.mountFiltered)
76 ImGui::Text("%d entries", static_cast<int>(ctx.mountFiltered->size()));
77 ImGui::Separator();
78
79 ImGui::BeginChild("##MountList", ImVec2(0, 0), ImGuiChildFlags_Borders);
80 if (ctx.mountFiltered)
81 {
82 ImGuiListClipper clipper;
83 clipper.Begin(static_cast<int>(ctx.mountFiltered->size()));
84 while (clipper.Step())
85 {
86 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
87 {
88 size_t idx = (*ctx.mountFiltered)[i];
89 ImGui::PushID(static_cast<int>(idx));
90
91 int tab = ctx.mountTab ? *ctx.mountTab : 0;
92 if (tab == 0 && ctx.mountList)
93 {
94 const auto& me = (*ctx.mountList)[idx];
95 std::string label = std::format("{} (DisplayID:{})", me.name, me.displayID);
96 if (ImGui::Selectable(label.c_str()))
97 {
98 if (ctx.mountCharacter)
99 ctx.mountCharacter(me.displayID, nullptr);
100 }
101 }
102 else if (ctx.creatureModelNames && ctx.creatureModels)
103 {
104 if (ImGui::Selectable((*ctx.creatureModelNames)[idx].c_str()))
105 {
106 if (ctx.mountCharacter)
107 ctx.mountCharacter(-1, (*ctx.creatureModels)[idx]);
108 }
109 }
110
111 ImGui::PopID();
112 }
113 }
114 }
115 ImGui::EndChild();
116 }
117 }
118 else
119 {
120 ImGui::TextDisabled("Load a character model first.");
121 }
122}
123
124} // namespace MountsPanel
Core WoW .m2 model: geometry, animation, textures, and character data.
Definition WoWModel.h:50
ImGui panel for mounting and dismounting characters.
void draw(DrawContext &ctx)
Per-frame context for the mounts panel.
Definition MountsPanel.h:23
std::vector< GameFile * > * creatureModels
Definition MountsPanel.h:29
std::function< WoWModel *()> getLoadedModel
Definition MountsPanel.h:35
std::function< void()> dismountCharacter
Definition MountsPanel.h:39
std::string * mountSearchBuf
Definition MountsPanel.h:33
std::function< void()> buildMountList
Definition MountsPanel.h:36
std::function< void()> rebuildMountFilter
Definition MountsPanel.h:37
std::vector< size_t > * mountFiltered
Definition MountsPanel.h:30
std::function< void(int, GameFile *)> mountCharacter
Definition MountsPanel.h:38
std::vector< std::string > * creatureModelNames
Definition MountsPanel.h:28
std::vector< MountEntry > * mountList
Definition MountsPanel.h:27