From fa401ce64515f0c85b8a36a00f3431992c5461c2 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 5 Jul 2020 23:08:24 +0200 Subject: [PATCH] Fixed processor_get_node_for's parameter, and now PropInstance will create hidden nodes as preview for using it in the editor. --- prop_instance.cpp | 30 +++++++++++++++++++++++++++++- prop_instance.h | 1 + props/prop_data_entry.cpp | 4 ++-- props/prop_data_entry.h | 2 +- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/prop_instance.cpp b/prop_instance.cpp index 11ce20d..6e3351e 100644 --- a/prop_instance.cpp +++ b/prop_instance.cpp @@ -4,6 +4,8 @@ #include "../thread_pool/thread_pool.h" +#include "core/engine.h" + Ref PropInstance::get_prop_data() { return _prop_data; } @@ -113,7 +115,12 @@ void PropInstance::build() { } for (int i = 0; i < get_child_count(); ++i) { - get_child(i)->queue_delete(); + Node *n = get_child(i); + + //this way we won't delete the user's nodes + if (n->get_owner() == NULL) { + n->queue_delete(); + } } if (!_prop_data.is_valid()) @@ -124,6 +131,15 @@ void PropInstance::build() { if (!e.is_valid()) continue; + + Node *n = e->processor_get_node_for(get_transform()); + + if (n) { + add_child(n); + + //if (Engine::get_singleton()->is_editor_hint()) + // n->set_owner(get_tree()->get_edited_scene_root()); + } } } @@ -141,7 +157,19 @@ PropInstance::~PropInstance() { _prop_data.unref(); } +void PropInstance::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + build(); + } + } +} + void PropInstance::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_prop_data"), &PropInstance::get_prop_data); + ClassDB::bind_method(D_METHOD("set_prop_data", "value"), &PropInstance::set_prop_data); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop_data", "get_prop_data"); + ClassDB::bind_method(D_METHOD("get_auto_bake"), &PropInstance::get_auto_bake); ClassDB::bind_method(D_METHOD("set_auto_bake", "value"), &PropInstance::set_auto_bake); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_bake"), "set_auto_bake", "get_auto_bake"); diff --git a/prop_instance.h b/prop_instance.h index a769bef..fcc90d9 100644 --- a/prop_instance.h +++ b/prop_instance.h @@ -70,6 +70,7 @@ public: ~PropInstance(); protected: + void _notification(int p_what); static void _bind_methods(); private: diff --git a/props/prop_data_entry.cpp b/props/prop_data_entry.cpp index 2bd1ccb..2f0f605 100644 --- a/props/prop_data_entry.cpp +++ b/props/prop_data_entry.cpp @@ -45,8 +45,8 @@ bool PropDataEntry::processor_handles(Node *node) { void PropDataEntry::processor_process(Ref prop_data, Node *node, const Transform &transform) { call("_processor_process", prop_data, node, transform); } -Node *PropDataEntry::processor_get_node_for(const Ref &prop_data) { - return call("_processor_get_node_for", prop_data); +Node *PropDataEntry::processor_get_node_for(const Transform &transform) { + return call("_processor_get_node_for", transform); } bool PropDataEntry::_processor_handles(Node *node) { diff --git a/props/prop_data_entry.h b/props/prop_data_entry.h index 5a529a5..dc60cb7 100644 --- a/props/prop_data_entry.h +++ b/props/prop_data_entry.h @@ -45,7 +45,7 @@ public: bool processor_handles(Node *node); void processor_process(Ref prop_data, Node *node, const Transform &transform); - Node *processor_get_node_for(const Ref &prop_data); + Node *processor_get_node_for(const Transform &transform); virtual bool _processor_handles(Node *node); virtual void _processor_process(Ref prop_data, Node *node, const Transform &transform);