editor_interface.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**************************************************************************/
  2. /* editor_interface.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_INTERFACE_H
  31. #define EDITOR_INTERFACE_H
  32. #include "core/io/resource.h"
  33. #include "core/object/class_db.h"
  34. #include "core/object/object.h"
  35. #include "core/object/script_language.h"
  36. class Control;
  37. class CreateDialog;
  38. class EditorCommandPalette;
  39. class EditorFileSystem;
  40. class EditorInspector;
  41. class EditorPaths;
  42. class EditorPlugin;
  43. class EditorResourcePreview;
  44. class EditorSelection;
  45. class EditorSettings;
  46. class EditorToaster;
  47. class EditorUndoRedoManager;
  48. class FileSystemDock;
  49. class Mesh;
  50. class Node;
  51. class PropertySelector;
  52. class SceneTreeDialog;
  53. class ScriptEditor;
  54. class SubViewport;
  55. class Texture2D;
  56. class Theme;
  57. class VBoxContainer;
  58. class Window;
  59. class EditorInterface : public Object {
  60. GDCLASS(EditorInterface, Object);
  61. static EditorInterface *singleton;
  62. // Editor dialogs.
  63. PropertySelector *property_selector = nullptr;
  64. PropertySelector *method_selector = nullptr;
  65. SceneTreeDialog *node_selector = nullptr;
  66. CreateDialog *create_dialog = nullptr;
  67. void _node_selected(const NodePath &p_node_paths, const Callable &p_callback);
  68. void _property_selected(const String &p_property_name, const Callable &p_callback);
  69. void _method_selected(const String &p_property_name, const Callable &p_callback);
  70. void _quick_open(const String &p_file_path, const Callable &p_callback);
  71. void _create_dialog_item_selected(bool p_is_canceled, const Callable &p_callback);
  72. void _call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context);
  73. // Editor tools.
  74. TypedArray<Texture2D> _make_mesh_previews(const TypedArray<Mesh> &p_meshes, int p_preview_size);
  75. AABB _calculate_aabb_for_scene(Node *p_node, AABB &p_scene_aabb);
  76. protected:
  77. static void _bind_methods();
  78. #ifndef DISABLE_DEPRECATED
  79. void _popup_node_selector_bind_compat_94323(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>());
  80. void _popup_property_selector_bind_compat_94323(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array());
  81. void _open_scene_from_path_bind_compat_90057(const String &scene_path);
  82. static void _bind_compatibility_methods();
  83. #endif
  84. public:
  85. static EditorInterface *get_singleton() { return singleton; }
  86. void restart_editor(bool p_save = true);
  87. // Editor tools.
  88. EditorCommandPalette *get_command_palette() const;
  89. EditorFileSystem *get_resource_file_system() const;
  90. EditorPaths *get_editor_paths() const;
  91. EditorResourcePreview *get_resource_previewer() const;
  92. EditorSelection *get_selection() const;
  93. Ref<EditorSettings> get_editor_settings() const;
  94. EditorToaster *get_editor_toaster() const;
  95. EditorUndoRedoManager *get_editor_undo_redo() const;
  96. Vector<Ref<Texture2D>> make_mesh_previews(const Vector<Ref<Mesh>> &p_meshes, Vector<Transform3D> *p_transforms, int p_preview_size);
  97. void make_scene_preview(const String &p_path, Node *p_scene, int p_preview_size);
  98. void set_plugin_enabled(const String &p_plugin, bool p_enabled);
  99. bool is_plugin_enabled(const String &p_plugin) const;
  100. // Editor GUI.
  101. Ref<Theme> get_editor_theme() const;
  102. Control *get_base_control() const;
  103. VBoxContainer *get_editor_main_screen() const;
  104. ScriptEditor *get_script_editor() const;
  105. SubViewport *get_editor_viewport_2d() const;
  106. SubViewport *get_editor_viewport_3d(int p_idx = 0) const;
  107. void set_main_screen_editor(const String &p_name);
  108. void set_distraction_free_mode(bool p_enter);
  109. bool is_distraction_free_mode_enabled() const;
  110. bool is_multi_window_enabled() const;
  111. float get_editor_scale() const;
  112. void popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect = Rect2i());
  113. void popup_dialog_centered(Window *p_dialog, const Size2i &p_minsize = Size2i());
  114. void popup_dialog_centered_ratio(Window *p_dialog, float p_ratio = 0.8);
  115. void popup_dialog_centered_clamped(Window *p_dialog, const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75);
  116. String get_current_feature_profile() const;
  117. void set_current_feature_profile(const String &p_profile_name);
  118. // Editor dialogs.
  119. void popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>(), Node *p_current_value = nullptr);
  120. // Must use Vector<int> because exposing Vector<Variant::Type> is not supported.
  121. void popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array(), const String &p_current_value = String());
  122. void popup_method_selector(Object *p_object, const Callable &p_callback, const String &p_current_value = String());
  123. void popup_quick_open(const Callable &p_callback, const TypedArray<StringName> &p_base_types = TypedArray<StringName>());
  124. void popup_create_dialog(const Callable &p_callback, const StringName &p_base_type = "", const String &p_current_type = "", const String &p_dialog_title = "", const TypedArray<StringName> &p_custom_type_blocklist = TypedArray<StringName>());
  125. // Editor docks.
  126. FileSystemDock *get_file_system_dock() const;
  127. void select_file(const String &p_file);
  128. Vector<String> get_selected_paths() const;
  129. String get_current_path() const;
  130. String get_current_directory() const;
  131. EditorInspector *get_inspector() const;
  132. // Object/Resource/Node editing.
  133. void inspect_object(Object *p_obj, const String &p_for_property = String(), bool p_inspector_only = false);
  134. void edit_resource(const Ref<Resource> &p_resource);
  135. void edit_node(Node *p_node);
  136. void edit_script(const Ref<Script> &p_script, int p_line = -1, int p_col = 0, bool p_grab_focus = true);
  137. void open_scene_from_path(const String &scene_path, bool p_set_inherited = false);
  138. void reload_scene_from_path(const String &scene_path);
  139. PackedStringArray get_open_scenes() const;
  140. Node *get_edited_scene_root() const;
  141. Error save_scene();
  142. void save_scene_as(const String &p_scene, bool p_with_preview = true);
  143. void mark_scene_as_unsaved();
  144. void save_all_scenes();
  145. // Scene playback.
  146. void play_main_scene();
  147. void play_current_scene();
  148. void play_custom_scene(const String &scene_path);
  149. void stop_playing_scene();
  150. bool is_playing_scene() const;
  151. String get_playing_scene() const;
  152. void set_movie_maker_enabled(bool p_enabled);
  153. bool is_movie_maker_enabled() const;
  154. #ifdef TOOLS_ENABLED
  155. virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
  156. #endif
  157. // Base.
  158. static void create();
  159. static void free();
  160. EditorInterface();
  161. };
  162. #endif // EDITOR_INTERFACE_H