1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 03:52:55 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneModsEffectDisplay.cs

83 lines
3.0 KiB
C#
Raw Normal View History

2022-08-28 01:12:45 +08:00
// 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.
2022-08-28 07:59:38 +08:00
using System.Linq;
2022-08-28 01:12:45 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2022-08-28 07:59:38 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2022-08-28 01:12:45 +08:00
using osu.Framework.Localisation;
2022-08-28 07:59:38 +08:00
using osu.Framework.Testing;
2022-08-28 01:12:45 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
2022-08-28 07:59:38 +08:00
using osu.Game.Rulesets.Mods;
using osuTK.Graphics;
2022-08-28 01:12:45 +08:00
namespace osu.Game.Tests.Visual.UserInterface
{
2022-08-28 07:59:38 +08:00
[TestFixture]
2022-08-28 01:12:45 +08:00
public class TestSceneModsEffectDisplay : OsuTestScene
{
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
2022-08-28 07:59:38 +08:00
[Resolved]
private OsuColour colours { get; set; } = null!;
2022-08-28 01:12:45 +08:00
[Test]
2022-08-28 07:59:38 +08:00
public void TestModsEffectDisplay()
2022-08-28 01:12:45 +08:00
{
2022-08-28 07:59:38 +08:00
TestDisplay testDisplay = null!;
Box background = null!;
AddStep("add display", () =>
2022-08-28 01:12:45 +08:00
{
2022-08-28 07:59:38 +08:00
Add(testDisplay = new TestDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
var boxes = testDisplay.ChildrenOfType<Box>();
background = boxes.First();
2022-08-28 01:12:45 +08:00
});
2022-08-28 07:59:38 +08:00
2022-08-30 03:48:45 +08:00
AddStep("set value to default", () => testDisplay.Current.Value = 50);
2022-08-28 07:59:38 +08:00
AddUntilStep("colours are correct", () => testDisplay.Container.Colour == Color4.White && background.Colour == colourProvider.Background3);
2022-08-30 03:48:45 +08:00
AddStep("set value to less", () => testDisplay.Current.Value = 40);
2022-08-28 07:59:38 +08:00
AddUntilStep("colours are correct", () => testDisplay.Container.Colour == colourProvider.Background5 && background.Colour == colours.ForModType(ModType.DifficultyReduction));
2022-08-30 03:48:45 +08:00
AddStep("set value to bigger", () => testDisplay.Current.Value = 60);
2022-08-28 07:59:38 +08:00
AddUntilStep("colours are correct", () => testDisplay.Container.Colour == colourProvider.Background5 && background.Colour == colours.ForModType(ModType.DifficultyIncrease));
2022-08-28 01:12:45 +08:00
}
2022-08-30 03:48:45 +08:00
private class TestDisplay : ModsEffectDisplay<int>
2022-08-28 01:12:45 +08:00
{
private readonly OsuSpriteText text;
2022-08-28 07:59:38 +08:00
public Container<Drawable> Container => Content;
2022-08-28 01:12:45 +08:00
protected override LocalisableString Label => "Test display";
2022-08-30 03:48:45 +08:00
protected override ModEffect CalculateEffect(int value) => CalculateForSign(value.CompareTo(50));
2022-08-28 01:12:45 +08:00
public TestDisplay()
{
Add(text = new OsuSpriteText
{
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold),
Text = "50"
});
}
2022-08-30 03:48:45 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindValueChanged(e => text.Text = e.NewValue.ToString(), true);
}
2022-08-28 01:12:45 +08:00
}
}
}