diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-05-10 15:45:33 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-05-10 15:45:33 -0300 |
commit | 9b692b174b06ebb80d6e5a82309b9c9fc44c797d (patch) | |
tree | 9ab3b9b6ec39cdd9ce02ff2edb8689f204a413d1 /scene/main | |
parent | d1e4d6e997d2c2f753ee510fcd13dee08b214968 (diff) |
-convert to subscene keeps signal connections, fixes #1863
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/node.cpp | 36 | ||||
-rw-r--r-- | scene/main/node.h | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index e0181b9238..5c60b9fbff 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1417,6 +1417,41 @@ 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) + 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) { + //user connected + NodePath p = p_original->get_path_to(this); + Node *copy = p_copy->get_node(p); + + Node *target = E->get().target->cast_to<Node>(); + 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); + } + } + } + + for(int i=0;i<get_child_count();i++) { + get_child(i)->_duplicate_signals(p_original,p_copy); + } + +} + + Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const { @@ -1455,6 +1490,7 @@ Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const { get_child(i)->_duplicate_and_reown(node,p_reown_map); } + _duplicate_signals(this,node); return node; } diff --git a/scene/main/node.h b/scene/main/node.h index 4d0a84d347..be32c4e726 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -126,6 +126,7 @@ private: void _propagate_pause_owner(Node*p_owner); Array _get_node_and_resource(const NodePath& p_path); + 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; Array _get_children() const; Array _get_groups() const; |