diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-07-06 21:43:31 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-07-06 21:43:31 -0300 |
commit | 17e4ead62a949e2a1568574228a157ea4b403d30 (patch) | |
tree | 7e6cada697e890f8ab6b61c46a45f84b6a0c4aa9 | |
parent | a78226c32ceb0614e079f5cdd5653af7be729dac (diff) |
Fix several bugs related to node duplication and signals, closes #5405
-rw-r--r-- | scene/main/node.cpp | 22 | ||||
-rw-r--r-- | scene/main/node.h | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index bea6e75aef..29851efaff 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1513,7 +1513,7 @@ int Node::get_position_in_parent() const { -Node *Node::duplicate(bool p_use_instancing) const { +Node *Node::_duplicate(bool p_use_instancing) const { Node *node=NULL; @@ -1592,9 +1592,21 @@ Node *Node::duplicate(bool p_use_instancing) const { node->add_child(dup); } + return node; } +Node *Node::duplicate(bool p_use_instancing) const { + + Node* dupe = _duplicate(p_use_instancing); + + if (dupe) { + _duplicate_signals(this,dupe); + } + + return dupe; +} + void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const { @@ -1664,12 +1676,13 @@ void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_re void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const { - if (this!=p_original && get_owner()!=p_original) + if (this!=p_original && (get_owner()!=p_original && get_owner()!=p_original->get_owner())) return; List<Connection> conns; get_all_signal_connections(&conns); + for (List<Connection>::Element *E=conns.front();E;E=E->next()) { if (E->get().flags&CONNECT_PERSIST) { @@ -1678,14 +1691,17 @@ void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const { Node *copy = p_copy->get_node(p); Node *target = E->get().target->cast_to<Node>(); - if (!target) + if (!target) { continue; + } NodePath ptarget = p_original->get_path_to(target); Node *copytarget = p_copy->get_node(ptarget); + if (copy && copytarget) { copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST); } + } } diff --git a/scene/main/node.h b/scene/main/node.h index dcc3829d15..10cfc5f9e6 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -138,6 +138,8 @@ private: void _duplicate_signals(const Node* p_original,Node* p_copy) const; void _duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const; + Node *_duplicate(bool p_use_instancing) const; + Array _get_children() const; Array _get_groups() const; |