editor_plugin.h 13 KB

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