editor_plugin.h 11 KB

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