From 9b692b174b06ebb80d6e5a82309b9c9fc44c797d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 10 May 2015 15:45:33 -0300 Subject: -convert to subscene keeps signal connections, fixes #1863 --- scene/main/node.cpp | 36 ++++++++++++++++++++++++++++++++++++ scene/main/node.h | 1 + 2 files changed, 37 insertions(+) (limited to 'scene/main') 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& p_re } + +void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const { + + if (this!=p_original && get_owner()!=p_original) + return; + + List conns; + get_all_signal_connections(&conns); + + for (List::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(); + 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_duplicate_signals(p_original,p_copy); + } + +} + + Node *Node::duplicate_and_reown(const Map& p_reown_map) const { @@ -1455,6 +1490,7 @@ Node *Node::duplicate_and_reown(const Map& 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& p_reown_map) const; Array _get_children() const; Array _get_groups() const; -- cgit v1.2.3