mirror of
https://github.com/godotengine/godot.git
synced 2025-02-17 22:43:01 +08:00
Merge pull request #30321 from KoBeWi/underdup
Smarter node placement after duplicating
This commit is contained in:
commit
a9ad1e6692
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user