Skip to content

Commit 3bc2821

Browse files
committed
Merge pull request #102372 from Rindbee/display-the-actual-used-theme-items-in-the-Inspector
Display the actual used theme items in the Inspector
2 parents 1d8fa8b + bef64ba commit 3bc2821

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
@@ -618,6 +618,16 @@ StringName EditorProperty::get_edited_property() const {
618618
return property;
619619
}
620620

621+
Variant EditorProperty::get_edited_property_display_value() const {
622+
ERR_FAIL_NULL_V(object, Variant());
623+
Control *control = Object::cast_to<Control>(object);
624+
if (checkable && !checked && control && String(property).begins_with("theme_override_")) {
625+
return control->get_used_theme_item(property);
626+
} else {
627+
return get_edited_property_value();
628+
}
629+
}
630+
621631
EditorInspector *EditorProperty::get_parent_inspector() const {
622632
Node *parent = get_parent();
623633
while (parent) {
@@ -4466,13 +4476,26 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
44664476
_edit_set(p_path, Variant(), false, "");
44674477
} else {
44684478
Variant to_create;
4469-
List<PropertyInfo> pinfo;
4470-
object->get_property_list(&pinfo);
4471-
for (const PropertyInfo &E : pinfo) {
4472-
if (E.name == p_path) {
4473-
Callable::CallError ce;
4474-
Variant::construct(E.type, to_create, nullptr, 0, ce);
4475-
break;
4479+
Control *control = Object::cast_to<Control>(object);
4480+
bool skip = false;
4481+
if (control && p_path.begins_with("theme_override_")) {
4482+
to_create = control->get_used_theme_item(p_path);
4483+
Ref<Resource> resource = to_create;
4484+
if (resource.is_valid()) {
4485+
to_create = resource->duplicate();
4486+
}
4487+
skip = true;
4488+
}
4489+
4490+
if (!skip) {
4491+
List<PropertyInfo> pinfo;
4492+
object->get_property_list(&pinfo);
4493+
for (const PropertyInfo &E : pinfo) {
4494+
if (E.name == p_path) {
4495+
Callable::CallError ce;
4496+
Variant::construct(E.type, to_create, nullptr, 0, ce);
4497+
break;
4498+
}
44764499
}
44774500
}
44784501
_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
@@ -183,6 +183,7 @@ class EditorProperty : public Container {
183183
ERR_FAIL_NULL_V(object, Variant());
184184
return object->get(property);
185185
}
186+
Variant get_edited_property_display_value() const;
186187
EditorInspector *get_parent_inspector() const;
187188

188189
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
@@ -1326,7 +1326,7 @@ void EditorPropertyInteger::_value_changed(int64_t val) {
13261326
}
13271327

13281328
void EditorPropertyInteger::update_property() {
1329-
int64_t val = get_edited_property_value();
1329+
int64_t val = get_edited_property_display_value();
13301330
spin->set_value_no_signal(val);
13311331
#ifdef DEBUG_ENABLED
13321332
// If spin (currently EditorSplinSlider : Range) is changed so that it can use int64_t, then the below warning wouldn't be a problem.
@@ -2635,7 +2635,7 @@ void EditorPropertyColor::_notification(int p_what) {
26352635
}
26362636

26372637
void EditorPropertyColor::update_property() {
2638-
picker->set_pick_color(get_edited_property_value());
2638+
picker->set_pick_color(get_edited_property_display_value());
26392639
const Color color = picker->get_pick_color();
26402640

26412641
// Add a tooltip to display each channel's values without having to click the ColorPickerButton
@@ -3015,7 +3015,7 @@ void EditorPropertyResource::_resource_selected(const Ref<Resource> &p_resource,
30153015
bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
30163016
get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
30173017
update_property();
3018-
} else {
3018+
} else if (!is_checkable() || is_checked()) {
30193019
emit_signal(SNAME("resource_selected"), get_edited_property(), p_resource);
30203020
}
30213021
}
@@ -3276,7 +3276,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const
32763276
}
32773277

32783278
void EditorPropertyResource::update_property() {
3279-
Ref<Resource> res = get_edited_property_value();
3279+
Ref<Resource> res = get_edited_property_display_value();
32803280

32813281
if (use_sub_inspector) {
32823282
if (res.is_valid() != resource_picker->is_toggle_mode()) {
@@ -3328,6 +3328,8 @@ void EditorPropertyResource::update_property() {
33283328
}
33293329
}
33303330

3331+
sub_inspector->set_read_only(is_checkable() && !is_checked());
3332+
33313333
if (res.ptr() != sub_inspector->get_edited_object()) {
33323334
sub_inspector->edit(res.ptr());
33333335
_update_property_bg();

scene/gui/control.cpp

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

2798+
Variant Control::get_used_theme_item(const String &p_full_name, const StringName &p_theme_type) const {
2799+
if (p_full_name.begins_with("theme_override_icons/")) {
2800+
String name = p_full_name.substr(strlen("theme_override_icons/"));
2801+
if (has_theme_icon(name)) { // Exclude cached and default ones.
2802+
return get_theme_icon(name);
2803+
}
2804+
} else if (p_full_name.begins_with("theme_override_styles/")) {
2805+
String name = p_full_name.substr(strlen("theme_override_styles/"));
2806+
if (has_theme_stylebox(name)) {
2807+
return get_theme_stylebox(name);
2808+
}
2809+
} else if (p_full_name.begins_with("theme_override_fonts/")) {
2810+
String name = p_full_name.substr(strlen("theme_override_fonts/"));
2811+
if (has_theme_font(name)) {
2812+
return get_theme_font(name);
2813+
}
2814+
} else if (p_full_name.begins_with("theme_override_font_sizes/")) {
2815+
String name = p_full_name.substr(strlen("theme_override_font_sizes/"));
2816+
if (has_theme_font_size(name)) {
2817+
return get_theme_font_size(name);
2818+
}
2819+
} else if (p_full_name.begins_with("theme_override_colors/")) {
2820+
String name = p_full_name.substr(strlen("theme_override_colors/"));
2821+
if (has_theme_color(name)) {
2822+
return get_theme_color(name);
2823+
}
2824+
} else if (p_full_name.begins_with("theme_override_constants/")) {
2825+
String name = p_full_name.substr(strlen("theme_override_constants/"));
2826+
if (has_theme_constant(name)) {
2827+
return get_theme_constant(name);
2828+
}
2829+
} else {
2830+
ERR_FAIL_V_MSG(Variant(), vformat("The property %s is not a theme item.", p_full_name));
2831+
}
2832+
2833+
return Variant();
2834+
}
2835+
27982836
#ifdef TOOLS_ENABLED
27992837
Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const {
28002838
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
@@ -606,6 +606,7 @@ class Control : public CanvasItem {
606606
Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
607607
int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
608608
Variant get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type = StringName()) const;
609+
Variant get_used_theme_item(const String &p_full_name, const StringName &p_theme_type = StringName()) const;
609610
#ifdef TOOLS_ENABLED
610611
Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const;
611612
#endif //TOOLS_ENABLED

0 commit comments

Comments
 (0)