/** * limbo_ai_editor_plugin.cpp * ============================================================================= * Copyright 2021-2023 Serhii Snitsaruk * * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. * ============================================================================= */ #ifdef TOOLS_ENABLED #include "limbo_ai_editor_plugin.h" #include "../bt/behavior_tree.h" #include "../bt/tasks/bt_comment.h" #include "../bt/tasks/composites/bt_probability_selector.h" #include "../bt/tasks/composites/bt_selector.h" #include "../bt/tasks/decorators/bt_subtree.h" #include "../editor/debugger/limbo_debugger_plugin.h" #include "../editor/editor_property_bb_param.h" #include "../util/limbo_compat.h" #include "../util/limbo_utility.h" #include "action_banner.h" #ifdef LIMBOAI_MODULE #include "core/config/project_settings.h" #include "core/error/error_macros.h" #include "core/input/input.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/script_editor_debugger.h" #include "editor/editor_file_system.h" #include "editor/editor_help.h" #include "editor/editor_paths.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/inspector_dock.h" #include "editor/plugins/script_editor_plugin.h" #include "editor/project_settings_editor.h" #include "scene/gui/panel_container.h" #include "scene/gui/separator.h" #endif // ! LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif // ! LIMBOAI_GDEXTENSION //**** LimboAIEditor _FORCE_INLINE_ String _get_script_template_path() { String templates_search_path = GLOBAL_GET("editor/script/templates_search_path"); return templates_search_path.path_join("BTTask").path_join("custom_task.gd"); } void LimboAIEditor::_add_task(const Ref &p_task) { if (task_tree->get_bt().is_null()) { return; } ERR_FAIL_COND(p_task.is_null()); EditorUndoRedoManager *undo_redo = GET_UNDO_REDO(); undo_redo->create_action(TTR("Add BT Task")); int insert_idx = -1; Ref selected = task_tree->get_selected(); Ref parent = selected; if (parent.is_null()) { // When no task is selected, use the root task. parent = task_tree->get_bt()->get_root_task(); selected = parent; } if (parent.is_null()) { // When tree is empty. undo_redo->add_do_method(task_tree->get_bt().ptr(), LW_NAME(set_root_task), p_task); undo_redo->add_undo_method(task_tree->get_bt().ptr(), LW_NAME(set_root_task), task_tree->get_bt()->get_root_task()); } else { if (Input::get_singleton()->is_key_pressed(LW_KEY(SHIFT)) && selected->get_parent().is_valid()) { // When shift is pressed, insert task after the currently selected and on the same level. parent = selected->get_parent(); insert_idx = selected->get_index() + 1; } undo_redo->add_do_method(parent.ptr(), LW_NAME(add_child_at_index), p_task, insert_idx); undo_redo->add_undo_method(parent.ptr(), LW_NAME(remove_child), p_task); } undo_redo->add_do_method(task_tree, LW_NAME(update_tree)); undo_redo->add_undo_method(task_tree, LW_NAME(update_tree)); undo_redo->commit_action(); _mark_as_dirty(true); } Ref LimboAIEditor::_create_task_by_class_or_path(const String &p_class_or_path) const { Ref ret; if (p_class_or_path.begins_with("res:")) { Ref