Skip to content

Commit bef64ba

Browse files
committed
Display the actual used theme items in the Inspector
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.
1 parent f60f69a commit bef64ba

File tree

5 files changed

+76
-11
lines changed

5 files changed

+76
-11
lines changed

editor/editor_inspector.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,16 @@ StringName EditorProperty::get_edited_property() const {
567567
return property;
568568
}
569569

570+
Variant EditorProperty::get_edited_property_display_value() const {
571+
ERR_FAIL_NULL_V(object, Variant());
572+
Control *control = Object::cast_to<Control>(object);
573+
if (checkable && !checked && control && String(property).begins_with("theme_override_")) {
574+
return control->get_used_theme_item(property);
575+
} else {
576+
return get_edited_property_value();
577+
}
578+
}
579+
570580
EditorInspector *EditorProperty::get_parent_inspector() const {
571581
Node *parent = get_parent();
572582
while (parent) {
@@ -4386,13 +4396,26 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
43864396
_edit_set(p_path, Variant(), false, "");
43874397
} else {
43884398
Variant to_create;
4389-
List<PropertyInfo> pinfo;
4390-
object->get_property_list(&pinfo);
4391-
for (const PropertyInfo &E : pinfo) {
4392-
if (E.name == p_path) {
4393-
Callable::CallError ce;
4394-
Variant::construct(E.type, to_create, nullptr, 0, ce);
4395-
break;
4399+
Control *control = Object::cast_to<Control>(object);
4400+
bool skip = false;
4401+
if (control && p_path.begins_with("theme_override_")) {
4402+
to_create = control->get_used_theme_item(p_path);
4403+
Ref<Resource> resource = to_create;
4404+
if (resource.is_valid()) {
4405+
to_create = resource->duplicate();
4406+
}
4407+
skip = true;
4408+
}
4409+
4410+
if (!skip) {
4411+
List<PropertyInfo> pinfo;
4412+
object->get_property_list(&pinfo);
4413+
for (const PropertyInfo &E : pinfo) {
4414+
if (E.name == p_path) {
4415+
Callable::CallError ce;
4416+
Variant::construct(E.type, to_create, nullptr, 0, ce);
4417+
break;
4418+
}
43964419
}
43974420
}
43984421
_edit_set(p_path, to_create, false, "");

editor/editor_inspector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class EditorProperty : public Container {
184184
ERR_FAIL_NULL_V(object, Variant());
185185
return object->get(property);
186186
}
187+
Variant get_edited_property_display_value() const;
187188
EditorInspector *get_parent_inspector() const;
188189

189190
void set_doc_path(const String &p_doc_path);

editor/editor_properties.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ void EditorPropertyInteger::_value_changed(int64_t val) {
13201320
}
13211321

13221322
void EditorPropertyInteger::update_property() {
1323-
int64_t val = get_edited_property_value();
1323+
int64_t val = get_edited_property_display_value();
13241324
spin->set_value_no_signal(val);
13251325
#ifdef DEBUG_ENABLED
13261326
// 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) {
26282628
}
26292629

26302630
void EditorPropertyColor::update_property() {
2631-
picker->set_pick_color(get_edited_property_value());
2631+
picker->set_pick_color(get_edited_property_display_value());
26322632
const Color color = picker->get_pick_color();
26332633

26342634
// 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<Resource> &p_resource,
30083008
bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
30093009
get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
30103010
update_property();
3011-
} else {
3011+
} else if (!is_checkable() || is_checked()) {
30123012
emit_signal(SNAME("resource_selected"), get_edited_property(), p_resource);
30133013
}
30143014
}
@@ -3269,7 +3269,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const
32693269
}
32703270

32713271
void EditorPropertyResource::update_property() {
3272-
Ref<Resource> res = get_edited_property_value();
3272+
Ref<Resource> res = get_edited_property_display_value();
32733273

32743274
if (use_sub_inspector) {
32753275
if (res.is_valid() != resource_picker->is_toggle_mode()) {
@@ -3321,6 +3321,8 @@ void EditorPropertyResource::update_property() {
33213321
}
33223322
}
33233323

3324+
sub_inspector->set_read_only(is_checkable() && !is_checked());
3325+
33243326
if (res.ptr() != sub_inspector->get_edited_object()) {
33253327
sub_inspector->edit(res.ptr());
33263328
_update_property_bg();

scene/gui/control.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,44 @@ Variant Control::get_theme_item(Theme::DataType p_data_type, const StringName &p
28082808
return Variant();
28092809
}
28102810

2811+
Variant Control::get_used_theme_item(const String &p_full_name, const StringName &p_theme_type) const {
2812+
if (p_full_name.begins_with("theme_override_icons/")) {
2813+
String name = p_full_name.substr(strlen("theme_override_icons/"));
2814+
if (has_theme_icon(name)) { // Exclude cached and default ones.
2815+
return get_theme_icon(name);
2816+
}
2817+
} else if (p_full_name.begins_with("theme_override_styles/")) {
2818+
String name = p_full_name.substr(strlen("theme_override_styles/"));
2819+
if (has_theme_stylebox(name)) {
2820+
return get_theme_stylebox(name);
2821+
}
2822+
} else if (p_full_name.begins_with("theme_override_fonts/")) {
2823+
String name = p_full_name.substr(strlen("theme_override_fonts/"));
2824+
if (has_theme_font(name)) {
2825+
return get_theme_font(name);
2826+
}
2827+
} else if (p_full_name.begins_with("theme_override_font_sizes/")) {
2828+
String name = p_full_name.substr(strlen("theme_override_font_sizes/"));
2829+
if (has_theme_font_size(name)) {
2830+
return get_theme_font_size(name);
2831+
}
2832+
} else if (p_full_name.begins_with("theme_override_colors/")) {
2833+
String name = p_full_name.substr(strlen("theme_override_colors/"));
2834+
if (has_theme_color(name)) {
2835+
return get_theme_color(name);
2836+
}
2837+
} else if (p_full_name.begins_with("theme_override_constants/")) {
2838+
String name = p_full_name.substr(strlen("theme_override_constants/"));
2839+
if (has_theme_constant(name)) {
2840+
return get_theme_constant(name);
2841+
}
2842+
} else {
2843+
ERR_FAIL_V_MSG(Variant(), vformat("The property %s is not a theme item.", p_full_name));
2844+
}
2845+
2846+
return Variant();
2847+
}
2848+
28112849
#ifdef TOOLS_ENABLED
28122850
Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const {
28132851
return get_theme_icon(p_name, SNAME("EditorIcons"));

scene/gui/control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ class Control : public CanvasItem {
607607
Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
608608
int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
609609
Variant get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type = StringName()) const;
610+
Variant get_used_theme_item(const String &p_full_name, const StringName &p_theme_type = StringName()) const;
610611
#ifdef TOOLS_ENABLED
611612
Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const;
612613
#endif //TOOLS_ENABLED

0 commit comments

Comments
 (0)