Debian Codegraph @

editor/docks/scene_tree_dock.h

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