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

Adjust inheritors and test

This commit is contained in:
ansel 2022-08-29 22:48:45 +03:00
parent 5343c26452
commit 545e0bbcef
3 changed files with 17 additions and 31 deletions

View File

@ -44,32 +44,24 @@ namespace osu.Game.Tests.Visual.UserInterface
background = boxes.First(); 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); 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)); 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)); 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; private readonly OsuSpriteText text;
public Container<Drawable> Container => Content; public Container<Drawable> Container => Content;
protected override LocalisableString Label => "Test display"; protected override LocalisableString Label => "Test display";
protected override ModEffect CalculateEffect(int value) => CalculateForSign(value.CompareTo(50));
public int Value
{
set
{
text.Text = value.ToString();
SetColours(value.CompareTo(50));
}
}
public TestDisplay() public TestDisplay()
{ {
@ -80,8 +72,11 @@ namespace osu.Game.Tests.Visual.UserInterface
}); });
} }
[BackgroundDependencyLoader] protected override void LoadComplete()
private void load() => SetColours(0); {
base.LoadComplete();
Current.BindValueChanged(e => text.Text = e.NewValue.ToString(), true);
}
} }
} }
} }

View File

@ -3,12 +3,10 @@
#nullable disable #nullable disable
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -18,22 +16,17 @@ using osu.Game.Localisation;
namespace osu.Game.Overlays.Mods namespace osu.Game.Overlays.Mods
{ {
public sealed class DifficultyMultiplierDisplay : ModsEffectDisplay, IHasCurrentValue<double> public sealed class DifficultyMultiplierDisplay : ModsEffectDisplay<double>
{ {
protected override LocalisableString Label => DifficultyMultiplierDisplayStrings.DifficultyMultiplier; protected override LocalisableString Label => DifficultyMultiplierDisplayStrings.DifficultyMultiplier;
protected override ModEffect CalculateEffect(double value) => CalculateForSign(value.CompareTo(1d));
public Bindable<double> Current
{
get => current.Current;
set => current.Current = value;
}
private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>(1);
private readonly MultiplierCounter multiplierCounter; private readonly MultiplierCounter multiplierCounter;
public DifficultyMultiplierDisplay() public DifficultyMultiplierDisplay()
{ {
Current.Default = 1d;
Current.Value = 1d;
Add(new FillFlowContainer Add(new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -63,11 +56,9 @@ namespace osu.Game.Overlays.Mods
{ {
base.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 // required to prevent the counter initially rolling up from 0 to 1
// due to `Current.Value` having a nonstandard default value of 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> private class MultiplierCounter : RollingCounter<double>

View File

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