diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 111 |
1 files changed, 64 insertions, 47 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index ce869feddd..91ae81dea2 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -30,10 +30,10 @@ #include "scene_tree_dock.h" +#include "core/config/project_settings.h" #include "core/input/input.h" #include "core/io/resource_saver.h" #include "core/os/keyboard.h" -#include "core/project_settings.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" @@ -114,7 +114,12 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { _tool_selected(TOOL_COPY_NODE_PATH); } else if (ED_IS_SHORTCUT("scene_tree/delete", p_event)) { _tool_selected(TOOL_ERASE); + } else { + return; } + + // Tool selection was successful, accept the event to stop propagation. + accept_event(); } void SceneTreeDock::instance(const String &p_file) { @@ -1010,7 +1015,7 @@ 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_margins_preset(PRESET_WIDE); //more useful for resizable UIs. + node->set_anchors_and_offsets_preset(PRESET_WIDE); //more useful for resizable UIs. new_node = node; } break; @@ -1068,14 +1073,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_compat("item_lock_status_changed", scene_tree, "_update_tree"); - canvas_item_plugin->get_canvas_item_editor()->connect_compat("item_group_status_changed", scene_tree, "_update_tree"); + 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")); scene_tree->connect("node_changed", callable_mp((CanvasItem *)canvas_item_plugin->get_canvas_item_editor()->get_viewport_control(), &CanvasItem::update)); } Node3DEditorPlugin *spatial_editor_plugin = Object::cast_to<Node3DEditorPlugin>(editor_data->get_editor("3D")); - spatial_editor_plugin->get_spatial_editor()->connect_compat("item_lock_status_changed", scene_tree, "_update_tree"); - spatial_editor_plugin->get_spatial_editor()->connect_compat("item_group_status_changed", scene_tree, "_update_tree"); + 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")); button_add->set_icon(get_theme_icon("Add", "EditorIcons")); button_instance->set_icon(get_theme_icon("Instance", "EditorIcons")); @@ -1102,7 +1107,7 @@ void SceneTreeDock::_notification(int p_what) { node_shortcuts_toggle->set_toggle_mode(true); node_shortcuts_toggle->set_tooltip(TTR("Switch to Favorite Nodes")); node_shortcuts_toggle->set_pressed(EDITOR_GET("_use_favorites_root_selection")); - node_shortcuts_toggle->set_anchors_and_margins_preset(Control::PRESET_CENTER_RIGHT); + node_shortcuts_toggle->set_anchors_and_offsets_preset(Control::PRESET_CENTER_RIGHT); node_shortcuts_toggle->connect("pressed", callable_mp(this, &SceneTreeDock::_update_create_root_dialog)); top_row->add_child(node_shortcuts_toggle); @@ -1115,7 +1120,7 @@ void SceneTreeDock::_notification(int p_what) { beginner_node_shortcuts->set_name("BeginnerNodeShortcuts"); node_shortcuts->add_child(beginner_node_shortcuts); - Button *button_2d = memnew(Button); + button_2d = memnew(Button); beginner_node_shortcuts->add_child(button_2d); button_2d->set_text(TTR("2D Scene")); button_2d->set_icon(get_theme_icon("Node2D", "EditorIcons")); @@ -1127,7 +1132,7 @@ void SceneTreeDock::_notification(int p_what) { button_3d->set_icon(get_theme_icon("Node3D", "EditorIcons")); button_3d->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_CREATE_3D_SCENE, false)); - Button *button_ui = memnew(Button); + button_ui = memnew(Button); beginner_node_shortcuts->add_child(button_ui); button_ui->set_text(TTR("User Interface")); button_ui->set_icon(get_theme_icon("Control", "EditorIcons")); @@ -1137,11 +1142,11 @@ void SceneTreeDock::_notification(int p_what) { favorite_node_shortcuts->set_name("FavoriteNodeShortcuts"); node_shortcuts->add_child(favorite_node_shortcuts); - Button *button_custom = memnew(Button); + button_custom = memnew(Button); node_shortcuts->add_child(button_custom); button_custom->set_text(TTR("Other Node")); button_custom->set_icon(get_theme_icon("Add", "EditorIcons")); - button_custom->connect("pressed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_NEW, false)); + button_custom->connect("pressed", callable_bind(callable_mp(this, &SceneTreeDock::_tool_selected), TOOL_NEW, false)); node_shortcuts->add_spacer(); create_root_dialog->add_child(node_shortcuts); @@ -1160,6 +1165,10 @@ void SceneTreeDock::_notification(int p_what) { button_instance->set_icon(get_theme_icon("Instance", "EditorIcons")); button_create_script->set_icon(get_theme_icon("ScriptCreate", "EditorIcons")); button_detach_script->set_icon(get_theme_icon("ScriptRemove", "EditorIcons")); + button_2d->set_icon(get_theme_icon("Node2D", "EditorIcons")); + button_3d->set_icon(get_theme_icon("Node3D", "EditorIcons")); + button_ui->set_icon(get_theme_icon("Control", "EditorIcons")); + button_custom->set_icon(get_theme_icon("Add", "EditorIcons")); filter->set_right_icon(get_theme_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); @@ -1266,10 +1275,6 @@ void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<Stri } void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames) { - if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true))) { - return; - } - Vector<StringName> base_path; Node *n = p_node->get_parent(); while (n) { @@ -1314,32 +1319,50 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP if (si) { List<PropertyInfo> properties; si->get_property_list(&properties); + NodePath root_path = p_base->get_path(); for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { String propertyname = E->get().name; Variant p = p_base->get(propertyname); if (p.get_type() == Variant::NODE_PATH) { - // Goes through all paths to check if its matching + NodePath root_path_new = root_path; for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - NodePath root_path = p_base->get_path(); + if (root_path == F->get().first) { + root_path_new = F->get().second; + break; + } + } + // Goes through all paths to check if its matching + for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { NodePath rel_path_old = root_path.rel_path_to(F->get().first); - NodePath rel_path_new = F->get().second; - - // if not empty, get new relative path - if (F->get().second != NodePath()) { - rel_path_new = root_path.rel_path_to(F->get().second); - } - // if old path detected, then it needs to be replaced with the new one if (p == rel_path_old) { + NodePath rel_path_new = F->get().second; + + // if not empty, get new relative path + if (!rel_path_new.is_empty()) { + rel_path_new = root_path_new.rel_path_to(F->get().second); + } + editor_data->get_undo_redo().add_do_property(p_base, propertyname, rel_path_new); editor_data->get_undo_redo().add_undo_property(p_base, propertyname, rel_path_old); p_base->set(propertyname, rel_path_new); break; } + + // update the node itself if it has a valid node path and has not been deleted + if (root_path == F->get().first && p != NodePath() && F->get().second != NodePath()) { + NodePath abs_path = NodePath(String(root_path).plus_file(p)).simplified(); + NodePath rel_path_new = F->get().second.rel_path_to(abs_path); + + editor_data->get_undo_redo().add_do_property(p_base, propertyname, rel_path_new); + editor_data->get_undo_redo().add_undo_property(p_base, propertyname, p); + + p_base->set(propertyname, rel_path_new); + } } } } @@ -1740,6 +1763,8 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) { 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)); } void SceneTreeDock::_toggle_editable_children_from_selection() { @@ -1909,23 +1934,6 @@ void SceneTreeDock::_selection_changed() { _update_script_button(); } -Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List<Node *> p_list) { - Node *tail = p_node; - Node *parent = tail->get_parent(); - - for (int i = p_node->get_index(); i < parent->get_child_count(); i++) { - Node *sibling = parent->get_child(i); - - if (p_list.find(sibling)) { - tail = sibling; - } else { - break; - } - } - - return tail; -} - void SceneTreeDock::_do_create(Node *p_parent) { Object *c = create_dialog->instance_selected(); @@ -1970,6 +1978,9 @@ void SceneTreeDock::_do_create(Node *p_parent) { if (ms.height < 4) { ms.height = 40; } + if (ct->is_layout_rtl()) { + ct->set_position(ct->get_position() - Vector2(ms.x, 0)); + } ct->set_size(ms); } } @@ -2085,8 +2096,12 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop } if (E->get().name == "__meta__") { - if (Object::cast_to<CanvasItem>(newnode)) { - Dictionary metadata = n->get(E->get().name); + Dictionary metadata = n->get(E->get().name); + if (metadata.has("_editor_description_")) { + newnode->set_meta("_editor_description_", metadata["_editor_description_"]); + } + + if (Object::cast_to<CanvasItem>(newnode) || Object::cast_to<Node3D>(newnode)) { if (metadata.has("_edit_group_") && metadata["_edit_group_"]) { newnode->set_meta("_edit_group_", true); } @@ -2625,7 +2640,8 @@ 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("popup_hide", callable_mp(this, &SceneTreeDock::_script_creation_closed), varray(), CONNECT_ONESHOT); + 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->set_inheritance_base_type("Node"); script_create_dialog->config(inherits, path); script_create_dialog->popup_centered(); @@ -2799,8 +2815,8 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel HBoxContainer *filter_hbc = memnew(HBoxContainer); filter_hbc->add_theme_constant_override("separate", 0); - ED_SHORTCUT("scene_tree/rename", TTR("Rename")); - ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KEY_MASK_CMD | KEY_F2); + ED_SHORTCUT("scene_tree/rename", TTR("Rename"), KEY_F2); + ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KEY_MASK_SHIFT | KEY_F2); ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KEY_MASK_CMD | KEY_A); ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene")); ED_SHORTCUT("scene_tree/expand_collapse_all", TTR("Expand/Collapse All")); @@ -2929,6 +2945,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel quick_open = memnew(EditorQuickOpen); add_child(quick_open); quick_open->connect("quick_open", callable_mp(this, &SceneTreeDock::_quick_open)); + set_process_unhandled_key_input(true); delete_dialog = memnew(ConfirmationDialog); @@ -2965,7 +2982,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel clear_inherit_confirm = memnew(ConfirmationDialog); clear_inherit_confirm->set_text(TTR("Clear Inheritance? (No Undo!)")); - clear_inherit_confirm->get_ok()->set_text(TTR("Clear")); + clear_inherit_confirm->get_ok_button()->set_text(TTR("Clear")); add_child(clear_inherit_confirm); set_process_input(true); |