| 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 | #ifndef EDITOR_PLUGIN_H | 
|---|
| 32 | #define EDITOR_PLUGIN_H | 
|---|
| 33 |  | 
|---|
| 34 | #include "core/io/config_file.h" | 
|---|
| 35 | #include "scene/3d/camera_3d.h" | 
|---|
| 36 | #include "scene/gui/control.h" | 
|---|
| 37 |  | 
|---|
| 38 | class Node3D; | 
|---|
| 39 | class Button; | 
|---|
| 40 | class ; | 
|---|
| 41 | class EditorDebuggerPlugin; | 
|---|
| 42 | class EditorExport; | 
|---|
| 43 | class EditorExportPlugin; | 
|---|
| 44 | class EditorImportPlugin; | 
|---|
| 45 | class EditorInspectorPlugin; | 
|---|
| 46 | class EditorInterface; | 
|---|
| 47 | class EditorNode3DGizmoPlugin; | 
|---|
| 48 | class EditorResourceConversionPlugin; | 
|---|
| 49 | class EditorSceneFormatImporter; | 
|---|
| 50 | class EditorScenePostImportPlugin; | 
|---|
| 51 | class EditorToolAddons; | 
|---|
| 52 | class EditorTranslationParserPlugin; | 
|---|
| 53 | class EditorUndoRedoManager; | 
|---|
| 54 | class ScriptCreateDialog; | 
|---|
| 55 |  | 
|---|
| 56 | class EditorPlugin : public Node { | 
|---|
| 57 | GDCLASS(EditorPlugin, Node); | 
|---|
| 58 | friend class EditorData; | 
|---|
| 59 |  | 
|---|
| 60 | bool input_event_forwarding_always_enabled = false; | 
|---|
| 61 | bool force_draw_over_forwarding_enabled = false; | 
|---|
| 62 |  | 
|---|
| 63 | String last_main_screen_name; | 
|---|
| 64 | String plugin_version; | 
|---|
| 65 |  | 
|---|
| 66 | #ifndef DISABLE_DEPRECATED | 
|---|
| 67 | void _editor_project_settings_changed(); | 
|---|
| 68 | #endif | 
|---|
| 69 |  | 
|---|
| 70 | protected: | 
|---|
| 71 | void _notification(int p_what); | 
|---|
| 72 |  | 
|---|
| 73 | static void _bind_methods(); | 
|---|
| 74 | EditorUndoRedoManager *get_undo_redo(); | 
|---|
| 75 |  | 
|---|
| 76 | void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon); | 
|---|
| 77 | void remove_custom_type(const String &p_type); | 
|---|
| 78 |  | 
|---|
| 79 | GDVIRTUAL1R(bool, _forward_canvas_gui_input, Ref<InputEvent>) | 
|---|
| 80 | GDVIRTUAL1(_forward_canvas_draw_over_viewport, Control *) | 
|---|
| 81 | GDVIRTUAL1(_forward_canvas_force_draw_over_viewport, Control *) | 
|---|
| 82 | GDVIRTUAL2R(int, _forward_3d_gui_input, Camera3D *, Ref<InputEvent>) | 
|---|
| 83 | GDVIRTUAL1(_forward_3d_draw_over_viewport, Control *) | 
|---|
| 84 | GDVIRTUAL1(_forward_3d_force_draw_over_viewport, Control *) | 
|---|
| 85 | GDVIRTUAL0RC(String, _get_plugin_name) | 
|---|
| 86 | GDVIRTUAL0RC(Ref<Texture2D>, _get_plugin_icon) | 
|---|
| 87 | GDVIRTUAL0RC(bool, _has_main_screen) | 
|---|
| 88 | GDVIRTUAL1(_make_visible, bool) | 
|---|
| 89 | GDVIRTUAL1(_edit, Object *) | 
|---|
| 90 | GDVIRTUAL1RC(bool, _handles, Object *) | 
|---|
| 91 | GDVIRTUAL0RC(Dictionary, _get_state) | 
|---|
| 92 | GDVIRTUAL1(_set_state, Dictionary) | 
|---|
| 93 | GDVIRTUAL0(_clear) | 
|---|
| 94 | GDVIRTUAL1RC(String, _get_unsaved_status, String) | 
|---|
| 95 | GDVIRTUAL0(_save_external_data) | 
|---|
| 96 | GDVIRTUAL0(_apply_changes) | 
|---|
| 97 | GDVIRTUAL0RC(Vector<String>, _get_breakpoints) | 
|---|
| 98 | GDVIRTUAL1(_set_window_layout, Ref<ConfigFile>) | 
|---|
| 99 | GDVIRTUAL1(_get_window_layout, Ref<ConfigFile>) | 
|---|
| 100 | GDVIRTUAL0R(bool, _build) | 
|---|
| 101 | GDVIRTUAL0(_enable_plugin) | 
|---|
| 102 | GDVIRTUAL0(_disable_plugin) | 
|---|
| 103 |  | 
|---|
| 104 | public: | 
|---|
| 105 | enum CustomControlContainer { | 
|---|
| 106 | CONTAINER_TOOLBAR, | 
|---|
| 107 | , | 
|---|
| 108 | CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, | 
|---|
| 109 | CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, | 
|---|
| 110 | CONTAINER_SPATIAL_EDITOR_BOTTOM, | 
|---|
| 111 | , | 
|---|
| 112 | CONTAINER_CANVAS_EDITOR_SIDE_LEFT, | 
|---|
| 113 | CONTAINER_CANVAS_EDITOR_SIDE_RIGHT, | 
|---|
| 114 | CONTAINER_CANVAS_EDITOR_BOTTOM, | 
|---|
| 115 | CONTAINER_INSPECTOR_BOTTOM, | 
|---|
| 116 | CONTAINER_PROJECT_SETTING_TAB_LEFT, | 
|---|
| 117 | CONTAINER_PROJECT_SETTING_TAB_RIGHT, | 
|---|
| 118 | }; | 
|---|
| 119 |  | 
|---|
| 120 | enum DockSlot { | 
|---|
| 121 | DOCK_SLOT_LEFT_UL, | 
|---|
| 122 | DOCK_SLOT_LEFT_BL, | 
|---|
| 123 | DOCK_SLOT_LEFT_UR, | 
|---|
| 124 | DOCK_SLOT_LEFT_BR, | 
|---|
| 125 | DOCK_SLOT_RIGHT_UL, | 
|---|
| 126 | DOCK_SLOT_RIGHT_BL, | 
|---|
| 127 | DOCK_SLOT_RIGHT_UR, | 
|---|
| 128 | DOCK_SLOT_RIGHT_BR, | 
|---|
| 129 | DOCK_SLOT_MAX | 
|---|
| 130 | }; | 
|---|
| 131 |  | 
|---|
| 132 | enum AfterGUIInput { | 
|---|
| 133 | AFTER_GUI_INPUT_PASS, | 
|---|
| 134 | AFTER_GUI_INPUT_STOP, | 
|---|
| 135 | AFTER_GUI_INPUT_CUSTOM | 
|---|
| 136 | }; | 
|---|
| 137 |  | 
|---|
| 138 | //TODO: send a resource for editing to the editor node? | 
|---|
| 139 |  | 
|---|
| 140 | void add_control_to_container(CustomControlContainer p_location, Control *p_control); | 
|---|
| 141 | void remove_control_from_container(CustomControlContainer p_location, Control *p_control); | 
|---|
| 142 | Button *add_control_to_bottom_panel(Control *p_control, const String &p_title); | 
|---|
| 143 | void add_control_to_dock(DockSlot p_slot, Control *p_control); | 
|---|
| 144 | void remove_control_from_docks(Control *p_control); | 
|---|
| 145 | void remove_control_from_bottom_panel(Control *p_control); | 
|---|
| 146 |  | 
|---|
| 147 | void (const String &p_name, const Callable &p_callable); | 
|---|
| 148 | void (const String &p_name, PopupMenu *); | 
|---|
| 149 | void (const String &p_name); | 
|---|
| 150 |  | 
|---|
| 151 | PopupMenu *(); | 
|---|
| 152 |  | 
|---|
| 153 | void set_input_event_forwarding_always_enabled(); | 
|---|
| 154 | bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; } | 
|---|
| 155 |  | 
|---|
| 156 | void set_force_draw_over_forwarding_enabled(); | 
|---|
| 157 | bool is_force_draw_over_forwarding_enabled() { return force_draw_over_forwarding_enabled; } | 
|---|
| 158 |  | 
|---|
| 159 | void notify_main_screen_changed(const String &screen_name); | 
|---|
| 160 | void notify_scene_changed(const Node *scn_root); | 
|---|
| 161 | void notify_scene_closed(const String &scene_filepath); | 
|---|
| 162 | void notify_resource_saved(const Ref<Resource> &p_resource); | 
|---|
| 163 |  | 
|---|
| 164 | virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event); | 
|---|
| 165 | virtual void forward_canvas_draw_over_viewport(Control *p_overlay); | 
|---|
| 166 | virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay); | 
|---|
| 167 |  | 
|---|
| 168 | virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event); | 
|---|
| 169 | virtual void forward_3d_draw_over_viewport(Control *p_overlay); | 
|---|
| 170 | virtual void forward_3d_force_draw_over_viewport(Control *p_overlay); | 
|---|
| 171 |  | 
|---|
| 172 | virtual String get_name() const; | 
|---|
| 173 | virtual const Ref<Texture2D> get_icon() const; | 
|---|
| 174 | virtual String get_plugin_version() const; | 
|---|
| 175 | virtual void set_plugin_version(const String &p_version); | 
|---|
| 176 | virtual bool has_main_screen() const; | 
|---|
| 177 | virtual void make_visible(bool p_visible); | 
|---|
| 178 | virtual void selected_notify() {} //notify that it was raised by the user, not the editor | 
|---|
| 179 | virtual void edit(Object *p_object); | 
|---|
| 180 | virtual bool handles(Object *p_object) const; | 
|---|
| 181 | virtual Dictionary get_state() const; //save editor state so it can't be reloaded when reloading scene | 
|---|
| 182 | virtual void set_state(const Dictionary &p_state); //restore editor state (likely was saved with the scene) | 
|---|
| 183 | virtual void clear(); // clear any temporary data in the editor, reset it (likely new scene or load another scene) | 
|---|
| 184 | virtual String get_unsaved_status(const String &p_for_scene = "") const; | 
|---|
| 185 | virtual void save_external_data(); // if editor references external resources/scenes, save them | 
|---|
| 186 | virtual void apply_changes(); // if changes are pending in editor, apply them | 
|---|
| 187 | virtual void get_breakpoints(List<String> *p_breakpoints); | 
|---|
| 188 | virtual bool get_remove_list(List<Node *> *p_list); | 
|---|
| 189 | virtual void set_window_layout(Ref<ConfigFile> p_layout); | 
|---|
| 190 | virtual void get_window_layout(Ref<ConfigFile> p_layout); | 
|---|
| 191 | virtual void edited_scene_changed() {} // if changes are pending in editor, apply them | 
|---|
| 192 | virtual bool build(); // builds with external tools. Returns true if safe to continue running scene. | 
|---|
| 193 |  | 
|---|
| 194 | EditorInterface *get_editor_interface(); | 
|---|
| 195 | ScriptCreateDialog *get_script_create_dialog(); | 
|---|
| 196 |  | 
|---|
| 197 | void add_undo_redo_inspector_hook_callback(Callable p_callable); | 
|---|
| 198 | void remove_undo_redo_inspector_hook_callback(Callable p_callable); | 
|---|
| 199 |  | 
|---|
| 200 | int update_overlays() const; | 
|---|
| 201 |  | 
|---|
| 202 | void queue_save_layout(); | 
|---|
| 203 |  | 
|---|
| 204 | void make_bottom_panel_item_visible(Control *p_item); | 
|---|
| 205 | void hide_bottom_panel(); | 
|---|
| 206 |  | 
|---|
| 207 | void add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser); | 
|---|
| 208 | void remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser); | 
|---|
| 209 |  | 
|---|
| 210 | void add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority = false); | 
|---|
| 211 | void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer); | 
|---|
| 212 |  | 
|---|
| 213 | void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter); | 
|---|
| 214 | void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter); | 
|---|
| 215 |  | 
|---|
| 216 | void add_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin); | 
|---|
| 217 | void remove_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin); | 
|---|
| 218 |  | 
|---|
| 219 | void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); | 
|---|
| 220 | void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); | 
|---|
| 221 |  | 
|---|
| 222 | void add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer, bool p_first_priority = false); | 
|---|
| 223 | void remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer); | 
|---|
| 224 |  | 
|---|
| 225 | void add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer, bool p_first_priority = false); | 
|---|
| 226 | void remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer); | 
|---|
| 227 |  | 
|---|
| 228 | void add_autoload_singleton(const String &p_name, const String &p_path); | 
|---|
| 229 | void remove_autoload_singleton(const String &p_name); | 
|---|
| 230 |  | 
|---|
| 231 | void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin); | 
|---|
| 232 | void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin); | 
|---|
| 233 |  | 
|---|
| 234 | void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin); | 
|---|
| 235 | void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin); | 
|---|
| 236 |  | 
|---|
| 237 | void enable_plugin(); | 
|---|
| 238 | void disable_plugin(); | 
|---|
| 239 |  | 
|---|
| 240 | EditorPlugin() {} | 
|---|
| 241 | virtual ~EditorPlugin() {} | 
|---|
| 242 | }; | 
|---|
| 243 |  | 
|---|
| 244 | VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer); | 
|---|
| 245 | VARIANT_ENUM_CAST(EditorPlugin::DockSlot); | 
|---|
| 246 | VARIANT_ENUM_CAST(EditorPlugin::AfterGUIInput); | 
|---|
| 247 |  | 
|---|
| 248 | typedef EditorPlugin *(*EditorPluginCreateFunc)(); | 
|---|
| 249 |  | 
|---|
| 250 | class EditorPlugins { | 
|---|
| 251 | enum { | 
|---|
| 252 | MAX_CREATE_FUNCS = 128 | 
|---|
| 253 | }; | 
|---|
| 254 |  | 
|---|
| 255 | static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS]; | 
|---|
| 256 | static int creation_func_count; | 
|---|
| 257 |  | 
|---|
| 258 | template <class T> | 
|---|
| 259 | static EditorPlugin *creator() { | 
|---|
| 260 | return memnew(T); | 
|---|
| 261 | } | 
|---|
| 262 |  | 
|---|
| 263 | public: | 
|---|
| 264 | static int get_plugin_count() { return creation_func_count; } | 
|---|
| 265 | static EditorPlugin *create(int p_idx) { | 
|---|
| 266 | ERR_FAIL_INDEX_V(p_idx, creation_func_count, nullptr); | 
|---|
| 267 | return creation_funcs[p_idx](); | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | template <class T> | 
|---|
| 271 | static void add_by_type() { | 
|---|
| 272 | add_create_func(creator<T>); | 
|---|
| 273 | } | 
|---|
| 274 |  | 
|---|
| 275 | static void add_create_func(EditorPluginCreateFunc p_func) { | 
|---|
| 276 | ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS); | 
|---|
| 277 | creation_funcs[creation_func_count++] = p_func; | 
|---|
| 278 | } | 
|---|
| 279 | }; | 
|---|
| 280 |  | 
|---|
| 281 | #endif // EDITOR_PLUGIN_H | 
|---|
| 282 |  | 
|---|