summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorreduz <juan@okamstudio.com>2015-10-16 19:11:23 -0300
committerreduz <juan@okamstudio.com>2015-10-16 19:11:23 -0300
commit078a474135b47adb3cbdf414c737b77ee17fe596 (patch)
treeb496b103491830f4e9339b9f25bd71f4dfdef184 /scene/main
parent6b20ee4324224d926a3eb43a59068c2cf12dc75e (diff)
-fixes and more fixes to new scene system, seems stable now..
BUT DONT TRUST ME IT MAY STILL BREAK, USE WITH CARE!!
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/instance_placeholder.cpp74
-rw-r--r--scene/main/instance_placeholder.h37
-rw-r--r--scene/main/node.cpp12
-rw-r--r--scene/main/node.h12
4 files changed, 124 insertions, 11 deletions
diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp
new file mode 100644
index 0000000000..370eb1e74a
--- /dev/null
+++ b/scene/main/instance_placeholder.cpp
@@ -0,0 +1,74 @@
+#include "instance_placeholder.h"
+
+#include "scene/resources/packed_scene.h"
+#include "io/resource_loader.h"
+
+bool InstancePlaceholder::_set(const StringName& p_name, const Variant& p_value) {
+
+ PropSet ps;
+ ps.name=p_name;
+ ps.value=p_value;
+ stored_values.push_back(ps);
+ return true;
+}
+
+bool InstancePlaceholder::_get(const StringName& p_name,Variant &r_ret) const{
+
+ return false;
+}
+void InstancePlaceholder::_get_property_list( List<PropertyInfo> *p_list) const{
+
+
+}
+
+
+void InstancePlaceholder::set_path(const String& p_name) {
+
+ path=p_name;
+}
+
+String InstancePlaceholder::get_path() const {
+
+ return path;
+}
+void InstancePlaceholder::replace_by_instance(const Ref<PackedScene> &p_custom_scene){
+
+ ERR_FAIL_COND(!is_inside_tree());
+
+ Node *base = get_parent();
+ if (!base)
+ return;
+
+ Ref<PackedScene> ps;
+ if (p_custom_scene.is_valid())
+ ps = p_custom_scene;
+ else
+ ps = ResourceLoader::load(path,"PackedScene");
+
+ if (!ps.is_valid())
+ return;
+ Node *scene = ps->instance();
+ scene->set_name(get_name());
+ int pos = get_position_in_parent();
+
+ for(List<PropSet>::Element *E=stored_values.front();E;E=E->next()) {
+ scene->set(E->get().name,E->get().value);
+ }
+
+ queue_delete();
+
+ base->remove_child(this);
+ base->add_child(scene);
+ base->move_child(scene,pos);
+
+}
+
+void InstancePlaceholder::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("replace_by_instance","custom_scene:PackedScene"),&InstancePlaceholder::replace_by_instance,DEFVAL(Variant()));
+}
+
+InstancePlaceholder::InstancePlaceholder() {
+
+
+}
diff --git a/scene/main/instance_placeholder.h b/scene/main/instance_placeholder.h
new file mode 100644
index 0000000000..e9e76e7a2d
--- /dev/null
+++ b/scene/main/instance_placeholder.h
@@ -0,0 +1,37 @@
+#ifndef INSTANCE_PLACEHOLDER_H
+#define INSTANCE_PLACEHOLDER_H
+
+#include "scene/main/node.h"
+
+class PackedScene;
+
+class InstancePlaceholder : public Node {
+
+ OBJ_TYPE(InstancePlaceholder,Node);
+
+ String path;
+ struct PropSet {
+ StringName name;
+ Variant value;
+ };
+
+ List<PropSet> stored_values;
+
+protected:
+ bool _set(const StringName& p_name, const Variant& p_value);
+ bool _get(const StringName& p_name,Variant &r_ret) const;
+ void _get_property_list( List<PropertyInfo> *p_list) const;
+
+ static void _bind_methods();
+
+public:
+
+ void set_path(const String& p_name);
+ String get_path() const;
+
+ void replace_by_instance(const Ref<PackedScene>& p_custom_scene=Ref<PackedScene>());
+
+ InstancePlaceholder();
+};
+
+#endif // INSTANCE_PLACEHOLDER_H
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index b02e9c5645..dd4587c19f 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1052,6 +1052,7 @@ void Node::get_owned_by(Node *p_by,List<Node*> *p_owned) {
void Node::_set_owner_nocheck(Node* p_owner) {
+ ERR_FAIL_COND(data.owner);
data.owner=p_owner;
data.owner->data.owned.push_back( this );
data.OW = data.owner->data.owned.back();
@@ -1443,13 +1444,14 @@ Ref<SceneState> Node::get_scene_inherited_state() const{
return data.inherited_state;
}
-Vector<StringName> Node::get_instance_groups() const {
+void Node::set_scene_instance_load_placeholder(bool p_enable) {
- return data.instance_groups;
+ data.use_placeholder=p_enable;
}
-Vector<Node::Connection> Node::get_instance_connections() const{
- return data.instance_connections;
+bool Node::get_scene_instance_load_placeholder() const{
+
+ return data.use_placeholder;
}
int Node::get_position_in_parent() const {
@@ -2109,6 +2111,7 @@ Node::Node() {
data.parent_owned=false;
data.in_constructor=true;
data.viewport=NULL;
+ data.use_placeholder=false;
}
Node::~Node() {
@@ -2125,3 +2128,4 @@ Node::~Node() {
}
+////////////////////////////////
diff --git a/scene/main/node.h b/scene/main/node.h
index 55557c6356..87fa4dd6ca 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -75,9 +75,6 @@ private:
HashMap<NodePath,int> editable_instances;
- Vector<StringName> instance_groups;
- Vector<Connection> instance_connections;
-
Node *parent;
Node *owner;
Vector<Node*> children; // list of children
@@ -111,6 +108,8 @@ private:
bool parent_owned;
bool in_constructor;
+ bool use_placeholder;
+
} data;
@@ -241,6 +240,7 @@ public:
void set_editable_instance(Node* p_node,bool p_editable);
bool is_editable_instance(Node* p_node) const;
+
/* NOTIFICATIONS */
void propagate_notification(int p_notification);
@@ -278,8 +278,8 @@ public:
void set_scene_inherited_state(const Ref<SceneState>& p_state);
Ref<SceneState> get_scene_inherited_state() const;
- Vector<StringName> get_instance_groups() const;
- Vector<Connection> get_instance_connections() const;
+ void set_scene_instance_load_placeholder(bool p_enable);
+ bool get_scene_instance_load_placeholder() const;
static Vector<Variant> make_binds(VARIANT_ARG_LIST);
@@ -322,6 +322,4 @@ public:
typedef Set<Node*,Node::Comparator> NodeSet;
-
-
#endif