diff --git a/osu.Game/Configuration/SettingSourceAttribute.cs b/osu.Game/Configuration/SettingSourceAttribute.cs index cfce615130..a8cebb97b4 100644 --- a/osu.Game/Configuration/SettingSourceAttribute.cs +++ b/osu.Game/Configuration/SettingSourceAttribute.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Reflection; using JetBrains.Annotations; using osu.Framework.Bindables; +using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Graphics; using osu.Framework.Localisation; using osu.Game.Overlays.Settings; @@ -61,9 +62,13 @@ namespace osu.Game.Configuration public static class SettingSourceExtensions { - public static IEnumerable CreateSettingsControls(this object obj) + public static IEnumerable CreateSettingsControls(this object obj) => createSettingsControls(obj, obj.GetOrderedSettingsSourceProperties()); + + public static IEnumerable CreateSettingsControlsFromAllBindables(this object obj) => createSettingsControls(obj, obj.GetSettingsSourcePropertiesFromBindables()); + + private static IEnumerable createSettingsControls(object obj, IEnumerable<(SettingSourceAttribute, PropertyInfo)> sourceAttribs) { - foreach (var (attr, property) in obj.GetOrderedSettingsSourceProperties()) + foreach (var (attr, property) in sourceAttribs) { object value = property.GetValue(obj); @@ -139,6 +144,30 @@ namespace osu.Game.Configuration } } + public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetSettingsSourcePropertiesFromBindables(this object obj) + { + HashSet handledProperties = new HashSet(); + + // reverse and de-dupe properties to surface base class settings to the top of return order. + foreach (var type in obj.GetType().EnumerateBaseTypes().Reverse()) + { + foreach (var property in type.GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance)) + { + if (handledProperties.Contains(property.Name)) + continue; + + handledProperties.Add(property.Name); + + if (typeof(IBindable).IsAssignableFrom(property.PropertyType)) + { + var val = property.GetValue(obj); + string description = (val as IHasDescription)?.Description ?? string.Empty; + yield return (new SettingSourceAttribute(property.Name, description), property); + } + } + } + } + public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetSettingsSourceProperties(this object obj) { foreach (var property in obj.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))