1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Add a method of finding and applying settings with classic default value

This commit is contained in:
Dean Herbert 2022-04-22 18:04:43 +09:00
parent 7258a09748
commit 2a043aa6de
2 changed files with 41 additions and 1 deletions

View File

@ -9,5 +9,11 @@ namespace osu.Game.Overlays.Settings
public interface ISettingsItem : IDrawable, IDisposable
{
event Action SettingChanged;
/// <summary>
/// Apply the default values of a setting item, if the setting item specifies a "classic" default via <see cref="SettingsItem{T}.ApplyClassicDefault"/>.
/// </summary>
/// <param name="useClassicDefault">Whether to apply the classic value. If <c>false</c>, the standard default is applied.</param>
void ApplyClassicDefault(bool useClassicDefault);
}
}

View File

@ -30,6 +30,8 @@ namespace osu.Game.Overlays.Settings
/// </summary>
public object SettingSourceObject { get; internal set; }
public const string CLASSIC_DEFAULT_SEARCH_TERM = @"has-classic-default";
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
protected override Container<Drawable> Content => FlowContent;
@ -96,7 +98,23 @@ namespace osu.Game.Overlays.Settings
set => controlWithCurrent.Current = value;
}
public virtual IEnumerable<string> FilterTerms => Keywords == null ? new[] { LabelText.ToString() } : new List<string>(Keywords) { LabelText.ToString() }.ToArray();
public virtual IEnumerable<string> FilterTerms
{
get
{
var keywords = new List<string>(Keywords ?? Array.Empty<string>())
{
LabelText.ToString()
};
if (GetClassicDefault != null)
{
keywords.Add(CLASSIC_DEFAULT_SEARCH_TERM);
}
return keywords;
}
}
public IEnumerable<string> Keywords { get; set; }
@ -108,6 +126,22 @@ namespace osu.Game.Overlays.Settings
public event Action SettingChanged;
/// <summary>
/// An action which when invoked will apply a classic default value to this setting.
/// </summary>
public Func<T> GetClassicDefault { get; set; }
public void ApplyClassicDefault(bool useClassicDefault)
{
if (GetClassicDefault != null)
{
if (useClassicDefault)
Current.Value = GetClassicDefault();
else
Current.SetDefault();
}
}
protected SettingsItem()
{
RelativeSizeAxes = Axes.X;