diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-07-05 09:56:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-05 09:56:31 +0200 |
commit | a9ad1e6692af85fbe8aab36361c304b81ed376f4 (patch) | |
tree | e36902cdd81f41834240ad40792263bbe55c92cc | |
parent | 26cff6ff926b2f2cd879daf9aadc99e16fd6516b (diff) | |
parent | 0cd9a65aa49d9c8c8b806e4675b1bddb33698a98 (diff) |
Merge pull request #30321 from KoBeWi/underdup
Smarter node placement after duplicating
-rw-r--r-- | editor/scene_tree_dock.cpp | 22 | ||||
-rw-r--r-- | editor/scene_tree_dock.h | 1 |
2 files changed, 21 insertions, 2 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 37e37e28a6..5f62ed0702 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -573,6 +573,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *node = E->get(); Node *parent = node->get_parent(); + Node *selection_tail = _get_selection_group_tail(node, selection); List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); @@ -590,7 +591,7 @@ 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(parent, "add_child_below_node", node, dup); + editor_data->get_undo_redo().add_do_method(parent, "add_child_below_node", selection_tail, dup); for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { if (!duplimap.has(F->get())) { @@ -598,7 +599,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { continue; } Node *d = duplimap[F->get()]; - editor_data->get_undo_redo().add_do_method(d, "set_owner", node->get_owner()); + editor_data->get_undo_redo().add_do_method(d, "set_owner", selection_tail->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); @@ -1885,6 +1886,23 @@ 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_position_in_parent(); 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::_create() { if (current_option == TOOL_NEW) { diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index 3729e27ce6..8a2b237b8b 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -195,6 +195,7 @@ class SceneTreeDock : public VBoxContainer { bool _validate_no_foreign(); void _selection_changed(); void _update_script_button(); + Node *_get_selection_group_tail(Node *p_node, List<Node *> p_list); void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath> > *p_renames); |