2022-09-01 22:20:37 +00:00
|
|
|
/* limbo_ai_editor_plugin.h */
|
|
|
|
|
2022-09-02 12:25:03 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-09-01 22:20:37 +00:00
|
|
|
#ifndef LIMBO_AI_EDITOR_PLUGIN_H
|
|
|
|
#define LIMBO_AI_EDITOR_PLUGIN_H
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "core/object/class_db.h"
|
|
|
|
#include "core/object/object.h"
|
|
|
|
#include "core/templates/hash_set.h"
|
2022-09-01 22:20:37 +00:00
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_plugin.h"
|
2022-09-02 22:10:22 +00:00
|
|
|
#include "modules/limboai/bt/behavior_tree.h"
|
2022-09-03 15:00:20 +00:00
|
|
|
#include "modules/limboai/bt/bt_task.h"
|
2022-09-02 12:25:03 +00:00
|
|
|
#include "scene/gui/box_container.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "scene/gui/control.h"
|
2022-09-01 22:20:37 +00:00
|
|
|
#include "scene/gui/file_dialog.h"
|
2022-09-02 12:25:03 +00:00
|
|
|
#include "scene/gui/flow_container.h"
|
|
|
|
#include "scene/gui/line_edit.h"
|
2022-12-15 07:26:52 +00:00
|
|
|
#include "scene/gui/panel_container.h"
|
2022-09-01 22:20:37 +00:00
|
|
|
#include "scene/gui/popup_menu.h"
|
2022-09-06 11:28:25 +00:00
|
|
|
#include "scene/gui/split_container.h"
|
2022-09-01 22:20:37 +00:00
|
|
|
#include "scene/gui/tree.h"
|
2022-09-05 14:39:40 +00:00
|
|
|
#include "scene/resources/texture.h"
|
2022-09-01 22:20:37 +00:00
|
|
|
|
|
|
|
class TaskTree : public Control {
|
|
|
|
GDCLASS(TaskTree, Control);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Tree *tree;
|
|
|
|
Ref<BehaviorTree> bt;
|
|
|
|
Ref<BTTask> last_selected;
|
2022-09-03 15:00:20 +00:00
|
|
|
bool editable;
|
2022-09-01 22:20:37 +00:00
|
|
|
|
|
|
|
TreeItem *_create_tree(const Ref<BTTask> &p_task, TreeItem *p_parent, int p_idx = -1);
|
|
|
|
void _update_item(TreeItem *p_item);
|
|
|
|
void _update_tree();
|
|
|
|
TreeItem *_find_item(const Ref<BTTask> &p_task) const;
|
|
|
|
|
|
|
|
void _on_item_selected();
|
2022-11-23 15:25:32 +00:00
|
|
|
void _on_item_double_clicked();
|
2022-12-15 07:26:52 +00:00
|
|
|
void _on_item_mouse_selected(const Vector2 &p_pos, int p_button_index);
|
2022-09-03 15:13:15 +00:00
|
|
|
void _on_task_changed();
|
2022-09-01 22:20:37 +00:00
|
|
|
|
2023-04-06 21:54:56 +00:00
|
|
|
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);
|
2022-09-03 15:00:20 +00:00
|
|
|
|
2022-09-01 22:20:37 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void load_bt(const Ref<BehaviorTree> &p_behavior_tree);
|
2022-12-19 09:29:46 +00:00
|
|
|
void unload();
|
2022-09-01 22:20:37 +00:00
|
|
|
Ref<BehaviorTree> get_bt() const { return bt; }
|
|
|
|
void update_tree() { _update_tree(); }
|
|
|
|
void update_task(const Ref<BTTask> &p_task);
|
|
|
|
Ref<BTTask> get_selected() const;
|
|
|
|
void deselect();
|
|
|
|
|
2022-11-22 20:00:08 +00:00
|
|
|
virtual bool editor_can_reload_from_file() { return false; }
|
|
|
|
|
2022-09-01 22:20:37 +00:00
|
|
|
TaskTree();
|
|
|
|
~TaskTree();
|
|
|
|
};
|
|
|
|
|
2022-09-02 12:25:03 +00:00
|
|
|
class TaskSection : public VBoxContainer {
|
|
|
|
GDCLASS(TaskSection, VBoxContainer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
FlowContainer *tasks_container;
|
|
|
|
Button *section_header;
|
|
|
|
|
|
|
|
void _on_task_button_pressed(const StringName &p_task);
|
|
|
|
void _on_header_pressed();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_filter(String p_filter);
|
2022-09-02 17:30:32 +00:00
|
|
|
void add_task_button(String p_name, const Ref<Texture> &icon, Variant p_meta);
|
2022-09-02 12:25:03 +00:00
|
|
|
|
2022-11-23 00:04:35 +00:00
|
|
|
void set_collapsed(bool p_collapsed);
|
|
|
|
bool is_collapsed() const;
|
|
|
|
|
|
|
|
String get_category_name() const { return section_header->get_text(); }
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
TaskSection(String p_category_name);
|
2022-09-02 12:25:03 +00:00
|
|
|
~TaskSection();
|
|
|
|
};
|
|
|
|
|
|
|
|
class TaskPanel : public PanelContainer {
|
|
|
|
GDCLASS(TaskPanel, PanelContainer)
|
|
|
|
|
|
|
|
private:
|
|
|
|
LineEdit *filter_edit;
|
|
|
|
VBoxContainer *sections;
|
|
|
|
|
2022-09-02 17:30:32 +00:00
|
|
|
void _populate_core_tasks_from_class(const StringName &p_base_class, List<String> *p_task_classes);
|
2022-10-28 23:50:47 +00:00
|
|
|
void _populate_from_user_dir(String p_path, HashMap<String, List<String>> *p_categories);
|
2022-09-02 22:10:22 +00:00
|
|
|
void _populate_scripted_tasks_from_dir(String p_path, List<String> *p_task_classes);
|
2022-09-02 12:25:03 +00:00
|
|
|
void _on_task_button_pressed(const StringName &p_task);
|
|
|
|
void _on_filter_text_changed(String p_text);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-11-23 00:04:35 +00:00
|
|
|
void _notification(int p_what);
|
|
|
|
|
2022-09-02 12:25:03 +00:00
|
|
|
public:
|
2022-09-05 15:56:38 +00:00
|
|
|
void refresh();
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
TaskPanel();
|
2022-09-02 12:25:03 +00:00
|
|
|
~TaskPanel();
|
|
|
|
};
|
|
|
|
|
2022-09-01 22:20:37 +00:00
|
|
|
class LimboAIEditor : public Control {
|
|
|
|
GDCLASS(LimboAIEditor, Control);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum Action {
|
|
|
|
ACTION_REMOVE,
|
|
|
|
ACTION_MOVE_UP,
|
|
|
|
ACTION_MOVE_DOWN,
|
|
|
|
ACTION_DUPLICATE,
|
|
|
|
ACTION_MAKE_ROOT,
|
|
|
|
};
|
|
|
|
|
2022-09-02 13:43:54 +00:00
|
|
|
Vector<Ref<BehaviorTree>> history;
|
|
|
|
int idx_history;
|
2022-12-15 07:26:52 +00:00
|
|
|
HashSet<Ref<BehaviorTree>> dirty;
|
2022-09-02 13:43:54 +00:00
|
|
|
|
2022-09-01 22:20:37 +00:00
|
|
|
Button *header;
|
2022-09-06 11:28:25 +00:00
|
|
|
HSplitContainer *hsc;
|
2022-09-01 22:20:37 +00:00
|
|
|
TaskTree *task_tree;
|
2022-09-05 19:57:24 +00:00
|
|
|
Panel *usage_hint;
|
2022-09-01 22:20:37 +00:00
|
|
|
PopupMenu *menu;
|
|
|
|
FileDialog *save_dialog;
|
|
|
|
FileDialog *load_dialog;
|
2022-09-02 13:43:54 +00:00
|
|
|
Button *history_back;
|
|
|
|
Button *history_forward;
|
2022-09-05 15:56:38 +00:00
|
|
|
TaskPanel *task_panel;
|
2022-09-01 22:20:37 +00:00
|
|
|
|
2022-11-23 15:25:32 +00:00
|
|
|
ConfirmationDialog *rename_dialog;
|
|
|
|
LineEdit *rename_edit;
|
|
|
|
|
2022-11-22 20:00:08 +00:00
|
|
|
ConfirmationDialog *disk_changed;
|
|
|
|
Tree *disk_changed_list;
|
2022-12-15 07:26:52 +00:00
|
|
|
HashSet<String> disk_changed_files;
|
2022-11-22 20:00:08 +00:00
|
|
|
|
2022-09-03 12:11:47 +00:00
|
|
|
void _add_task(const Ref<BTTask> &p_task);
|
2022-12-22 12:19:39 +00:00
|
|
|
void _remove_task(const Ref<BTTask> &p_task);
|
2022-09-03 12:11:47 +00:00
|
|
|
_FORCE_INLINE_ void _add_task_with_prototype(const Ref<BTTask> &p_prototype) { _add_task(p_prototype->clone()); }
|
2022-11-22 21:58:53 +00:00
|
|
|
void _update_header() const;
|
2022-09-02 13:43:54 +00:00
|
|
|
void _update_history_buttons();
|
2022-09-01 22:20:37 +00:00
|
|
|
void _new_bt();
|
|
|
|
void _save_bt(String p_path);
|
|
|
|
void _load_bt(String p_path);
|
2022-09-03 12:01:13 +00:00
|
|
|
void _mark_as_dirty(bool p_dirty);
|
2022-09-01 22:20:37 +00:00
|
|
|
|
2022-11-22 20:00:08 +00:00
|
|
|
void _reload_modified();
|
|
|
|
void _resave_modified(String _str = "");
|
|
|
|
|
2022-12-17 12:39:37 +00:00
|
|
|
void _rename_task_confirmed();
|
2022-11-23 15:25:32 +00:00
|
|
|
|
2022-09-01 22:20:37 +00:00
|
|
|
void _on_tree_rmb(const Vector2 &p_menu_pos);
|
|
|
|
void _on_action_selected(int p_id);
|
2022-12-15 07:26:52 +00:00
|
|
|
void _on_tree_task_selected(const Ref<BTTask> &p_task);
|
2022-11-23 15:25:32 +00:00
|
|
|
void _on_tree_task_double_clicked();
|
2022-12-15 07:26:52 +00:00
|
|
|
void _on_visibility_changed();
|
|
|
|
void _on_header_pressed();
|
2022-09-01 22:20:37 +00:00
|
|
|
void _on_save_pressed();
|
2022-09-02 22:10:22 +00:00
|
|
|
void _on_panel_task_selected(String p_task);
|
2022-09-02 13:43:54 +00:00
|
|
|
void _on_history_back();
|
|
|
|
void _on_history_forward();
|
2022-09-03 15:00:20 +00:00
|
|
|
void _on_task_dragged(Ref<BTTask> p_task, Ref<BTTask> p_to_task, int p_type);
|
2022-11-22 20:00:08 +00:00
|
|
|
void _on_resources_reload(const Vector<String> &p_resources);
|
2022-09-01 22:20:37 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-09-06 11:28:25 +00:00
|
|
|
void _notification(int p_what);
|
|
|
|
|
2022-09-01 22:20:37 +00:00
|
|
|
public:
|
2022-09-05 14:39:40 +00:00
|
|
|
static Ref<Texture> get_task_icon(String p_script_path_or_class);
|
|
|
|
|
2022-11-22 20:00:08 +00:00
|
|
|
void edit_bt(Ref<BehaviorTree> p_behavior_tree, bool p_force_refresh = false);
|
2022-09-05 19:57:24 +00:00
|
|
|
|
2022-09-03 12:01:13 +00:00
|
|
|
void apply_changes();
|
|
|
|
|
2022-12-15 07:26:52 +00:00
|
|
|
LimboAIEditor();
|
2022-09-01 22:20:37 +00:00
|
|
|
~LimboAIEditor();
|
|
|
|
};
|
|
|
|
|
|
|
|
class LimboAIEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(LimboAIEditorPlugin, EditorPlugin);
|
|
|
|
|
|
|
|
private:
|
|
|
|
LimboAIEditor *limbo_ai_editor;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_notification);
|
|
|
|
|
|
|
|
public:
|
2022-12-15 07:26:52 +00:00
|
|
|
virtual String get_name() const override { return "LimboAI"; }
|
|
|
|
virtual const Ref<Texture2D> get_icon() const override;
|
|
|
|
bool has_main_screen() const override { return true; }
|
|
|
|
virtual void make_visible(bool p_visible) override;
|
|
|
|
virtual void apply_changes() override;
|
|
|
|
virtual void edit(Object *p_object) override;
|
|
|
|
virtual bool handles(Object *p_object) const override;
|
|
|
|
|
|
|
|
LimboAIEditorPlugin();
|
2022-09-01 22:20:37 +00:00
|
|
|
~LimboAIEditorPlugin();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
|
|
|
|
#endif // LIMBO_AI_EDITOR_PLUGIN_H
|