Smarter node placement after duplicating

This commit is contained in:
Tomasz Chabora 2019-05-01 17:14:18 +02:00
parent 36d8936b8b
commit 0cd9a65aa4
2 changed files with 21 additions and 2 deletions

View file

@ -572,6 +572,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);
@ -589,7 +590,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())) {
@ -597,7 +598,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);
@ -1884,6 +1885,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) {

View file

@ -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);