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