mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Add a method of finding and applying settings with classic default value
This commit is contained in:
parent
7258a09748
commit
2a043aa6de
@ -9,5 +9,11 @@ namespace osu.Game.Overlays.Settings
|
|||||||
public interface ISettingsItem : IDrawable, IDisposable
|
public interface ISettingsItem : IDrawable, IDisposable
|
||||||
{
|
{
|
||||||
event Action SettingChanged;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ namespace osu.Game.Overlays.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public object SettingSourceObject { get; internal set; }
|
public object SettingSourceObject { get; internal set; }
|
||||||
|
|
||||||
|
public const string CLASSIC_DEFAULT_SEARCH_TERM = @"has-classic-default";
|
||||||
|
|
||||||
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
|
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
|
||||||
|
|
||||||
protected override Container<Drawable> Content => FlowContent;
|
protected override Container<Drawable> Content => FlowContent;
|
||||||
@ -96,7 +98,23 @@ namespace osu.Game.Overlays.Settings
|
|||||||
set => controlWithCurrent.Current = value;
|
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; }
|
public IEnumerable<string> Keywords { get; set; }
|
||||||
|
|
||||||
@ -108,6 +126,22 @@ namespace osu.Game.Overlays.Settings
|
|||||||
|
|
||||||
public event Action SettingChanged;
|
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()
|
protected SettingsItem()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
|
Loading…
Reference in New Issue
Block a user