diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index 1b289a90..e2c39ad8 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -45,7 +45,7 @@ namespace SHADE SHEditorWindow::Update(); isAnyNodeSelected = false; - + if (Begin()) { if (skipFrame) @@ -108,6 +108,12 @@ namespace SHADE } } + if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) + { + ParentSelectedEntities(MAX_EID, draggingEntities); + draggingEntities.clear(); + ImGui::ClearDragDrop(); + } ImGui::End(); } @@ -195,7 +201,7 @@ namespace SHADE if (SHDragDrop::BeginSource()) { std::string moveLabel = "Moving EID: "; - static std::vector draggingEntities = editor->selectedEntities; + draggingEntities = editor->selectedEntities; if (!isSelected) { draggingEntities.clear(); @@ -217,7 +223,8 @@ namespace SHADE { if (const std::vector* eidPayload = SHDragDrop::AcceptPayload>(SHDragDrop::DRAG_EID)) //If payload is valid { - ParentSelectedEntities(eid); + ParentSelectedEntities(eid, draggingEntities); + draggingEntities.clear(); SHDragDrop::EndTarget(); } } @@ -255,7 +262,7 @@ namespace SHADE if ((currentNode->GetParent() != sceneGraph.GetRoot()) && ImGui::Selectable(std::format("{} Unparent Selected", ICON_MD_NORTH_WEST).data())) { - ParentSelectedEntities(MAX_EID); + ParentSelectedEntities(MAX_EID, editor->selectedEntities); } ImGui::EndPopup(); } @@ -323,14 +330,16 @@ namespace SHADE SHEntityManager::CreateEntity(MAX_EID, "DefaultChild", parentEID); } - void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID) const noexcept + void SHHierarchyPanel::ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept { auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); - auto const editor = SHSystemManager::GetSystem(); + //auto const editor = SHSystemManager::GetSystem(); SHEntityParentCommand::EntityParentData entityParentData; std::vector parentedEIDS; - for (auto const& eid : editor->selectedEntities) + for (auto const& eid : entities) { + if(eid == parentEID) + continue; if (sceneGraph.GetChild(eid, parentEID) == nullptr) { parentedEIDS.push_back(eid); diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h index 9b26e9d6..64f841d6 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.h @@ -28,7 +28,7 @@ namespace SHADE void DrawMenuBar() const noexcept; ImRect RecursivelyDrawEntityNode(SHSceneNode* const); void CreateChildEntity(EntityID parentEID) const noexcept; - void ParentSelectedEntities(EntityID parentEID) const noexcept; + void ParentSelectedEntities(EntityID parentEID, std::vector const& entities) const noexcept; void SelectRangeOfEntities(EntityID beginEID, EntityID EndEID); void SelectAllEntities(); void CopySelectedEntities(); @@ -37,6 +37,8 @@ namespace SHADE std::string filter; bool isAnyNodeSelected = false; EntityID scrollTo = MAX_EID; + std::vector draggingEntities; + };//class SHHierarchyPanel //Might move to a different file