Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/plugins/editor_plugin.h
20892 views
1
/**************************************************************************/
2
/* editor_plugin.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/io/config_file.h"
34
#include "editor/inspector/editor_context_menu_plugin.h"
35
#include "scene/3d/camera_3d.h"
36
#include "scene/gui/control.h"
37
38
class Node3D;
39
class Button;
40
class PopupMenu;
41
class EditorDebuggerPlugin;
42
class EditorDock;
43
class EditorExport;
44
class EditorExportPlugin;
45
class EditorExportPlatform;
46
class EditorImportPlugin;
47
class EditorInspectorPlugin;
48
class EditorInterface;
49
class EditorNode3DGizmoPlugin;
50
class EditorResourceConversionPlugin;
51
class EditorSceneFormatImporter;
52
class EditorScenePostImportPlugin;
53
class EditorToolAddons;
54
class EditorTranslationParserPlugin;
55
class EditorUndoRedoManager;
56
class ScriptCreateDialog;
57
58
class EditorPlugin : public Node {
59
GDCLASS(EditorPlugin, Node);
60
friend class EditorData;
61
62
bool input_event_forwarding_always_enabled = false;
63
bool force_draw_over_forwarding_enabled = false;
64
65
String last_main_screen_name;
66
String plugin_version;
67
68
#ifndef DISABLE_DEPRECATED
69
static inline HashMap<Control *, EditorDock *> legacy_docks;
70
71
void _editor_project_settings_changed();
72
#endif
73
74
public:
75
enum CustomControlContainer {
76
CONTAINER_TOOLBAR,
77
CONTAINER_SPATIAL_EDITOR_MENU,
78
CONTAINER_SPATIAL_EDITOR_SIDE_LEFT,
79
CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT,
80
CONTAINER_SPATIAL_EDITOR_BOTTOM,
81
CONTAINER_CANVAS_EDITOR_MENU,
82
CONTAINER_CANVAS_EDITOR_SIDE_LEFT,
83
CONTAINER_CANVAS_EDITOR_SIDE_RIGHT,
84
CONTAINER_CANVAS_EDITOR_BOTTOM,
85
CONTAINER_INSPECTOR_BOTTOM,
86
CONTAINER_PROJECT_SETTING_TAB_LEFT,
87
CONTAINER_PROJECT_SETTING_TAB_RIGHT,
88
};
89
90
#ifndef DISABLE_DEPRECATED
91
enum DockSlot {
92
DOCK_SLOT_NONE = -1,
93
DOCK_SLOT_LEFT_UL,
94
DOCK_SLOT_LEFT_BL,
95
DOCK_SLOT_LEFT_UR,
96
DOCK_SLOT_LEFT_BR,
97
DOCK_SLOT_RIGHT_UL,
98
DOCK_SLOT_RIGHT_BL,
99
DOCK_SLOT_RIGHT_UR,
100
DOCK_SLOT_RIGHT_BR,
101
DOCK_SLOT_BOTTOM,
102
DOCK_SLOT_MAX
103
};
104
#endif
105
106
enum AfterGUIInput {
107
AFTER_GUI_INPUT_PASS,
108
AFTER_GUI_INPUT_STOP,
109
AFTER_GUI_INPUT_CUSTOM,
110
};
111
112
protected:
113
void _notification(int p_what);
114
115
static void _bind_methods();
116
EditorUndoRedoManager *get_undo_redo();
117
118
void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon);
119
void remove_custom_type(const String &p_type);
120
121
GDVIRTUAL1R(bool, _forward_canvas_gui_input, Ref<InputEvent>)
122
GDVIRTUAL1(_forward_canvas_draw_over_viewport, Control *)
123
GDVIRTUAL1(_forward_canvas_force_draw_over_viewport, Control *)
124
GDVIRTUAL2R(int, _forward_3d_gui_input, Camera3D *, Ref<InputEvent>)
125
GDVIRTUAL1(_forward_3d_draw_over_viewport, Control *)
126
GDVIRTUAL1(_forward_3d_force_draw_over_viewport, Control *)
127
GDVIRTUAL0RC(String, _get_plugin_name)
128
GDVIRTUAL0RC(Ref<Texture2D>, _get_plugin_icon)
129
GDVIRTUAL0RC(bool, _has_main_screen)
130
GDVIRTUAL1(_make_visible, bool)
131
GDVIRTUAL1(_edit, Object *)
132
GDVIRTUAL1RC(bool, _handles, Object *)
133
GDVIRTUAL0RC(Dictionary, _get_state)
134
GDVIRTUAL1(_set_state, Dictionary)
135
GDVIRTUAL0(_clear)
136
GDVIRTUAL1RC(String, _get_unsaved_status, String)
137
GDVIRTUAL0(_save_external_data)
138
GDVIRTUAL0(_apply_changes)
139
GDVIRTUAL0RC(Vector<String>, _get_breakpoints)
140
GDVIRTUAL1(_set_window_layout, Ref<ConfigFile>)
141
GDVIRTUAL1(_get_window_layout, Ref<ConfigFile>)
142
GDVIRTUAL0R(bool, _build)
143
GDVIRTUAL2RC(Vector<String>, _run_scene, String, Vector<String>)
144
GDVIRTUAL0(_enable_plugin)
145
GDVIRTUAL0(_disable_plugin)
146
147
#ifndef DISABLE_DEPRECATED
148
Button *_add_control_to_bottom_panel_compat_88081(Control *p_control, const String &p_title);
149
void _add_control_to_dock_compat_88081(DockSlot p_slot, Control *p_control);
150
static void _bind_compatibility_methods();
151
152
void add_control_to_dock(DockSlot p_slot, Control *p_control, const Ref<Shortcut> &p_shortcut = nullptr);
153
void remove_control_from_docks(Control *p_control);
154
void set_dock_tab_icon(Control *p_control, const Ref<Texture2D> &p_icon);
155
156
Button *add_control_to_bottom_panel(Control *p_control, const String &p_title, const Ref<Shortcut> &p_shortcut = nullptr);
157
void remove_control_from_bottom_panel(Control *p_control);
158
#endif
159
160
public:
161
//TODO: send a resource for editing to the editor node?
162
163
void add_control_to_container(CustomControlContainer p_location, Control *p_control);
164
void remove_control_from_container(CustomControlContainer p_location, Control *p_control);
165
166
void add_dock(EditorDock *p_dock);
167
void remove_dock(EditorDock *p_dock);
168
169
void add_tool_menu_item(const String &p_name, const Callable &p_callable);
170
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
171
void remove_tool_menu_item(const String &p_name);
172
173
PopupMenu *get_export_as_menu();
174
175
void set_input_event_forwarding_always_enabled();
176
bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; }
177
178
void set_force_draw_over_forwarding_enabled();
179
bool is_force_draw_over_forwarding_enabled() { return force_draw_over_forwarding_enabled; }
180
181
void notify_main_screen_changed(const String &screen_name);
182
void notify_scene_changed(const Node *scn_root);
183
void notify_scene_closed(const String &scene_filepath);
184
void notify_resource_saved(const Ref<Resource> &p_resource);
185
void notify_scene_saved(const String &p_scene_filepath);
186
187
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
188
virtual void forward_canvas_draw_over_viewport(Control *p_overlay);
189
virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay);
190
191
virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event);
192
virtual void forward_3d_draw_over_viewport(Control *p_overlay);
193
virtual void forward_3d_force_draw_over_viewport(Control *p_overlay);
194
195
virtual String get_plugin_name() const;
196
virtual const Ref<Texture2D> get_plugin_icon() const;
197
virtual String get_plugin_version() const;
198
virtual void set_plugin_version(const String &p_version);
199
virtual bool has_main_screen() const;
200
virtual void make_visible(bool p_visible);
201
virtual void selected_notify() {} //notify that it was raised by the user, not the editor
202
virtual void edit(Object *p_object);
203
virtual bool handles(Object *p_object) const;
204
virtual bool can_auto_hide() const;
205
virtual Dictionary get_state() const; //save editor state so it can't be reloaded when reloading scene
206
virtual void set_state(const Dictionary &p_state); //restore editor state (likely was saved with the scene)
207
virtual void clear(); // clear any temporary data in the editor, reset it (likely new scene or load another scene)
208
virtual String get_unsaved_status(const String &p_for_scene = "") const;
209
virtual void save_external_data(); // if editor references external resources/scenes, save them
210
virtual void apply_changes(); // if changes are pending in editor, apply them
211
virtual void get_breakpoints(List<String> *p_breakpoints);
212
virtual bool get_remove_list(List<Node *> *p_list);
213
virtual void set_window_layout(Ref<ConfigFile> p_layout);
214
virtual void get_window_layout(Ref<ConfigFile> p_layout);
215
virtual void edited_scene_changed() {} // if changes are pending in editor, apply them
216
virtual bool build(); // builds with external tools. Returns true if safe to continue running scene.
217
virtual void run_scene(const String &p_scene, Vector<String> &r_args);
218
219
EditorInterface *get_editor_interface();
220
ScriptCreateDialog *get_script_create_dialog();
221
222
void add_undo_redo_inspector_hook_callback(Callable p_callable);
223
void remove_undo_redo_inspector_hook_callback(Callable p_callable);
224
225
int update_overlays() const;
226
227
void queue_save_layout();
228
229
void make_bottom_panel_item_visible(Control *p_item);
230
void hide_bottom_panel();
231
232
void add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser);
233
void remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser);
234
235
void add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority = false);
236
void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer);
237
238
void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
239
void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
240
241
void add_export_platform(const Ref<EditorExportPlatform> &p_platform);
242
void remove_export_platform(const Ref<EditorExportPlatform> &p_platform);
243
244
void add_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin);
245
void remove_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin);
246
247
void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
248
void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
249
250
void add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer, bool p_first_priority = false);
251
void remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer);
252
253
void add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer, bool p_first_priority = false);
254
void remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer);
255
256
void add_autoload_singleton(const String &p_name, const String &p_path);
257
void remove_autoload_singleton(const String &p_name);
258
259
void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
260
void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
261
262
void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
263
void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
264
265
void add_context_menu_plugin(EditorContextMenuPlugin::ContextMenuSlot p_slot, const Ref<EditorContextMenuPlugin> &p_plugin);
266
void remove_context_menu_plugin(const Ref<EditorContextMenuPlugin> &p_plugin);
267
268
void enable_plugin();
269
void disable_plugin();
270
};
271
272
#ifndef DISABLE_DEPRECATED
273
VARIANT_ENUM_CAST(EditorPlugin::DockSlot);
274
#endif
275
VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer);
276
VARIANT_ENUM_CAST(EditorPlugin::AfterGUIInput);
277
278
typedef EditorPlugin *(*EditorPluginCreateFunc)();
279
280
class EditorPlugins {
281
enum {
282
MAX_CREATE_FUNCS = 128
283
};
284
285
static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS];
286
static int creation_func_count;
287
288
template <typename T>
289
static EditorPlugin *creator() {
290
return memnew(T);
291
}
292
293
public:
294
static int get_plugin_count() { return creation_func_count; }
295
static EditorPlugin *create(int p_idx) {
296
ERR_FAIL_INDEX_V(p_idx, creation_func_count, nullptr);
297
return creation_funcs[p_idx]();
298
}
299
300
template <typename T>
301
static void add_by_type() {
302
add_create_func(creator<T>);
303
}
304
305
static void add_create_func(EditorPluginCreateFunc p_func) {
306
ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS);
307
creation_funcs[creation_func_count++] = p_func;
308
}
309
};
310
311