|
|
|
|
@ -87,8 +87,6 @@ namespace lunarium { namespace editor
|
|
|
|
|
if (ImGui::TreeNode("World Root"))
|
|
|
|
|
{
|
|
|
|
|
// List all world entities
|
|
|
|
|
// This will fail if we end up implementing child entities
|
|
|
|
|
// In that case this needs to become recursive
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (auto iter = mpWorld->EntitiesBegin(); !mpWorld->EntitiesIsEnd(iter); iter++, idx++)
|
|
|
|
|
{
|
|
|
|
|
@ -117,6 +115,35 @@ namespace lunarium { namespace editor
|
|
|
|
|
bool was_right_clicked = false;
|
|
|
|
|
if (ImGui::TreeNode(pEnt->GetName().c_str()))
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::BeginDragDropSource())
|
|
|
|
|
{
|
|
|
|
|
// Need to pass a pointer to the payload data. This means we need to pass a
|
|
|
|
|
// pointer to the Entity pointer (Entity**) which &(*pEnt) becomes
|
|
|
|
|
ImGui::SetDragDropPayload("Entity", (void *)&(*pEnt), sizeof(Entity *));
|
|
|
|
|
ImGui::Text("%s", pEnt->GetName().c_str());
|
|
|
|
|
ImGui::EndDragDropSource();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginDragDropTarget())
|
|
|
|
|
{
|
|
|
|
|
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("Entity"))
|
|
|
|
|
{
|
|
|
|
|
Entity* pDroppedEnt = *((Entity**) payload->Data);
|
|
|
|
|
|
|
|
|
|
// Can't drop and entity on itself
|
|
|
|
|
if (pDroppedEnt != pEnt)
|
|
|
|
|
{
|
|
|
|
|
// If the dropped ent is the parent of pEnt then we need to swap the relationship
|
|
|
|
|
|
|
|
|
|
// If the dropped ent is already a child of pEnt then we do nothing
|
|
|
|
|
|
|
|
|
|
// Else add dropped ent as a child of pEnt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndDragDropTarget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
was_clicked = ImGui::IsItemClicked(ImGuiMouseButton_Left);
|
|
|
|
|
was_right_clicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
|
|
|
|
|
|
|
|
|
|
@ -166,6 +193,56 @@ namespace lunarium { namespace editor
|
|
|
|
|
OpenPopup(PopUp::NEW_ENTITY).LogIfFailed(Editor::LogCat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mNewChild)
|
|
|
|
|
{
|
|
|
|
|
if (ImGui::Button("Delete Entity"))
|
|
|
|
|
{
|
|
|
|
|
// 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 patch some relationships
|
|
|
|
|
bool has_parent = false;
|
|
|
|
|
LUUID parent_id = 0;
|
|
|
|
|
if (ToRemove->HasComponent<ParentEntityComponent>())
|
|
|
|
|
{
|
|
|
|
|
// These will be used to patch the children to the grandparent - now the parent
|
|
|
|
|
parent_id = ToRemove->GetComponent<ParentEntityComponent>().Parent;
|
|
|
|
|
has_parent = true;
|
|
|
|
|
|
|
|
|
|
// Tell the parent this child does not exist anymore
|
|
|
|
|
mpWorld->GetEntity(parent_id)->RemoveChild(ToRemove->GetUUID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ToRemove->HasChildren())
|
|
|
|
|
{
|
|
|
|
|
auto children = ToRemove->GetChildren();
|
|
|
|
|
for (LUUID child : children)
|
|
|
|
|
{
|
|
|
|
|
// Clear the parent for each child
|
|
|
|
|
mpWorld->GetEntity(child)->ClearParent();
|
|
|
|
|
|
|
|
|
|
if (has_parent)
|
|
|
|
|
{
|
|
|
|
|
// Make the grandparent the new parent (if there is a grandparent)
|
|
|
|
|
mpWorld->GetEntity(parent_id)->AddChild(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Relationships are all patched so finally remove the entity
|
|
|
|
|
mpWorld->RemoveEntity(ToRemove->GetUUID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("Delete Hierarchy"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|