From 5a0ff91658a8d162bc8c13c164e59f82a6cf91f7 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 28 Aug 2023 16:22:44 +0200 Subject: [PATCH] Fix task disappearing on drag & drop --- editor/limbo_ai_editor_plugin.cpp | 6 ++++-- editor/task_tree.cpp | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 3a5a870..fcc56ac 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -539,6 +539,8 @@ void LimboAIEditor::_on_history_forward() { void LimboAIEditor::_on_task_dragged(Ref p_task, Ref p_to_task, int p_type) { ERR_FAIL_COND(p_type < -1 || p_type > 1); + ERR_FAIL_COND(p_type != 0 && p_to_task->get_parent().is_null()); + if (p_task == p_to_task) { return; } @@ -550,10 +552,10 @@ void LimboAIEditor::_on_task_dragged(Ref p_task, Ref p_to_task, if (p_type == 0) { undo_redo->add_do_method(p_to_task.ptr(), SNAME("add_child"), p_task); undo_redo->add_undo_method(p_to_task.ptr(), SNAME("remove_child"), p_task); - } else if (p_type == -1 && p_to_task->get_parent().is_valid()) { + } else if (p_type == -1) { undo_redo->add_do_method(p_to_task->get_parent().ptr(), SNAME("add_child_at_index"), p_task, p_to_task->get_parent()->get_child_index(p_to_task)); undo_redo->add_undo_method(p_to_task->get_parent().ptr(), SNAME("remove_child"), p_task); - } else if (p_type == 1 && p_to_task->get_parent().is_valid()) { + } else if (p_type == 1) { undo_redo->add_do_method(p_to_task->get_parent().ptr(), SNAME("add_child_at_index"), p_task, p_to_task->get_parent()->get_child_index(p_to_task) + 1); undo_redo->add_undo_method(p_to_task->get_parent().ptr(), SNAME("remove_child"), p_task); } diff --git a/editor/task_tree.cpp b/editor/task_tree.cpp index 88cf36a..c5750cd 100644 --- a/editor/task_tree.cpp +++ b/editor/task_tree.cpp @@ -213,7 +213,11 @@ bool TaskTree::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data) c int section = tree->get_drop_section_at_position(p_point); TreeItem *item = tree->get_item_at_position(p_point); - if (!item || section < -1 || (section == -1 && !item->get_parent())) { + if (!item || section < -1) { + return false; + } + + if (!item->get_parent() && section != 0) { // before/after root item return false; }