Fix several bugs related to node duplication and signals, closes #5405
(cherry picked from commit 17e4ead62a
)
This commit is contained in:
parent
d4cb381ce0
commit
f4a5963ca9
|
@ -1488,7 +1488,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;
|
Node *node=NULL;
|
||||||
|
@ -1567,9 +1567,21 @@ Node *Node::duplicate(bool p_use_instancing) const {
|
||||||
node->add_child(dup);
|
node->add_child(dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return node;
|
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 {
|
void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const {
|
||||||
|
|
||||||
|
@ -1639,12 +1651,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 {
|
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;
|
return;
|
||||||
|
|
||||||
List<Connection> conns;
|
List<Connection> conns;
|
||||||
get_all_signal_connections(&conns);
|
get_all_signal_connections(&conns);
|
||||||
|
|
||||||
|
|
||||||
for (List<Connection>::Element *E=conns.front();E;E=E->next()) {
|
for (List<Connection>::Element *E=conns.front();E;E=E->next()) {
|
||||||
|
|
||||||
if (E->get().flags&CONNECT_PERSIST) {
|
if (E->get().flags&CONNECT_PERSIST) {
|
||||||
|
@ -1653,14 +1666,17 @@ void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const {
|
||||||
Node *copy = p_copy->get_node(p);
|
Node *copy = p_copy->get_node(p);
|
||||||
|
|
||||||
Node *target = E->get().target->cast_to<Node>();
|
Node *target = E->get().target->cast_to<Node>();
|
||||||
if (!target)
|
if (!target) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
NodePath ptarget = p_original->get_path_to(target);
|
NodePath ptarget = p_original->get_path_to(target);
|
||||||
Node *copytarget = p_copy->get_node(ptarget);
|
Node *copytarget = p_copy->get_node(ptarget);
|
||||||
|
|
||||||
|
|
||||||
if (copy && copytarget) {
|
if (copy && copytarget) {
|
||||||
copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST);
|
copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,8 @@ private:
|
||||||
|
|
||||||
void _duplicate_signals(const Node* p_original,Node* p_copy) const;
|
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;
|
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_children() const;
|
||||||
Array _get_groups() const;
|
Array _get_groups() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue