Browse Source

Merge pull request #102372 from Rindbee/display-the-actual-used-theme-items-in-the-Inspector

Display the actual used theme items in the Inspector
Thaddeus Crews 5 months ago
parent
commit
3bc2821e26

+ 30 - 7
editor/editor_inspector.cpp

@@ -618,6 +618,16 @@ StringName EditorProperty::get_edited_property() const {
 	return property;
 	return property;
 }
 }
 
 
+Variant EditorProperty::get_edited_property_display_value() const {
+	ERR_FAIL_NULL_V(object, Variant());
+	Control *control = Object::cast_to<Control>(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 {
 EditorInspector *EditorProperty::get_parent_inspector() const {
 	Node *parent = get_parent();
 	Node *parent = get_parent();
 	while (parent) {
 	while (parent) {
@@ -4466,13 +4476,26 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
 			_edit_set(p_path, Variant(), false, "");
 			_edit_set(p_path, Variant(), false, "");
 		} else {
 		} else {
 			Variant to_create;
 			Variant to_create;
-			List<PropertyInfo> 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<Control>(object);
+			bool skip = false;
+			if (control && p_path.begins_with("theme_override_")) {
+				to_create = control->get_used_theme_item(p_path);
+				Ref<Resource> resource = to_create;
+				if (resource.is_valid()) {
+					to_create = resource->duplicate();
+				}
+				skip = true;
+			}
+
+			if (!skip) {
+				List<PropertyInfo> 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, "");
 			_edit_set(p_path, to_create, false, "");

+ 1 - 0
editor/editor_inspector.h

@@ -183,6 +183,7 @@ public:
 		ERR_FAIL_NULL_V(object, Variant());
 		ERR_FAIL_NULL_V(object, Variant());
 		return object->get(property);
 		return object->get(property);
 	}
 	}
+	Variant get_edited_property_display_value() const;
 	EditorInspector *get_parent_inspector() const;
 	EditorInspector *get_parent_inspector() const;
 
 
 	void set_doc_path(const String &p_doc_path);
 	void set_doc_path(const String &p_doc_path);

+ 6 - 4
editor/editor_properties.cpp

@@ -1326,7 +1326,7 @@ void EditorPropertyInteger::_value_changed(int64_t val) {
 }
 }
 
 
 void EditorPropertyInteger::update_property() {
 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);
 	spin->set_value_no_signal(val);
 #ifdef DEBUG_ENABLED
 #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.
 	// 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) {
 }
 }
 
 
 void EditorPropertyColor::update_property() {
 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();
 	const Color color = picker->get_pick_color();
 
 
 	// Add a tooltip to display each channel's values without having to click the ColorPickerButton
 	// 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,
 		bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
 		bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property());
 		get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
 		get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold);
 		update_property();
 		update_property();
-	} else {
+	} else if (!is_checkable() || is_checked()) {
 		emit_signal(SNAME("resource_selected"), get_edited_property(), p_resource);
 		emit_signal(SNAME("resource_selected"), get_edited_property(), p_resource);
 	}
 	}
 }
 }
@@ -3276,7 +3276,7 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const
 }
 }
 
 
 void EditorPropertyResource::update_property() {
 void EditorPropertyResource::update_property() {
-	Ref<Resource> res = get_edited_property_value();
+	Ref<Resource> res = get_edited_property_display_value();
 
 
 	if (use_sub_inspector) {
 	if (use_sub_inspector) {
 		if (res.is_valid() != resource_picker->is_toggle_mode()) {
 		if (res.is_valid() != resource_picker->is_toggle_mode()) {
@@ -3328,6 +3328,8 @@ void EditorPropertyResource::update_property() {
 				}
 				}
 			}
 			}
 
 
+			sub_inspector->set_read_only(is_checkable() && !is_checked());
+
 			if (res.ptr() != sub_inspector->get_edited_object()) {
 			if (res.ptr() != sub_inspector->get_edited_object()) {
 				sub_inspector->edit(res.ptr());
 				sub_inspector->edit(res.ptr());
 				_update_property_bg();
 				_update_property_bg();

+ 38 - 0
scene/gui/control.cpp

@@ -2795,6 +2795,44 @@ Variant Control::get_theme_item(Theme::DataType p_data_type, const StringName &p
 	return Variant();
 	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
 #ifdef TOOLS_ENABLED
 Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const {
 Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const {
 	return get_theme_icon(p_name, SNAME("EditorIcons"));
 	return get_theme_icon(p_name, SNAME("EditorIcons"));

+ 1 - 0
scene/gui/control.h

@@ -606,6 +606,7 @@ public:
 	Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
 	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;
 	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_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
 #ifdef TOOLS_ENABLED
 	Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const;
 	Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const;
 #endif //TOOLS_ENABLED
 #endif //TOOLS_ENABLED