From 114ab9dd0436093fbe948bb8546d406451c23949 Mon Sep 17 00:00:00 2001 From: ajreckof Date: Sun, 12 May 2024 21:35:57 +0200 Subject: [PATCH] fix infinite call loop on theme change. Apply suggestions from code review --- editor/editor_inspector.cpp | 18 ++++++++++++++++++ editor/editor_inspector.h | 2 ++ editor/editor_properties.cpp | 9 +-------- editor/editor_properties_array_dict.cpp | 16 +++------------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 266901c9384..a9c5586ba2f 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -50,6 +50,7 @@ #include "scene/property_utils.h" #include "scene/resources/packed_scene.h" #include "scene/resources/style_box_flat.h" +#include "scene/scene_string_names.h" bool EditorInspector::_property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) { if (p_property_path.containsn(p_filter)) { @@ -390,6 +391,17 @@ void EditorProperty::_notification(int p_what) { delete_rect = Rect2(); } } break; + case NOTIFICATION_ENTER_TREE: { + if (has_borders) { + get_parent()->connect(SceneStringName(theme_changed), callable_mp(this, &EditorProperty::_update_property_bg)); + _update_property_bg(); + } + } break; + case NOTIFICATION_EXIT_TREE: { + if (has_borders) { + get_parent()->disconnect(SceneStringName(theme_changed), callable_mp(this, &EditorProperty::_update_property_bg)); + } + } } } @@ -810,6 +822,9 @@ void EditorProperty::set_label_reference(Control *p_control) { void EditorProperty::set_bottom_editor(Control *p_control) { bottom_editor = p_control; + if (has_borders) { + _update_property_bg(); + } } Variant EditorProperty::_get_cache_value(const StringName &p_prop, bool &r_valid) const { @@ -4087,6 +4102,9 @@ void EditorInspector::_notification(int p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { bool needs_update = false; + if (EditorThemeManager::is_generated_theme_outdated() && !sub_inspector) { + add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree"))); + } if (use_settings_name_style && EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) { EditorPropertyNameProcessor::Style style = EditorPropertyNameProcessor::get_settings_style(); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index b052693524c..8fe690fddfc 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -136,6 +136,8 @@ private: void _update_pin_flags(); protected: + bool has_borders = false; + void _notification(int p_what); static void _bind_methods(); virtual void _set_read_only(bool p_read_only); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 67bfeed8be0..c73bdafb1a6 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -3364,8 +3364,6 @@ void EditorPropertyResource::update_property() { EditorNode::get_singleton()->hide_unused_editors(); opened_editor = false; } - - _update_property_bg(); } } } @@ -3422,12 +3420,6 @@ bool EditorPropertyResource::is_colored(ColorationMode p_mode) { void EditorPropertyResource::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { - if (EditorThemeManager::is_generated_theme_outdated()) { - _update_property_bg(); - } - } break; - case NOTIFICATION_EXIT_TREE: { const EditorInspector *ei = get_parent_inspector(); if (ei && !ei->is_main_editor_inspector()) { @@ -3439,6 +3431,7 @@ void EditorPropertyResource::_notification(int p_what) { EditorPropertyResource::EditorPropertyResource() { use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector")); + has_borders = true; } ////////////// DEFAULT PLUGIN ////////////////////// diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index c3142b4cd09..e338c5c8bd6 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -391,8 +391,6 @@ void EditorPropertyArray::update_property() { paginator->connect("page_changed", callable_mp(this, &EditorPropertyArray::_page_changed)); vbox->add_child(paginator); - _update_property_bg(); - for (int i = 0; i < page_length; i++) { _create_new_property_slot(); } @@ -454,7 +452,6 @@ void EditorPropertyArray::update_property() { memdelete(container); button_add_item = nullptr; container = nullptr; - _update_property_bg(); slots.clear(); } } @@ -628,10 +625,6 @@ Node *EditorPropertyArray::get_base_node() { void EditorPropertyArray::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: - if (EditorThemeManager::is_generated_theme_outdated()) { - _update_property_bg(); - } - [[fallthrough]]; case NOTIFICATION_ENTER_TREE: { change_type->clear(); for (int i = 0; i < Variant::VARIANT_MAX; i++) { @@ -851,6 +844,7 @@ EditorPropertyArray::EditorPropertyArray() { subtype = Variant::NIL; subtype_hint = PROPERTY_HINT_NONE; subtype_hint_string = ""; + has_borders = true; } ///////////////////// DICTIONARY /////////////////////////// @@ -1000,7 +994,6 @@ void EditorPropertyDictionary::update_property() { paginator = memnew(EditorPaginator); paginator->connect("page_changed", callable_mp(this, &EditorPropertyDictionary::_page_changed)); vbox->add_child(paginator); - _update_property_bg(); for (int i = 0; i < page_length; i++) { _create_new_property_slot(slots.size()); @@ -1075,7 +1068,6 @@ void EditorPropertyDictionary::update_property() { memdelete(container); button_add_item = nullptr; container = nullptr; - _update_property_bg(); add_panel = nullptr; slots.clear(); } @@ -1089,10 +1081,6 @@ void EditorPropertyDictionary::_object_id_selected(const StringName &p_property, void EditorPropertyDictionary::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: - if (EditorThemeManager::is_generated_theme_outdated()) { - _update_property_bg(); - } - [[fallthrough]]; case NOTIFICATION_ENTER_TREE: { change_type->clear(); for (int i = 0; i < Variant::VARIANT_MAX; i++) { @@ -1109,6 +1097,7 @@ void EditorPropertyDictionary::_notification(int p_what) { if (button_add_item) { button_add_item->set_icon(get_editor_theme_icon(SNAME("Add"))); + add_panel->add_theme_style_override(SNAME("panel"), get_theme_stylebox(SNAME("DictionaryAddItem"))); } } break; } @@ -1166,6 +1155,7 @@ EditorPropertyDictionary::EditorPropertyDictionary() { add_child(change_type); change_type->connect("id_pressed", callable_mp(this, &EditorPropertyDictionary::_change_type_menu)); changing_type_index = -1; + has_borders = true; } ///////////////////// LOCALIZABLE STRING ///////////////////////////