Delete entity hierarchy working

master
Joey Pollack 3 years ago
parent 7e41b4d259
commit c5ef8805db

@ -23,7 +23,7 @@ namespace lunarium { namespace editor
mpEditor(editor),
// TODO: Temp world created here
mpWorld(nullptr),
mpSelectedEntity(nullptr), mNewChild(false), mParentEnt(nullptr)
mpSelectedEntity(nullptr), mNewChild(false), mParentEnt(nullptr), mCMenuOpen(false)
{
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
{
@ -196,6 +196,7 @@ namespace lunarium { namespace editor
if (mNewChild)
{
mCMenuOpen = true;
if (ImGui::Button("Delete Entity"))
{
// mParentEnt is the entity that was right-clicked on
@ -238,13 +239,64 @@ namespace lunarium { namespace editor
mpWorld->RemoveEntity(ToRemove->GetUUID());
}
if (ImGui::Button("Delete Hierarchy"))
if (ImGui::Button("Delete Entity Hierarchy"))
{
// mParentEnt is the entity that was right-clicked on
// Lets give it a less confusing name for this context
Entity *ToRemove = mParentEnt;
// Give the editor a chance to clean up any refs to this entity
mpEditor->OnEntityDelete(ToRemove);
// If this entity has a parent we need to tell it we don't exist anymore
LUUID parent_id = 0;
if (ToRemove->HasComponent<ParentEntityComponent>())
{
parent_id = ToRemove->GetComponent<ParentEntityComponent>().Parent;
mpWorld->GetEntity(parent_id)->RemoveChild(ToRemove->GetUUID());
}
if (ToRemove->HasChildren())
{
// Recursively remove all children
auto children = ToRemove->GetChildren();
for (LUUID child : children)
{
RecursiveEntDelete(mpWorld->GetEntity(child));
}
}
// All children are removed so remove the entity
mpWorld->RemoveEntity(ToRemove->GetUUID());
}
}
ImGui::EndPopup();
}
else if (mNewChild && mCMenuOpen)
{
mNewChild = false;
mCMenuOpen = false;
mParentEnt = nullptr;
}
}
void WorldTree::RecursiveEntDelete(Entity* pe)
{
mpEditor->OnEntityDelete(pe);
if (pe->HasChildren())
{
auto children = pe->GetChildren();
for (LUUID child : children)
{
RecursiveEntDelete(mpWorld->GetEntity(child));
}
}
mpWorld->RemoveEntity(pe->GetUUID());
}
}}

@ -34,6 +34,7 @@ namespace editor
lunarium::World* mpWorld;
Editor* mpEditor;
Entity* mpSelectedEntity;
bool mCMenuOpen;
// Helpers
void ShowEntity(Entity* pEnt);
@ -43,6 +44,7 @@ namespace editor
void HandlePopupEvents();
void PopupNewEntity();
void RecursiveEntDelete(Entity* pe);
private: // POPUP ENUMS

Loading…
Cancel
Save