Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/docks/scene_tree_dock.h
9896 views
1
/**************************************************************************/
2
/* scene_tree_dock.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 "editor/scene/scene_tree_editor.h"
34
#include "editor/script/script_create_dialog.h"
35
#include "scene/gui/box_container.h"
36
#include "scene/resources/animation.h"
37
38
class CheckBox;
39
class EditorData;
40
class EditorSelection;
41
class MenuButton;
42
class RenameDialog;
43
class ReparentDialog;
44
class ShaderCreateDialog;
45
class TextureRect;
46
47
class SceneTreeDock : public VBoxContainer {
48
GDCLASS(SceneTreeDock, VBoxContainer);
49
50
enum Tool {
51
TOOL_NEW,
52
TOOL_INSTANTIATE,
53
TOOL_EXPAND_COLLAPSE,
54
TOOL_CUT,
55
TOOL_COPY,
56
TOOL_PASTE,
57
TOOL_PASTE_AS_SIBLING,
58
TOOL_RENAME,
59
TOOL_BATCH_RENAME,
60
TOOL_REPLACE,
61
TOOL_EXTEND_SCRIPT,
62
TOOL_ATTACH_SCRIPT,
63
TOOL_DETACH_SCRIPT,
64
TOOL_MOVE_UP,
65
TOOL_MOVE_DOWN,
66
TOOL_DUPLICATE,
67
TOOL_REPARENT,
68
TOOL_REPARENT_TO_NEW_NODE,
69
TOOL_MAKE_ROOT,
70
TOOL_NEW_SCENE_FROM,
71
TOOL_MULTI_EDIT,
72
TOOL_ERASE,
73
TOOL_COPY_NODE_PATH,
74
TOOL_SHOW_IN_FILE_SYSTEM,
75
TOOL_OPEN_DOCUMENTATION,
76
TOOL_AUTO_EXPAND,
77
TOOL_SCENE_EDITABLE_CHILDREN,
78
TOOL_SCENE_USE_PLACEHOLDER,
79
TOOL_SCENE_MAKE_LOCAL,
80
TOOL_SCENE_OPEN,
81
TOOL_SCENE_CLEAR_INHERITANCE,
82
TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM,
83
TOOL_SCENE_OPEN_INHERITED,
84
TOOL_TOGGLE_SCENE_UNIQUE_NAME,
85
TOOL_CREATE_2D_SCENE,
86
TOOL_CREATE_3D_SCENE,
87
TOOL_CREATE_USER_INTERFACE,
88
TOOL_CREATE_FAVORITE,
89
TOOL_CENTER_PARENT,
90
TOOL_HIDE_FILTERED_OUT_PARENTS,
91
TOOL_ACCESSIBILITY_WARNINGS,
92
};
93
94
enum {
95
EDIT_SUBRESOURCE_BASE = 100
96
};
97
98
Vector<ObjectID> subresources;
99
100
bool reset_create_dialog = false;
101
102
int current_option = 0;
103
CreateDialog *create_dialog = nullptr;
104
RenameDialog *rename_dialog = nullptr;
105
106
Button *button_add = nullptr;
107
Button *button_instance = nullptr;
108
Button *button_create_script = nullptr;
109
Button *button_detach_script = nullptr;
110
Button *button_extend_script = nullptr;
111
MenuButton *button_tree_menu = nullptr;
112
113
Button *node_shortcuts_toggle = nullptr;
114
VBoxContainer *beginner_node_shortcuts = nullptr;
115
VBoxContainer *favorite_node_shortcuts = nullptr;
116
117
Button *button_2d = nullptr;
118
Button *button_3d = nullptr;
119
Button *button_ui = nullptr;
120
Button *button_custom = nullptr;
121
Button *button_clipboard = nullptr;
122
123
HBoxContainer *button_hb = nullptr;
124
Button *edit_local, *edit_remote;
125
SceneTreeEditor *scene_tree = nullptr;
126
Control *remote_tree = nullptr;
127
128
HBoxContainer *tool_hbc = nullptr;
129
void _tool_selected(int p_tool, bool p_confirm_override = false);
130
void _property_selected(int p_idx);
131
132
Node *property_drop_node = nullptr;
133
String resource_drop_path;
134
void _perform_property_drop(Node *p_node, const String &p_property, Ref<Resource> p_res);
135
136
EditorData *editor_data = nullptr;
137
EditorSelection *editor_selection = nullptr;
138
LocalVector<ObjectID> node_previous_selection;
139
bool update_script_button_queued = false;
140
141
List<Node *> node_clipboard;
142
HashSet<Node *> node_clipboard_edited_scene_owned;
143
String clipboard_source_scene;
144
HashMap<String, HashMap<Ref<Resource>, Ref<Resource>>> clipboard_resource_remap;
145
146
ScriptCreateDialog *script_create_dialog = nullptr;
147
ShaderCreateDialog *shader_create_dialog = nullptr;
148
AcceptDialog *accept = nullptr;
149
ConfirmationDialog *delete_dialog = nullptr;
150
Label *delete_dialog_label = nullptr;
151
CheckBox *delete_tracks_checkbox = nullptr;
152
ConfirmationDialog *editable_instance_remove_dialog = nullptr;
153
ConfirmationDialog *placeholder_editable_instance_remove_dialog = nullptr;
154
155
ReparentDialog *reparent_dialog = nullptr;
156
EditorFileDialog *new_scene_from_dialog = nullptr;
157
158
enum FilterMenuItems {
159
FILTER_BY_TYPE = 64, // Used in the same menus as the Tool enum.
160
FILTER_BY_GROUP,
161
};
162
163
LineEdit *filter = nullptr;
164
PopupMenu *filter_quick_menu = nullptr;
165
TextureRect *filter_icon = nullptr;
166
167
PopupMenu *menu = nullptr;
168
PopupMenu *menu_subresources = nullptr;
169
PopupMenu *menu_properties = nullptr;
170
ConfirmationDialog *clear_inherit_confirm = nullptr;
171
172
bool first_enter = true;
173
174
void _create();
175
Node *_do_create(Node *p_parent);
176
void _post_do_create(Node *p_child);
177
Node *scene_root = nullptr;
178
Node *edited_scene = nullptr;
179
Node *pending_click_select = nullptr;
180
bool tree_clicked = false;
181
182
VBoxContainer *create_root_dialog = nullptr;
183
String selected_favorite_root;
184
185
Ref<ShaderMaterial> selected_shader_material;
186
187
void _add_children_to_popup(Object *p_obj, int p_depth);
188
189
void _node_reparent(NodePath p_path, bool p_keep_global_xform);
190
void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform);
191
192
void _set_owners(Node *p_owner, const Array &p_nodes);
193
194
enum ReplaceOwnerMode {
195
MODE_BIDI,
196
MODE_DO,
197
MODE_UNDO
198
};
199
200
void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode = MODE_BIDI);
201
void _node_strip_signal_inheritance(Node *p_node);
202
void _load_request(const String &p_path);
203
void _script_open_request(const Ref<Script> &p_script);
204
void _push_item(Object *p_object);
205
void _handle_select(Node *p_node);
206
207
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
208
bool _track_inherit(const String &p_target_scene_path, Node *p_desired_node);
209
210
void _node_selected();
211
void _node_renamed();
212
void _script_created(Ref<Script> p_script);
213
void _shader_created(Ref<Shader> p_shader);
214
void _script_creation_closed();
215
void _shader_creation_closed();
216
217
void _delete_confirm(bool p_cut = false);
218
void _delete_dialog_closed();
219
220
void _toggle_editable_children_from_selection();
221
222
void _reparent_nodes_to_root(Node *p_root, const Array &p_nodes, Node *p_owner);
223
void _reparent_nodes_to_paths_with_transform_and_name(Node *p_root, const Array &p_nodes, const Array &p_paths, const Array &p_transforms, const Array &p_names, Node *p_owner);
224
void _toggle_editable_children(Node *p_node);
225
226
void _toggle_placeholder_from_selection();
227
228
void _node_prerenamed(Node *p_node, const String &p_new_name);
229
230
void _nodes_drag_begin();
231
232
void _handle_hover_to_inspect();
233
void _inspect_hovered_node();
234
void _reset_hovering_timer();
235
Timer *inspect_hovered_node_delay = nullptr;
236
TreeItem *tree_item_inspected = nullptr;
237
Node *node_hovered_now = nullptr;
238
Node *node_hovered_previously = nullptr;
239
bool select_node_hovered_at_end_of_drag = false;
240
bool hovered_but_reparenting = false;
241
242
virtual void input(const Ref<InputEvent> &p_event) override;
243
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
244
void _scene_tree_gui_input(Ref<InputEvent> p_event);
245
246
void _new_scene_from(const String &p_file);
247
void _set_node_owner_recursive(Node *p_node, Node *p_owner, const HashMap<const Node *, Node *> &p_inverse_duplimap);
248
249
bool _validate_no_foreign();
250
bool _validate_no_instance();
251
void _selection_changed();
252
void _update_script_button();
253
void _queue_update_script_button();
254
255
void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, HashMap<Node *, NodePath> *p_renames);
256
bool _has_tracks_to_delete(Node *p_node, List<Node *> &p_to_delete) const;
257
258
void _normalize_drop(Node *&to_node, int &to_pos, int p_type);
259
Array _get_selection_array();
260
261
void _nodes_dragged(const Array &p_nodes, NodePath p_to, int p_type);
262
void _files_dropped(const Vector<String> &p_files, NodePath p_to, int p_type);
263
void _script_dropped(const String &p_file, NodePath p_to);
264
void _quick_open(const String &p_file_path);
265
266
void _tree_rmb(const Vector2 &p_menu_pos);
267
void _update_tree_menu();
268
269
void _filter_changed(const String &p_filter);
270
void _filter_gui_input(const Ref<InputEvent> &p_event);
271
void _filter_option_selected(int option);
272
void _append_filter_options_to(PopupMenu *p_menu, bool p_include_separator = true);
273
274
void _perform_instantiate_scenes(const Vector<String> &p_files, Node *p_parent, int p_pos);
275
void _perform_create_audio_stream_players(const Vector<String> &p_files, Node *p_parent, int p_pos);
276
void _replace_with_branch_scene(const String &p_file, Node *base);
277
278
void _remote_tree_selected();
279
void _local_tree_selected();
280
281
void _update_create_root_dialog(bool p_initializing = false);
282
void _favorite_root_selected(const String &p_class);
283
284
void _feature_profile_changed();
285
286
void _clear_clipboard();
287
void _create_remap_for_node(Node *p_node, HashMap<Ref<Resource>, Ref<Resource>> &r_remap);
288
void _create_remap_for_resource(Ref<Resource> p_resource, HashMap<Ref<Resource>, Ref<Resource>> &r_remap);
289
290
void _list_all_subresources(PopupMenu *p_menu);
291
void _gather_resources(Node *p_node, List<Pair<Ref<Resource>, Node *>> &r_resources);
292
void _edit_subresource(int p_idx, const PopupMenu *p_from_menu);
293
294
bool profile_allow_editing = true;
295
bool profile_allow_script_editing = true;
296
bool determine_path_automatically = true;
297
298
static void _update_configuration_warning();
299
300
bool _update_node_path(Node *p_root_node, NodePath &r_node_path, HashMap<Node *, NodePath> *p_renames) const;
301
void _check_object_properties_recursive(Node *p_root_node, Object *p_obj, HashMap<Node *, NodePath> *p_renames, bool p_inside_resource = false) const;
302
bool _check_node_path_recursive(Node *p_root_node, Variant &r_variant, HashMap<Node *, NodePath> *p_renames, bool p_inside_resource = false) const;
303
bool _check_node_recursive(Variant &r_variant, Node *p_node, Node *p_by_node, const String type_hint, String &r_warn_message);
304
void _replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties = true, bool p_remove_old = true);
305
306
private:
307
static SceneTreeDock *singleton;
308
309
public:
310
static SceneTreeDock *get_singleton() { return singleton; }
311
312
protected:
313
void _notification(int p_what);
314
static void _bind_methods();
315
316
public:
317
String get_filter();
318
void set_filter(const String &p_filter);
319
void save_branch_to_file(const String &p_directory);
320
321
void _focus_node();
322
323
void add_root_node(Node *p_node);
324
void set_edited_scene(Node *p_scene);
325
void instantiate(const String &p_file);
326
void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr);
327
void clear_previous_node_selection();
328
void set_selection(const Vector<Node *> &p_nodes);
329
void set_selected(Node *p_node, bool p_emit_selected = false);
330
void fill_path_renames(Node *p_node, Node *p_new_parent, HashMap<Node *, NodePath> *p_renames);
331
void perform_node_renames(Node *p_base, HashMap<Node *, NodePath> *p_renames, HashMap<Ref<Animation>, HashSet<int>> *r_rem_anims = nullptr);
332
void perform_node_replace(Node *p_base, Node *p_node, Node *p_by_node);
333
SceneTreeEditor *get_tree_editor() { return scene_tree; }
334
EditorData *get_editor_data() { return editor_data; }
335
336
void add_remote_tree_editor(Control *p_remote);
337
void show_remote_tree();
338
void hide_remote_tree();
339
void show_tab_buttons();
340
void hide_tab_buttons();
341
342
void replace_node(Node *p_node, Node *p_by_node);
343
344
void attach_script_to_selected(bool p_extend);
345
void open_script_dialog(Node *p_for_node, bool p_extend);
346
347
void attach_shader_to_selected(int p_preferred_mode = -1);
348
void open_shader_dialog(const Ref<ShaderMaterial> &p_for_material, int p_preferred_mode = -1);
349
350
void open_add_child_dialog();
351
void open_instance_child_dialog();
352
353
List<Node *> paste_nodes(bool p_paste_as_sibling = false);
354
List<Node *> get_node_clipboard() const;
355
356
ScriptCreateDialog *get_script_create_dialog() {
357
return script_create_dialog;
358
}
359
360
SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data);
361
~SceneTreeDock();
362
};
363
364