From d3d7c29b8c456026cd24b69661e26e317ed7e56f Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Fri, 24 Sep 2021 00:36:28 +0300 Subject: [PATCH] Disable sub-inspectors for properties with their own editors --- editor/editor_properties.cpp | 35 ++++++++++++++++------------------- editor/editor_properties.h | 1 + 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3585dc577fb..3f153c90815 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2237,7 +2237,7 @@ EditorPropertyRID::EditorPropertyRID() { ////////////// RESOURCE ////////////////////// void EditorPropertyResource::_resource_selected(const RES &p_resource) { - if (use_sub_inspector) { + if (_can_use_sub_inspector(p_resource)) { bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property()); get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold); update_property(); @@ -2399,6 +2399,20 @@ void EditorPropertyResource::_viewport_selected(const NodePath &p_path) { update_property(); } +bool EditorPropertyResource::_can_use_sub_inspector(const RES &p_resource) { + bool use_editor = false; + if (p_resource.is_valid()) { + for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) { + EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i); + if (ep->handles((Resource *)p_resource.ptr())) { + use_editor = true; + } + } + } + + return !use_editor && use_sub_inspector; +} + void EditorPropertyResource::setup(Object *p_object, const String &p_path, const String &p_base_type) { if (resource_picker) { resource_picker->disconnect("resource_selected", this, "_resource_selected"); @@ -2433,7 +2447,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const void EditorPropertyResource::update_property() { RES res = get_edited_object()->get(get_edited_property()); - if (use_sub_inspector) { + if (_can_use_sub_inspector(res)) { if (res.is_valid() != resource_picker->is_toggle_mode()) { resource_picker->set_toggle_mode(res.is_valid()); } @@ -2462,23 +2476,6 @@ void EditorPropertyResource::update_property() { sub_inspector_vbox->add_child(sub_inspector); resource_picker->set_toggle_pressed(true); - bool use_editor = false; - for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) { - EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i); - if (ep->handles(res.ptr())) { - use_editor = true; - } - } - - if (use_editor) { - // Open editor directly and hide other such editors which are currently open. - _open_editor_pressed(); - if (is_inside_tree()) { - get_tree()->call_deferred("call_group", "_editor_resource_properties", "_fold_other_editors", this); - } - opened_editor = true; - } - _update_property_bg(); } diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 71956301c6e..012fe238635 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -562,6 +562,7 @@ class EditorPropertyResource : public EditorProperty { void _sub_inspector_resource_selected(const RES &p_resource, const String &p_property); void _sub_inspector_object_id_selected(int p_id); + bool _can_use_sub_inspector(const RES &p_resource); void _open_editor_pressed(); void _fold_other_editors(Object *p_self); void _update_property_bg();