forked from limbonaut/limboai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimbo_ai_editor_plugin.h
325 lines (280 loc) · 9.81 KB
/
limbo_ai_editor_plugin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* limbo_ai_editor_plugin.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
#ifndef LIMBO_AI_EDITOR_PLUGIN_H
#define LIMBO_AI_EDITOR_PLUGIN_H
#include "../bt/behavior_tree.h"
#include "../bt/tasks/bt_task.h"
#include "editor_property_variable_name.h"
#include "owner_picker.h"
#include "task_palette.h"
#include "task_tree.h"
#include "tree_search.h"
#ifdef LIMBOAI_MODULE
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/templates/hash_set.h"
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_spin_slider.h"
#include "editor/plugins/editor_plugin.h"
#include "scene/gui/box_container.h"
#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/flow_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/link_button.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/popup.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"
#include "scene/resources/texture.h"
#endif // LIMBOAI_MODULE
#ifdef LIMBOAI_GDEXTENSION
#include "godot_cpp/classes/accept_dialog.hpp"
#include <godot_cpp/classes/config_file.hpp>
#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/editor_plugin.hpp>
#include <godot_cpp/classes/editor_spin_slider.hpp>
#include <godot_cpp/classes/editor_undo_redo_manager.hpp>
#include <godot_cpp/classes/file_dialog.hpp>
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/h_split_container.hpp>
#include <godot_cpp/classes/input_event.hpp>
#include <godot_cpp/classes/link_button.hpp>
#include <godot_cpp/classes/menu_button.hpp>
#include <godot_cpp/classes/panel.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/tab_bar.hpp>
#include <godot_cpp/classes/texture2d.hpp>
#include <godot_cpp/variant/packed_string_array.hpp>
#include <godot_cpp/variant/variant.hpp>
using namespace godot;
#endif // LIMBOAI_GDEXTENSION
class LimboAIEditor : public Control {
GDCLASS(LimboAIEditor, Control);
private:
enum Action {
ACTION_EDIT_PROBABILITY,
ACTION_RENAME,
ACTION_CHANGE_TYPE,
ACTION_EDIT_SCRIPT,
ACTION_OPEN_DOC,
ACTION_CUT,
ACTION_COPY,
ACTION_PASTE,
ACTION_PASTE_AFTER,
ACTION_MOVE_UP,
ACTION_MOVE_DOWN,
ACTION_DUPLICATE,
ACTION_MAKE_ROOT,
ACTION_EXTRACT_SUBTREE,
ACTION_REMOVE,
};
enum MiscMenu {
MISC_ONLINE_DOCUMENTATION,
MISC_DOC_INTRODUCTION,
MISC_DOC_CUSTOM_TASKS,
MISC_OPEN_DEBUGGER,
MISC_LAYOUT_CLASSIC,
MISC_LAYOUT_WIDESCREEN_OPTIMIZED,
MISC_PROJECT_SETTINGS,
MISC_CREATE_SCRIPT_TEMPLATE,
MISC_SEARCH_TREE
};
enum TabMenu {
TAB_SHOW_IN_FILESYSTEM,
TAB_JUMP_TO_OWNER,
TAB_CLOSE,
TAB_CLOSE_OTHER,
TAB_CLOSE_RIGHT,
TAB_CLOSE_ALL,
};
enum EditorLayout {
LAYOUT_CLASSIC,
LAYOUT_WIDESCREEN_OPTIMIZED,
};
struct ThemeCache {
Ref<Texture2D> duplicate_task_icon;
Ref<Texture2D> edit_script_icon;
Ref<Texture2D> make_root_icon;
Ref<Texture2D> move_task_down_icon;
Ref<Texture2D> move_task_up_icon;
Ref<Texture2D> open_debugger_icon;
Ref<Texture2D> doc_icon;
Ref<Texture2D> introduction_icon;
Ref<Texture2D> percent_icon;
Ref<Texture2D> remove_task_icon;
Ref<Texture2D> rename_task_icon;
Ref<Texture2D> change_type_icon;
Ref<Texture2D> extract_subtree_icon;
Ref<Texture2D> behavior_tree_icon;
Ref<Texture2D> cut_icon;
Ref<Texture2D> copy_icon;
Ref<Texture2D> paste_icon;
Ref<Texture2D> search_icon;
} theme_cache;
EditorPlugin *plugin;
EditorLayout editor_layout;
Vector<Ref<BehaviorTree>> history;
int idx_history;
HashMap<Ref<BehaviorTree>, TreeSearch::SearchInfo> tab_search_context;
bool updating_tabs = false;
bool request_update_tabs = false;
HashSet<Ref<BehaviorTree>> dirty;
Ref<BTTask> clipboard_task;
VBoxContainer *vbox;
PanelContainer *tab_bar_panel;
HBoxContainer *tab_bar_container;
LinkButton *version_btn;
TabBar *tab_bar;
PopupMenu *tab_menu;
OwnerPicker *owner_picker;
HSplitContainer *hsc;
TaskTree *task_tree;
VBoxContainer *banners;
Panel *usage_hint;
PopupMenu *menu;
HBoxContainer *fav_tasks_hbox;
TaskPalette *task_palette;
PopupPanel *probability_popup;
EditorSpinSlider *probability_edit;
Button *weight_mode;
Button *percent_mode;
PopupPanel *change_type_popup;
TaskPalette *change_type_palette;
FileDialog *save_dialog;
FileDialog *load_dialog;
FileDialog *extract_dialog;
Button *new_btn;
Button *load_btn;
Button *save_btn;
Button *new_script_btn;
MenuButton *misc_btn;
ConfirmationDialog *rename_dialog;
LineEdit *rename_edit;
ConfirmationDialog *disk_changed;
Tree *disk_changed_list;
HashSet<String> disk_changed_files;
AcceptDialog *info_dialog;
// ! HACK: Force global history to be used for resources without a set path.
Object *dummy_history_context = nullptr;
EditorUndoRedoManager *_new_undo_redo_action(const String &p_name = "", UndoRedo::MergeMode p_mode = UndoRedo::MERGE_DISABLE);
void _commit_action_with_update(EditorUndoRedoManager *p_undo_redo);
void _add_task(const Ref<BTTask> &p_task, bool p_as_sibling);
void _add_task_with_prototype(const Ref<BTTask> &p_prototype);
Ref<BTTask> _create_task_by_class_or_path(const String &p_class_or_path) const;
void _add_task_by_class_or_path(const String &p_class_or_path);
void _remove_task(const Ref<BTTask> &p_task);
void _update_favorite_tasks();
void _update_misc_menu();
void _update_banners();
void _new_bt();
void _save_bt(String p_path);
void _load_bt(String p_path);
void _update_task_tree(const Ref<BehaviorTree> &p_bt, const Ref<BTTask> &p_specific_task = nullptr);
void _disable_editing();
void _mark_as_dirty(bool p_dirty);
void _create_user_task_dir();
void _remove_task_from_favorite(const String &p_task);
void _save_and_restart();
void _extract_subtree(const String &p_path);
void _replace_task(const Ref<BTTask> &p_task, const Ref<BTTask> &p_by_task);
void _tab_clicked(int p_tab);
void _tab_closed(int p_tab);
void _update_tabs();
void _move_active_tab(int p_to_index);
void _tab_input(const Ref<InputEvent> &p_input);
void _show_tab_context_menu();
void _tab_menu_option_selected(int p_id);
void _tab_plan_edited(int p_tab);
void _reload_modified();
void _resave_modified(String _str = "");
void _popup_file_dialog(FileDialog *p_dialog) { p_dialog->popup_centered_clamped(Size2i(700, 500), 0.8f); }
void _popup_info_dialog(const String &p_text);
void _rename_task_confirmed();
void _on_tree_rmb(const Vector2 &p_menu_pos);
void _action_selected(int p_id);
void _misc_option_selected(int p_id);
void _on_probability_edited(double p_value);
void _update_probability_edit();
void _probability_popup_closed();
void _on_tree_task_selected(const Ref<BTTask> &p_task);
void _on_tree_task_activated();
void _on_visibility_changed();
void _on_header_pressed();
void _on_save_pressed();
void _on_history_back();
void _on_history_forward();
void _on_tasks_dragged(const TypedArray<BTTask> &p_tasks, Ref<BTTask> p_to_task, int p_to_pos);
void _on_resources_reload(const PackedStringArray &p_resources);
void _on_filesystem_changed();
void _on_new_script_pressed();
void _task_type_selected(const String &p_class_or_path);
void _copy_version_info();
void _edit_project_settings();
void _process_shortcut_input(const Ref<InputEvent> &p_event);
#ifdef LIMBOAI_MODULE
virtual void shortcut_input(const Ref<InputEvent> &p_event) override { _process_shortcut_input(p_event); }
#endif // LIMBOAI_MODULE
protected:
virtual void _do_update_theme_item_cache();
void _notification(int p_what);
static void _bind_methods();
public:
void set_plugin(EditorPlugin *p_plugin) { plugin = p_plugin; };
void edit_bt(const Ref<BehaviorTree> &p_behavior_tree, bool p_force_refresh = false);
Ref<BlackboardPlan> get_edited_blackboard_plan();
void set_window_layout(const Ref<ConfigFile> &p_configuration);
void get_window_layout(const Ref<ConfigFile> &p_configuration);
void apply_changes();
#ifdef LIMBOAI_GDEXTENSION
virtual void _shortcut_input(const Ref<InputEvent> &p_event) override { _process_shortcut_input(p_event); }
#endif
LimboAIEditor();
~LimboAIEditor();
};
class LimboAIEditorPlugin : public EditorPlugin {
GDCLASS(LimboAIEditorPlugin, EditorPlugin);
private:
LimboAIEditor *limbo_ai_editor;
protected:
static void _bind_methods();
void _notification(int p_notification);
public:
#ifdef LIMBOAI_MODULE
bool has_main_screen() const override { return true; }
virtual String get_name() const override { return "LimboAI"; }
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;
virtual void set_window_layout(Ref<ConfigFile> p_configuration) override;
virtual void get_window_layout(Ref<ConfigFile> p_configuration) override;
#elif LIMBOAI_GDEXTENSION
bool _has_main_screen() const override { return true; }
virtual String _get_plugin_name() const override { return "LimboAI"; }
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;
virtual Ref<Texture2D> _get_plugin_icon() const override;
virtual void _set_window_layout(const Ref<ConfigFile> &p_configuration) override;
virtual void _get_window_layout(const Ref<ConfigFile> &p_configuration) override;
#endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION
LimboAIEditorPlugin();
~LimboAIEditorPlugin();
};
#endif // LIMBO_AI_EDITOR_PLUGIN_H
#endif // ! TOOLS_ENABLED