From 86bec25c510c77aa79407938a19ad19ac2da29b0 Mon Sep 17 00:00:00 2001 From: Hristo Stamenov Date: Mon, 8 Nov 2021 06:24:12 +0200 Subject: [PATCH] Add the instance to the script property evaluation. This needs to be done so that tool scripts are evaluated properly and their properties are categorized in the inspector (due to a bug of them being missing). I am talking about the properties coming from _get_property_list. Also added a fallback so that we don't lose properties in the inspector even if they are not properly categorized. --- core/object/script_language.h | 2 +- editor/editor_inspector.cpp | 25 +++- editor/property_selector.cpp | 2 +- .../gdnative/nativescript/nativescript.cpp | 6 +- modules/gdnative/nativescript/nativescript.h | 2 +- .../pluginscript/pluginscript_instance.cpp | 2 +- .../pluginscript/pluginscript_script.cpp | 2 +- .../pluginscript/pluginscript_script.h | 2 +- modules/gdscript/gdscript.cpp | 127 ++++++++++-------- modules/gdscript/gdscript.h | 3 +- modules/gdscript/gdscript_editor.cpp | 2 +- modules/mono/csharp_script.cpp | 2 +- modules/mono/csharp_script.h | 2 +- modules/visual_script/visual_script.cpp | 2 +- modules/visual_script/visual_script.h | 2 +- .../visual_script_property_selector.cpp | 2 +- 16 files changed, 104 insertions(+), 81 deletions(-) diff --git a/core/object/script_language.h b/core/object/script_language.h index 8d76cbf479..d012595efe 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -150,7 +150,7 @@ public: virtual void update_exports() {} //editor tool virtual void get_script_method_list(List *p_list) const = 0; - virtual void get_script_property_list(List *p_list) const = 0; + virtual void get_script_property_list(List *p_list, const ScriptInstance *p_instance = nullptr) const = 0; virtual int get_member_line(const StringName &p_member) const { return -1; } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 4ffa90777c..8f6aa39907 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3459,7 +3459,7 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li } List props; - s->get_script_property_list(&props); + s->get_script_property_list(&props, p_object.get_script_instance()); // Script Variables -> NodeA -> bottom (insert_here) List::Element *category = r_list.insert_before(insert_here, PropertyInfo(Variant::NIL, name, PROPERTY_HINT_NONE, path, PROPERTY_USAGE_CATEGORY)); @@ -3481,11 +3481,24 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li // NodeC -> C props... -> NodeB..C.. if (script_variables) { - r_list.erase(script_variables); - List::Element *to_delete = bottom->next(); - while (to_delete && !(to_delete->get().usage & PROPERTY_USAGE_CATEGORY)) { - r_list.erase(to_delete); - to_delete = bottom->next(); + bool properties_left = false; + List::Element *current = bottom->next(); + List::Element *previous = bottom; + while (current && !(current->get().usage & PROPERTY_USAGE_CATEGORY)) { + // Fallback check so that we don't lose editor fields + // for properties coming from _get_property_list + if (added.has(current->get().name)) { + r_list.erase(current); + } else { + properties_left = true; + previous = current; + } + + current = previous->next(); + } + + if (!properties_left) { + r_list.erase(script_variables); } r_list.erase(bottom); } diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index f167ded4e7..48ce56ba06 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -105,7 +105,7 @@ void PropertySelector::_update_search() { Object *obj = ObjectDB::get_instance(script); if (Object::cast_to