mirror of https://github.com/ppy/osu
Adjust inheritors and test
This commit is contained in:
parent
5343c26452
commit
545e0bbcef
|
@ -44,32 +44,24 @@ public void TestModsEffectDisplay()
|
|||
background = boxes.First();
|
||||
});
|
||||
|
||||
AddStep("set value to default", () => testDisplay.Value = 50);
|
||||
AddStep("set value to default", () => testDisplay.Current.Value = 50);
|
||||
AddUntilStep("colours are correct", () => testDisplay.Container.Colour == Color4.White && background.Colour == colourProvider.Background3);
|
||||
|
||||
AddStep("set value to less", () => testDisplay.Value = 40);
|
||||
AddStep("set value to less", () => testDisplay.Current.Value = 40);
|
||||
AddUntilStep("colours are correct", () => testDisplay.Container.Colour == colourProvider.Background5 && background.Colour == colours.ForModType(ModType.DifficultyReduction));
|
||||
|
||||
AddStep("set value to bigger", () => testDisplay.Value = 60);
|
||||
AddStep("set value to bigger", () => testDisplay.Current.Value = 60);
|
||||
AddUntilStep("colours are correct", () => testDisplay.Container.Colour == colourProvider.Background5 && background.Colour == colours.ForModType(ModType.DifficultyIncrease));
|
||||
}
|
||||
|
||||
private class TestDisplay : ModsEffectDisplay
|
||||
private class TestDisplay : ModsEffectDisplay<int>
|
||||
{
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
public Container<Drawable> Container => Content;
|
||||
|
||||
protected override LocalisableString Label => "Test display";
|
||||
|
||||
public int Value
|
||||
{
|
||||
set
|
||||
{
|
||||
text.Text = value.ToString();
|
||||
SetColours(value.CompareTo(50));
|
||||
}
|
||||
}
|
||||
protected override ModEffect CalculateEffect(int value) => CalculateForSign(value.CompareTo(50));
|
||||
|
||||
public TestDisplay()
|
||||
{
|
||||
|
@ -80,8 +72,11 @@ public TestDisplay()
|
|||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load() => SetColours(0);
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Current.BindValueChanged(e => text.Text = e.NewValue.ToString(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
|
||||
#nullable disable
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
@ -18,22 +16,17 @@
|
|||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public sealed class DifficultyMultiplierDisplay : ModsEffectDisplay, IHasCurrentValue<double>
|
||||
public sealed class DifficultyMultiplierDisplay : ModsEffectDisplay<double>
|
||||
{
|
||||
protected override LocalisableString Label => DifficultyMultiplierDisplayStrings.DifficultyMultiplier;
|
||||
|
||||
public Bindable<double> Current
|
||||
{
|
||||
get => current.Current;
|
||||
set => current.Current = value;
|
||||
}
|
||||
|
||||
private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>(1);
|
||||
protected override ModEffect CalculateEffect(double value) => CalculateForSign(value.CompareTo(1d));
|
||||
|
||||
private readonly MultiplierCounter multiplierCounter;
|
||||
|
||||
public DifficultyMultiplierDisplay()
|
||||
{
|
||||
Current.Default = 1d;
|
||||
Current.Value = 1d;
|
||||
Add(new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
|
@ -63,11 +56,9 @@ protected override void LoadComplete()
|
|||
{
|
||||
base.LoadComplete();
|
||||
|
||||
current.BindValueChanged(e => SetColours(e.NewValue.CompareTo(current.Default)), true);
|
||||
|
||||
// required to prevent the counter initially rolling up from 0 to 1
|
||||
// due to `Current.Value` having a nonstandard default value of 1.
|
||||
multiplierCounter.SetCountWithoutRolling(current.Value);
|
||||
multiplierCounter.SetCountWithoutRolling(Current.Value);
|
||||
}
|
||||
|
||||
private class MultiplierCounter : RollingCounter<double>
|
||||
|
|
|
@ -153,7 +153,7 @@ private void load(OsuGameBase game, OsuColour colours, AudioManager audio)
|
|||
{
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
Top = (ShowTotalMultiplier ? ModsEffectDisplay.HEIGHT : 0) + PADDING,
|
||||
Top = (ShowTotalMultiplier ? ModsEffectDisplay<int>.HEIGHT : 0) + PADDING,
|
||||
Bottom = PADDING
|
||||
},
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
|
@ -191,7 +191,7 @@ private void load(OsuGameBase game, OsuColour colours, AudioManager audio)
|
|||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Height = ModsEffectDisplay.HEIGHT,
|
||||
Height = ModsEffectDisplay<int>.HEIGHT,
|
||||
Margin = new MarginPadding { Horizontal = 100 },
|
||||
Child = multiplierDisplay = new DifficultyMultiplierDisplay
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue