osu/osu.Game.Tests/Visual/UserInterface/TestSceneModsEffectDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.9 KiB
C#
Raw Normal View History

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