Fix drag-drop parenting issue
Users can now drop onto empty space in hierarchy panel to unparent
This commit is contained in:
parent
74b9882024
commit
2b34e8c13b
|
@ -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<EntityID> draggingEntities = editor->selectedEntities;
|
||||
draggingEntities = editor->selectedEntities;
|
||||
if (!isSelected)
|
||||
{
|
||||
draggingEntities.clear();
|
||||
|
@ -217,7 +223,8 @@ namespace SHADE
|
|||
{
|
||||
if (const std::vector<EntityID>* eidPayload = SHDragDrop::AcceptPayload<std::vector<EntityID>>(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<EntityID> const& entities) const noexcept
|
||||
{
|
||||
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
|
||||
auto const editor = SHSystemManager::GetSystem<SHEditor>();
|
||||
//auto const editor = SHSystemManager::GetSystem<SHEditor>();
|
||||
SHEntityParentCommand::EntityParentData entityParentData;
|
||||
std::vector<EntityID> 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);
|
||||
|
|
|
@ -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<EntityID> 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<EntityID> draggingEntities;
|
||||
|
||||
};//class SHHierarchyPanel
|
||||
|
||||
//Might move to a different file
|
||||
|
|
Loading…
Reference in New Issue