Extract hierarchy and project drag semantics

This commit is contained in:
2026-03-27 00:30:11 +08:00
parent 6ec5f05601
commit c97510ed5b
7 changed files with 119 additions and 72 deletions

View File

@@ -100,15 +100,7 @@ void HierarchyPanel::Render() {
}
ImGui::InvisibleButton("##DragTarget", ImVec2(-1, -1));
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY_PTR")) {
::XCEngine::Components::GameObject* sourceGameObject = *(::XCEngine::Components::GameObject**)payload->Data;
if (sourceGameObject && sourceGameObject->GetParent() != nullptr) {
Commands::ReparentEntityPreserveWorldTransform(*m_context, sourceGameObject, 0);
}
}
ImGui::EndDragDropTarget();
}
Actions::AcceptHierarchyEntityDropToRoot(*m_context);
}
@@ -192,21 +184,15 @@ void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject
gameObject->GetChildCount() == 0);
if (node.clicked) {
ImGuiIO& io = ImGui::GetIO();
if (io.KeyCtrl) {
if (!m_context->GetSelectionManager().IsSelected(gameObject->GetID())) {
m_context->GetSelectionManager().AddToSelection(gameObject->GetID());
}
} else {
m_context->GetSelectionManager().SetSelectedEntity(gameObject->GetID());
}
Actions::HandleHierarchySelectionClick(*m_context, gameObject->GetID(), ImGui::GetIO().KeyCtrl);
}
if (node.doubleClicked) {
BeginRename(gameObject);
}
HandleDragDrop(gameObject);
Actions::BeginHierarchyEntityDrag(gameObject);
Actions::AcceptHierarchyEntityDrop(*m_context, gameObject);
if (UI::BeginPopupContextItem("EntityContextMenu")) {
Actions::DrawHierarchyContextActions(*m_context, gameObject);
@@ -250,24 +236,6 @@ void HierarchyPanel::CancelRename() {
m_renameState.Cancel();
}
void HierarchyPanel::HandleDragDrop(::XCEngine::Components::GameObject* gameObject) {
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload("ENTITY_PTR", &gameObject, sizeof(::XCEngine::Components::GameObject*));
ImGui::Text("%s", gameObject->GetName().c_str());
ImGui::EndDragDropSource();
}
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY_PTR")) {
::XCEngine::Components::GameObject* sourceGameObject = *(::XCEngine::Components::GameObject**)payload->Data;
if (sourceGameObject != gameObject && Commands::CanReparentEntity(sourceGameObject, gameObject)) {
Commands::ReparentEntityPreserveWorldTransform(*m_context, sourceGameObject, gameObject->GetID());
}
}
ImGui::EndDragDropTarget();
}
}
bool HierarchyPanel::PassesFilter(::XCEngine::Components::GameObject* gameObject, const std::string& filter) {
if (!gameObject) return false;