From 29148d71e7dfdd2dc40d267f2ec14bad0f6f124c Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 20 Jun 2025 15:07:07 +0200 Subject: [PATCH] Improve editor settings override display --- editor/icons/Hierarchy.svg | 1 + editor/settings/editor_settings_dialog.cpp | 92 +++++++++++++--------- editor/settings/editor_settings_dialog.h | 16 ++-- 3 files changed, 64 insertions(+), 45 deletions(-) create mode 100644 editor/icons/Hierarchy.svg diff --git a/editor/icons/Hierarchy.svg b/editor/icons/Hierarchy.svg new file mode 100644 index 00000000000..5a00864ee38 --- /dev/null +++ b/editor/icons/Hierarchy.svg @@ -0,0 +1 @@ + diff --git a/editor/settings/editor_settings_dialog.cpp b/editor/settings/editor_settings_dialog.cpp index 39454ac9040..d7c25d35aa6 100644 --- a/editor/settings/editor_settings_dialog.cpp +++ b/editor/settings/editor_settings_dialog.cpp @@ -1028,6 +1028,41 @@ EditorSettingsDialog::EditorSettingsDialog() { EditorInspector::add_inspector_plugin(plugin); } +void EditorSettingsPropertyWrapper::_setup_override_info() { + override_container = memnew(HBoxContainer); + + override_icon = memnew(TextureRect); + override_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); + override_container->add_child(override_icon); + + Variant::Type type = ProjectSettings::get_singleton()->get_editor_setting_override(property).get_type(); + override_editor_property = get_parent_inspector()->instantiate_property_editor(ProjectSettings::get_singleton(), type, ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property, hint, hint_text, usage); + override_editor_property->set_object_and_property(ProjectSettings::get_singleton(), ProjectSettings::EDITOR_SETTING_OVERRIDE_PREFIX + property); + override_editor_property->set_read_only(true); + override_editor_property->set_label(TTR("Overridden in project")); + override_editor_property->set_h_size_flags(SIZE_EXPAND_FILL); + override_container->add_child(override_editor_property); + + goto_button = memnew(Button); + goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings.")); + override_container->add_child(goto_button); + if (EditorNode::get_singleton()) { + goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED); + } + + remove_button = memnew(Button); + remove_button->set_tooltip_text(TTRC("Remove this override.")); + override_container->add_child(remove_button); + remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override)); + + add_child(override_container); + + if (is_ready()) { + // Setup icons. + _notification(NOTIFICATION_THEME_CHANGED); + } +} + void EditorSettingsPropertyWrapper::_update_override() { // Don't allow overriding theme properties, because it causes problems. Overriding Project Manager settings makes no sense. // TODO: Find a better way to define exception prefixes (if the list happens to grow). @@ -1038,12 +1073,16 @@ void EditorSettingsPropertyWrapper::_update_override() { const bool has_override = ProjectSettings::get_singleton()->is_project_loaded() && ProjectSettings::get_singleton()->has_editor_setting_override(property); if (has_override) { - const Variant override_value = EDITOR_GET(property); - override_label->set_text(vformat(TTR("Overridden in project: %s"), override_value)); - // In case the text is too long and trimmed. - override_label->set_tooltip_text(override_value); + if (!override_container) { + _setup_override_info(); + } + override_editor_property->update_property(); + set_bottom_editor(override_container); + override_container->show(); + } else if (override_container) { + override_container->hide(); + set_bottom_editor(nullptr); } - override_info->set_visible(has_override); can_override = !has_override; } @@ -1060,13 +1099,14 @@ void EditorSettingsPropertyWrapper::_remove_override() { EditorNode::get_singleton()->notify_settings_overrides_changed(); _update_override(); - if (requires_restart) { + if (usage & PROPERTY_USAGE_RESTART_IF_CHANGED) { restart_request_callback.call(); } } void EditorSettingsPropertyWrapper::_notification(int p_what) { - if (p_what == NOTIFICATION_THEME_CHANGED) { + if (override_container && p_what == NOTIFICATION_THEME_CHANGED) { + override_icon->set_texture(get_editor_theme_icon(SNAME("Hierarchy"))); goto_button->set_button_icon(get_editor_theme_icon(SNAME("MethodOverride"))); remove_button->set_button_icon(get_editor_theme_icon(SNAME("Close"))); } @@ -1076,40 +1116,15 @@ void EditorSettingsPropertyWrapper::update_property() { editor_property->update_property(); } -void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart) { - requires_restart = p_requires_restart; +void EditorSettingsPropertyWrapper::setup(const String &p_property, EditorProperty *p_editor_property, PropertyHint p_hint, const String &p_hint_text, uint32_t p_usage) { + hint = p_hint; + hint_text = p_hint_text; + usage = p_usage; property = p_property; - container = memnew(VBoxContainer); - editor_property = p_editor_property; - editor_property->set_h_size_flags(SIZE_EXPAND_FILL); - container->add_child(editor_property); + add_child(editor_property); - override_info = memnew(HBoxContainer); - override_info->hide(); - container->add_child(override_info); - - override_label = memnew(Label); - override_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); - override_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); - override_label->set_mouse_filter(MOUSE_FILTER_STOP); // For tooltip. - override_label->set_h_size_flags(SIZE_EXPAND_FILL); - override_info->add_child(override_label); - - goto_button = memnew(Button); - goto_button->set_tooltip_text(TTRC("Go to the override in the Project Settings.")); - override_info->add_child(goto_button); - if (EditorNode::get_singleton()) { - goto_button->connect(SceneStringName(pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::open_setting_override).bind(property), CONNECT_DEFERRED); - } - - remove_button = memnew(Button); - remove_button->set_tooltip_text(TTRC("Remove this override.")); - override_info->add_child(remove_button); - remove_button->connect(SceneStringName(pressed), callable_mp(this, &EditorSettingsPropertyWrapper::_remove_override)); - - add_child(container); _update_override(); connect(SNAME("property_overridden"), callable_mp(this, &EditorSettingsPropertyWrapper::_create_override)); @@ -1134,8 +1149,9 @@ bool EditorSettingsInspectorPlugin::parse_property(Object *p_object, const Varia EditorSettingsPropertyWrapper *editor = memnew(EditorSettingsPropertyWrapper); EditorProperty *real_property = inspector->get_inspector()->instantiate_property_editor(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide); real_property->set_object_and_property(p_object, p_path); + real_property->set_h_size_flags(Control::SIZE_EXPAND_FILL); real_property->set_name_split_ratio(0.0); - editor->setup(property, real_property, bool(p_usage & PROPERTY_USAGE_RESTART_IF_CHANGED)); + editor->setup(property, real_property, p_hint, p_hint_text, p_usage); add_property_editor(p_path, editor); current_object = nullptr; diff --git a/editor/settings/editor_settings_dialog.h b/editor/settings/editor_settings_dialog.h index dd3f7a92a40..ed40aad4183 100644 --- a/editor/settings/editor_settings_dialog.h +++ b/editor/settings/editor_settings_dialog.h @@ -141,17 +141,19 @@ class EditorSettingsPropertyWrapper : public EditorProperty { GDCLASS(EditorSettingsPropertyWrapper, EditorProperty); String property; + PropertyHint hint; + String hint_text; + uint32_t usage; + EditorProperty *editor_property = nullptr; - BoxContainer *container = nullptr; - - HBoxContainer *override_info = nullptr; - Label *override_label = nullptr; + HBoxContainer *override_container = nullptr; + TextureRect *override_icon = nullptr; + EditorProperty *override_editor_property = nullptr; Button *goto_button = nullptr; Button *remove_button = nullptr; - bool requires_restart = false; - + void _setup_override_info(); void _update_override(); void _create_override(); void _remove_override(); @@ -163,7 +165,7 @@ public: static inline Callable restart_request_callback; virtual void update_property() override; - void setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart); + void setup(const String &p_property, EditorProperty *p_editor_property, PropertyHint p_hint, const String &p_hint_text, uint32_t p_usage); }; class EditorSettingsInspectorPlugin : public EditorInspectorPlugin {