WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
NpcBrowserPanel.cpp
Go to the documentation of this file.
1#include "NpcBrowserPanel.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
14void draw(DrawContext& ctx)
15{
16 assert(ctx.npcs && "DrawContext::npcs must not be null");
17 assert(ctx.npcFiltered && "DrawContext::npcFiltered must not be null");
18 assert(ctx.npcSearchBuf && "DrawContext::npcSearchBuf must not be null");
19
20 if (!ctx.isWoWLoaded || !ctx.isDBReady)
21 {
22 ImGui::TextDisabled("Game not loaded.");
23 return;
24 }
25
26 ImGui::Text("Search:");
27 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 60.0f);
28 if (ImGui::InputText("##npcSearch", ctx.npcSearchBuf,
29 ImGuiInputTextFlags_EnterReturnsTrue))
30 {
31 if (ctx.npcFilterDirty) *ctx.npcFilterDirty = true;
32 }
33 ImGui::SameLine();
34 if (ImGui::Button("Apply##npc", ImVec2(-1, 0)))
35 {
36 if (ctx.npcFilterDirty) *ctx.npcFilterDirty = true;
37 }
38
39 if (ctx.npcFilterDirty && *ctx.npcFilterDirty && ctx.rebuildNpcFilter)
40 ctx.rebuildNpcFilter();
41
42 if (ctx.npcFiltered)
43 ImGui::Text("%d NPCs", static_cast<int>(ctx.npcFiltered->size()));
44 ImGui::Separator();
45
46 ImGui::BeginChild("##NpcList", ImVec2(0, 0), ImGuiChildFlags_None);
47 if (ctx.npcFiltered && ctx.npcs)
48 {
49 ImGuiListClipper clipper;
50 clipper.Begin(static_cast<int>(ctx.npcFiltered->size()));
51 while (clipper.Step())
52 {
53 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
54 {
55 const auto& npc = (*ctx.npcs)[(*ctx.npcFiltered)[i]];
56 ImGui::PushID(static_cast<int>((*ctx.npcFiltered)[i]));
57 std::string label = std::format("{} (ID:{} Type:{})", npc.name, npc.id, npc.type);
58 if (ImGui::Selectable(label.c_str()))
59 {
60 if (ctx.loadNPC)
61 ctx.loadNPC(static_cast<unsigned int>(npc.id));
62 }
63 ImGui::PopID();
64 }
65 }
66 }
67 ImGui::EndChild();
68}
69
70} // namespace NpcBrowserPanel
ImGui panel for browsing and loading NPC models.
void draw(DrawContext &ctx)
Per-frame context for the NPC browser panel.
std::vector< size_t > * npcFiltered
const std::vector< NPCRecord > * npcs
std::function< void()> rebuildNpcFilter
std::function< void(unsigned int)> loadNPC