/** * task_tree.h * ============================================================================= * 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 "../bt/behavior_tree.h" #ifdef LIMBOAI_MODULE #include "scene/gui/control.h" #include "scene/gui/tree.h" #include "scene/resources/style_box_flat.h" #define RECT_CACHE_KEY ObjectID #endif // LIMBOAI_MODULE #ifdef LIMBOAI_GDEXTENSION #include #include #include #include #include #include #define RECT_CACHE_KEY uint64_t #endif // LIMBOAI_GDEXTENSION class TaskTree : public Control { GDCLASS(TaskTree, Control); private: Tree *tree; Ref bt; Ref last_selected; bool editable; bool updating_tree; HashMap probability_rect_cache; struct ThemeCache { Ref comment_font; Ref name_font; Ref custom_name_font; Ref normal_name_font; Ref probability_font; double name_font_size = 18.0; double probability_font_size = 16.0; Ref task_warning_icon; Color comment_color; Color probability_font_color; Ref probability_bg; } theme_cache; TreeItem *_create_tree(const Ref &p_task, TreeItem *p_parent, int p_idx = -1); void _update_item(TreeItem *p_item); void _update_tree(); TreeItem *_find_item(const Ref &p_task) const; void _on_item_selected(); void _on_item_activated(); void _on_item_collapsed(Object *p_obj); void _on_item_mouse_selected(const Vector2 &p_pos, MouseButton p_button_index); void _on_task_changed(); Variant _get_drag_data_fw(const Point2 &p_point); bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data) const; void _drop_data_fw(const Point2 &p_point, const Variant &p_data); void _draw_probability(Object *item_obj, Rect2 rect); protected: virtual void _do_update_theme_item_cache(); void _notification(int p_what); static void _bind_methods(); public: void load_bt(const Ref &p_behavior_tree); void unload(); Ref get_bt() const { return bt; } void update_tree() { _update_tree(); } void update_task(const Ref &p_task); void add_selection(const Ref &p_task); void remove_selection(const Ref &p_task); Ref get_selected() const; Vector> get_selected_tasks() const; void clear_selection(); Rect2 get_selected_probability_rect() const; double get_selected_probability_weight() const; double get_selected_probability_percent() const; bool selected_has_probability() const; virtual bool editor_can_reload_from_file() { return false; } TaskTree(); ~TaskTree(); }; #endif // ! TOOLS_ENABLED