diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-10 01:04:31 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-10 01:07:03 -0300 |
commit | a503f8aadcb8cbc85bde589fb25ea06e599b367b (patch) | |
tree | 070ebbf0dd6af2d43c5519f5e32045b3512f0e9e /core | |
parent | 68c008ca8d87a1f72fcf17467ee43714954e9ce4 (diff) |
Groundbreaking!! Godot resources can now be flagged to be local to the scene being edited!
This means that each time this scene is instanced, the resource will be unique!
As such, thanks to this, the following features were implemented:
-ButtonGroup is no longer a control, it's now a resource local to the scene
-ViewportTexture can be created from the editor and set to any object, making ViewportSprite and other kind of nodes obsolete!
Diffstat (limited to 'core')
-rw-r--r-- | core/resource.cpp | 125 | ||||
-rw-r--r-- | core/resource.h | 15 |
2 files changed, 118 insertions, 22 deletions
diff --git a/core/resource.cpp b/core/resource.cpp index 7bcdd88891..9545d8c3da 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -31,6 +31,7 @@ #include <stdio.h> #include "os/file_access.h" #include "io/resource_loader.h" +#include "script_language.h" void ResourceImportMetadata::set_editor(const String& p_editor) { @@ -201,7 +202,7 @@ void Resource::set_path(const String& p_path, bool p_take_over) { ResourceCache::lock->write_unlock(); } - _change_notify("resource/path"); + _change_notify("resource_path"); _resource_path_changed(); } @@ -225,7 +226,7 @@ int Resource::get_subindex() const{ void Resource::set_name(const String& p_name) { name=p_name; - _change_notify("resource/name"); + _change_notify("resource_name"); } String Resource::get_name() const { @@ -257,7 +258,7 @@ void Resource::reload_from_file() { if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) continue; - if (E->get().name=="resource/path") + if (E->get().name=="resource_path") continue; //do not change path set(E->get().name,s->get(E->get().name)); @@ -266,8 +267,51 @@ void Resource::reload_from_file() { } +Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) { + + + List<PropertyInfo> plist; + get_property_list(&plist); + + + Resource *r = (Resource*)ClassDB::instance(get_class()); + ERR_FAIL_COND_V(!r,Ref<Resource>()); + + r->local_scene=p_for_scene; + + for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + + if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) + continue; + Variant p = get(E->get().name); + if (p.get_type()==Variant::OBJECT) { + + RES sr = p; + if (sr.is_valid()) { + + if (sr->is_local_to_scene()) { + if (remap_cache.has(sr)) { + p=remap_cache[sr]; + } else { + + + RES dupe = sr->duplicate_for_local_scene(p_for_scene,remap_cache); + p=dupe; + remap_cache[sr]=dupe; + } + } + } + } + + r->set(E->get().name,p); + } + + return Ref<Resource>(r); +} + Ref<Resource> Resource::duplicate(bool p_subresources) { + List<PropertyInfo> plist; get_property_list(&plist); @@ -305,24 +349,6 @@ void Resource::_take_over_path(const String& p_path) { } -void Resource::_bind_methods() { - - ClassDB::bind_method(_MD("set_path","path"),&Resource::_set_path); - ClassDB::bind_method(_MD("take_over_path","path"),&Resource::_take_over_path); - ClassDB::bind_method(_MD("get_path"),&Resource::get_path); - ClassDB::bind_method(_MD("set_name","name"),&Resource::set_name); - ClassDB::bind_method(_MD("get_name"),&Resource::get_name); - ClassDB::bind_method(_MD("get_rid"),&Resource::get_rid); - ClassDB::bind_method(_MD("set_import_metadata","metadata"),&Resource::set_import_metadata); - ClassDB::bind_method(_MD("get_import_metadata"),&Resource::get_import_metadata); - - ClassDB::bind_method(_MD("duplicate","subresources"),&Resource::duplicate,DEFVAL(false)); - ADD_SIGNAL( MethodInfo("changed") ); - ADD_GROUP("Resource","resource_"); - ADD_PROPERTY( PropertyInfo(Variant::STRING,"resource_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ), _SCS("set_path"),_SCS("get_path")); - ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"resource_name"), _SCS("set_name"),_SCS("get_name")); -} - RID Resource::get_rid() const { return RID(); @@ -394,6 +420,62 @@ uint32_t Resource::hash_edited_version() const { #endif +void Resource::set_local_to_scene(bool p_enable) { + + local_to_scene=p_enable; +} + +bool Resource::is_local_to_scene() const { + + return local_to_scene; +} + +Node* Resource::get_local_scene() const { + + if (local_scene) + return local_scene; + + if (_get_local_scene_func) { + return _get_local_scene_func(); + } + + return NULL; +} + +void Resource::setup_local_to_scene() { + + if (get_script_instance()) + get_script_instance()->call("_setup_local_to_scene"); +} + +Node* (*Resource::_get_local_scene_func)()=NULL; + + +void Resource::_bind_methods() { + + ClassDB::bind_method(_MD("set_path","path"),&Resource::_set_path); + ClassDB::bind_method(_MD("take_over_path","path"),&Resource::_take_over_path); + ClassDB::bind_method(_MD("get_path"),&Resource::get_path); + ClassDB::bind_method(_MD("set_name","name"),&Resource::set_name); + ClassDB::bind_method(_MD("get_name"),&Resource::get_name); + ClassDB::bind_method(_MD("get_rid"),&Resource::get_rid); + ClassDB::bind_method(_MD("set_import_metadata","metadata"),&Resource::set_import_metadata); + ClassDB::bind_method(_MD("get_import_metadata"),&Resource::get_import_metadata); + ClassDB::bind_method(_MD("set_local_to_scene","enable"),&Resource::set_local_to_scene); + ClassDB::bind_method(_MD("is_local_to_scene"),&Resource::is_local_to_scene); + ClassDB::bind_method(_MD("get_local_scene:Node"),&Resource::get_local_scene); + ClassDB::bind_method(_MD("setup_local_to_scene"),&Resource::setup_local_to_scene); + + ClassDB::bind_method(_MD("duplicate","subresources"),&Resource::duplicate,DEFVAL(false)); + ADD_SIGNAL( MethodInfo("changed") ); + ADD_GROUP("Resource","resource_"); + ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"resource_local_to_scene" ), _SCS("set_local_to_scene"),_SCS("is_local_to_scene")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"resource_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ), _SCS("set_path"),_SCS("get_path")); + ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"resource_name"), _SCS("set_name"),_SCS("get_name")); + + BIND_VMETHOD( MethodInfo("_setup_local_to_scene") ); + +} Resource::Resource() { @@ -402,6 +484,7 @@ Resource::Resource() { #endif subindex=0; + local_scene=NULL; } diff --git a/core/resource.h b/core/resource.h index 40b6dd78a0..8b73bcdc57 100644 --- a/core/resource.h +++ b/core/resource.h @@ -61,6 +61,7 @@ class ResourceImportMetadata : public Reference { Map<String,Variant> options; StringArray _get_options() const; + protected: static void _bind_methods(); @@ -82,6 +83,7 @@ public: void get_options(List<String> *r_options) const; + ResourceImportMetadata(); }; @@ -108,6 +110,10 @@ friend class ResourceCache; uint64_t last_modified_time; #endif + bool local_to_scene; +friend class SceneState; + Node* local_scene; + protected: void emit_changed(); @@ -121,6 +127,8 @@ protected: void _take_over_path(const String& p_path); public: + static Node* (*_get_local_scene_func)(); //used by editor + virtual bool editor_can_reload_from_file(); virtual void reload_from_file(); @@ -137,12 +145,17 @@ public: int get_subindex() const; Ref<Resource> duplicate(bool p_subresources=false); + Ref<Resource> duplicate_for_local_scene(Node *p_scene,Map<Ref<Resource>,Ref<Resource> >& remap_cache); + void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata); Ref<ResourceImportMetadata> get_import_metadata() const; + void set_local_to_scene(bool p_enable); + bool is_local_to_scene() const; + virtual void setup_local_to_scene(); - + Node* get_local_scene() const; #ifdef TOOLS_ENABLED |