editor_plugin.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*************************************************************************/
  2. /* editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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 "io/config_file.h"
  33. #include "scene/gui/tool_button.h"
  34. #include "scene/main/node.h"
  35. #include "scene/resources/texture.h"
  36. #include "undo_redo.h"
  37. /**
  38. @author Juan Linietsky <reduzio@gmail.com>
  39. */
  40. class EditorNode;
  41. class Spatial;
  42. class Camera;
  43. class EditorSelection;
  44. class EditorImportExport;
  45. class EditorSettings;
  46. class SpatialEditorGizmo;
  47. class EditorImportPlugin;
  48. class EditorExportPlugin;
  49. class EditorPlugin : public Node {
  50. OBJ_TYPE(EditorPlugin, Node);
  51. friend class EditorData;
  52. UndoRedo *undo_redo;
  53. UndoRedo *_get_undo_redo() { return undo_redo; }
  54. protected:
  55. static void _bind_methods();
  56. UndoRedo &get_undo_redo() { return *undo_redo; }
  57. void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture> &p_icon);
  58. void remove_custom_type(const String &p_type);
  59. public:
  60. enum CustomControlContainer {
  61. CONTAINER_TOOLBAR,
  62. CONTAINER_SPATIAL_EDITOR_MENU,
  63. CONTAINER_SPATIAL_EDITOR_SIDE,
  64. CONTAINER_SPATIAL_EDITOR_BOTTOM,
  65. CONTAINER_CANVAS_EDITOR_MENU,
  66. CONTAINER_CANVAS_EDITOR_SIDE,
  67. CONTAINER_CANVAS_EDITOR_BOTTOM,
  68. CONTAINER_PROPERTY_EDITOR_BOTTOM
  69. };
  70. enum DockSlot {
  71. DOCK_SLOT_LEFT_UL,
  72. DOCK_SLOT_LEFT_BL,
  73. DOCK_SLOT_LEFT_UR,
  74. DOCK_SLOT_LEFT_BR,
  75. DOCK_SLOT_RIGHT_UL,
  76. DOCK_SLOT_RIGHT_BL,
  77. DOCK_SLOT_RIGHT_UR,
  78. DOCK_SLOT_RIGHT_BR,
  79. DOCK_SLOT_MAX
  80. };
  81. //TODO: send a resource for editing to the editor node?
  82. void add_control_to_container(CustomControlContainer p_location, Control *p_control);
  83. ToolButton *add_control_to_bottom_panel(Control *p_control, const String &p_title);
  84. void add_control_to_dock(DockSlot p_slot, Control *p_control);
  85. void remove_control_from_docks(Control *p_control);
  86. void remove_control_from_bottom_panel(Control *p_control);
  87. Control *get_editor_viewport();
  88. void edit_resource(const Ref<Resource> &p_resource);
  89. virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
  90. virtual bool forward_input_event(const InputEvent &p_event);
  91. virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event);
  92. virtual String get_name() const;
  93. virtual bool has_main_screen() const;
  94. virtual void make_visible(bool p_visible);
  95. virtual void selected_notify() {} //notify that it was raised by the user, not the editor
  96. virtual void edit(Object *p_object);
  97. virtual bool handles(Object *p_node) const;
  98. virtual Dictionary get_state() const; //save editor state so it can't be reloaded when reloading scene
  99. virtual void set_state(const Dictionary &p_state); //restore editor state (likely was saved with the scene)
  100. virtual void clear(); // clear any temporary data in te editor, reset it (likely new scene or load another scene)
  101. virtual void save_external_data(); // if editor references external resources/scenes, save them
  102. virtual void apply_changes(); // if changes are pending in editor, apply them
  103. virtual void get_breakpoints(List<String> *p_breakpoints);
  104. virtual bool get_remove_list(List<Node *> *p_list);
  105. virtual void set_window_layout(Ref<ConfigFile> p_layout);
  106. virtual void get_window_layout(Ref<ConfigFile> p_layout);
  107. virtual void edited_scene_changed(){}; // if changes are pending in editor, apply them
  108. void queue_save_layout() const;
  109. Control *get_base_control();
  110. void add_import_plugin(const Ref<EditorImportPlugin> &p_editor_import);
  111. void remove_import_plugin(const Ref<EditorImportPlugin> &p_editor_import);
  112. void add_export_plugin(const Ref<EditorExportPlugin> &p_editor_export);
  113. void remove_export_plugin(const Ref<EditorExportPlugin> &p_editor_export);
  114. EditorSelection *get_selection();
  115. //EditorImportExport *get_import_export();
  116. EditorSettings *get_editor_settings();
  117. virtual void restore_global_state();
  118. virtual void save_global_state();
  119. EditorPlugin();
  120. virtual ~EditorPlugin();
  121. };
  122. VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer);
  123. VARIANT_ENUM_CAST(EditorPlugin::DockSlot);
  124. typedef EditorPlugin *(*EditorPluginCreateFunc)(EditorNode *);
  125. class EditorPlugins {
  126. enum {
  127. MAX_CREATE_FUNCS = 64
  128. };
  129. static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS];
  130. static int creation_func_count;
  131. template <class T>
  132. static EditorPlugin *creator(EditorNode *p_node) {
  133. return memnew(T(p_node));
  134. }
  135. public:
  136. static int get_plugin_count() { return creation_func_count; }
  137. static EditorPlugin *create(int p_idx, EditorNode *p_editor) {
  138. ERR_FAIL_INDEX_V(p_idx, creation_func_count, NULL);
  139. return creation_funcs[p_idx](p_editor);
  140. }
  141. template <class T>
  142. static void add_by_type() {
  143. add_create_func(creator<T>);
  144. }
  145. static void add_create_func(EditorPluginCreateFunc p_func) {
  146. ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS);
  147. creation_funcs[creation_func_count++] = p_func;
  148. }
  149. };
  150. #endif