From 1597082c85a2bf3ddca0414de1fa32fb5f2e5350 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 2 Jan 2016 20:17:31 -0300 Subject: -Ability to roll-back script-exported properties to their default value on the script, closes #2128 --- core/script_language.h | 1 + core/variant.cpp | 11 +++ core/variant.h | 1 + modules/gdscript/gd_script.cpp | 22 +++++ modules/gdscript/gd_script.h | 2 + tools/editor/property_editor.cpp | 170 ++++++++++++++++++++++++++++----------- tools/editor/property_editor.h | 2 + 7 files changed, 160 insertions(+), 49 deletions(-) diff --git a/core/script_language.h b/core/script_language.h index a179949c19..3138c88e8e 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -98,6 +98,7 @@ public: virtual bool has_script_signal(const StringName& p_signal) const=0; virtual void get_script_signal_list(List *r_signals) const=0; + virtual bool get_property_default_value(const StringName& p_property,Variant& r_value) const=0; virtual void update_exports() {} //editor tool diff --git a/core/variant.cpp b/core/variant.cpp index ab560e0d45..674c57a0fc 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -706,6 +706,17 @@ bool Variant::operator==(const Variant& p_variant) const { } +bool Variant::operator!=(const Variant& p_variant) const { + + if (type!=p_variant.type) //evaluation of operator== needs to be more strict + return true; + bool v; + Variant r; + evaluate(OP_NOT_EQUAL,*this,p_variant,r,v); + return r; + +} + bool Variant::operator<(const Variant& p_variant) const { if (type!=p_variant.type) //if types differ, then order by type first return type::Element *I=member_default_values.front();I;I=I->next()) { + // print_line("\t"+String(String(I->key())+":"+String(I->get()))); + //} + const Map::Element *E=member_default_values_cache.find(p_property); + if (E) { + r_value=E->get(); + return true; + } + + if (base_cache.is_valid()) { + return base_cache->get_property_default_value(p_property,r_value); + } +#endif + return false; + +} + ScriptInstance* GDScript::instance_create(Object *p_this) { diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 173997a1fe..cf8f762a86 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -352,6 +352,8 @@ public: Vector get_as_byte_code() const; + bool get_property_default_value(const StringName& p_property,Variant& r_value) const; + virtual ScriptLanguage *get_language() const; GDScript(); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 31979e5d47..9989169b0e 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -2113,6 +2113,65 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p } +void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) { + + bool has_reload=false; + int found=-1; + + for(int i=0;iget_button_count(1);i++) { + + if (item->get_button_id(1,i)==3) { + found=i; + break; + } + } + + if (_might_be_in_instance()) { + + + Variant vorig; + Dictionary d=item->get_metadata(0); + int usage = d.has("usage")?int(int(d["usage"])&(PROPERTY_USAGE_STORE_IF_NONONE|PROPERTY_USAGE_STORE_IF_NONZERO)):0; + + + if (_get_instanced_node_original_property(p_name,vorig) || usage) { + Variant v = obj->get(p_name); + + bool changed = _is_property_different(v,vorig,usage); + + if ((found!=-1)!=changed) { + + if (changed) { + + has_reload=true; + } else { + + } + + } + + } + + + + } + + if (!has_reload && !obj->get_script().is_null()) { + Ref