2023-07-21 09:50:06 +00:00
|
|
|
/**
|
|
|
|
* behavior_tree_view.h
|
|
|
|
* =============================================================================
|
|
|
|
* 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.
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-04-27 07:41:59 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2023-04-13 07:29:45 +00:00
|
|
|
#ifndef BEHAVIOR_TREE_VIEW_H
|
|
|
|
#define BEHAVIOR_TREE_VIEW_H
|
|
|
|
|
|
|
|
#include "behavior_tree_data.h"
|
2023-07-20 16:35:36 +00:00
|
|
|
|
2024-01-07 05:51:34 +00:00
|
|
|
#ifdef LIMBOAI_MODULE
|
2023-04-13 07:29:45 +00:00
|
|
|
#include "scene/gui/control.h"
|
|
|
|
#include "scene/gui/tree.h"
|
2023-10-28 11:07:11 +00:00
|
|
|
#include "scene/resources/style_box_flat.h"
|
2023-04-14 11:18:23 +00:00
|
|
|
#include "scene/resources/texture.h"
|
2024-01-07 05:51:34 +00:00
|
|
|
#endif // LIMBOAI_MODULE
|
|
|
|
|
|
|
|
#ifdef LIMBOAI_GDEXTENSION
|
|
|
|
#include <godot_cpp/classes/control.hpp>
|
|
|
|
#include <godot_cpp/classes/font.hpp>
|
|
|
|
#include <godot_cpp/classes/style_box_flat.hpp>
|
|
|
|
#include <godot_cpp/classes/tree.hpp>
|
2024-01-13 16:10:42 +00:00
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
2023-04-13 07:29:45 +00:00
|
|
|
|
|
|
|
class BehaviorTreeView : public Control {
|
|
|
|
GDCLASS(BehaviorTreeView, Control);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Tree *tree;
|
|
|
|
|
2023-08-29 08:45:00 +00:00
|
|
|
struct ThemeCache {
|
|
|
|
Ref<StyleBoxFlat> sbf_running;
|
|
|
|
Ref<StyleBoxFlat> sbf_success;
|
|
|
|
Ref<StyleBoxFlat> sbf_failure;
|
|
|
|
|
|
|
|
Ref<Texture2D> icon_running;
|
|
|
|
Ref<Texture2D> icon_success;
|
|
|
|
Ref<Texture2D> icon_failure;
|
|
|
|
|
|
|
|
Ref<Font> font_custom_name;
|
|
|
|
} theme_cache;
|
|
|
|
|
2024-02-17 10:42:48 +00:00
|
|
|
Vector<uint64_t> collapsed_ids;
|
|
|
|
uint64_t last_root_id = 0;
|
2023-04-14 11:18:23 +00:00
|
|
|
|
2024-02-17 12:40:53 +00:00
|
|
|
int last_update_msec = 0;
|
|
|
|
int update_interval_msec = 0;
|
|
|
|
Ref<BehaviorTreeData> update_data;
|
|
|
|
bool update_pending = false;
|
|
|
|
|
2023-04-14 08:16:26 +00:00
|
|
|
void _draw_success_status(Object *p_obj, Rect2 p_rect);
|
|
|
|
void _draw_running_status(Object *p_obj, Rect2 p_rect);
|
|
|
|
void _draw_failure_status(Object *p_obj, Rect2 p_rect);
|
2024-02-17 10:42:48 +00:00
|
|
|
void _draw_fresh(Object *p_obj, Rect2 p_rect) {}
|
2023-04-14 08:16:26 +00:00
|
|
|
void _item_collapsed(Object *p_obj);
|
2024-02-03 15:31:21 +00:00
|
|
|
double _get_editor_scale() const;
|
2023-04-14 08:16:26 +00:00
|
|
|
|
2024-02-17 12:40:53 +00:00
|
|
|
void _update_tree(const Ref<BehaviorTreeData> &p_data);
|
|
|
|
|
2023-04-14 08:16:26 +00:00
|
|
|
protected:
|
2024-01-07 05:51:34 +00:00
|
|
|
void _do_update_theme_item_cache();
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
2023-04-13 07:29:45 +00:00
|
|
|
|
2023-08-29 08:45:00 +00:00
|
|
|
static void _bind_methods();
|
2023-04-14 11:18:23 +00:00
|
|
|
|
2023-04-14 08:16:26 +00:00
|
|
|
public:
|
2023-04-13 07:29:45 +00:00
|
|
|
void clear();
|
2024-02-17 12:40:53 +00:00
|
|
|
void update_tree(const Ref<BehaviorTreeData> &p_data);
|
|
|
|
|
|
|
|
void set_update_interval_msec(int p_milliseconds) { update_interval_msec = p_milliseconds; }
|
|
|
|
int get_update_interval_msec() const { return update_interval_msec; }
|
2023-04-14 08:16:26 +00:00
|
|
|
|
|
|
|
BehaviorTreeView();
|
2023-04-13 07:29:45 +00:00
|
|
|
};
|
|
|
|
|
2024-01-11 10:22:02 +00:00
|
|
|
#endif // ! BEHAVIOR_TREE_VIEW_H
|
2023-04-27 07:41:59 +00:00
|
|
|
|
2024-01-11 10:22:02 +00:00
|
|
|
#endif // ! TOOLS_ENABLED
|