osu/osu.Game.Tests/Visual/TestCaseBackgroundScreenBea...

128 lines
4.1 KiB
C#
Raw Normal View History

2019-02-15 07:17:01 +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.
2019-02-15 07:38:27 +00:00
using NUnit.Framework;
using osu.Framework.Configuration;
2019-02-15 07:17:01 +00:00
using osu.Game.Graphics;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
2019-02-15 07:17:01 +00:00
using osu.Game.Screens;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
using osu.Game.Users;
using osuTK.Graphics;
2019-02-15 07:17:01 +00:00
namespace osu.Game.Tests.Visual
{
2019-02-15 07:38:27 +00:00
[TestFixture]
2019-02-15 07:17:01 +00:00
public class TestCaseBackgroundScreenBeatmap : TestCasePlayer
{
public TestCaseBackgroundScreenBeatmap() : base(new OsuRuleset())
{
}
[SetUp]
public void Setup()
{
((DimAccessiblePlayer)Player).UpdateBindables();
}
/// <summary>
/// Check if the fade container is properly being reset when screen dim is disabled.
/// </summary>
[Test]
public void DisableUserDimTest()
{
AddStep("Test User Undimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = false);
AddWaitStep(5, "Wait for dim");
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
}
2019-02-15 07:50:37 +00:00
/// <summary>
/// Check if the fade container is properly being faded when screen dim is enabled.
/// </summary>
2019-02-15 07:17:01 +00:00
[Test]
public void EnableUserDimTest()
{
AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true);
2019-02-15 07:38:27 +00:00
AddWaitStep(5, "Wait for dim");
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimState());
2019-02-15 07:17:01 +00:00
}
2019-02-15 07:50:37 +00:00
/// <summary>
/// Check if the fade container retains dim when pausing
2019-02-15 07:50:37 +00:00
/// </summary>
2019-02-15 07:38:27 +00:00
[Test]
public void PauseTest()
2019-02-15 07:38:27 +00:00
{
AddStep("Transition to Results", () => ((DimAccessiblePlayer)Player).TriggerExit());
2019-02-15 07:38:27 +00:00
AddWaitStep(5, "Wait for dim");
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimState());
}
/// <summary>
/// Check if the fade container removes user dim when leaving the player
/// </summary>
[Test]
public void TransitionTest()
{
AddStep("Transition to Results", () => LoadScreen(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }})));
AddWaitStep(5, "Wait for dim");
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
2019-02-15 07:38:27 +00:00
}
2019-02-15 07:17:01 +00:00
protected override Player CreatePlayer(Ruleset ruleset) => new DimAccessiblePlayer();
private class FadeAccesibleResults : SoloResults
{
public FadeAccesibleResults(ScoreInfo score) : base(score)
{
}
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
}
2019-02-15 07:17:01 +00:00
private class DimAccessiblePlayer : Player
{
public Bindable<bool> DimEnabled;
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
2019-02-15 07:17:01 +00:00
public void UpdateBindables()
2019-02-15 07:17:01 +00:00
{
DimEnabled = Background.UpdateDim;
2019-02-15 07:17:01 +00:00
}
public bool AssertDimState()
{
return ((FadeAccessibleBackground)Background).AssertDimState();
}
2019-02-15 07:38:27 +00:00
public bool AssertUndimmed()
{
return ((FadeAccessibleBackground)Background).AssertUndimmed();
}
public void TriggerExit()
{
OnExiting(new PlaySongSelect());
}
}
private class FadeAccessibleBackground : BackgroundScreenBeatmap
{
public bool AssertDimState()
{
return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel);
}
public bool AssertUndimmed()
2019-02-15 07:17:01 +00:00
{
return FadeContainer.Colour == Color4.White;
2019-02-15 07:17:01 +00:00
}
}
}
}