editor_plugin.h 12 KB

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