Merge pull request #5058 from neikeq/pr-issue-1461

Preserve signal connections when replacing target node
This commit is contained in:
Juan Linietsky 2016-06-13 15:50:31 -03:00 committed by GitHub
commit d03f1131d7
2 changed files with 17 additions and 1 deletions

View File

@ -1770,6 +1770,8 @@ void Node::replace_by(Node* p_node,bool p_keep_data) {
}
}
_replace_connections_target(p_node);
if (data.owner) {
for(int i=0;i<get_child_count();i++)
find_owned_by(data.owner,get_child(i),&owned_by_owner);
@ -1808,6 +1810,20 @@ void Node::replace_by(Node* p_node,bool p_keep_data) {
}
void Node::_replace_connections_target(Node* p_new_target) {
List<Connection> cl;
get_signals_connected_to_this(&cl);
for(List<Connection>::Element *E=cl.front();E;E=E->next()) {
Connection &c=E->get();
c.source->disconnect(c.signal,this,c.method);
c.source->connect(c.signal,p_new_target,c.method,c.binds,c.flags);
}
}
Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) {

View File

@ -121,7 +121,7 @@ private:
Node *_get_node(const NodePath& p_path) const;
Node *_get_child_by_name(const StringName& p_name) const;
void _replace_connections_target(Node* p_new_target);
void _validate_child_name(Node *p_name, bool p_force_human_readable=false);