From 17db92b8b83b22d5054bc5ea00399903f522792b Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sun, 1 Dec 2024 06:40:29 -0800 Subject: [PATCH] Clarify API for top selected nodes in EditorSelection and make public --- doc/classes/EditorSelection.xml | 11 ++- editor/editor_data.cpp | 17 +++-- editor/editor_data.h | 11 +-- editor/editor_node.cpp | 2 +- editor/gui/scene_tree_editor.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 27 +++---- editor/plugins/control_editor_plugin.cpp | 12 +-- .../mesh_instance_3d_editor_plugin.cpp | 2 +- editor/plugins/node_3d_editor_plugin.cpp | 57 ++++++++------- editor/plugins/particles_editor_plugin.cpp | 2 +- .../plugins/sprite_frames_editor_plugin.cpp | 5 +- editor/scene_tree_dock.cpp | 73 ++++++++++--------- 12 files changed, 119 insertions(+), 102 deletions(-) diff --git a/doc/classes/EditorSelection.xml b/doc/classes/EditorSelection.xml index 4ef960ac5ca..40dc1a24198 100644 --- a/doc/classes/EditorSelection.xml +++ b/doc/classes/EditorSelection.xml @@ -30,10 +30,17 @@ Returns the list of selected nodes. - + - Returns the list of selected nodes, optimized for transform operations (i.e. moving them, rotating, etc.). This list can be used to avoid situations where a node is selected and is also a child/grandchild. + Returns the list of top selected nodes only, excluding any children. This is useful for performing transform operations (moving them, rotating, etc.). + For example, if there is a node A with a child B and a sibling C, then selecting all three will cause this method to return only A and C. Changing the global transform of A will affect the global transform of B, so there is no need to change B separately. + + + + + + Returns the list of top selected nodes only, excluding any children. This is useful for performing transform operations (moving them, rotating, etc.). See [method get_top_selected_nodes]. diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 07d7217f378..a9a4bb43c0e 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -1252,7 +1252,10 @@ void EditorSelection::_bind_methods() { ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node); ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node); ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes); - ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes); + ClassDB::bind_method(D_METHOD("get_top_selected_nodes"), &EditorSelection::get_top_selected_nodes); +#ifndef DISABLE_DEPRECATED + ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::get_top_selected_nodes); +#endif // DISABLE_DEPRECATED ADD_SIGNAL(MethodInfo("selection_changed")); } @@ -1265,7 +1268,7 @@ void EditorSelection::_update_node_list() { return; } - selected_node_list.clear(); + top_selected_node_list.clear(); // If the selection does not have the parent of the selected node, then add the node to the node list. // However, if the parent is already selected, then adding this node is redundant as @@ -1285,7 +1288,7 @@ void EditorSelection::_update_node_list() { if (skip) { continue; } - selected_node_list.push_back(E.key); + top_selected_node_list.push_back(E.key); } node_list_changed = true; @@ -1309,10 +1312,10 @@ void EditorSelection::_emit_change() { emitted = false; } -TypedArray EditorSelection::_get_transformable_selected_nodes() { +TypedArray EditorSelection::get_top_selected_nodes() { TypedArray ret; - for (const Node *E : selected_node_list) { + for (const Node *E : top_selected_node_list) { ret.push_back(E); } @@ -1329,13 +1332,13 @@ TypedArray EditorSelection::get_selected_nodes() { return ret; } -const List &EditorSelection::get_selected_node_list() { +const List &EditorSelection::get_top_selected_node_list() { if (changed) { update(); } else { _update_node_list(); } - return selected_node_list; + return top_selected_node_list; } List EditorSelection::get_full_selected_node_list() { diff --git a/editor/editor_data.h b/editor/editor_data.h index a3a4623e2c7..22f44db7213 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -286,10 +286,9 @@ class EditorSelection : public Object { // Editor plugins which are related to selection. List editor_plugins; - List selected_node_list; + List top_selected_node_list; void _update_node_list(); - TypedArray _get_transformable_selected_nodes(); void _emit_change(); protected: @@ -314,13 +313,15 @@ public: void update(); void clear(); - // Returns all the selected nodes. - TypedArray get_selected_nodes(); // Returns only the top level selected nodes. // That is, if the selection includes some node and a child of that node, only the parent is returned. - const List &get_selected_node_list(); + const List &get_top_selected_node_list(); + // Same as get_top_selected_node_list but returns a copy in a TypedArray for binding to scripts. + TypedArray get_top_selected_nodes(); // Returns all the selected nodes (list version of "get_selected_nodes"). List get_full_selected_node_list(); + // Same as get_full_selected_node_list but returns a copy in a TypedArray for binding to scripts. + TypedArray get_selected_nodes(); // Returns the map of selected objects and their metadata. HashMap &get_selection() { return selection; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6f5d53ac541..aaced21803c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6449,7 +6449,7 @@ void EditorNode::reload_instances_with_path_in_edited_scenes() { // Store all the paths for any selected nodes which are ancestors of the node we're replacing. List selected_node_paths; - for (Node *selected_node : editor_selection->get_selected_node_list()) { + for (Node *selected_node : editor_selection->get_top_selected_node_list()) { if (selected_node == original_node || original_node->is_ancestor_of(selected_node)) { selected_node_paths.push_back(original_node->get_path_to(selected_node)); editor_selection->remove_node(selected_node); diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index ffc432896a7..79b8641cfb5 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -112,7 +112,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i } else if (p_id == BUTTON_VISIBILITY) { undo_redo->create_action(TTR("Toggle Visible")); _toggle_visible(n); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); if (selection.size() > 1 && selection.find(n) != nullptr) { for (Node *nv : selection) { ERR_FAIL_NULL(nv); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 423b6e0f841..a8ab496ea4a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -770,14 +770,15 @@ void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_n bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_pos, bool p_append) { bool still_selected = true; - if (p_append && !editor_selection->get_selected_node_list().is_empty()) { + const List &top_node_list = editor_selection->get_top_selected_node_list(); + if (p_append && !top_node_list.is_empty()) { if (editor_selection->is_selected(item)) { // Already in the selection, remove it from the selected nodes editor_selection->remove_node(item); still_selected = false; - if (editor_selection->get_selected_node_list().size() == 1) { - EditorNode::get_singleton()->push_item(editor_selection->get_selected_node_list().front()->get()); + if (top_node_list.size() == 1) { + EditorNode::get_singleton()->push_item(top_node_list.front()->get()); } } else { // Add the item to the selection @@ -974,7 +975,7 @@ void CanvasItemEditor::_add_node_pressed(int p_result) { [[fallthrough]]; } case ADD_MOVE: { - nodes_to_move = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list(); + nodes_to_move = EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list(); if (nodes_to_move.is_empty()) { return; } @@ -2468,7 +2469,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref &p_event) { break; } } - for (Node *node : EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list()) { + for (Node *node : EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list()) { if (Object::cast_to(node)) { add_node_menu->add_icon_item(get_editor_theme_icon(SNAME("ToolMove")), TTR("Move Node(s) Here"), ADD_MOVE); break; @@ -2599,7 +2600,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref &p_event) { } _find_canvas_items_in_rect(Rect2(bsfrom, bsto - bsfrom), scene, &selitems); - if (selitems.size() == 1 && editor_selection->get_selected_node_list().is_empty()) { + if (selitems.size() == 1 && editor_selection->get_top_selected_node_list().is_empty()) { EditorNode::get_singleton()->push_item(selitems.front()->get()); } for (CanvasItem *E : selitems) { @@ -2812,7 +2813,7 @@ void CanvasItemEditor::_update_lock_and_group_button() { bool all_locked = true; bool all_group = true; bool has_canvas_item = false; - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); if (selection.is_empty()) { all_locked = false; all_group = false; @@ -4584,7 +4585,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { snap_dialog->popup_centered(Size2(320, 160) * EDSCALE); } break; case SKELETON_SHOW_BONES: { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { // Add children nodes so they are processed for (int child = 0; child < E->get_child_count(); child++) { @@ -4619,7 +4620,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { case LOCK_SELECTED: { undo_redo->create_action(TTR("Lock Selected")); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { CanvasItem *ci = Object::cast_to(E); if (!ci || !ci->is_inside_tree()) { @@ -4638,7 +4639,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { case UNLOCK_SELECTED: { undo_redo->create_action(TTR("Unlock Selected")); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { CanvasItem *ci = Object::cast_to(E); if (!ci || !ci->is_inside_tree()) { @@ -4657,7 +4658,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { case GROUP_SELECTED: { undo_redo->create_action(TTR("Group Selected")); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { CanvasItem *ci = Object::cast_to(E); if (!ci || !ci->is_inside_tree()) { @@ -4676,7 +4677,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { case UNGROUP_SELECTED: { undo_redo->create_action(TTR("Ungroup Selected")); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { CanvasItem *ci = Object::cast_to(E); if (!ci || !ci->is_inside_tree()) { @@ -6276,7 +6277,7 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p return; } - List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list(); + List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list(); Node *root_node = EditorNode::get_singleton()->get_edited_scene(); if (selected_nodes.size() > 0) { Node *selected_node = selected_nodes.front()->get(); diff --git a/editor/plugins/control_editor_plugin.cpp b/editor/plugins/control_editor_plugin.cpp index e3ac7751857..93a6a85214e 100644 --- a/editor/plugins/control_editor_plugin.cpp +++ b/editor/plugins/control_editor_plugin.cpp @@ -740,7 +740,7 @@ SizeFlagPresetPicker::SizeFlagPresetPicker(bool p_vertical) { void ControlEditorToolbar::_anchors_preset_selected(int p_preset) { LayoutPreset preset = (LayoutPreset)p_preset; - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Change Anchors, Offsets, Grow Direction")); @@ -761,7 +761,7 @@ void ControlEditorToolbar::_anchors_preset_selected(int p_preset) { } void ControlEditorToolbar::_anchors_to_current_ratio() { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Change Anchors, Offsets (Keep Ratio)")); @@ -812,7 +812,7 @@ void ControlEditorToolbar::_anchor_mode_toggled(bool p_status) { } void ControlEditorToolbar::_container_flags_selected(int p_flags, bool p_vertical) { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); if (p_vertical) { @@ -839,7 +839,7 @@ void ControlEditorToolbar::_container_flags_selected(int p_flags, bool p_vertica } void ControlEditorToolbar::_expand_flag_toggled(bool p_expand, bool p_vertical) { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); if (p_vertical) { @@ -973,7 +973,7 @@ void ControlEditorToolbar::_selection_changed() { int nb_valid_controls = 0; int nb_anchors_mode = 0; - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Control *control = Object::cast_to(E); if (!control) { @@ -1023,7 +1023,7 @@ void ControlEditorToolbar::_selection_changed() { int nb_h_expand = 0; int nb_v_expand = 0; - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Control *control = Object::cast_to(E); if (!control) { diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp index fc0541281d4..5ee746e34ba 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp @@ -133,7 +133,7 @@ void MeshInstance3DEditor::_create_collision_shape() { break; } - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); bool verbose = false; if (selection.is_empty()) { diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 3488cefd2f4..18f9933aae9 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -662,7 +662,7 @@ int Node3DEditorViewport::get_selected_count() const { } void Node3DEditorViewport::cancel_transform() { - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); @@ -791,7 +791,8 @@ void Node3DEditorViewport::_select_clicked(bool p_allow_locked) { if (p_allow_locked || (selected != nullptr && !_is_node_locked(selected))) { if (clicked_wants_append) { - Node *active_node = editor_selection->get_selected_node_list().is_empty() ? nullptr : editor_selection->get_selected_node_list().back()->get(); + const List &top_node_list = editor_selection->get_top_selected_node_list(); + const Node *active_node = top_node_list.is_empty() ? nullptr : top_node_list.back()->get(); if (editor_selection->is_selected(selected)) { editor_selection->remove_node(selected); if (selected != active_node) { @@ -808,8 +809,9 @@ void Node3DEditorViewport::_select_clicked(bool p_allow_locked) { } } - if (editor_selection->get_selected_node_list().size() == 1) { - EditorNode::get_singleton()->edit_node(editor_selection->get_selected_node_list().front()->get()); + const List &top_node_list = editor_selection->get_top_selected_node_list(); + if (top_node_list.size() == 1) { + EditorNode::get_singleton()->edit_node(top_node_list.front()->get()); } } } @@ -1139,8 +1141,9 @@ void Node3DEditorViewport::_select_region() { } } - if (editor_selection->get_selected_node_list().size() == 1) { - EditorNode::get_singleton()->edit_node(editor_selection->get_selected_node_list().front()->get()); + const List &top_node_list = editor_selection->get_top_selected_node_list(); + if (top_node_list.size() == 1) { + EditorNode::get_singleton()->edit_node(top_node_list.front()->get()); } } @@ -1227,7 +1230,7 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { se->original_local = selected->get_transform(); se->original = selected->get_global_transform(); } else { - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); @@ -2430,7 +2433,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { return; } - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); @@ -2471,7 +2474,7 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { begin_transform(TRANSFORM_SCALE, true); } } - if (ED_IS_SHORTCUT("spatial_editor/collision_reposition", p_event) && editor_selection->get_selected_node_list().size() == 1 && !collision_reposition) { + if (ED_IS_SHORTCUT("spatial_editor/collision_reposition", p_event) && editor_selection->get_top_selected_node_list().size() == 1 && !collision_reposition) { if (_edit.mode == TRANSFORM_NONE || _edit.instant) { if (_edit.mode == TRANSFORM_NONE) { _compute_edit(_edit.mouse_pos); @@ -3173,7 +3176,7 @@ void Node3DEditorViewport::_notification(int p_what) { selected_node = ruler_start_point; } } else { - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); if (selection.size() == 1) { selected_node = Object::cast_to(selection.front()->get()); } @@ -3566,7 +3569,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { Transform3D camera_transform = camera->get_global_transform(); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); undo_redo->create_action(TTR("Align Transform with View")); @@ -3612,7 +3615,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { Transform3D camera_transform = camera->get_global_transform(); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); undo_redo->create_action(TTR("Align Rotation with View")); for (Node *E : selection) { @@ -4350,7 +4353,7 @@ void Node3DEditorViewport::focus_selection() { Vector3 center; int count = 0; - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *node : selection) { Node3D *node_3d = Object::cast_to(node); @@ -4419,7 +4422,7 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos, Node3D HashSet rids; if (!preview_node->is_inside_tree() && !ruler->is_inside_tree()) { - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); Node3D *first_selected_node = Object::cast_to(selection.front()->get()); @@ -5028,7 +5031,7 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ selected_files = d["files"]; } - List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list(); + List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list(); Node *root_node = EditorNode::get_singleton()->get_edited_scene(); if (selected_nodes.size() > 0) { Node *selected_node = selected_nodes.front()->get(); @@ -5078,7 +5081,7 @@ void Node3DEditorViewport::commit_transform() { EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(_transform_name[_edit.mode]); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); @@ -5103,7 +5106,7 @@ void Node3DEditorViewport::commit_transform() { void Node3DEditorViewport::apply_transform(Vector3 p_motion, double p_snap) { bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); if (!sp) { @@ -6297,7 +6300,7 @@ void Node3DEditor::update_transform_gizmo() { count++; } } else { - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); if (!sp) { @@ -6766,7 +6769,7 @@ void Node3DEditor::_xform_dialog_action() { EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("XForm Dialog")); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *sp = Object::cast_to(E); @@ -6979,7 +6982,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_LOCK_SELECTED: { undo_redo->create_action(TTR("Lock Selected")); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7000,7 +7003,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_UNLOCK_SELECTED: { undo_redo->create_action(TTR("Unlock Selected")); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7021,7 +7024,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { case MENU_GROUP_SELECTED: { undo_redo->create_action(TTR("Group Selected")); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7041,7 +7044,7 @@ void Node3DEditor::_menu_item_pressed(int p_option) { } break; case MENU_UNGROUP_SELECTED: { undo_redo->create_action(TTR("Ungroup Selected")); - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); for (Node *E : selection) { Node3D *spatial = Object::cast_to(E); @@ -7918,7 +7921,7 @@ void Node3DEditor::_selection_changed() { continue; } - if (sp == editor_selection->get_selected_node_list().back()->get()) { + if (sp == editor_selection->get_top_selected_node_list().back()->get()) { RenderingServer::get_singleton()->instance_set_base(se->sbox_instance, active_selection_box->get_rid()); RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_xray, active_selection_box_xray->get_rid()); RenderingServer::get_singleton()->instance_set_base(se->sbox_instance_offset, active_selection_box->get_rid()); @@ -7931,7 +7934,7 @@ void Node3DEditor::_selection_changed() { } } - if (selected && editor_selection->get_selected_node_list().size() != 1) { + if (selected && editor_selection->get_top_selected_node_list().size() != 1) { Vector> gizmos = selected->get_gizmos(); for (int i = 0; i < gizmos.size(); i++) { Ref seg = gizmos[i]; @@ -7957,7 +7960,7 @@ void Node3DEditor::_refresh_menu_icons() { bool all_grouped = true; bool has_node3d_item = false; - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); if (selection.is_empty()) { all_locked = false; @@ -8032,7 +8035,7 @@ void Node3DEditor::snap_selected_nodes_to_floor() { } void Node3DEditor::_snap_selected_nodes_to_floor() { - const List &selection = editor_selection->get_selected_node_list(); + const List &selection = editor_selection->get_top_selected_node_list(); Dictionary snap_data; for (Node *E : selection) { diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index a83576d1f39..35181cda111 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -292,7 +292,7 @@ Particles2DEditorPlugin::Particles2DEditorPlugin() { } void Particles2DEditorPlugin::_selection_changed() { - List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list(); + List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list(); if (selected_particles.is_empty() && selected_nodes.is_empty()) { return; } diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 4bbe4166355..c3526052085 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -1806,8 +1806,9 @@ void SpriteFramesEditor::_remove_sprite_node() { void SpriteFramesEditor::_fetch_sprite_node() { Node *selected = nullptr; EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); - if (editor_selection->get_selected_node_list().size() == 1) { - selected = editor_selection->get_selected_node_list().front()->get(); + const List &top_node_list = editor_selection->get_top_selected_node_list(); + if (top_node_list.size() == 1) { + selected = top_node_list.front()->get(); } bool show_node_edit = false; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index c45213cdc4c..54e03cf0248 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -560,7 +560,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (!profile_allow_editing) { break; } - if (editor_selection->get_selected_node_list().size() > 1) { + if (editor_selection->get_top_selected_node_list().size() > 1) { if (!_validate_no_foreign()) { break; } @@ -658,7 +658,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); if (selection.size() == 0) { break; } @@ -738,8 +738,9 @@ 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().is_empty()) { - selected = editor_selection->get_selected_node_list().front()->get(); + const List &top_node_list = editor_selection->get_top_selected_node_list(); + if (!selected && !top_node_list.is_empty()) { + selected = top_node_list.front()->get(); } if (selected) { @@ -815,7 +816,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { bool MOVING_UP = !MOVING_DOWN; Node *common_parent = scene_tree->get_selected()->get_parent(); - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); selection.sort_custom(); // sort by index if (MOVING_DOWN) { selection.reverse(); @@ -885,7 +886,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); if (selection.size() == 0) { break; } @@ -980,7 +981,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - List nodes = editor_selection->get_selected_node_list(); + List nodes = editor_selection->get_top_selected_node_list(); HashSet nodeset; for (Node *E : nodes) { nodeset.insert(E); @@ -993,7 +994,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - List nodes = editor_selection->get_selected_node_list(); + List nodes = editor_selection->get_top_selected_node_list(); ERR_FAIL_COND(nodes.size() != 1); Node *node = nodes.front()->get(); @@ -1076,7 +1077,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - List remove_list = editor_selection->get_selected_node_list(); + List remove_list = editor_selection->get_top_selected_node_list(); if (remove_list.is_empty()) { return; @@ -1146,7 +1147,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); if (selection.size() != 1) { accept->set_text(vformat(TTR("Saving the branch as a scene requires selecting only one node, but you have selected %d nodes."), selection.size())); @@ -1202,7 +1203,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { new_scene_from_dialog->popup_file_dialog(); } break; case TOOL_COPY_NODE_PATH: { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); List::Element *e = selection.front(); if (e) { Node *node = e->get(); @@ -1214,7 +1215,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_SHOW_IN_FILE_SYSTEM: { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); List::Element *e = selection.front(); if (e) { const Node *node = e->get(); @@ -1224,7 +1225,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } break; case TOOL_OPEN_DOCUMENTATION: { - List selection = editor_selection->get_selected_node_list(); + List selection = editor_selection->get_top_selected_node_list(); for (const Node *node : selection) { String class_name; Ref