1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-23 16:27:20 +08:00

Remove generic and add default implementation for CalculateEffect

This commit is contained in:
ansel 2022-09-10 08:21:38 +03:00
parent 545e0bbcef
commit b056cac10a
3 changed files with 13 additions and 8 deletions

View File

@ -16,10 +16,9 @@ using osu.Game.Localisation;
namespace osu.Game.Overlays.Mods
{
public sealed class DifficultyMultiplierDisplay : ModsEffectDisplay<double>
public sealed class DifficultyMultiplierDisplay : ModsEffectDisplay
{
protected override LocalisableString Label => DifficultyMultiplierDisplayStrings.DifficultyMultiplier;
protected override ModEffect CalculateEffect(double value) => CalculateForSign(value.CompareTo(1d));
private readonly MultiplierCounter multiplierCounter;

View File

@ -153,7 +153,7 @@ namespace osu.Game.Overlays.Mods
{
Padding = new MarginPadding
{
Top = (ShowTotalMultiplier ? ModsEffectDisplay<int>.HEIGHT : 0) + PADDING,
Top = (ShowTotalMultiplier ? ModsEffectDisplay.HEIGHT : 0) + PADDING,
Bottom = PADDING
},
RelativeSizeAxes = Axes.Both,
@ -191,7 +191,7 @@ namespace osu.Game.Overlays.Mods
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.X,
Height = ModsEffectDisplay<int>.HEIGHT,
Height = ModsEffectDisplay.HEIGHT,
Margin = new MarginPadding { Horizontal = 100 },
Child = multiplierDisplay = new DifficultyMultiplierDisplay
{

View File

@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Mods
/// <summary>
/// Base class for displays of mods effects.
/// </summary>
public abstract class ModsEffectDisplay<TValue> : Container, IHasCurrentValue<TValue>
public abstract class ModsEffectDisplay : Container, IHasCurrentValue<double>
{
public const float HEIGHT = 42;
private const float transition_duration = 200;
@ -28,13 +28,13 @@ namespace osu.Game.Overlays.Mods
private readonly Box labelBackground;
private readonly Container content;
public Bindable<TValue> Current
public Bindable<double> Current
{
get => current.Current;
set => current.Current = value;
}
private readonly BindableWithCurrent<TValue> current = new BindableWithCurrent<TValue>();
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
[Resolved]
private OsuColour colours { get; set; } = null!;
@ -52,7 +52,13 @@ namespace osu.Game.Overlays.Mods
/// </summary>
/// <param name="value">Value to calculate for. Will arrive from <see cref="Current"/> bindable once it changes.</param>
/// <returns>Effect of the value.</returns>
protected abstract ModEffect CalculateEffect(TValue value);
/// <remarks>
/// Default implementation compares the value with <see cref="Current"/>.<see cref="Bindable{T}.Default"/>, bigger value counts as difficulty increase.
/// </remarks>
protected virtual ModEffect CalculateEffect(double value)
{
return CalculateForSign(value.CompareTo(Current.Default));
}
protected virtual float ValueAreaWidth => 56;