Add flags parameter to Node.duplicate()
to decide whether signals, groups and/or scripts should be set in the copied nodes or not; it's default value makes the method work as usual, that is, including everything
This commit is contained in:
parent
34b6caa433
commit
bbbc3a91c9
2 changed files with 29 additions and 13 deletions
|
@ -1545,7 +1545,7 @@ int Node::get_position_in_parent() const {
|
|||
|
||||
|
||||
|
||||
Node *Node::_duplicate(bool p_use_instancing) const {
|
||||
Node *Node::_duplicate(bool p_use_instancing,int p_flags) const {
|
||||
|
||||
|
||||
Node *node=NULL;
|
||||
|
@ -1592,20 +1592,26 @@ Node *Node::_duplicate(bool p_use_instancing) const {
|
|||
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
|
||||
continue;
|
||||
String name = E->get().name;
|
||||
if (!(p_flags&DUPLICATE_SCRIPTS) && name=="script/script")
|
||||
continue;
|
||||
|
||||
node->set( name, get(name) );
|
||||
|
||||
}
|
||||
|
||||
node->set_name(get_name());
|
||||
|
||||
List<GroupInfo> gi;
|
||||
get_groups(&gi);
|
||||
for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) {
|
||||
if (p_flags & DUPLICATE_GROUPS) {
|
||||
List<GroupInfo> gi;
|
||||
get_groups(&gi);
|
||||
for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) {
|
||||
|
||||
node->add_to_group(E->get().name, E->get().persistent);
|
||||
node->add_to_group(E->get().name, E->get().persistent);
|
||||
}
|
||||
}
|
||||
|
||||
_duplicate_signals(this, node);
|
||||
if (p_flags & DUPLICATE_SIGNALS)
|
||||
_duplicate_signals(this, node);
|
||||
|
||||
for(int i=0;i<get_child_count();i++) {
|
||||
|
||||
|
@ -1614,7 +1620,7 @@ Node *Node::_duplicate(bool p_use_instancing) const {
|
|||
if (instanced && get_child(i)->data.owner==this)
|
||||
continue; //part of instance
|
||||
|
||||
Node *dup = get_child(i)->duplicate(p_use_instancing);
|
||||
Node *dup = get_child(i)->duplicate(p_use_instancing,p_flags);
|
||||
if (!dup) {
|
||||
|
||||
memdelete(node);
|
||||
|
@ -1628,11 +1634,11 @@ Node *Node::_duplicate(bool p_use_instancing) const {
|
|||
return node;
|
||||
}
|
||||
|
||||
Node *Node::duplicate(bool p_use_instancing) const {
|
||||
Node *Node::duplicate(bool p_use_instancing,int p_flags) const {
|
||||
|
||||
Node* dupe = _duplicate(p_use_instancing);
|
||||
Node* dupe = _duplicate(p_use_instancing,p_flags);
|
||||
|
||||
if (dupe) {
|
||||
if (dupe && (p_flags&DUPLICATE_SIGNALS)) {
|
||||
_duplicate_signals(this,dupe);
|
||||
}
|
||||
|
||||
|
@ -2210,7 +2216,7 @@ void Node::_bind_methods() {
|
|||
|
||||
ObjectTypeDB::bind_method(_MD("get_tree:SceneTree"),&Node::get_tree);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("duplicate:Node","use_instancing"),&Node::duplicate,DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("duplicate:Node","use_instancing","flags"),&Node::duplicate,DEFVAL(false),DEFVAL(DUPLICATE_SIGNALS|DUPLICATE_GROUPS|DUPLICATE_SCRIPTS));
|
||||
ObjectTypeDB::bind_method(_MD("replace_by","node:Node","keep_data"),&Node::replace_by,DEFVAL(false));
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_scene_instance_load_placeholder","load_placeholder"),&Node::set_scene_instance_load_placeholder);
|
||||
|
@ -2252,6 +2258,10 @@ void Node::_bind_methods() {
|
|||
BIND_CONSTANT( PAUSE_MODE_STOP );
|
||||
BIND_CONSTANT( PAUSE_MODE_PROCESS );
|
||||
|
||||
BIND_CONSTANT( DUPLICATE_SIGNALS );
|
||||
BIND_CONSTANT( DUPLICATE_GROUPS );
|
||||
BIND_CONSTANT( DUPLICATE_SCRIPTS );
|
||||
|
||||
ADD_SIGNAL( MethodInfo("renamed") );
|
||||
ADD_SIGNAL( MethodInfo("enter_tree") );
|
||||
ADD_SIGNAL( MethodInfo("exit_tree") );
|
||||
|
|
|
@ -53,6 +53,12 @@ public:
|
|||
PAUSE_MODE_PROCESS
|
||||
};
|
||||
|
||||
enum DuplicateFlags {
|
||||
|
||||
DUPLICATE_SIGNALS=1,
|
||||
DUPLICATE_GROUPS=2,
|
||||
DUPLICATE_SCRIPTS=4
|
||||
};
|
||||
|
||||
struct Comparator {
|
||||
|
||||
|
@ -139,7 +145,7 @@ 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;
|
||||
Node *_duplicate(bool p_use_instancing,int p_flags) const;
|
||||
|
||||
Array _get_children() const;
|
||||
Array _get_groups() const;
|
||||
|
@ -278,7 +284,7 @@ public:
|
|||
|
||||
int get_position_in_parent() const;
|
||||
|
||||
Node *duplicate(bool p_use_instancing=false) const;
|
||||
Node *duplicate(bool p_use_instancing=false,int p_flags=DUPLICATE_GROUPS|DUPLICATE_SIGNALS|DUPLICATE_SCRIPTS) const;
|
||||
Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const;
|
||||
|
||||
//Node *clone_tree() const;
|
||||
|
|
Loading…
Reference in a new issue