From 803fa8f2e8ee60789413c0dd0fd46c8bd098e007 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 19 Jan 2024 16:00:55 +0100 Subject: [PATCH] Export `EditorInspector::instantiate_property_editor` for use by plugins And export useful properties and methods in the `EditorProperty` class. --- doc/classes/EditorInspector.xml | 13 ++++++++++ doc/classes/EditorProperty.xml | 43 +++++++++++++++++++++++++++++++++ editor/editor_inspector.cpp | 20 +++++++++++++++ editor/editor_inspector.h | 5 +++- 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/doc/classes/EditorInspector.xml b/doc/classes/EditorInspector.xml index 6b25be490ed..e516ff84447 100644 --- a/doc/classes/EditorInspector.xml +++ b/doc/classes/EditorInspector.xml @@ -26,6 +26,19 @@ Gets the path of the currently selected property. + + + + + + + + + + + Creates a property editor that can be used by plugin UI to edit the specified property of an [param object]. + + diff --git a/doc/classes/EditorProperty.xml b/doc/classes/EditorProperty.xml index 2b1083393f6..96703fde90b 100644 --- a/doc/classes/EditorProperty.xml +++ b/doc/classes/EditorProperty.xml @@ -29,6 +29,12 @@ If any of the controls added can gain keyboard focus, add it here. This ensures that focus will be restored if the inspector is refreshed. + + + + Draw property as not selected. Used by the inspector. + + @@ -51,6 +57,19 @@ Gets the edited property. If your editor is for a single property (added via [method EditorInspectorPlugin._parse_property]), then this will return the property. + + + + Returns [code]true[/code] if property is drawn as selected. Used by the inspector. + + + + + + + Draw property as selected. Used by the inspector. + + @@ -58,6 +77,21 @@ Puts the [param editor] control below the property label. The control must be previously added using [method Node.add_child]. + + + + + Used by the inspector, set to a control that will be used as a reference to calculate the size of the label. + + + + + + + + Assigns object and property to edit. + + @@ -84,9 +118,18 @@ Set this property to change the label (if you want to show one). + + Space distribution ratio between the label and the editing field. + Used by the inspector, set to [code]true[/code] when the property is read-only. + + Used by the inspector, set to [code]true[/code] when the property is selectable. + + + Used by the inspector, set to [code]true[/code] when the property is using folding. + diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index a14c6e84623..e65612e8efc 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -999,6 +999,21 @@ void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable); ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor); + ClassDB::bind_method(D_METHOD("set_selectable", "selectable"), &EditorProperty::set_selectable); + ClassDB::bind_method(D_METHOD("is_selectable"), &EditorProperty::is_selectable); + + ClassDB::bind_method(D_METHOD("set_use_folding", "use_folding"), &EditorProperty::set_use_folding); + ClassDB::bind_method(D_METHOD("is_using_folding"), &EditorProperty::is_using_folding); + + ClassDB::bind_method(D_METHOD("set_name_split_ratio", "ratio"), &EditorProperty::set_name_split_ratio); + ClassDB::bind_method(D_METHOD("get_name_split_ratio"), &EditorProperty::get_name_split_ratio); + + ClassDB::bind_method(D_METHOD("deselect"), &EditorProperty::deselect); + ClassDB::bind_method(D_METHOD("is_selected"), &EditorProperty::is_selected); + ClassDB::bind_method(D_METHOD("select", "focusable"), &EditorProperty::select, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("set_object_and_property", "object", "property"), &EditorProperty::set_object_and_property); + ClassDB::bind_method(D_METHOD("set_label_reference", "control"), &EditorProperty::set_label_reference); + ClassDB::bind_method(D_METHOD("emit_changed", "property", "value", "field", "changing"), &EditorProperty::emit_changed, DEFVAL(StringName()), DEFVAL(false)); ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); @@ -1008,6 +1023,9 @@ void EditorProperty::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_warning"), "set_draw_warning", "is_draw_warning"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keying"), "set_keying", "is_keying"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deletable"), "set_deletable", "is_deletable"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_folding"), "set_use_folding", "is_using_folding"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "name_split_ratio"), "set_name_split_ratio", "get_name_split_ratio"); ADD_SIGNAL(MethodInfo("property_changed", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::STRING_NAME, "field"), PropertyInfo(Variant::BOOL, "changing"))); ADD_SIGNAL(MethodInfo("multiple_properties_changed", PropertyInfo(Variant::PACKED_STRING_ARRAY, "properties"), PropertyInfo(Variant::ARRAY, "value"))); @@ -4251,6 +4269,8 @@ void EditorInspector::_bind_methods() { ClassDB::bind_method("get_selected_path", &EditorInspector::get_selected_path); ClassDB::bind_method("get_edited_object", &EditorInspector::get_edited_object); + ClassDB::bind_static_method("EditorInspector", D_METHOD("instantiate_property_editor", "object", "type", "path", "hint", "hint_text", "usage", "wide"), &EditorInspector::instantiate_property_editor, DEFVAL(false)); + ADD_SIGNAL(MethodInfo("property_selected", PropertyInfo(Variant::STRING, "property"))); ADD_SIGNAL(MethodInfo("property_keyed", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::BOOL, "advance"))); ADD_SIGNAL(MethodInfo("property_deleted", PropertyInfo(Variant::STRING, "property"))); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 8c55950a2b4..e4da43e5292 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -153,7 +153,10 @@ public: Object *get_edited_object(); StringName get_edited_property() const; - inline Variant get_edited_property_value() const { return object->get(property); } + inline Variant get_edited_property_value() const { + ERR_FAIL_NULL_V(object, Variant()); + return object->get(property); + } EditorInspector *get_parent_inspector() const; void set_doc_path(const String &p_doc_path);