0.2.0-dev Download ZIP
224 lines ·9.1 KB Raw
| 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 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include "core/io/resource.h" |
| 34 | #include "core/object/object.h" |
| 35 | #include "core/object/script_language.h" |
| 36 | |
| 37 | class Control; |
| 38 | class CreateDialog; |
| 39 | class EditorCommandPalette; |
| 40 | class EditorDock; |
| 41 | class EditorFileSystem; |
| 42 | class EditorInspector; |
| 43 | class EditorPaths; |
| 44 | class EditorPlugin; |
| 45 | class EditorResourcePreview; |
| 46 | class EditorSelection; |
| 47 | class EditorSettings; |
| 48 | class EditorToaster; |
| 49 | class EditorUndoRedoManager; |
| 50 | class ScenePaint2DEditor; |
| 51 | class FileSystemDock; |
| 52 | class Mesh; |
| 53 | class Node; |
| 54 | class PropertySelector; |
| 55 | class SceneTreeDialog; |
| 56 | class ScriptEditor; |
| 57 | class SubViewport; |
| 58 | class Texture2D; |
| 59 | class Theme; |
| 60 | class VBoxContainer; |
| 61 | class Window; |
| 62 | |
| 63 | class EditorInterface : public Object { |
| 64 | GDCLASS(EditorInterface, Object); |
| 65 | |
| 66 | static EditorInterface *singleton; |
| 67 | |
| 68 | // Editor dialogs. |
| 69 | |
| 70 | PropertySelector *property_selector = nullptr; |
| 71 | PropertySelector *method_selector = nullptr; |
| 72 | SceneTreeDialog *node_selector = nullptr; |
| 73 | CreateDialog *create_dialog = nullptr; |
| 74 | |
| 75 | void _node_selected(const NodePath &p_node_paths, const Callable &p_callback); |
| 76 | void _property_selected(const String &p_property_name, const Callable &p_callback); |
| 77 | void _method_selected(const String &p_property_name, const Callable &p_callback); |
| 78 | void _quick_open(const String &p_file_path, const Callable &p_callback); |
| 79 | void _create_dialog_item_selected(bool p_is_canceled, const Callable &p_callback); |
| 80 | void _call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context); |
| 81 | |
| 82 | // Editor tools. |
| 83 | |
| 84 | TypedArray<Texture2D> _make_mesh_previews(const TypedArray<Mesh> &p_meshes, int p_preview_size); |
| 85 | AABB _calculate_aabb_for_scene(Node *p_node, AABB &p_scene_aabb); |
| 86 | |
| 87 | protected: |
| 88 | static void _bind_methods(); |
| 89 | |
| 90 | #ifndef DISABLE_DEPRECATED |
| 91 | void _popup_node_selector_bind_compat_94323(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>()); |
| 92 | void _popup_property_selector_bind_compat_94323(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array()); |
| 93 | void _open_scene_from_path_bind_compat_90057(const String &scene_path); |
| 94 | static void _bind_compatibility_methods(); |
| 95 | #endif |
| 96 | |
| 97 | public: |
| 98 | static EditorInterface *get_singleton() { return singleton; } |
| 99 | |
| 100 | bool is_exiting() const; |
| 101 | void restart_editor(bool p_save = true); |
| 102 | |
| 103 | // Editor tools. |
| 104 | |
| 105 | EditorCommandPalette *get_command_palette() const; |
| 106 | EditorFileSystem *get_resource_filesystem() const; |
| 107 | EditorPaths *get_editor_paths() const; |
| 108 | EditorResourcePreview *get_resource_previewer() const; |
| 109 | EditorSelection *get_selection() const; |
| 110 | Ref<EditorSettings> get_editor_settings() const; |
| 111 | EditorToaster *get_editor_toaster() const; |
| 112 | EditorUndoRedoManager *get_editor_undo_redo() const; |
| 113 | ScenePaint2DEditor *get_scene_paint_2d() const; |
| 114 | |
| 115 | Vector<Ref<Texture2D>> make_mesh_previews(const Vector<Ref<Mesh>> &p_meshes, Vector<Transform3D> *p_transforms, int p_preview_size); |
| 116 | void make_scene_preview(const String &p_path, Node *p_scene, int p_preview_size); |
| 117 | |
| 118 | void set_plugin_enabled(const String &p_plugin, bool p_enabled); |
| 119 | bool is_plugin_enabled(const String &p_plugin) const; |
| 120 | |
| 121 | // Editor GUI. |
| 122 | |
| 123 | Ref<Theme> get_editor_theme() const; |
| 124 | |
| 125 | Control *get_base_control() const; |
| 126 | #ifndef DISABLE_DEPRECATED |
| 127 | VBoxContainer *get_editor_main_screen() const; |
| 128 | #endif |
| 129 | ScriptEditor *get_script_editor() const; |
| 130 | SubViewport *get_editor_viewport_2d() const; |
| 131 | SubViewport *get_editor_viewport_3d(int p_idx = 0) const; |
| 132 | |
| 133 | #ifndef DISABLE_DEPRECATED |
| 134 | void set_main_screen_editor(const String &p_name); |
| 135 | #endif |
| 136 | EditorDock *get_dock_by_name(const String &p_name); |
| 137 | void set_distraction_free_mode(bool p_enter); |
| 138 | bool is_distraction_free_mode_enabled() const; |
| 139 | bool is_multi_window_enabled() const; |
| 140 | |
| 141 | float get_editor_scale() const; |
| 142 | String get_editor_language() const; |
| 143 | |
| 144 | bool is_node_3d_snap_enabled() const; |
| 145 | real_t get_node_3d_translate_snap() const; |
| 146 | real_t get_node_3d_rotate_snap() const; |
| 147 | real_t get_node_3d_scale_snap() const; |
| 148 | |
| 149 | void popup_dialog(Window *p_dialog, const Rect2i &p_screen_rect = Rect2i()); |
| 150 | void popup_dialog_centered(Window *p_dialog, const Size2i &p_minsize = Size2i()); |
| 151 | void popup_dialog_centered_ratio(Window *p_dialog, float p_ratio = 0.8); |
| 152 | void popup_dialog_centered_clamped(Window *p_dialog, const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75); |
| 153 | |
| 154 | String get_current_feature_profile() const; |
| 155 | void set_current_feature_profile(const String &p_profile_name); |
| 156 | |
| 157 | // Editor dialogs. |
| 158 | |
| 159 | void popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>(), Node *p_current_value = nullptr); |
| 160 | // Must use Vector<int> because exposing Vector<Variant::Type> is not supported. |
| 161 | void popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array(), const String &p_current_value = String()); |
| 162 | void popup_method_selector(Object *p_object, const Callable &p_callback, const String &p_current_value = String()); |
| 163 | void popup_quick_open(const Callable &p_callback, const TypedArray<StringName> &p_base_types = TypedArray<StringName>()); |
| 164 | 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>()); |
| 165 | |
| 166 | // Editor docks. |
| 167 | |
| 168 | FileSystemDock *get_file_system_dock() const; |
| 169 | void select_file(const String &p_file); |
| 170 | Vector<String> get_selected_paths() const; |
| 171 | String get_current_path() const; |
| 172 | String get_current_directory() const; |
| 173 | |
| 174 | EditorInspector *get_inspector() const; |
| 175 | |
| 176 | // Object/Resource/Node editing. |
| 177 | |
| 178 | void inspect_object(Object *p_obj, const String &p_for_property = String(), bool p_inspector_only = false); |
| 179 | |
| 180 | void edit_resource(const Ref<Resource> &p_resource); |
| 181 | void edit_node(Node *p_node); |
| 182 | void edit_script(const Ref<Script> &p_script, int p_line = -1, int p_col = 0, bool p_grab_focus = true); |
| 183 | void open_scene_from_path(const String &scene_path, bool p_set_inherited = false); |
| 184 | void reload_scene_from_path(const String &scene_path); |
| 185 | |
| 186 | void set_object_edited(Object *p_object, bool p_edited); |
| 187 | bool is_object_edited(Object *p_object) const; |
| 188 | |
| 189 | PackedStringArray get_open_scenes() const; |
| 190 | PackedStringArray get_unsaved_scenes() const; |
| 191 | |
| 192 | TypedArray<Node> get_open_scene_roots() const; |
| 193 | Node *get_edited_scene_root() const; |
| 194 | |
| 195 | void add_root_node(Node *p_node); |
| 196 | |
| 197 | Error save_scene(); |
| 198 | void save_scene_as(const String &p_scene, bool p_with_preview = true); |
| 199 | void mark_scene_as_unsaved(); |
| 200 | void save_all_scenes(); |
| 201 | Error close_scene(); |
| 202 | |
| 203 | // Scene playback. |
| 204 | |
| 205 | void play_main_scene(); |
| 206 | void play_current_scene(); |
| 207 | void play_custom_scene(const String &scene_path); |
| 208 | void stop_playing_scene(); |
| 209 | bool is_playing_scene() const; |
| 210 | String get_playing_scene() const; |
| 211 | |
| 212 | void set_movie_maker_enabled(bool p_enabled); |
| 213 | bool is_movie_maker_enabled() const; |
| 214 | |
| 215 | #ifdef TOOLS_ENABLED |
| 216 | virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 217 | #endif |
| 218 | |
| 219 | // Base. |
| 220 | static void create(); |
| 221 | static void free(); |
| 222 | |
| 223 | EditorInterface(); |
| 224 | }; |