Begin render Stage Slate.
Search String.
Begin render entity (tree)list.
0: NoSort, 1: Ascending, 2: Descending.
Add select entity.
Remove select entity.
Set a select entity.
remove source from source's parent.
Search Filter here.
Begin render add entity panel.
End render Visualizer.
Begin render Stage Slate.
Search String.
Begin render entity (tree)list.
0: NoSort, 1: Ascending, 2: Descending.
Add select entity.
Remove select entity.
Set a select entity.
remove source from source's parent.
Search Filter here.
Begin render add entity panel.
End render Visualizer.
27 {
29
34
38 static std::string searchString;
39 static bool isEnableSearch = false;
40
44 {
46
47 ImGui::Spacing();
48 ImGui::Spacing();
50 static char search[256] = {};
51 if (ImGui::InputTextWithHint(
"##",
ICON_TEXT(ICON_MD_SEARCH, Search), search, 128))
52 {
53 searchString = std::string(search);
54 if (searchString.size() == 0) isEnableSearch = false;
55 else isEnableSearch = true;
56 }
57 ImGui::PopItemWidth();
58
63 ImGui::Spacing();
64 }
65
69 {
71
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;
76
80 static int sortState = 0;
81
82 static std::function<void(
bool, Entity, uint32_t)> ClickSelect = [&](
bool selected, Entity& entity, uint32_t
e) {
83
84 if (ImGui::IsItemHovered() && ImGui::IsItemClicked(ImGuiMouseButton_Left))
85 {
86 auto& tagComp = entity.GetComponent<TagComponent>();
87
88 if (ImGui::GetIO().KeyShift)
89 {
90 if (!selected)
91 {
96 }
97 }
98 else if (ImGui::GetIO().KeyCtrl)
99 {
100 if (selected)
101 {
106 }
107 }
108 else
109 {
115 }
116 }
117 };
118
119 static std::function<void(uint32_t, uint32_t, uint32_t)> DragDrop = [&](uint32_t
e, uint32_t p, uint32_t depth) {
120
121 if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_AcceptNoDrawDefaultRect))
122 {
123 ImGui::SetDragDropPayload("Stage_Drag", &e, sizeof(e), ImGuiCond_Once);
124 ImGui::EndDragDropSource();
125
126 if (depth > 0)
127 {
129
134 EntityComponent&
comp = parent.GetComponent<EntityComponent>();
135 comp.RemoveEntity(e);
136 if (
comp.GetEntities().empty())
137 {
138 parent.RemoveComponent<EntityComponent>();
139 }
140 });
141 }
142 }
143 if (ImGui::BeginDragDropTarget())
144 {
145 if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("Stage_Drag"))
146 {
147 uint32_t sourceEntity = *(uint32_t*)payload->Data;
148
150
154 Entity((entt::entity)e,
FrameInfo::Get().m_World.get()).AddComponent<EntityComponent>().AddEntity(sourceEntity);
155
156 });
157 }
158 ImGui::EndDragDropTarget();
159 }
160 };
161
162 static std::function<void(uint32_t, uint32_t, uint32_t)> DrawStageTree = [&](uint32_t
e, uint32_t p, uint32_t depth) {
163
165
166 auto& tagComp = entity.GetComponent<TagComponent>();
167 bool hasChild = entity.HasComponent<EntityComponent>();
168
172 if (isEnableSearch)
173 {
174 if ((*tagComp.GetTag().begin()).find(searchString) == std::string::npos)
175 {
176 if (hasChild)
177 {
178 auto& entityComp = entity.GetComponent<EntityComponent>();
179 for (auto& child : entityComp.GetEntities())
180 {
181 DrawStageTree(child, e, depth + 1);
182 }
183 }
184
185 return;
186 }
187 }
188
189 std::stringstream ss;
190 ss << (*tagComp.GetTag().begin()).c_str() << "##" << (uint32_t)entity;
191
192 ImGui::PushID(ss.str().c_str());
193
194 ImGui::TableNextRow();
195 ImGui::TableNextColumn();
196
197 ImGuiTreeNodeFlags tree_node_flags = 0;
199 if (item_is_selected)
200 {
201 tree_node_flags |= ImGuiTreeNodeFlags_Selected;
202 }
203
204 std::stringstream space;
205 for (int i = 0; i < depth; i++)
206 {
207 space << " ";
208 }
209 ImGui::Text(space.str().c_str());
210 ImGui::SameLine();
211
212 if (hasChild)
213 {
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();
219 ImGui::TableNextColumn();
220 ImGui::Text("Entity");
221 if (open)
222 {
223 auto& entityComp = entity.GetComponent<EntityComponent>();
224 for (auto& child : entityComp.GetEntities())
225 {
226 DrawStageTree(child, e, depth + 1);
227 }
228
229 ImGui::TreePop();
230 }
231 }
232 else
233 {
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();
239 ImGui::TableNextColumn();
240 ImGui::Text("Entity");
241 }
242
243 ImGui::PopID();
244 };
245
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));
251
252 if (ImGui::BeginTable("EntityTree", 3, flags))
253 {
254
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();
259
260
261 if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs())
262 {
263
264 if (sort_specs->SpecsDirty)
265 {
266 sortState = 0;
267
268
269 if (sort_specs->SpecsCount > 0)
270 {
271 sortState = sort_specs->Specs->SortDirection;
272 }
273
274 sort_specs->SpecsDirty = false;
275 }
276 }
277
279 DrawStageTree(entity, 0, 0);
280 });
281
285 {
287
288 if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight))
289 {
290 if (ImGui::MenuItem("Create Empty Entity"))
291 {
293
295
296 });
297 }
298 ImGui::EndPopup();
299 }
300 }
301
302 ImGui::EndTable();
303 }
304 ImGui::PopStyleColor(4);
305 ImGui::PopStyleVar();
306 }
307
312 }
#define ICON_TEXT(icon, text)
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
static FrameInfo & Get()
Get FrameInfo.
std::shared_ptr< World > m_World
The shared pointer of specific world.
scl::linked_unordered_map< int, std::string > m_PickEntityID
static ImVec2 GetLineItemSize()
Get Line Width's Square Size.
void Begin(float alpha=1.0f, ImGuiWindowFlags flags=0)
Begin a common slate.
FrameInfo & m_FrameInfo
The FrameData reference.
ImVec2 m_PanelSize
This slate's size.
void erase(const K &key)
Remove a element inside the container if founded by key.
void clear()
Clear this container's data.
void push_back(const K &key, const V &value)
Add a element to this container.
bool has_key(const K &key)
Determine whether the key is in the container.
static auto AsyncTask(ThreadPoolEnum pool, F &&func, Args &&... args) -> std::future< decltype(func(std::forward< Args >(args)...))>