Fix task disappearing on drag & drop

This commit is contained in:
Serhii Snitsaruk 2023-08-28 16:22:44 +02:00
parent f89b7897f6
commit 5a0ff91658
2 changed files with 9 additions and 3 deletions

View File

@ -539,6 +539,8 @@ void LimboAIEditor::_on_history_forward() {
void LimboAIEditor::_on_task_dragged(Ref<BTTask> p_task, Ref<BTTask> p_to_task, int p_type) { void LimboAIEditor::_on_task_dragged(Ref<BTTask> p_task, Ref<BTTask> p_to_task, int p_type) {
ERR_FAIL_COND(p_type < -1 || p_type > 1); 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) { if (p_task == p_to_task) {
return; return;
} }
@ -550,10 +552,10 @@ void LimboAIEditor::_on_task_dragged(Ref<BTTask> p_task, Ref<BTTask> p_to_task,
if (p_type == 0) { if (p_type == 0) {
undo_redo->add_do_method(p_to_task.ptr(), SNAME("add_child"), p_task); 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); 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_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); 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_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); undo_redo->add_undo_method(p_to_task->get_parent().ptr(), SNAME("remove_child"), p_task);
} }

View File

@ -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); int section = tree->get_drop_section_at_position(p_point);
TreeItem *item = tree->get_item_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; return false;
} }