1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 16:42:57 +08:00

Make apply default methods more explicit in behaviour

This commit is contained in:
Dean Herbert 2022-04-27 15:59:39 +09:00
parent 4638dd97db
commit 0343687b85
3 changed files with 27 additions and 17 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -91,14 +92,14 @@ namespace osu.Game.Overlays.FirstRunSetup
private void applyClassic() private void applyClassic()
{ {
foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>()) foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>().Where(s => s.HasClassicDefault))
i.ApplyClassicDefault(true); i.ApplyClassicDefault();
} }
private void applyStandard() private void applyStandard()
{ {
foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>()) foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>().Where(s => s.HasClassicDefault))
i.ApplyClassicDefault(false); i.ApplyDefault();
} }
} }
} }

View File

@ -11,9 +11,18 @@ namespace osu.Game.Overlays.Settings
event Action SettingChanged; event Action SettingChanged;
/// <summary> /// <summary>
/// Apply the default values of a setting item, if the setting item specifies a "classic" default via <see cref="SettingsItem{T}.ApplyClassicDefault"/>. /// Whether this setting has a classic default (ie. a different default which better aligns with osu-stable expectations).
/// </summary> /// </summary>
/// <param name="useClassicDefault">Whether to apply the classic value. If <c>false</c>, the standard default is applied.</param> bool HasClassicDefault { get; }
void ApplyClassicDefault(bool useClassicDefault);
/// <summary>
/// Apply the classic default value of the associated setting. Will throw if <see cref="HasClassicDefault"/> is <c>false</c>.
/// </summary>
void ApplyClassicDefault();
/// <summary>
/// Apply the default value of the associated setting.
/// </summary>
void ApplyDefault();
} }
} }

View File

@ -107,7 +107,7 @@ namespace osu.Game.Overlays.Settings
LabelText.ToString() LabelText.ToString()
}; };
if (hasClassicDefault) if (HasClassicDefault)
keywords.Add(CLASSIC_DEFAULT_SEARCH_TERM); keywords.Add(CLASSIC_DEFAULT_SEARCH_TERM);
return keywords; return keywords;
@ -139,7 +139,8 @@ namespace osu.Game.Overlays.Settings
public event Action SettingChanged; public event Action SettingChanged;
private T classicDefault; private T classicDefault;
private bool hasClassicDefault;
public bool HasClassicDefault { get; private set; }
/// <summary> /// <summary>
/// A "classic" default value for this setting. /// A "classic" default value for this setting.
@ -149,21 +150,20 @@ namespace osu.Game.Overlays.Settings
set set
{ {
classicDefault = value; classicDefault = value;
hasClassicDefault = true; HasClassicDefault = true;
} }
} }
public void ApplyClassicDefault(bool useClassicDefault) public void ApplyClassicDefault()
{ {
if (!hasClassicDefault) if (!HasClassicDefault)
return; throw new InvalidOperationException($"Cannot apply a classic default to a setting which doesn't have one defined via {nameof(ClassicDefault)}.");
if (useClassicDefault)
Current.Value = classicDefault; Current.Value = classicDefault;
else
Current.SetDefault();
} }
public void ApplyDefault() => Current.SetDefault();
protected SettingsItem() protected SettingsItem()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;