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
11
namespace
NpcBrowserPanel
12
{
13
14
void
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
NpcBrowserPanel.h
database.h
NpcBrowserPanel
ImGui panel for browsing and loading NPC models.
Definition
NpcBrowserPanel.cpp:12
NpcBrowserPanel::draw
void draw(DrawContext &ctx)
Definition
NpcBrowserPanel.cpp:14
NpcBrowserPanel::DrawContext
Per-frame context for the NPC browser panel.
Definition
NpcBrowserPanel.h:15
NpcBrowserPanel::DrawContext::isDBReady
bool isDBReady
Definition
NpcBrowserPanel.h:17
NpcBrowserPanel::DrawContext::npcFiltered
std::vector< size_t > * npcFiltered
Definition
NpcBrowserPanel.h:20
NpcBrowserPanel::DrawContext::npcs
const std::vector< NPCRecord > * npcs
Definition
NpcBrowserPanel.h:19
NpcBrowserPanel::DrawContext::isWoWLoaded
bool isWoWLoaded
Definition
NpcBrowserPanel.h:16
NpcBrowserPanel::DrawContext::npcFilterDirty
bool * npcFilterDirty
Definition
NpcBrowserPanel.h:21
NpcBrowserPanel::DrawContext::npcSearchBuf
std::string * npcSearchBuf
Definition
NpcBrowserPanel.h:22
NpcBrowserPanel::DrawContext::rebuildNpcFilter
std::function< void()> rebuildNpcFilter
Definition
NpcBrowserPanel.h:24
NpcBrowserPanel::DrawContext::loadNPC
std::function< void(unsigned int)> loadNPC
Definition
NpcBrowserPanel.h:25
Source
App
Panels
NpcBrowserPanel.cpp
Generated by
1.9.8