1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 05:52:54 +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.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -91,14 +92,14 @@ namespace osu.Game.Overlays.FirstRunSetup
private void applyClassic()
{
foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>())
i.ApplyClassicDefault(true);
foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>().Where(s => s.HasClassicDefault))
i.ApplyClassicDefault();
}
private void applyStandard()
{
foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>())
i.ApplyClassicDefault(false);
foreach (var i in searchContainer.ChildrenOfType<ISettingsItem>().Where(s => s.HasClassicDefault))
i.ApplyDefault();
}
}
}

View File

@ -11,9 +11,18 @@ namespace osu.Game.Overlays.Settings
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"/>.
/// Whether this setting has a classic default (ie. a different default which better aligns with osu-stable expectations).
/// </summary>
/// <param name="useClassicDefault">Whether to apply the classic value. If <c>false</c>, the standard default is applied.</param>
void ApplyClassicDefault(bool useClassicDefault);
bool HasClassicDefault { get; }
/// <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()
};
if (hasClassicDefault)
if (HasClassicDefault)
keywords.Add(CLASSIC_DEFAULT_SEARCH_TERM);
return keywords;
@ -139,7 +139,8 @@ namespace osu.Game.Overlays.Settings
public event Action SettingChanged;
private T classicDefault;
private bool hasClassicDefault;
public bool HasClassicDefault { get; private set; }
/// <summary>
/// A "classic" default value for this setting.
@ -149,21 +150,20 @@ namespace osu.Game.Overlays.Settings
set
{
classicDefault = value;
hasClassicDefault = true;
HasClassicDefault = true;
}
}
public void ApplyClassicDefault(bool useClassicDefault)
public void ApplyClassicDefault()
{
if (!hasClassicDefault)
return;
if (!HasClassicDefault)
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;
else
Current.SetDefault();
}
public void ApplyDefault() => Current.SetDefault();
protected SettingsItem()
{
RelativeSizeAxes = Axes.X;