diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 735 |
1 files changed, 416 insertions, 319 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index cde4490cd3..5d1a2a49c5 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1,38 +1,39 @@ -/*************************************************************************/ -/* scene_tree_dock.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ +/**************************************************************************/ +/* scene_tree_dock.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ #include "scene_tree_dock.h" #include "core/config/project_settings.h" #include "core/input/input.h" #include "core/io/resource_saver.h" +#include "core/object/class_db.h" #include "core/object/message_queue.h" #include "core/os/keyboard.h" #include "editor/debugger/editor_debugger_node.h" @@ -40,13 +41,17 @@ #include "editor/editor_file_dialog.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" +#include "editor/editor_quick_open.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" +#include "editor/editor_undo_redo_manager.h" +#include "editor/inspector_dock.h" #include "editor/multi_node_edit.h" #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/reparent_dialog.h" #include "editor/shader_create_dialog.h" #include "scene/main/window.h" #include "scene/property_utils.h" @@ -105,7 +110,7 @@ void SceneTreeDock::shortcut_input(const Ref<InputEvent> &p_event) { #endif // MODULE_REGEX_ENABLED } else if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) { _tool_selected(TOOL_NEW); - } else if (ED_IS_SHORTCUT("scene_tree/instance_scene", p_event)) { + } else if (ED_IS_SHORTCUT("scene_tree/instantiate_scene", p_event)) { _tool_selected(TOOL_INSTANTIATE); } else if (ED_IS_SHORTCUT("scene_tree/expand_collapse_all", p_event)) { _tool_selected(TOOL_EXPAND_COLLAPSE); @@ -129,12 +134,16 @@ void SceneTreeDock::shortcut_input(const Ref<InputEvent> &p_event) { _tool_selected(TOOL_MOVE_DOWN); } else if (ED_IS_SHORTCUT("scene_tree/reparent", p_event)) { _tool_selected(TOOL_REPARENT); + } else if (ED_IS_SHORTCUT("scene_tree/reparent_to_new_node", p_event)) { + _tool_selected(TOOL_REPARENT_TO_NEW_NODE); } else if (ED_IS_SHORTCUT("scene_tree/save_branch_as_scene", p_event)) { _tool_selected(TOOL_NEW_SCENE_FROM); } else if (ED_IS_SHORTCUT("scene_tree/delete_no_confirm", p_event)) { _tool_selected(TOOL_ERASE, true); } else if (ED_IS_SHORTCUT("scene_tree/copy_node_path", p_event)) { _tool_selected(TOOL_COPY_NODE_PATH); + } else if (ED_IS_SHORTCUT("scene_tree/toggle_unique_name", p_event)) { + _tool_selected(TOOL_TOGGLE_SCENE_UNIQUE_NAME); } else if (ED_IS_SHORTCUT("scene_tree/delete", p_event)) { _tool_selected(TOOL_ERASE); } else { @@ -195,7 +204,7 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instantiated_scene) { current_option = -1; - accept->set_text(vformat(TTR("Error instancing scene from %s"), p_files[i])); + accept->set_text(vformat(TTR("Error instantiating scene from %s"), p_files[i])); accept->popup_centered(); error = true; break; @@ -203,7 +212,7 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N if (!edited_scene->get_scene_file_path().is_empty()) { if (_cyclical_dependency_exists(edited_scene->get_scene_file_path(), instantiated_scene)) { - accept->set_text(vformat(TTR("Cannot instance the scene '%s' because the current scene exists within one of its nodes."), p_files[i])); + accept->set_text(vformat(TTR("Cannot instantiate the scene '%s' because the current scene exists within one of its nodes."), p_files[i])); accept->popup_centered(); error = true; break; @@ -222,28 +231,29 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N return; } - editor_data->get_undo_redo()->create_action(TTR("Instance Scene(s)")); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Instantiate Scene(s)")); for (int i = 0; i < instances.size(); i++) { Node *instantiated_scene = instances[i]; - editor_data->get_undo_redo()->add_do_method(parent, "add_child", instantiated_scene, true); + undo_redo->add_do_method(parent, "add_child", instantiated_scene, true); if (p_pos >= 0) { - editor_data->get_undo_redo()->add_do_method(parent, "move_child", instantiated_scene, p_pos + i); + undo_redo->add_do_method(parent, "move_child", instantiated_scene, p_pos + i); } - editor_data->get_undo_redo()->add_do_method(instantiated_scene, "set_owner", edited_scene); - editor_data->get_undo_redo()->add_do_method(editor_selection, "clear"); - editor_data->get_undo_redo()->add_do_method(editor_selection, "add_node", instantiated_scene); - editor_data->get_undo_redo()->add_do_reference(instantiated_scene); - editor_data->get_undo_redo()->add_undo_method(parent, "remove_child", instantiated_scene); + undo_redo->add_do_method(instantiated_scene, "set_owner", edited_scene); + undo_redo->add_do_method(editor_selection, "clear"); + undo_redo->add_do_method(editor_selection, "add_node", instantiated_scene); + undo_redo->add_do_reference(instantiated_scene); + undo_redo->add_undo_method(parent, "remove_child", instantiated_scene); String new_name = parent->validate_child_name(instantiated_scene); EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); - editor_data->get_undo_redo()->add_do_method(ed, "live_debug_instance_node", edited_scene->get_path_to(parent), p_files[i], new_name); - editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).path_join(new_name))); + undo_redo->add_do_method(ed, "live_debug_instantiate_node", edited_scene->get_path_to(parent), p_files[i], new_name); + undo_redo->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).path_join(new_name))); } - editor_data->get_undo_redo()->commit_action(); + undo_redo->commit_action(); _push_item(instances[instances.size() - 1]); for (int i = 0; i < instances.size(); i++) { emit_signal(SNAME("node_created"), instances[i]); @@ -260,12 +270,12 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instantiated_scene) { - accept->set_text(vformat(TTR("Error instancing scene from %s"), p_file)); + accept->set_text(vformat(TTR("Error instantiating scene from %s"), p_file)); accept->popup_centered(); return; } - Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_undo_redo(); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Replace with Branch Scene")); Node *parent = base->get_parent(); @@ -328,9 +338,9 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de Ref<SceneState> ss = p->get_scene_inherited_state(); if (ss.is_valid()) { String path = ss->get_path(); - Ref<PackedScene> data = ResourceLoader::load(path); - if (data.is_valid()) { - p = data->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); + Ref<PackedScene> pack_data = ResourceLoader::load(path); + if (pack_data.is_valid()) { + p = pack_data->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!p) { continue; } @@ -439,8 +449,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } - bool collapsed = _is_collapsed_recursive(selected_item); - _set_collapsed_recursive(selected_item, !collapsed); + bool collapsed = selected_item->is_any_collapsed(); + selected_item->set_collapsed_recursive(!collapsed); tree->ensure_cursor_is_visible(); @@ -530,23 +540,24 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { return; } - editor_data->get_undo_redo()->create_action(TTR("Detach Script"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene()); - editor_data->get_undo_redo()->add_do_method(EditorNode::get_singleton(), "push_item", (Script *)nullptr); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Detach Script"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene()); + undo_redo->add_do_method(EditorNode::get_singleton(), "push_item", (Script *)nullptr); for (int i = 0; i < selection.size(); i++) { Node *n = Object::cast_to<Node>(selection[i]); Ref<Script> existing = n->get_script(); Ref<Script> empty = EditorNode::get_singleton()->get_object_custom_type_base(n); if (existing != empty) { - editor_data->get_undo_redo()->add_do_method(n, "set_script", empty); - editor_data->get_undo_redo()->add_undo_method(n, "set_script", existing); + undo_redo->add_do_method(n, "set_script", empty); + undo_redo->add_undo_method(n, "set_script", existing); } } - editor_data->get_undo_redo()->add_do_method(this, "_update_script_button"); - editor_data->get_undo_redo()->add_undo_method(this, "_update_script_button"); + undo_redo->add_do_method(this, "_update_script_button"); + undo_redo->add_undo_method(this, "_update_script_button"); - editor_data->get_undo_redo()->commit_action(); + undo_redo->commit_action(); } break; case TOOL_MOVE_UP: case TOOL_MOVE_DOWN: { @@ -600,11 +611,12 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; // one or more nodes can not be moved } + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); if (selection.size() == 1) { - editor_data->get_undo_redo()->create_action(TTR("Move Node In Parent")); + undo_redo->create_action(TTR("Move Node In Parent")); } if (selection.size() > 1) { - editor_data->get_undo_redo()->create_action(TTR("Move Nodes In Parent")); + undo_redo->create_action(TTR("Move Nodes In Parent")); } for (int i = 0; i < selection.size(); i++) { @@ -617,11 +629,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { int bottom_node_pos = bottom_node->get_index(); int top_node_pos_next = top_node->get_index() + (MOVING_DOWN ? 1 : -1); - editor_data->get_undo_redo()->add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next); - editor_data->get_undo_redo()->add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos); + undo_redo->add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next); + undo_redo->add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos); } - editor_data->get_undo_redo()->commit_action(); + undo_redo->commit_action(); } break; case TOOL_DUPLICATE: { @@ -649,8 +661,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - editor_data->get_undo_redo()->create_action(TTR("Duplicate Node(s)"), UndoRedo::MERGE_DISABLE, selection.front()->get()); - editor_data->get_undo_redo()->add_do_method(editor_selection, "clear"); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Duplicate Node(s)"), UndoRedo::MERGE_DISABLE, selection.front()->get()); + undo_redo->add_do_method(editor_selection, "clear"); Node *dupsingle = nullptr; @@ -675,28 +688,28 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { dup->set_name(parent->validate_child_name(dup)); - editor_data->get_undo_redo()->add_do_method(add_below_node, "add_sibling", dup, true); + undo_redo->add_do_method(add_below_node, "add_sibling", dup, true); for (Node *F : owned) { if (!duplimap.has(F)) { continue; } Node *d = duplimap[F]; - editor_data->get_undo_redo()->add_do_method(d, "set_owner", node->get_owner()); + undo_redo->add_do_method(d, "set_owner", node->get_owner()); } - editor_data->get_undo_redo()->add_do_method(editor_selection, "add_node", dup); - editor_data->get_undo_redo()->add_undo_method(parent, "remove_child", dup); - editor_data->get_undo_redo()->add_do_reference(dup); + undo_redo->add_do_method(editor_selection, "add_node", dup); + undo_redo->add_undo_method(parent, "remove_child", dup); + undo_redo->add_do_reference(dup); EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); - editor_data->get_undo_redo()->add_do_method(ed, "live_debug_duplicate_node", edited_scene->get_path_to(node), dup->get_name()); - editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).path_join(dup->get_name()))); + undo_redo->add_do_method(ed, "live_debug_duplicate_node", edited_scene->get_path_to(node), dup->get_name()); + undo_redo->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)).path_join(dup->get_name()))); add_below_node = dup; } - editor_data->get_undo_redo()->commit_action(); + undo_redo->commit_action(); if (dupsingle) { _push_item(dupsingle); @@ -765,29 +778,30 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { return; } - editor_data->get_undo_redo()->create_action(TTR("Make node as Root")); - editor_data->get_undo_redo()->add_do_method(node->get_parent(), "remove_child", node); - editor_data->get_undo_redo()->add_do_method(EditorNode::get_singleton(), "set_edited_scene", node); - editor_data->get_undo_redo()->add_do_method(node, "add_child", root, true); - editor_data->get_undo_redo()->add_do_method(node, "set_scene_file_path", root->get_scene_file_path()); - editor_data->get_undo_redo()->add_do_method(root, "set_scene_file_path", String()); - editor_data->get_undo_redo()->add_do_method(node, "set_owner", (Object *)nullptr); - editor_data->get_undo_redo()->add_do_method(root, "set_owner", node); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Make node as Root")); + undo_redo->add_do_method(node->get_parent(), "remove_child", node); + undo_redo->add_do_method(EditorNode::get_singleton(), "set_edited_scene", node); + undo_redo->add_do_method(node, "add_child", root, true); + undo_redo->add_do_method(node, "set_scene_file_path", root->get_scene_file_path()); + undo_redo->add_do_method(root, "set_scene_file_path", String()); + undo_redo->add_do_method(node, "set_owner", (Object *)nullptr); + undo_redo->add_do_method(root, "set_owner", node); _node_replace_owner(root, root, node, MODE_DO); - editor_data->get_undo_redo()->add_undo_method(root, "set_scene_file_path", root->get_scene_file_path()); - editor_data->get_undo_redo()->add_undo_method(node, "set_scene_file_path", String()); - editor_data->get_undo_redo()->add_undo_method(node, "remove_child", root); - editor_data->get_undo_redo()->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", root); - editor_data->get_undo_redo()->add_undo_method(node->get_parent(), "add_child", node, true); - editor_data->get_undo_redo()->add_undo_method(node->get_parent(), "move_child", node, node->get_index()); - editor_data->get_undo_redo()->add_undo_method(root, "set_owner", (Object *)nullptr); - editor_data->get_undo_redo()->add_undo_method(node, "set_owner", root); + undo_redo->add_undo_method(root, "set_scene_file_path", root->get_scene_file_path()); + undo_redo->add_undo_method(node, "set_scene_file_path", String()); + undo_redo->add_undo_method(node, "remove_child", root); + undo_redo->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", root); + undo_redo->add_undo_method(node->get_parent(), "add_child", node, true); + undo_redo->add_undo_method(node->get_parent(), "move_child", node, node->get_index()); + undo_redo->add_undo_method(root, "set_owner", (Object *)nullptr); + undo_redo->add_undo_method(node, "set_owner", root); _node_replace_owner(root, root, root, MODE_UNDO); - editor_data->get_undo_redo()->add_do_method(scene_tree, "update_tree"); - editor_data->get_undo_redo()->add_undo_method(scene_tree, "update_tree"); - editor_data->get_undo_redo()->commit_action(); + undo_redo->add_do_method(scene_tree, "update_tree"); + undo_redo->add_undo_method(scene_tree, "update_tree"); + undo_redo->commit_action(); } break; case TOOL_MULTI_EDIT: { if (!profile_allow_editing) { @@ -916,6 +930,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { String existing; if (extensions.size()) { String root_name(tocopy->get_name()); + root_name = EditorNode::adjust_scene_name_casing(root_name); existing = root_name + "." + extensions.front()->get().to_lower(); } new_scene_from_dialog->set_current_path(existing); @@ -943,7 +958,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); } break; case TOOL_AUTO_EXPAND: { - scene_tree->set_auto_expand_selected(!EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), true); + scene_tree->set_auto_expand_selected(!EDITOR_GET("docks/scene_tree/auto_expand_to_selected"), true); } break; case TOOL_SCENE_EDITABLE_CHILDREN: { if (!profile_allow_editing) { @@ -1008,7 +1023,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *node = e->get(); if (node) { Node *root = EditorNode::get_singleton()->get_edited_scene(); - Ref<EditorUndoRedoManager> undo_redo = editor_data->get_undo_redo(); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); if (!root) { break; } @@ -1073,10 +1088,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (first_selected == nullptr) { return; } + if (first_selected->get() == EditorNode::get_singleton()->get_edited_scene()) { + // Exclude Root Node. It should never be unique name in its own scene! + editor_selection->remove_node(first_selected->get()); + first_selected = editor_selection->get_selected_node_list().front(); + if (first_selected == nullptr) { + return; + } + } bool enabling = !first_selected->get()->is_unique_name_in_owner(); List<Node *> full_selection = editor_selection->get_full_selected_node_list(); - Ref<EditorUndoRedoManager> undo_redo = editor_data->get_undo_redo(); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); if (enabling) { Vector<Node *> new_unique_nodes; @@ -1135,11 +1158,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (TOOL_CREATE_FAVORITE == p_tool) { String name = selected_favorite_root.get_slicec(' ', 0); if (ScriptServer::is_global_class(name)) { - new_node = Object::cast_to<Node>(ClassDB::instantiate(ScriptServer::get_global_class_native_base(name))); - Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(name), "Script"); - if (new_node && script.is_valid()) { - new_node->set_script(script); - new_node->set_name(name); + Ref<Script> scr = ResourceLoader::load(ScriptServer::get_global_class_path(name), "Script"); + if (scr.is_valid()) { + new_node = Object::cast_to<Node>(ClassDB::instantiate(scr->get_instance_base_type())); + if (new_node) { + new_node->set_script(scr); + new_node->set_name(name); + } } } else { new_node = Object::cast_to<Node>(ClassDB::instantiate(selected_favorite_root)); @@ -1159,7 +1184,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; case TOOL_CREATE_USER_INTERFACE: { Control *node = memnew(Control); - node->set_anchors_and_offsets_preset(PRESET_FULL_RECT); //more useful for resizable UIs. + // Making the root control full rect by default is more useful for resizable UIs. + node->set_anchors_and_offsets_preset(PRESET_FULL_RECT); + node->set_grow_direction_preset(PRESET_FULL_RECT); new_node = node; } break; @@ -1176,6 +1203,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } break; default: { + _filter_option_selected(p_tool); + if (p_tool >= EDIT_SUBRESOURCE_BASE) { int idx = p_tool - EDIT_SUBRESOURCE_BASE; @@ -1197,30 +1226,21 @@ void SceneTreeDock::_property_selected(int p_idx) { } void SceneTreeDock::_perform_property_drop(Node *p_node, String p_property, Ref<Resource> p_res) { - editor_data->get_undo_redo()->create_action(vformat(TTR("Set %s"), p_property)); - editor_data->get_undo_redo()->add_do_property(p_node, p_property, p_res); - editor_data->get_undo_redo()->add_undo_property(p_node, p_property, p_node->get(p_property)); - editor_data->get_undo_redo()->commit_action(); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(vformat(TTR("Set %s"), p_property)); + undo_redo->add_do_property(p_node, p_property, p_res); + undo_redo->add_undo_property(p_node, p_property, p_node->get(p_property)); + undo_redo->commit_action(); } void SceneTreeDock::add_root_node(Node *p_node) { - editor_data->get_undo_redo()->create_action_for_history(TTR("New Scene Root"), editor_data->get_current_edited_scene_history_id()); - editor_data->get_undo_redo()->add_do_method(EditorNode::get_singleton(), "set_edited_scene", p_node); - editor_data->get_undo_redo()->add_do_method(scene_tree, "update_tree"); - editor_data->get_undo_redo()->add_do_reference(p_node); - editor_data->get_undo_redo()->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr); - editor_data->get_undo_redo()->commit_action(); -} - -void SceneTreeDock::_node_collapsed(Object *p_obj) { - TreeItem *ti = Object::cast_to<TreeItem>(p_obj); - if (!ti) { - return; - } - - if (Input::get_singleton()->is_key_pressed(Key::SHIFT)) { - _set_collapsed_recursive(ti, ti->is_collapsed()); - } + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action_for_history(TTR("New Scene Root"), editor_data->get_current_edited_scene_history_id()); + undo_redo->add_do_method(EditorNode::get_singleton(), "set_edited_scene", p_node); + undo_redo->add_do_method(scene_tree, "update_tree"); + undo_redo->add_do_reference(p_node); + undo_redo->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr); + undo_redo->commit_action(); } void SceneTreeDock::_notification(int p_what) { @@ -1235,14 +1255,14 @@ void SceneTreeDock::_notification(int p_what) { CanvasItemEditorPlugin *canvas_item_plugin = Object::cast_to<CanvasItemEditorPlugin>(editor_data->get_editor("2D")); if (canvas_item_plugin) { - canvas_item_plugin->get_canvas_item_editor()->connect("item_lock_status_changed", Callable(scene_tree, "_update_tree")); - canvas_item_plugin->get_canvas_item_editor()->connect("item_group_status_changed", Callable(scene_tree, "_update_tree")); + canvas_item_plugin->get_canvas_item_editor()->connect("item_lock_status_changed", callable_mp(scene_tree, &SceneTreeEditor::_update_tree).bind(false)); + canvas_item_plugin->get_canvas_item_editor()->connect("item_group_status_changed", callable_mp(scene_tree, &SceneTreeEditor::_update_tree).bind(false)); scene_tree->connect("node_changed", callable_mp((CanvasItem *)canvas_item_plugin->get_canvas_item_editor()->get_viewport_control(), &CanvasItem::queue_redraw)); } Node3DEditorPlugin *spatial_editor_plugin = Object::cast_to<Node3DEditorPlugin>(editor_data->get_editor("3D")); - spatial_editor_plugin->get_spatial_editor()->connect("item_lock_status_changed", Callable(scene_tree, "_update_tree")); - spatial_editor_plugin->get_spatial_editor()->connect("item_group_status_changed", Callable(scene_tree, "_update_tree")); + spatial_editor_plugin->get_spatial_editor()->connect("item_lock_status_changed", callable_mp(scene_tree, &SceneTreeEditor::_update_tree).bind(false)); + spatial_editor_plugin->get_spatial_editor()->connect("item_group_status_changed", callable_mp(scene_tree, &SceneTreeEditor::_update_tree).bind(false)); button_add->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); @@ -1323,7 +1343,7 @@ void SceneTreeDock::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { clear_inherit_confirm->connect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected).bind(TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM, false)); - scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false); + scene_tree->set_auto_expand_selected(EDITOR_GET("docks/scene_tree/auto_expand_to_selected"), false); } break; case NOTIFICATION_EXIT_TREE: { @@ -1331,7 +1351,7 @@ void SceneTreeDock::_notification(int p_what) { } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false); + scene_tree->set_auto_expand_selected(EDITOR_GET("docks/scene_tree/auto_expand_to_selected"), false); button_add->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons"))); @@ -1365,7 +1385,7 @@ void SceneTreeDock::_notification(int p_what) { void SceneTreeDock::_node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode) { if (p_node->get_owner() == p_base && p_node != p_root) { - Ref<EditorUndoRedoManager> undo_redo = editor_data->get_undo_redo(); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); switch (p_mode) { case MODE_BIDI: { bool disable_unique = p_node->is_unique_name_in_owner() && p_root->get_node_or_null(UNIQUE_NODE_PREFIX + String(p_node->get_name())) != nullptr; @@ -1399,6 +1419,7 @@ void SceneTreeDock::_node_replace_owner(Node *p_base, Node *p_node, Node *p_root void SceneTreeDock::_load_request(const String &p_path) { EditorNode::get_singleton()->open_request(p_path); + _local_tree_selected(); } void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) { @@ -1407,6 +1428,9 @@ void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) { void SceneTreeDock::_push_item(Object *p_object) { EditorNode::get_singleton()->push_item(p_object); + if (p_object == nullptr) { + EditorNode::get_singleton()->hide_unused_editors(this); + } } void SceneTreeDock::_handle_select(Node *p_node) { @@ -1598,8 +1622,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath> Variant old_variant = p_base->get(propertyname); Variant updated_variant = old_variant; if (_check_node_path_recursive(p_base, updated_variant, p_renames)) { - editor_data->get_undo_redo()->add_do_property(p_base, propertyname, updated_variant); - editor_data->get_undo_redo()->add_undo_property(p_base, propertyname, old_variant); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->add_do_property(p_base, propertyname, updated_variant); + undo_redo->add_undo_property(p_base, propertyname, old_variant); p_base->set(propertyname, updated_variant); } } @@ -1644,6 +1669,7 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath> } HashMap<Node *, NodePath>::Iterator found_path = p_renames->find(n); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); if (found_path) { if (found_path->value == NodePath()) { //will be erased @@ -1657,12 +1683,12 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath> ERR_FAIL_COND(!EI); //another bug } - editor_data->get_undo_redo()->add_do_method(anim.ptr(), "remove_track", idx); - editor_data->get_undo_redo()->add_undo_method(anim.ptr(), "add_track", anim->track_get_type(i), idx); - editor_data->get_undo_redo()->add_undo_method(anim.ptr(), "track_set_path", idx, track_np); - editor_data->get_undo_redo()->add_undo_method(anim.ptr(), "track_set_interpolation_type", idx, anim->track_get_interpolation_type(i)); + undo_redo->add_do_method(anim.ptr(), "remove_track", idx); + undo_redo->add_undo_method(anim.ptr(), "add_track", anim->track_get_type(i), idx); + undo_redo->add_undo_method(anim.ptr(), "track_set_path", idx, track_np); + undo_redo->add_undo_method(anim.ptr(), "track_set_interpolation_type", idx, anim->track_get_interpolation_type(i)); for (int j = 0; j < anim->track_get_key_count(i); j++) { - editor_data->get_undo_redo()->add_undo_method(anim.ptr(), "track_insert_key", idx, anim->track_get_key_time(i, j), anim->track_get_key_value(i, j), anim->track_get_key_transition(i, j)); + undo_redo->add_undo_method(anim.ptr(), "track_insert_key", idx, anim->track_get_key_time(i, j), anim->track_get_key_value(i, j), anim->track_get_key_transition(i, j)); } ran.erase(i); //byebye channel @@ -1675,8 +1701,8 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath> if (new_path == track_np) { continue; //bleh } - editor_data->get_undo_redo()->add_do_method(anim.ptr(), "track_set_path", i, new_path); - editor_data->get_undo_redo()->add_undo_method(anim.ptr(), "track_set_path", i, track_np); + undo_redo->add_do_method(anim.ptr(), "track_set_path", i, new_path); + undo_redo->add_undo_method(anim.ptr(), "track_set_path", i, track_np); } } } @@ -1810,7 +1836,8 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V // Sort by tree order, so re-adding is easy. p_nodes.sort_custom<Node::Comparator>(); - editor_data->get_undo_redo()->create_action(TTR("Reparent Node")); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Reparent Node"), UndoRedo::MERGE_DISABLE, p_nodes[0]); HashMap<Node *, NodePath> path_renames; Vector<StringName> former_names; @@ -1831,15 +1858,18 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V owners.push_back(E); } - if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) { + bool same_parent = new_parent == node->get_parent(); + if (same_parent && node->get_index() < p_position_in_parent + ni) { inc--; // If the child will generate a gap when moved, adjust. } - editor_data->get_undo_redo()->add_do_method(node->get_parent(), "remove_child", node); - editor_data->get_undo_redo()->add_do_method(new_parent, "add_child", node, true); + if (!same_parent) { + undo_redo->add_do_method(node->get_parent(), "remove_child", node); + undo_redo->add_do_method(new_parent, "add_child", node, true); + } - if (p_position_in_parent >= 0) { - editor_data->get_undo_redo()->add_do_method(new_parent, "move_child", node, p_position_in_parent + inc); + if (p_position_in_parent >= 0 || same_parent) { + undo_redo->add_do_method(new_parent, "move_child", node, p_position_in_parent + inc); } EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); @@ -1869,29 +1899,29 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V } } - editor_data->get_undo_redo()->add_do_method(ed, "live_debug_reparent_node", edited_scene->get_path_to(node), edited_scene->get_path_to(new_parent), new_name, p_position_in_parent + inc); - editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)).path_join(new_name)), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index()); + undo_redo->add_do_method(ed, "live_debug_reparent_node", edited_scene->get_path_to(node), edited_scene->get_path_to(new_parent), new_name, p_position_in_parent + inc); + undo_redo->add_undo_method(ed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)).path_join(new_name)), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index()); if (p_keep_global_xform) { if (Object::cast_to<Node2D>(node)) { - editor_data->get_undo_redo()->add_do_method(node, "set_global_transform", Object::cast_to<Node2D>(node)->get_global_transform()); + undo_redo->add_do_method(node, "set_global_transform", Object::cast_to<Node2D>(node)->get_global_transform()); } if (Object::cast_to<Node3D>(node)) { - editor_data->get_undo_redo()->add_do_method(node, "set_global_transform", Object::cast_to<Node3D>(node)->get_global_transform()); + undo_redo->add_do_method(node, "set_global_transform", Object::cast_to<Node3D>(node)->get_global_transform()); } if (Object::cast_to<Control>(node)) { - editor_data->get_undo_redo()->add_do_method(node, "set_global_position", Object::cast_to<Control>(node)->get_global_position()); + undo_redo->add_do_method(node, "set_global_position", Object::cast_to<Control>(node)->get_global_position()); } } - editor_data->get_undo_redo()->add_do_method(this, "_set_owners", edited_scene, owners); + undo_redo->add_do_method(this, "_set_owners", edited_scene, owners); if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == node) { - editor_data->get_undo_redo()->add_do_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", node); + undo_redo->add_do_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", node); } - editor_data->get_undo_redo()->add_undo_method(new_parent, "remove_child", node); - editor_data->get_undo_redo()->add_undo_method(node, "set_name", former_names[ni]); + undo_redo->add_undo_method(new_parent, "remove_child", node); + undo_redo->add_undo_method(node, "set_name", former_names[ni]); inc++; } @@ -1909,71 +1939,29 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V int child_pos = node->get_index(); - editor_data->get_undo_redo()->add_undo_method(node->get_parent(), "add_child", node, true); - editor_data->get_undo_redo()->add_undo_method(node->get_parent(), "move_child", node, child_pos); - editor_data->get_undo_redo()->add_undo_method(this, "_set_owners", edited_scene, owners); + undo_redo->add_undo_method(node->get_parent(), "add_child", node, true); + undo_redo->add_undo_method(node->get_parent(), "move_child", node, child_pos); + undo_redo->add_undo_method(this, "_set_owners", edited_scene, owners); if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == node) { - editor_data->get_undo_redo()->add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", node); + undo_redo->add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", node); } if (p_keep_global_xform) { if (Object::cast_to<Node2D>(node)) { - editor_data->get_undo_redo()->add_undo_method(node, "set_transform", Object::cast_to<Node2D>(node)->get_transform()); + undo_redo->add_undo_method(node, "set_transform", Object::cast_to<Node2D>(node)->get_transform()); } if (Object::cast_to<Node3D>(node)) { - editor_data->get_undo_redo()->add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform()); + undo_redo->add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform()); } if (Object::cast_to<Control>(node)) { - editor_data->get_undo_redo()->add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position()); + undo_redo->add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position()); } } } perform_node_renames(nullptr, &path_renames); - editor_data->get_undo_redo()->commit_action(); -} - -bool SceneTreeDock::_is_collapsed_recursive(TreeItem *p_item) const { - bool is_branch_collapsed = false; - - List<TreeItem *> needs_check; - needs_check.push_back(p_item); - - while (!needs_check.is_empty()) { - TreeItem *item = needs_check.back()->get(); - needs_check.pop_back(); - - TreeItem *child = item->get_first_child(); - is_branch_collapsed = item->is_collapsed() && child; - - if (is_branch_collapsed) { - break; - } - while (child) { - needs_check.push_back(child); - child = child->get_next(); - } - } - return is_branch_collapsed; -} - -void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed) { - List<TreeItem *> to_collapse; - to_collapse.push_back(p_item); - - while (!to_collapse.is_empty()) { - TreeItem *item = to_collapse.back()->get(); - to_collapse.pop_back(); - - item->set_collapsed(p_collapsed); - - TreeItem *child = item->get_first_child(); - while (child) { - to_collapse.push_back(child); - child = child->get_next(); - } - } + undo_redo->commit_action(); } void SceneTreeDock::_script_created(Ref<Script> p_script) { @@ -1983,37 +1971,22 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) { return; } - if (selected.size() == 1) { - Node *node = selected.front()->get(); - Ref<Script> existing = node->get_script(); - - editor_data->get_undo_redo()->create_action(TTR("Attach Script")); - editor_data->get_undo_redo()->add_do_method(InspectorDock::get_singleton(), "store_script_properties", node); - editor_data->get_undo_redo()->add_undo_method(InspectorDock::get_singleton(), "store_script_properties", node); - editor_data->get_undo_redo()->add_do_method(node, "set_script", p_script); - editor_data->get_undo_redo()->add_undo_method(node, "set_script", existing); - editor_data->get_undo_redo()->add_do_method(InspectorDock::get_singleton(), "apply_script_properties", node); - editor_data->get_undo_redo()->add_undo_method(InspectorDock::get_singleton(), "apply_script_properties", node); - editor_data->get_undo_redo()->add_do_method(this, "_update_script_button"); - editor_data->get_undo_redo()->add_undo_method(this, "_update_script_button"); - editor_data->get_undo_redo()->commit_action(); - } else { - editor_data->get_undo_redo()->create_action(TTR("Attach Script")); - for (Node *E : selected) { - Ref<Script> existing = E->get_script(); - editor_data->get_undo_redo()->add_do_method(InspectorDock::get_singleton(), "store_script_properties", E); - editor_data->get_undo_redo()->add_undo_method(InspectorDock::get_singleton(), "store_script_properties", E); - editor_data->get_undo_redo()->add_do_method(E, "set_script", p_script); - editor_data->get_undo_redo()->add_undo_method(E, "set_script", existing); - editor_data->get_undo_redo()->add_do_method(InspectorDock::get_singleton(), "apply_script_properties", E); - editor_data->get_undo_redo()->add_undo_method(InspectorDock::get_singleton(), "apply_script_properties", E); - editor_data->get_undo_redo()->add_do_method(this, "_update_script_button"); - editor_data->get_undo_redo()->add_undo_method(this, "_update_script_button"); - } - editor_data->get_undo_redo()->commit_action(); - } - - _push_item(p_script.operator->()); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Attach Script"), UndoRedo::MERGE_DISABLE, selected.front()->get()); + for (Node *E : selected) { + Ref<Script> existing = E->get_script(); + undo_redo->add_do_method(InspectorDock::get_singleton(), "store_script_properties", E); + undo_redo->add_undo_method(InspectorDock::get_singleton(), "store_script_properties", E); + undo_redo->add_do_method(E, "set_script", p_script); + undo_redo->add_undo_method(E, "set_script", existing); + undo_redo->add_do_method(InspectorDock::get_singleton(), "apply_script_properties", E); + undo_redo->add_undo_method(InspectorDock::get_singleton(), "apply_script_properties", E); + undo_redo->add_do_method(this, "_update_script_button"); + undo_redo->add_undo_method(this, "_update_script_button"); + } + undo_redo->commit_action(); + + _push_item(p_script.ptr()); _update_script_button(); } @@ -2024,22 +1997,23 @@ void SceneTreeDock::_shader_created(Ref<Shader> p_shader) { Ref<Shader> existing = selected_shader_material->get_shader(); - editor_data->get_undo_redo()->create_action(TTR("Set Shader")); - editor_data->get_undo_redo()->add_do_method(selected_shader_material.ptr(), "set_shader", p_shader); - editor_data->get_undo_redo()->add_undo_method(selected_shader_material.ptr(), "set_shader", existing); - editor_data->get_undo_redo()->commit_action(); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Set Shader")); + undo_redo->add_do_method(selected_shader_material.ptr(), "set_shader", p_shader); + undo_redo->add_undo_method(selected_shader_material.ptr(), "set_shader", existing); + undo_redo->commit_action(); } void SceneTreeDock::_script_creation_closed() { script_create_dialog->disconnect("script_created", callable_mp(this, &SceneTreeDock::_script_created)); script_create_dialog->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_script_creation_closed)); - script_create_dialog->disconnect("cancelled", callable_mp(this, &SceneTreeDock::_script_creation_closed)); + script_create_dialog->disconnect("canceled", callable_mp(this, &SceneTreeDock::_script_creation_closed)); } void SceneTreeDock::_shader_creation_closed() { shader_create_dialog->disconnect("shader_created", callable_mp(this, &SceneTreeDock::_shader_created)); shader_create_dialog->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); - shader_create_dialog->disconnect("cancelled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); + shader_create_dialog->disconnect("canceled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); } void SceneTreeDock::_toggle_editable_children_from_selection() { @@ -2090,28 +2064,26 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { return; } - EditorNode::get_singleton()->get_editor_plugins_over()->make_visible(false); + EditorNode::get_singleton()->hide_unused_editors(this); - if (p_cut) { - editor_data->get_undo_redo()->create_action(TTR("Cut Node(s)")); - } else { - editor_data->get_undo_redo()->create_action(TTR("Remove Node(s)")); - } + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(p_cut ? TTR("Cut Node(s)") : TTR("Remove Node(s)"), UndoRedo::MERGE_DISABLE, remove_list.front()->get()); bool entire_scene = false; for (const Node *E : remove_list) { if (E == edited_scene) { entire_scene = true; + break; } } if (entire_scene) { - editor_data->get_undo_redo()->add_do_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr); - editor_data->get_undo_redo()->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", edited_scene); - editor_data->get_undo_redo()->add_undo_method(edited_scene, "set_owner", edited_scene->get_owner()); - editor_data->get_undo_redo()->add_undo_method(scene_tree, "update_tree"); - editor_data->get_undo_redo()->add_undo_reference(edited_scene); + undo_redo->add_do_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr); + undo_redo->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", edited_scene); + undo_redo->add_undo_method(edited_scene, "set_owner", edited_scene->get_owner()); + undo_redo->add_undo_method(scene_tree, "update_tree"); + undo_redo->add_undo_reference(edited_scene); } else { remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions @@ -2140,21 +2112,21 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { owners.push_back(F); } - editor_data->get_undo_redo()->add_do_method(n->get_parent(), "remove_child", n); - editor_data->get_undo_redo()->add_undo_method(n->get_parent(), "add_child", n, true); - editor_data->get_undo_redo()->add_undo_method(n->get_parent(), "move_child", n, n->get_index()); + undo_redo->add_do_method(n->get_parent(), "remove_child", n); + undo_redo->add_undo_method(n->get_parent(), "add_child", n, true); + undo_redo->add_undo_method(n->get_parent(), "move_child", n, n->get_index()); if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == n) { - editor_data->get_undo_redo()->add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", n); + undo_redo->add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", n); } - editor_data->get_undo_redo()->add_undo_method(this, "_set_owners", edited_scene, owners); - editor_data->get_undo_redo()->add_undo_reference(n); + undo_redo->add_undo_method(this, "_set_owners", edited_scene, owners); + undo_redo->add_undo_reference(n); EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); - editor_data->get_undo_redo()->add_do_method(ed, "live_debug_remove_and_keep_node", edited_scene->get_path_to(n), n->get_instance_id()); - editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_restore_node", n->get_instance_id(), edited_scene->get_path_to(n->get_parent()), n->get_index()); + undo_redo->add_do_method(ed, "live_debug_remove_and_keep_node", edited_scene->get_path_to(n), n->get_instance_id()); + undo_redo->add_undo_method(ed, "live_debug_restore_node", n->get_instance_id(), edited_scene->get_path_to(n->get_parent()), n->get_index()); } } - editor_data->get_undo_redo()->commit_action(); + undo_redo->commit_action(); // hack, force 2d editor viewport to refresh after deletion if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) { @@ -2214,35 +2186,39 @@ void SceneTreeDock::_selection_changed() { } void SceneTreeDock::_do_create(Node *p_parent) { - Variant c = create_dialog->instance_selected(); - - ERR_FAIL_COND(!c); + Variant c = create_dialog->instantiate_selected(); Node *child = Object::cast_to<Node>(c); ERR_FAIL_COND(!child); - editor_data->get_undo_redo()->create_action(TTR("Create Node")); + String new_name = p_parent->validate_child_name(child); + if (GLOBAL_GET("editor/node_naming/name_casing").operator int() != NAME_CASING_PASCAL_CASE) { + new_name = adjust_name_casing(new_name); + } + child->set_name(new_name); + + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action_for_history(TTR("Create Node"), editor_data->get_current_edited_scene_history_id()); if (edited_scene) { - editor_data->get_undo_redo()->add_do_method(p_parent, "add_child", child, true); - editor_data->get_undo_redo()->add_do_method(child, "set_owner", edited_scene); - editor_data->get_undo_redo()->add_do_method(editor_selection, "clear"); - editor_data->get_undo_redo()->add_do_method(editor_selection, "add_node", child); - editor_data->get_undo_redo()->add_do_reference(child); - editor_data->get_undo_redo()->add_undo_method(p_parent, "remove_child", child); - - String new_name = p_parent->validate_child_name(child); + undo_redo->add_do_method(p_parent, "add_child", child, true); + undo_redo->add_do_method(child, "set_owner", edited_scene); + undo_redo->add_do_method(editor_selection, "clear"); + undo_redo->add_do_method(editor_selection, "add_node", child); + undo_redo->add_do_reference(child); + undo_redo->add_undo_method(p_parent, "remove_child", child); + EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); - editor_data->get_undo_redo()->add_do_method(ed, "live_debug_create_node", edited_scene->get_path_to(p_parent), child->get_class(), new_name); - editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(p_parent)).path_join(new_name))); + undo_redo->add_do_method(ed, "live_debug_create_node", edited_scene->get_path_to(p_parent), child->get_class(), new_name); + undo_redo->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(p_parent)).path_join(new_name))); } else { - editor_data->get_undo_redo()->add_do_method(EditorNode::get_singleton(), "set_edited_scene", child); - editor_data->get_undo_redo()->add_do_method(scene_tree, "update_tree"); - editor_data->get_undo_redo()->add_do_reference(child); - editor_data->get_undo_redo()->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr); + undo_redo->add_do_method(EditorNode::get_singleton(), "set_edited_scene", child); + undo_redo->add_do_method(scene_tree, "update_tree"); + undo_redo->add_do_reference(child); + undo_redo->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr); } - editor_data->get_undo_redo()->commit_action(); + undo_redo->commit_action(); _push_item(c); editor_selection->clear(); editor_selection->add_node(child); @@ -2289,13 +2265,13 @@ void SceneTreeDock::_create() { List<Node *> selection = editor_selection->get_selected_node_list(); ERR_FAIL_COND(selection.size() <= 0); - Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change type of node(s)"), UndoRedo::MERGE_DISABLE, selection.front()->get()); for (Node *n : selection) { ERR_FAIL_COND(!n); - Variant c = create_dialog->instance_selected(); + Variant c = create_dialog->instantiate_selected(); ERR_FAIL_COND(!c); Node *newnode = Object::cast_to<Node>(c); @@ -2423,7 +2399,7 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop } //p_remove_old was added to support undo if (p_remove_old) { - editor_data->get_undo_redo()->clear_history(); + EditorUndoRedoManager::get_singleton()->clear_history(); } newnode->set_name(newname); @@ -2468,9 +2444,12 @@ void SceneTreeDock::_new_scene_from(String p_file) { Node *copy = base->duplicate_from_editor(duplimap); if (copy) { + // Handle Unique Nodes. for (int i = 0; i < copy->get_child_count(false); i++) { _set_node_owner_recursive(copy->get_child(i, false), copy); } + // Root node cannot ever be unique name in its own Scene! + copy->set_unique_name_in_owner(false); Ref<PackedScene> sdata = memnew(PackedScene); Error err = sdata->pack(copy); @@ -2483,7 +2462,7 @@ void SceneTreeDock::_new_scene_from(String p_file) { } int flg = 0; - if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { + if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; } @@ -2636,17 +2615,50 @@ void SceneTreeDock::_files_dropped(Vector<String> p_files, NodePath p_to, int p_ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) { Ref<Script> scr = ResourceLoader::load(p_file); ERR_FAIL_COND(!scr.is_valid()); - if (Node *n = get_node(p_to)) { - editor_data->get_undo_redo()->create_action(TTR("Attach Script")); - editor_data->get_undo_redo()->add_do_method(InspectorDock::get_singleton(), "store_script_properties", n); - editor_data->get_undo_redo()->add_undo_method(InspectorDock::get_singleton(), "store_script_properties", n); - editor_data->get_undo_redo()->add_do_method(n, "set_script", scr); - editor_data->get_undo_redo()->add_undo_method(n, "set_script", n->get_script()); - editor_data->get_undo_redo()->add_do_method(InspectorDock::get_singleton(), "apply_script_properties", n); - editor_data->get_undo_redo()->add_undo_method(InspectorDock::get_singleton(), "apply_script_properties", n); - editor_data->get_undo_redo()->add_do_method(this, "_update_script_button"); - editor_data->get_undo_redo()->add_undo_method(this, "_update_script_button"); - editor_data->get_undo_redo()->commit_action(); + Node *n = get_node(p_to); + + if (!n) { + return; + } + + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + if (Input::get_singleton()->is_key_pressed(Key::CTRL)) { + Object *obj = ClassDB::instantiate(scr->get_instance_base_type()); + ERR_FAIL_NULL(obj); + + Node *new_node = Object::cast_to<Node>(obj); + if (!new_node) { + if (!obj->is_ref_counted()) { + memdelete(obj); + } + ERR_FAIL_MSG("Script does not extend Node-derived type."); + } + new_node->set_name(Node::adjust_name_casing(p_file.get_file().get_basename())); + new_node->set_script(scr); + + undo_redo->create_action(TTR("Instantiate Script")); + undo_redo->add_do_method(n, "add_child", new_node, true); + undo_redo->add_do_method(new_node, "set_owner", edited_scene); + undo_redo->add_do_method(editor_selection, "clear"); + undo_redo->add_do_method(editor_selection, "add_node", new_node); + undo_redo->add_do_reference(new_node); + undo_redo->add_undo_method(n, "remove_child", new_node); + + EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton(); + undo_redo->add_do_method(ed, "live_debug_create_node", edited_scene->get_path_to(n), new_node->get_class(), new_node->get_name()); + undo_redo->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(n)).path_join(new_node->get_name()))); + undo_redo->commit_action(); + } else { + undo_redo->create_action(TTR("Attach Script"), UndoRedo::MERGE_DISABLE, n); + undo_redo->add_do_method(InspectorDock::get_singleton(), "store_script_properties", n); + undo_redo->add_undo_method(InspectorDock::get_singleton(), "store_script_properties", n); + undo_redo->add_do_method(n, "set_script", scr); + undo_redo->add_undo_method(n, "set_script", n->get_script()); + undo_redo->add_do_method(InspectorDock::get_singleton(), "apply_script_properties", n); + undo_redo->add_undo_method(InspectorDock::get_singleton(), "apply_script_properties", n); + undo_redo->add_do_method(this, "_update_script_button"); + undo_redo->add_undo_method(this, "_update_script_button"); + undo_redo->commit_action(); } } @@ -2720,7 +2732,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); if (profile_allow_editing) { menu->add_icon_shortcut(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); - menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE); + menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instantiate_scene"), TOOL_INSTANTIATE); } menu->reset_size(); @@ -2753,7 +2765,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } menu->add_icon_shortcut(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); - menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE); + menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instantiate_scene"), TOOL_INSTANTIATE); } menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE); menu->add_separator(); @@ -2864,10 +2876,13 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } } if (all_owned) { - menu->add_separator(); - menu->add_icon_check_item(get_theme_icon(SNAME("SceneUniqueName"), SNAME("EditorIcons")), TTR("Access as Scene Unique Name"), TOOL_TOGGLE_SCENE_UNIQUE_NAME); - // Checked based on `selection[0]` because `full_selection` has undesired ordering. - menu->set_item_checked(menu->get_item_index(TOOL_TOGGLE_SCENE_UNIQUE_NAME), selection[0]->is_unique_name_in_owner()); + // Group "toggle_unique_name" with "copy_node_path", if it is available. + if (menu->get_item_index(TOOL_COPY_NODE_PATH) == -1) { + menu->add_separator(); + } + Node *node = full_selection[0]; + menu->add_icon_shortcut(get_theme_icon(SNAME("SceneUniqueName"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/toggle_unique_name"), TOOL_TOGGLE_SCENE_UNIQUE_NAME); + menu->set_item_text(menu->get_item_index(TOOL_TOGGLE_SCENE_UNIQUE_NAME), node->is_unique_name_in_owner() ? TTR("Revoke Unique Name") : TTR("Access as Unique Name")); } } @@ -2921,11 +2936,83 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { void SceneTreeDock::_update_tree_menu() { PopupMenu *tree_menu = button_tree_menu->get_popup(); - tree_menu->set_item_checked(tree_menu->get_item_idx_from_text(TTR("Auto Expand to Selected")), EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected")); + tree_menu->clear(); + + _append_filter_options_to(tree_menu); + + tree_menu->add_separator(); + tree_menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND); + tree_menu->set_item_checked(tree_menu->get_item_index(TOOL_AUTO_EXPAND), EDITOR_GET("docks/scene_tree/auto_expand_to_selected")); +} + +void SceneTreeDock::_update_filter_menu() { + _append_filter_options_to(filter->get_menu()); } void SceneTreeDock::_filter_changed(const String &p_filter) { scene_tree->set_filter(p_filter); + + String warning = scene_tree->get_filter_term_warning(); + if (!warning.is_empty()) { + filter->add_theme_icon_override(SNAME("clear"), get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons"))); + filter->set_tooltip_text(warning); + } else { + filter->remove_theme_icon_override(SNAME("clear")); + filter->set_tooltip_text(""); + } +} + +void SceneTreeDock::_filter_gui_input(const Ref<InputEvent> &p_event) { + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_null()) { + return; + } + + if (mb->is_pressed() && mb->get_button_index() == MouseButton::MIDDLE) { + filter_quick_menu->clear(); + + _append_filter_options_to(filter_quick_menu, false); + filter_quick_menu->set_position(get_screen_position() + get_local_mouse_position()); + filter_quick_menu->reset_size(); + filter_quick_menu->popup(); + filter_quick_menu->grab_focus(); + accept_event(); + } +} + +void SceneTreeDock::_filter_option_selected(int p_option) { + String filter_parameter; + switch (p_option) { + case FILTER_BY_TYPE: { + filter_parameter = "type"; + } break; + case FILTER_BY_GROUP: { + filter_parameter = "group"; + } break; + } + + if (!filter_parameter.is_empty()) { + set_filter((get_filter() + " " + filter_parameter + ":").strip_edges()); + filter->set_caret_column(filter->get_text().length()); + filter->grab_focus(); + } +} + +void SceneTreeDock::_append_filter_options_to(PopupMenu *p_menu, bool p_include_separator) { + if (p_include_separator) { + p_menu->add_separator(); + + p_menu->set_item_text(-1, TTR("Filters")); + p_menu->set_item_icon(-1, get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + p_menu->set_item_indent(-1, -2); + } + + p_menu->add_item(TTR("Filter by Type"), FILTER_BY_TYPE); + p_menu->add_item(TTR("Filter by Group"), FILTER_BY_GROUP); + p_menu->set_item_icon(p_menu->get_item_index(FILTER_BY_TYPE), get_theme_icon(SNAME("Node"), SNAME("EditorIcons"))); + p_menu->set_item_icon(p_menu->get_item_index(FILTER_BY_GROUP), get_theme_icon(SNAME("Groups"), SNAME("EditorIcons"))); + p_menu->set_item_tooltip(p_menu->get_item_index(FILTER_BY_TYPE), TTR("Selects all Nodes of the given type.")); + p_menu->set_item_tooltip(p_menu->get_item_index(FILTER_BY_GROUP), TTR("Selects all Nodes belonging to the given group.\nIf empty, selects any Node belonging to any group.")); } String SceneTreeDock::get_filter() { @@ -3006,7 +3093,7 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) { script_create_dialog->connect("script_created", callable_mp(this, &SceneTreeDock::_script_created)); script_create_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_script_creation_closed)); - script_create_dialog->connect("cancelled", callable_mp(this, &SceneTreeDock::_script_creation_closed)); + script_create_dialog->connect("canceled", callable_mp(this, &SceneTreeDock::_script_creation_closed)); script_create_dialog->set_inheritance_base_type("Node"); script_create_dialog->config(inherits, path); script_create_dialog->popup_centered(); @@ -3048,7 +3135,7 @@ void SceneTreeDock::attach_shader_to_selected(int p_preferred_mode) { shader_create_dialog->connect("shader_created", callable_mp(this, &SceneTreeDock::_shader_created)); shader_create_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); - shader_create_dialog->connect("cancelled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); + shader_create_dialog->connect("canceled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); shader_create_dialog->config(path, true, true, -1, p_preferred_mode); shader_create_dialog->popup_centered(); } @@ -3106,7 +3193,7 @@ List<Node *> SceneTreeDock::paste_nodes() { owner = paste_parent; } - Ref<EditorUndoRedoManager> &ur = editor_data->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Paste Node(s)"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene()); ur->add_do_method(editor_selection, "clear"); @@ -3137,6 +3224,7 @@ List<Node *> SceneTreeDock::paste_nodes() { if (!paste_parent) { paste_parent = dup; owner = dup; + dup->set_scene_file_path(String()); // Make sure the scene path is empty, to avoid accidental references. ur->add_do_method(EditorNode::get_singleton(), "set_edited_scene", dup); } else { ur->add_do_method(paste_parent, "add_child", dup, true); @@ -3179,6 +3267,7 @@ void SceneTreeDock::add_remote_tree_editor(Control *p_remote) { add_child(p_remote); remote_tree = p_remote; remote_tree->hide(); + remote_tree->connect("open", callable_mp(this, &SceneTreeDock::_load_request)); } void SceneTreeDock::show_remote_tree() { @@ -3225,7 +3314,7 @@ void SceneTreeDock::_update_create_root_dialog() { EditorSettings::get_singleton()->save(); if (node_shortcuts_toggle->is_pressed()) { for (int i = 0; i < favorite_node_shortcuts->get_child_count(); i++) { - favorite_node_shortcuts->get_child(i)->queue_delete(); + favorite_node_shortcuts->get_child(i)->queue_free(); } Ref<FileAccess> f = FileAccess::open(EditorPaths::get_singleton()->get_project_settings_dir().path_join("favorites.Node"), FileAccess::READ); @@ -3402,24 +3491,25 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KeyModifierMask::SHIFT | Key::F2); ED_SHORTCUT_OVERRIDE("scene_tree/batch_rename", "macos", KeyModifierMask::SHIFT | Key::ENTER); - ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KeyModifierMask::CMD | Key::A); - ED_SHORTCUT("scene_tree/instance_scene", TTR("Instantiate Child Scene"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::A); + ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KeyModifierMask::CMD_OR_CTRL | Key::A); + ED_SHORTCUT("scene_tree/instantiate_scene", TTR("Instantiate Child Scene"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::A); ED_SHORTCUT("scene_tree/expand_collapse_all", TTR("Expand/Collapse Branch")); - ED_SHORTCUT("scene_tree/cut_node", TTR("Cut"), KeyModifierMask::CMD | Key::X); - ED_SHORTCUT("scene_tree/copy_node", TTR("Copy"), KeyModifierMask::CMD | Key::C); - ED_SHORTCUT("scene_tree/paste_node", TTR("Paste"), KeyModifierMask::CMD | Key::V); + ED_SHORTCUT("scene_tree/cut_node", TTR("Cut"), KeyModifierMask::CMD_OR_CTRL | Key::X); + ED_SHORTCUT("scene_tree/copy_node", TTR("Copy"), KeyModifierMask::CMD_OR_CTRL | Key::C); + ED_SHORTCUT("scene_tree/paste_node", TTR("Paste"), KeyModifierMask::CMD_OR_CTRL | Key::V); ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type")); ED_SHORTCUT("scene_tree/attach_script", TTR("Attach Script")); ED_SHORTCUT("scene_tree/extend_script", TTR("Extend Script")); ED_SHORTCUT("scene_tree/detach_script", TTR("Detach Script")); - ED_SHORTCUT("scene_tree/move_up", TTR("Move Up"), KeyModifierMask::CMD | Key::UP); - ED_SHORTCUT("scene_tree/move_down", TTR("Move Down"), KeyModifierMask::CMD | Key::DOWN); - ED_SHORTCUT("scene_tree/duplicate", TTR("Duplicate"), KeyModifierMask::CMD | Key::D); + ED_SHORTCUT("scene_tree/move_up", TTR("Move Up"), KeyModifierMask::CMD_OR_CTRL | Key::UP); + ED_SHORTCUT("scene_tree/move_down", TTR("Move Down"), KeyModifierMask::CMD_OR_CTRL | Key::DOWN); + ED_SHORTCUT("scene_tree/duplicate", TTR("Duplicate"), KeyModifierMask::CMD_OR_CTRL | Key::D); ED_SHORTCUT("scene_tree/reparent", TTR("Reparent")); ED_SHORTCUT("scene_tree/reparent_to_new_node", TTR("Reparent to New Node")); ED_SHORTCUT("scene_tree/make_root", TTR("Make Scene Root")); ED_SHORTCUT("scene_tree/save_branch_as_scene", TTR("Save Branch as Scene")); - ED_SHORTCUT("scene_tree/copy_node_path", TTR("Copy Node Path"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::C); + ED_SHORTCUT("scene_tree/copy_node_path", TTR("Copy Node Path"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::C); + ED_SHORTCUT("scene_tree/toggle_unique_name", TTR("Toggle Access as Unique Name")); ED_SHORTCUT("scene_tree/delete_no_confirm", TTR("Delete (No Confirm)"), KeyModifierMask::SHIFT | Key::KEY_DELETE); ED_SHORTCUT("scene_tree/delete", TTR("Delete"), Key::KEY_DELETE); @@ -3434,16 +3524,24 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec button_instance->set_flat(true); button_instance->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected).bind(TOOL_INSTANTIATE, false)); button_instance->set_tooltip_text(TTR("Instantiate a scene file as a Node. Creates an inherited scene if no root node exists.")); - button_instance->set_shortcut(ED_GET_SHORTCUT("scene_tree/instance_scene")); + button_instance->set_shortcut(ED_GET_SHORTCUT("scene_tree/instantiate_scene")); filter_hbc->add_child(button_instance); - vbc->add_child(filter_hbc); + + // The "Filter Nodes" text input above the Scene Tree Editor. filter = memnew(LineEdit); filter->set_h_size_flags(SIZE_EXPAND_FILL); filter->set_placeholder(TTR("Filter Nodes")); filter_hbc->add_child(filter); filter->add_theme_constant_override("minimum_character_width", 0); filter->connect("text_changed", callable_mp(this, &SceneTreeDock::_filter_changed)); + filter->connect("gui_input", callable_mp(this, &SceneTreeDock::_filter_gui_input)); + filter->get_menu()->connect("about_to_popup", callable_mp(this, &SceneTreeDock::_update_filter_menu)); + filter->get_menu()->connect("id_pressed", callable_mp(this, &SceneTreeDock::_filter_option_selected)); + + filter_quick_menu = memnew(PopupMenu); + filter_quick_menu->connect("id_pressed", callable_mp(this, &SceneTreeDock::_filter_option_selected)); + filter->add_child(filter_quick_menu); button_create_script = memnew(Button); button_create_script->set_flat(true); @@ -3463,11 +3561,11 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec button_tree_menu = memnew(MenuButton); button_tree_menu->set_flat(true); + button_tree_menu->set_tooltip_text(TTR("Extra scene options.")); button_tree_menu->connect("about_to_popup", callable_mp(this, &SceneTreeDock::_update_tree_menu)); filter_hbc->add_child(button_tree_menu); PopupMenu *tree_menu = button_tree_menu->get_popup(); - tree_menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND); tree_menu->connect("id_pressed", callable_mp(this, &SceneTreeDock::_tool_selected).bind(false)); button_hb = memnew(HBoxContainer); @@ -3516,11 +3614,10 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec scene_tree->connect("nodes_dragged", callable_mp(this, &SceneTreeDock::_nodes_drag_begin)); scene_tree->get_scene_tree()->connect("item_double_clicked", callable_mp(this, &SceneTreeDock::_focus_node)); - scene_tree->get_scene_tree()->connect("item_collapsed", callable_mp(this, &SceneTreeDock::_node_collapsed)); editor_selection->connect("selection_changed", callable_mp(this, &SceneTreeDock::_selection_changed)); - scene_tree->set_undo_redo(editor_data->get_undo_redo()); + scene_tree->set_as_scene_tree_dock(); scene_tree->set_editor_selection(editor_selection); create_dialog = memnew(CreateDialog); @@ -3530,7 +3627,7 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec create_dialog->connect("favorites_updated", callable_mp(this, &SceneTreeDock::_update_create_root_dialog)); #ifdef MODULE_REGEX_ENABLED - rename_dialog = memnew(RenameDialog(scene_tree, editor_data->get_undo_redo())); + rename_dialog = memnew(RenameDialog(scene_tree)); add_child(rename_dialog); #endif // MODULE_REGEX_ENABLED |