diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 171 |
1 files changed, 87 insertions, 84 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index ce869feddd..ac1beb1c37 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -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" @@ -57,10 +57,7 @@ void SceneTreeDock::_nodes_drag_begin() { } void SceneTreeDock::_quick_open() { - Vector<String> files = quick_open->get_selected_files(); - for (int i = 0; i < files.size(); i++) { - instance(files[i]); - } + instance_scenes(quick_open->get_selected_files(), scene_tree->get_selected()); } void SceneTreeDock::_input(Ref<InputEvent> p_event) { @@ -114,28 +111,18 @@ 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) { - Node *parent = scene_tree->get_selected(); - - if (!parent) { - parent = edited_scene; - }; - - if (!edited_scene) { - current_option = -1; - accept->set_text(TTR("No parent to instance a child at.")); - accept->popup_centered(); - return; - }; - - ERR_FAIL_COND(!parent); - Vector<String> scenes; scenes.push_back(p_file); - _perform_instance_scenes(scenes, parent, -1); + instance_scenes(scenes, scene_tree->get_selected()); } void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_parent) { @@ -146,7 +133,11 @@ void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_paren } if (!parent || !edited_scene) { - accept->set_text(TTR("No parent to instance the scenes at.")); + if (p_files.size() == 1) { + accept->set_text(TTR("No parent to instance a child at.")); + } else { + accept->set_text(TTR("No parent to instance the scenes at.")); + } accept->popup_centered(); return; }; @@ -223,6 +214,7 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node } editor_data->get_undo_redo().commit_action(); + editor->push_item(instances[instances.size() - 1]); } void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) { @@ -356,7 +348,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (current_edited_scene_root) { String root_class = current_edited_scene_root->get_class_name(); static Vector<String> preferred_types; - if (preferred_types.empty()) { + if (preferred_types.is_empty()) { preferred_types.push_back("Control"); preferred_types.push_back("Node2D"); preferred_types.push_back("Node3D"); @@ -411,7 +403,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } Node *selected = scene_tree->get_selected(); - if (!selected && !editor_selection->get_selected_node_list().empty()) { + if (!selected && !editor_selection->get_selected_node_list().is_empty()) { selected = editor_selection->get_selected_node_list().front()->get(); } @@ -433,7 +425,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Array selection = editor_selection->get_selected_nodes(); - if (selection.empty()) { + if (selection.is_empty()) { return; } @@ -732,7 +724,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { List<Node *> remove_list = editor_selection->get_selected_node_list(); - if (remove_list.empty()) { + if (remove_list.is_empty()) { return; } @@ -1010,7 +1002,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 +1060,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 +1094,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 +1107,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 +1119,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 +1129,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 +1152,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 +1262,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 +1306,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); + } } } } @@ -1506,7 +1516,7 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) { List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) { + if (selection.is_empty()) { return; // Nothing to reparent. } @@ -1680,7 +1690,7 @@ bool SceneTreeDock::_is_collapsed_recursive(TreeItem *p_item) const { List<TreeItem *> needs_check; needs_check.push_back(p_item); - while (!needs_check.empty()) { + while (!needs_check.is_empty()) { TreeItem *item = needs_check.back()->get(); needs_check.pop_back(); @@ -1702,7 +1712,7 @@ void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed) List<TreeItem *> to_collapse; to_collapse.push_back(p_item); - while (!to_collapse.empty()) { + while (!to_collapse.is_empty()) { TreeItem *item = to_collapse.back()->get(); to_collapse.pop_back(); @@ -1719,7 +1729,7 @@ void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed) void SceneTreeDock::_script_created(Ref<Script> p_script) { List<Node *> selected = editor_selection->get_selected_node_list(); - if (selected.empty()) { + if (selected.is_empty()) { return; } @@ -1740,6 +1750,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() { @@ -1786,7 +1798,7 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) { void SceneTreeDock::_delete_confirm() { List<Node *> remove_list = editor_selection->get_selected_node_list(); - if (remove_list.empty()) { + if (remove_list.is_empty()) { return; } @@ -1909,25 +1921,8 @@ 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(); + Variant c = create_dialog->instance_selected(); ERR_FAIL_COND(!c); Node *child = Object::cast_to<Node>(c); @@ -1970,6 +1965,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); } } @@ -2004,7 +2002,7 @@ void SceneTreeDock::_create() { Node *n = E->get(); ERR_FAIL_COND(!n); - Object *c = create_dialog->instance_selected(); + Variant c = create_dialog->instance_selected(); ERR_FAIL_COND(!c); Node *newnode = Object::cast_to<Node>(c); @@ -2085,8 +2083,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); } @@ -2138,7 +2140,6 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop if (n == edited_scene) { edited_scene = newnode; editor->set_edited_scene(newnode); - newnode->set_editable_instances(n->get_editable_instances()); } //small hack to make collisionshapes and other kind of nodes to work @@ -2334,7 +2335,7 @@ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) { void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) { + if (selection.is_empty()) { return; //nothing to reparent } @@ -2586,7 +2587,7 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) { } List<Node *> selection = editor_selection->get_selected_node_list(); - if (selection.empty()) { + if (selection.is_empty()) { return; } @@ -2625,7 +2626,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 +2801,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 +2931,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 +2968,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); |