From f0521539831c2d3230e537a4efc0b485b8f64f49 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 8 Jun 2015 00:33:10 -0300 Subject: Added Node.find_node(mask) function by popular request --- scene/main/node.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'scene/main/node.cpp') diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5c60b9fbff..ab530866bb 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -840,6 +840,28 @@ bool Node::has_node(const NodePath& p_path) const { return _get_node(p_path)!=NULL; } + +Node* Node::find_node(const String& p_mask,bool p_recursive,bool p_owned) const { + + Node * const*cptr = data.children.ptr(); + int ccount = data.children.size(); + for(int i=0;idata.owner) + continue; + if (cptr[i]->data.name.operator String().match(p_mask)) + return cptr[i]; + + if (!p_recursive) + continue; + + Node* ret = cptr[i]->find_node(p_mask,true,p_owned); + if (ret) + return ret; + } + return NULL; + +} + Node *Node::get_parent() const { return data.parent; @@ -1807,6 +1829,7 @@ void Node::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_node","path"),&Node::has_node); ObjectTypeDB::bind_method(_MD("get_node:Node","path"),&Node::get_node); ObjectTypeDB::bind_method(_MD("get_parent:Parent"),&Node::get_parent); + ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::get_node,DEFVAL(true),DEFVAL(true)); ObjectTypeDB::bind_method(_MD("has_node_and_resource","path"),&Node::has_node_and_resource); ObjectTypeDB::bind_method(_MD("get_node_and_resource","path"),&Node::_get_node_and_resource); -- cgit v1.2.3 From 8228fea02feabbfdd4def950e67f9ea6507d981d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 14 Jun 2015 02:13:47 -0300 Subject: missing changes --- scene/main/node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scene/main/node.cpp') diff --git a/scene/main/node.cpp b/scene/main/node.cpp index ab530866bb..2530e3a36f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -641,6 +641,7 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { p_child->data.pos=data.children.size(); data.children.push_back( p_child ); p_child->data.parent=this; + p_child->notification(NOTIFICATION_PARENTED); if (data.tree) { p_child->_set_tree(data.tree); @@ -649,7 +650,6 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { /* Notify */ //recognize childs created in this node constructor p_child->data.parent_owned=data.in_constructor; - p_child->notification(NOTIFICATION_PARENTED); add_child_notify(p_child); -- cgit v1.2.3