2
3
4
5
10#include "Core/Library/StringLibrary.h"
11#include "World/World/World.h"
12#include "World/Entity.h"
13#include "World/Components/EntityComponent.h"
14#include "Core/Input/Input.h"
15#include "Core/Thread/ThreadModel.h"
20 const std::string& panelName ,
31
32
36
37
38 static std::string searchString;
39 static bool isEnableSearch =
false;
42
43
49 ImGui::PushItemWidth(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 2.0f - ImGui::GetStyle().WindowPadding.x);
50 static char search[256] = {};
51 if (ImGui::InputTextWithHint(
"##",
ICON_TEXT(ICON_MD_SEARCH, Search), search, 128))
53 searchString = std::string(search);
54 if (searchString.size() == 0) isEnableSearch =
false;
55 else isEnableSearch =
true;
57 ImGui::PopItemWidth();
59 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 2.0f);
60 ImGui::Button(ICON_MD_FILTER_ALT, ImGuiH::GetLineItemSize());
61 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 1.0f);
62 ImGui::Button(ICON_MD_REORDER, ImGuiH::GetLineItemSize());
67
68
72 static ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_Resizable | ImGuiTableFlags_NoBordersInBody |
73 ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_SortMulti | ImGuiTableFlags_Hideable |
74 ImGuiTableFlags_ScrollY | ImGuiTableFlags_SortTristate;
75 static constexpr ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap;
78
79
80 static int sortState = 0;
82 static std::function<
void(
bool,
Entity, uint32_t)> ClickSelect = [&](
bool selected, Entity& entity, uint32_t e) {
84 if (ImGui::IsItemHovered() && ImGui::IsItemClicked(ImGuiMouseButton_Left))
86 auto& tagComp = entity.GetComponent<TagComponent>();
88 if (ImGui::GetIO().KeyShift)
93
94
95 m_FrameInfo.m_PickEntityID.push_back((
int)e, (*tagComp.GetTag().begin()));
98 else if (ImGui::GetIO().KeyCtrl)
103
104
105 m_FrameInfo.m_PickEntityID.erase((
int)e);
111
112
113 m_FrameInfo.m_PickEntityID.clear();
114 m_FrameInfo.m_PickEntityID.push_back((
int)e, (*tagComp.GetTag().begin()));
119 static std::function<
void(uint32_t, uint32_t, uint32_t)> DragDrop = [&](uint32_t e, uint32_t p, uint32_t depth) {
121 if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_AcceptNoDrawDefaultRect))
123 ImGui::SetDragDropPayload(
"Stage_Drag", &e,
sizeof(e), ImGuiCond_Once);
124 ImGui::EndDragDropSource();
128 AsyncTask(ThreadPoolEnum::Game, [=]() {
131
132
133 Entity parent((entt::entity)p, FrameInfo::Get().m_World.get());
134 EntityComponent& comp = parent.GetComponent<EntityComponent>();
135 comp.RemoveEntity(e);
136 if (comp.GetEntities().empty())
138 parent.RemoveComponent<EntityComponent>();
143 if (ImGui::BeginDragDropTarget())
145 if (
const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(
"Stage_Drag"))
147 uint32_t sourceEntity = *(uint32_t*)payload->Data;
149 AsyncTask(ThreadPoolEnum::Game, [=]() {
152
153
154 Entity((entt::entity)e, FrameInfo::Get().m_World.get()).AddComponent<EntityComponent>().AddEntity(sourceEntity);
158 ImGui::EndDragDropTarget();
162 static std::function<
void(uint32_t, uint32_t, uint32_t)> DrawStageTree = [&](uint32_t e, uint32_t p, uint32_t depth) {
164 Entity entity((entt::entity)e, FrameInfo::Get().m_World.get());
166 auto& tagComp = entity.GetComponent<TagComponent>();
167 bool hasChild = entity.HasComponent<EntityComponent>();
170
171
174 if ((*tagComp.GetTag().begin()).find(searchString) == std::string::npos)
178 auto& entityComp = entity.GetComponent<EntityComponent>();
179 for (
auto& child : entityComp.GetEntities())
181 DrawStageTree(child, e, depth + 1);
189 std::stringstream ss;
190 ss << (*tagComp.GetTag().begin()).c_str() <<
"##" << (uint32_t)entity;
192 ImGui::PushID(ss.str().c_str());
194 ImGui::TableNextRow();
195 ImGui::TableNextColumn();
197 ImGuiTreeNodeFlags tree_node_flags = 0;
198 const bool item_is_selected = m_FrameInfo.m_PickEntityID.has_key((
int)e);
199 if (item_is_selected)
201 tree_node_flags |= ImGuiTreeNodeFlags_Selected;
204 std::stringstream space;
205 for (
int i = 0; i < depth; i++)
209 ImGui::Text(space.str().c_str());
214 bool open = ImGui::TreeNodeEx(ss.str().c_str(), tree_node_flags);
215 ClickSelect(item_is_selected, entity, e);
216 DragDrop(e, p, depth);
217 ImGui::TableNextColumn();
218 ImGui::Button(ICON_MD_REMOVE_RED_EYE, ImGuiH::GetLineItemSize());
219 ImGui::TableNextColumn();
220 ImGui::Text(
"Entity");
223 auto& entityComp = entity.GetComponent<EntityComponent>();
224 for (
auto& child : entityComp.GetEntities())
226 DrawStageTree(child, e, depth + 1);
234 ImGui::TreeNodeEx(ss.str().c_str(), tree_node_flags | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Leaf);
235 ClickSelect(item_is_selected, entity, e);
236 DragDrop(e, p, depth);
237 ImGui::TableNextColumn();
238 ImGui::Button(ICON_MD_REMOVE_RED_EYE, ImGuiH::GetLineItemSize());
239 ImGui::TableNextColumn();
240 ImGui::Text(
"Entity");
246 ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 0.0f);
247 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
248 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
249 ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
250 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
252 if (ImGui::BeginTable(
"EntityTree", 3, flags))
255 ImGui::TableSetupColumn(
"Name", ImGuiTableColumnFlags_NoHide);
256 ImGui::TableSetupColumn(ICON_MD_REMOVE_RED_EYE, ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_NoResize, ImGuiH::GetLineItemSize().x);
257 ImGui::TableSetupColumn(
"Type", ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_NoResize, ImGuiH::GetLineItemSize().x * 3.0f);
258 ImGui::TableHeadersRow();
261 if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs())
264 if (sort_specs->SpecsDirty)
269 if (sort_specs->SpecsCount > 0)
271 sortState = sort_specs->Specs->SortDirection;
274 sort_specs->SpecsDirty =
false;
279 DrawStageTree(entity, 0, 0);
283
284
288 if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
290 if (ImGui::MenuItem(
"Create Empty Entity"))
292 AsyncTask(ThreadPoolEnum::Game, [=]() {
304 ImGui::PopStyleColor(4);
305 ImGui::PopStyleVar();
309
310
#define ICON_TEXT(icon, text)
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
Entity Class. This class defines the specific behaves of Entity.
static FrameInfo & Get()
Get FrameInfo.
FrameInfo Class. This class defines the FrameInfo data.
ImguiSlate(const std::string &panelName, FrameInfo &frameInfo)
Constructor Function. Init with Slate's name.
This Class defines the basic behaves of specific slate. When we add an new Slate, we need inherit fro...
virtual void OnRender() override
This interface is called On SlateRenderer Render.
ImguiStage(const std::string &panelName, FrameInfo &frameInfo)
Constructor Function.
The ImguiStage Class. This class defines how to render a Stage.