From bef64baa185dd2845135de340b2c8d6d3f3b3759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Mon, 3 Feb 2025 23:06:15 +0800 Subject: [PATCH] Display the actual used theme items in the Inspector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: godotengine/godot-proposals#4439. Allows viewing the default values ​​of the currently used theme item in the Inspector. For theme item properties of resource type, editing the default resource does not make sense. Use **Make Unique** to create a copy before editing. --- editor/editor_inspector.cpp | 37 ++++++++++++++++++++++++++++------- editor/editor_inspector.h | 1 + editor/editor_properties.cpp | 10 ++++++---- scene/gui/control.cpp | 38 ++++++++++++++++++++++++++++++++++++ scene/gui/control.h | 1 + 5 files changed, 76 insertions(+), 11 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index b79d1243ba6..b35765ecf9e 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -567,6 +567,16 @@ StringName EditorProperty::get_edited_property() const { return property; } +Variant EditorProperty::get_edited_property_display_value() const { + ERR_FAIL_NULL_V(object, Variant()); + Control *control = Object::cast_to(object); + if (checkable && !checked && control && String(property).begins_with("theme_override_")) { + return control->get_used_theme_item(property); + } else { + return get_edited_property_value(); + } +} + EditorInspector *EditorProperty::get_parent_inspector() const { Node *parent = get_parent(); while (parent) { @@ -4386,13 +4396,26 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) { _edit_set(p_path, Variant(), false, ""); } else { Variant to_create; - List pinfo; - object->get_property_list(&pinfo); - for (const PropertyInfo &E : pinfo) { - if (E.name == p_path) { - Callable::CallError ce; - Variant::construct(E.type, to_create, nullptr, 0, ce); - break; + Control *control = Object::cast_to(object); + bool skip = false; + if (control && p_path.begins_with("theme_override_")) { + to_create = control->get_used_theme_item(p_path); + Ref resource = to_create; + if (resource.is_valid()) { + to_create = resource->duplicate(); + } + skip = true; + } + + if (!skip) { + List pinfo; + object->get_property_list(&pinfo); + for (const PropertyInfo &E : pinfo) { + if (E.name == p_path) { + Callable::CallError ce; + Variant::construct(E.type, to_create, nullptr, 0, ce); + break; + } } } _edit_set(p_path, to_create, false, ""); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index ee82806003b..f69b668226b 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -184,6 +184,7 @@ public: ERR_FAIL_NULL_V(object, Variant()); return object->get(property); } + Variant get_edited_property_display_value() const; EditorInspector *get_parent_inspector() const; void set_doc_path(const String &p_doc_path); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 73f6c70f342..378312dc483 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1320,7 +1320,7 @@ void EditorPropertyInteger::_value_changed(int64_t val) { } void EditorPropertyInteger::update_property() { - int64_t val = get_edited_property_value(); + int64_t val = get_edited_property_display_value(); spin->set_value_no_signal(val); #ifdef DEBUG_ENABLED // If spin (currently EditorSplinSlider : Range) is changed so that it can use int64_t, then the below warning wouldn't be a problem. @@ -2628,7 +2628,7 @@ void EditorPropertyColor::_notification(int p_what) { } void EditorPropertyColor::update_property() { - picker->set_pick_color(get_edited_property_value()); + picker->set_pick_color(get_edited_property_display_value()); const Color color = picker->get_pick_color(); // Add a tooltip to display each channel's values without having to click the ColorPickerButton @@ -3008,7 +3008,7 @@ void EditorPropertyResource::_resource_selected(const Ref &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(); - } else { + } else if (!is_checkable() || is_checked()) { emit_signal(SNAME("resource_selected"), get_edited_property(), p_resource); } } @@ -3269,7 +3269,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const } void EditorPropertyResource::update_property() { - Ref res = get_edited_property_value(); + Ref res = get_edited_property_display_value(); if (use_sub_inspector) { if (res.is_valid() != resource_picker->is_toggle_mode()) { @@ -3321,6 +3321,8 @@ void EditorPropertyResource::update_property() { } } + sub_inspector->set_read_only(is_checkable() && !is_checked()); + if (res.ptr() != sub_inspector->get_edited_object()) { sub_inspector->edit(res.ptr()); _update_property_bg(); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 92b5f327775..7730a5a4671 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2808,6 +2808,44 @@ Variant Control::get_theme_item(Theme::DataType p_data_type, const StringName &p return Variant(); } +Variant Control::get_used_theme_item(const String &p_full_name, const StringName &p_theme_type) const { + if (p_full_name.begins_with("theme_override_icons/")) { + String name = p_full_name.substr(strlen("theme_override_icons/")); + if (has_theme_icon(name)) { // Exclude cached and default ones. + return get_theme_icon(name); + } + } else if (p_full_name.begins_with("theme_override_styles/")) { + String name = p_full_name.substr(strlen("theme_override_styles/")); + if (has_theme_stylebox(name)) { + return get_theme_stylebox(name); + } + } else if (p_full_name.begins_with("theme_override_fonts/")) { + String name = p_full_name.substr(strlen("theme_override_fonts/")); + if (has_theme_font(name)) { + return get_theme_font(name); + } + } else if (p_full_name.begins_with("theme_override_font_sizes/")) { + String name = p_full_name.substr(strlen("theme_override_font_sizes/")); + if (has_theme_font_size(name)) { + return get_theme_font_size(name); + } + } else if (p_full_name.begins_with("theme_override_colors/")) { + String name = p_full_name.substr(strlen("theme_override_colors/")); + if (has_theme_color(name)) { + return get_theme_color(name); + } + } else if (p_full_name.begins_with("theme_override_constants/")) { + String name = p_full_name.substr(strlen("theme_override_constants/")); + if (has_theme_constant(name)) { + return get_theme_constant(name); + } + } else { + ERR_FAIL_V_MSG(Variant(), vformat("The property %s is not a theme item.", p_full_name)); + } + + return Variant(); +} + #ifdef TOOLS_ENABLED Ref Control::get_editor_theme_icon(const StringName &p_name) const { return get_theme_icon(p_name, SNAME("EditorIcons")); diff --git a/scene/gui/control.h b/scene/gui/control.h index 496df44a3d2..c41b02e4316 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -607,6 +607,7 @@ public: Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const; int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const; Variant get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type = StringName()) const; + Variant get_used_theme_item(const String &p_full_name, const StringName &p_theme_type = StringName()) const; #ifdef TOOLS_ENABLED Ref get_editor_theme_icon(const StringName &p_name) const; #endif //TOOLS_ENABLED