/** * task_tree.cpp * ============================================================================= * Copyright 2021-2024 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 "task_tree.h" #include "../bt/tasks/bt_comment.h" #include "../bt/tasks/composites/bt_probability_selector.h" #include "../util/limbo_compat.h" #include "../util/limbo_utility.h" #ifdef LIMBOAI_MODULE #include "core/object/script_language.h" #include "editor/themes/editor_scale.h" #endif // LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION #include #include using namespace godot; #endif // LIMBOAI_GDEXTENSION //**** TaskTree TreeItem *TaskTree::_create_tree(const Ref &p_task, TreeItem *p_parent, int p_idx) { ERR_FAIL_COND_V(p_task.is_null(), nullptr); TreeItem *item = tree->create_item(p_parent, p_idx); item->set_metadata(0, p_task); for (int i = 0; i < p_task->get_child_count(); i++) { _create_tree(p_task->get_child(i), item); } _update_item(item); return item; } void TaskTree::_update_item(TreeItem *p_item) { if (p_item == nullptr) { return; } if (p_item->get_parent()) { Ref sel = p_item->get_parent()->get_metadata(0); if (sel.is_valid() && sel->has_probability(p_item->get_index())) { p_item->set_custom_draw(0, this, LW_NAME(_draw_probability)); p_item->set_cell_mode(0, TreeItem::CELL_MODE_CUSTOM); } } Ref task = p_item->get_metadata(0); ERR_FAIL_COND_MSG(!task.is_valid(), "Invalid task reference in metadata."); p_item->set_text(0, task->get_task_name()); if (IS_CLASS(task, BTComment)) { p_item->set_custom_font(0, theme_cache.comment_font); p_item->set_custom_color(0, theme_cache.comment_color); } else if (task->get_custom_name().is_empty()) { p_item->set_custom_font(0, theme_cache.normal_name_font); p_item->clear_custom_color(0); } else { p_item->set_custom_font(0, theme_cache.custom_name_font); // p_item->set_custom_color(0, get_theme_color(SNAME("warning_color"), SNAME("Editor"))); } String type_arg; if (task->get_script() != Variant()) { Ref