editor_plugin.h 11 KB

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