|
|
|
@ -23,7 +23,7 @@ namespace lunarium { namespace editor
|
|
|
|
mpEditor(editor),
|
|
|
|
mpEditor(editor),
|
|
|
|
// TODO: Temp world created here
|
|
|
|
// TODO: Temp world created here
|
|
|
|
mpWorld(nullptr),
|
|
|
|
mpWorld(nullptr),
|
|
|
|
mpSelectedEntity(nullptr), mNewChild(false), mParentEnt(nullptr)
|
|
|
|
mpSelectedEntity(nullptr), mNewChild(false), mParentEnt(nullptr), mCMenuOpen(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
|
|
|
|
AddPopup(PopUp::NEW_ENTITY, "New Entity", [](Panel *p)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -196,6 +196,7 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
|
|
if (mNewChild)
|
|
|
|
if (mNewChild)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
mCMenuOpen = true;
|
|
|
|
if (ImGui::Button("Delete Entity"))
|
|
|
|
if (ImGui::Button("Delete Entity"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// mParentEnt is the entity that was right-clicked on
|
|
|
|
// mParentEnt is the entity that was right-clicked on
|
|
|
|
@ -238,13 +239,64 @@ namespace lunarium { namespace editor
|
|
|
|
mpWorld->RemoveEntity(ToRemove->GetUUID());
|
|
|
|
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();
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
}}
|