summaryrefslogtreecommitdiff
path: root/scene/main/node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/node.cpp')
-rw-r--r--scene/main/node.cpp48
1 files changed, 43 insertions, 5 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index e30f58e012..d3282c6ada 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -31,10 +31,10 @@
#include "node.h"
#include "core/core_string_names.h"
+#include "core/io/resource_loader.h"
+#include "core/message_queue.h"
+#include "core/print_string.h"
#include "instance_placeholder.h"
-#include "io/resource_loader.h"
-#include "message_queue.h"
-#include "print_string.h"
#include "scene/resources/packed_scene.h"
#include "scene/scene_string_names.h"
#include "viewport.h"
@@ -238,6 +238,16 @@ void Node::_propagate_enter_tree() {
// enter groups
}
+void Node::_propagate_after_exit_tree() {
+
+ data.blocked++;
+ for (int i = 0; i < data.children.size(); i++) {
+ data.children[i]->_propagate_after_exit_tree();
+ }
+ data.blocked--;
+ emit_signal(SceneStringNames::get_singleton()->tree_exited);
+}
+
void Node::_propagate_exit_tree() {
//block while removing children
@@ -299,8 +309,6 @@ void Node::_propagate_exit_tree() {
data.ready_notified = false;
data.tree = NULL;
data.depth = -1;
-
- emit_signal(SceneStringNames::get_singleton()->tree_exited);
}
void Node::move_child(Node *p_child, int p_pos) {
@@ -1207,6 +1215,10 @@ void Node::remove_child(Node *p_child) {
// validate owner
p_child->_propagate_validate_owner();
+
+ if (data.inside_tree) {
+ p_child->_propagate_after_exit_tree();
+ }
}
int Node::get_child_count() const {
@@ -1336,6 +1348,19 @@ Node *Node::get_parent() const {
return data.parent;
}
+Node *Node::find_parent(const String &p_mask) const {
+
+ Node *p = data.parent;
+ while (p) {
+
+ if (p->data.name.operator String().match(p_mask))
+ return p;
+ p = p->data.parent;
+ }
+
+ return NULL;
+}
+
bool Node::is_a_parent_of(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node, false);
@@ -2104,6 +2129,12 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
node->set(name, value);
}
+ List<GroupInfo> groups;
+ get_groups(&groups);
+
+ for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next())
+ node->add_to_group(E->get().name, E->get().persistent);
+
node->set_name(get_name());
p_new_parent->add_child(node);
@@ -2198,6 +2229,12 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const {
node->set(name, get(name));
}
+ List<GroupInfo> groups;
+ get_groups(&groups);
+
+ for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next())
+ node->add_to_group(E->get().name, E->get().persistent);
+
for (int i = 0; i < get_child_count(); i++) {
get_child(i)->_duplicate_and_reown(node, p_reown_map);
@@ -2605,6 +2642,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node", "path"), &Node::get_node);
ClassDB::bind_method(D_METHOD("get_parent"), &Node::get_parent);
ClassDB::bind_method(D_METHOD("find_node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("find_parent", "mask"), &Node::find_parent);
ClassDB::bind_method(D_METHOD("has_node_and_resource", "path"), &Node::has_node_and_resource);
ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource);