editor_plugin.h 12 KB

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