2019-02-15 15:17:01 +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.
|
|
|
|
|
2019-02-15 15:38:27 +08:00
|
|
|
using NUnit.Framework;
|
2019-02-18 17:58:34 +08:00
|
|
|
using osu.Framework.Configuration;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Beatmaps;
|
2019-02-15 15:17:01 +08:00
|
|
|
using osu.Game.Graphics;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2019-02-18 17:58:34 +08:00
|
|
|
using osu.Game.Scoring;
|
2019-02-15 15:17:01 +08:00
|
|
|
using osu.Game.Screens;
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
|
|
|
using osu.Game.Screens.Play;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2019-02-18 18:53:55 +08:00
|
|
|
using osu.Game.Users;
|
2019-02-19 18:44:26 +08:00
|
|
|
using osuTK;
|
2019-02-18 18:53:55 +08:00
|
|
|
using osuTK.Graphics;
|
2019-02-15 15:17:01 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-02-15 15:38:27 +08:00
|
|
|
[TestFixture]
|
2019-02-19 18:44:26 +08:00
|
|
|
public class TestCaseBackgroundScreenBeatmap : ScreenTestCase
|
2019-02-15 15:17:01 +08:00
|
|
|
{
|
2019-02-19 18:44:26 +08:00
|
|
|
private DummySongSelect songSelect;
|
|
|
|
protected Player Player;
|
|
|
|
public TestCaseBackgroundScreenBeatmap()
|
2019-02-18 17:12:45 +08:00
|
|
|
{
|
2019-02-19 18:44:26 +08:00
|
|
|
AddStep("Load Song Select", () =>
|
|
|
|
{
|
|
|
|
LoadComponentAsync(new DummySongSelect(), p =>
|
|
|
|
{
|
|
|
|
songSelect = p;
|
|
|
|
LoadScreen(p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load");
|
|
|
|
AddStep("Create beatmap", () =>
|
|
|
|
{
|
|
|
|
Beatmap.Value = new TestWorkingBeatmap(new Beatmap<OsuHitObject>
|
|
|
|
{
|
|
|
|
HitObjects =
|
|
|
|
{
|
2019-02-19 18:57:55 +08:00
|
|
|
new HitCircle
|
2019-02-19 18:44:26 +08:00
|
|
|
{
|
|
|
|
StartTime = 3000,
|
|
|
|
Position = new Vector2(0, 0),
|
|
|
|
},
|
2019-02-19 18:57:55 +08:00
|
|
|
new HitCircle
|
2019-02-19 18:44:26 +08:00
|
|
|
{
|
|
|
|
StartTime = 15000,
|
|
|
|
Position = new Vector2(0, 0),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
AddStep("Load Player", () =>
|
|
|
|
{
|
|
|
|
var p = new DimAccessiblePlayer();
|
|
|
|
songSelect.Push(Player = p);
|
|
|
|
});
|
2019-02-18 17:12:45 +08:00
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
AddUntilStep(() => Player?.IsLoaded ?? false, "Wait for player to load");
|
|
|
|
AddStep("Update bindables", () => ((DimAccessiblePlayer)Player).UpdateBindables());
|
2019-02-18 17:58:34 +08:00
|
|
|
}
|
|
|
|
|
2019-02-18 18:53:55 +08:00
|
|
|
/// <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 15:50:37 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the fade container is properly being faded when screen dim is enabled.
|
|
|
|
/// </summary>
|
2019-02-15 15:17:01 +08:00
|
|
|
[Test]
|
|
|
|
public void EnableUserDimTest()
|
|
|
|
{
|
2019-02-18 17:58:34 +08:00
|
|
|
AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true);
|
2019-02-15 15:38:27 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-19 18:44:26 +08:00
|
|
|
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed());
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
|
|
|
|
2019-02-15 15:50:37 +08:00
|
|
|
/// <summary>
|
2019-02-18 18:53:55 +08:00
|
|
|
/// Check if the fade container retains dim when pausing
|
2019-02-15 15:50:37 +08:00
|
|
|
/// </summary>
|
2019-02-15 15:38:27 +08:00
|
|
|
[Test]
|
2019-02-18 18:53:55 +08:00
|
|
|
public void PauseTest()
|
2019-02-15 15:38:27 +08:00
|
|
|
{
|
2019-02-19 18:44:26 +08:00
|
|
|
AddStep("Transition to Pause", () => ((DimAccessiblePlayer)Player).Exit());
|
2019-02-15 15:38:27 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
2019-02-19 18:44:26 +08:00
|
|
|
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed());
|
2019-02-18 18:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-02-19 18:44:26 +08:00
|
|
|
/// Check if the fade container removes user dim when suspending player for results
|
2019-02-18 18:53:55 +08:00
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TransitionTest()
|
|
|
|
{
|
2019-02-19 18:44:26 +08:00
|
|
|
AddStep("Transition to Results", () => Player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }})));
|
|
|
|
AddWaitStep(5, "Wait for dim");
|
|
|
|
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Check if background gets undimmed when leaving the player for the previous screen
|
|
|
|
/// </summary>
|
|
|
|
[Test]
|
|
|
|
public void TransitionOutTest()
|
|
|
|
{
|
|
|
|
AddStep("Exit player", () =>
|
|
|
|
{
|
|
|
|
Player.MakeCurrent();
|
|
|
|
Player.Exit();
|
|
|
|
});
|
2019-02-18 18:53:55 +08:00
|
|
|
AddWaitStep(5, "Wait for dim");
|
|
|
|
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
|
2019-02-15 15:38:27 +08:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
private class DummySongSelect : OsuScreen
|
|
|
|
{
|
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
|
|
|
}
|
2019-02-15 15:17:01 +08:00
|
|
|
|
2019-02-18 18:53:55 +08:00
|
|
|
private class FadeAccesibleResults : SoloResults
|
|
|
|
{
|
|
|
|
public FadeAccesibleResults(ScoreInfo score) : base(score)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
|
|
|
}
|
|
|
|
|
2019-02-15 15:17:01 +08:00
|
|
|
private class DimAccessiblePlayer : Player
|
|
|
|
{
|
2019-02-18 17:58:34 +08:00
|
|
|
public Bindable<bool> DimEnabled;
|
2019-02-18 11:55:42 +08:00
|
|
|
|
2019-02-18 17:58:34 +08:00
|
|
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
2019-02-15 15:17:01 +08:00
|
|
|
|
2019-02-18 17:58:34 +08:00
|
|
|
public void UpdateBindables()
|
2019-02-15 15:17:01 +08:00
|
|
|
{
|
2019-02-20 15:56:57 +08:00
|
|
|
DimEnabled = Background.EnableUserDim;
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:44:26 +08:00
|
|
|
public bool AssertDimmed()
|
2019-02-15 15:17:01 +08:00
|
|
|
{
|
2019-02-19 18:44:26 +08:00
|
|
|
return ((FadeAccessibleBackground)Background).AssertDimmed();
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
|
|
|
|
2019-02-15 15:38:27 +08:00
|
|
|
public bool AssertUndimmed()
|
|
|
|
{
|
|
|
|
return ((FadeAccessibleBackground)Background).AssertUndimmed();
|
|
|
|
}
|
2019-02-18 18:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class FadeAccessibleBackground : BackgroundScreenBeatmap
|
|
|
|
{
|
2019-02-19 18:44:26 +08:00
|
|
|
public bool AssertDimmed()
|
2019-02-18 18:53:55 +08:00
|
|
|
{
|
|
|
|
return FadeContainer.Colour == OsuColour.Gray(1 - (float)DimLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool AssertUndimmed()
|
2019-02-15 15:17:01 +08:00
|
|
|
{
|
2019-02-18 18:53:55 +08:00
|
|
|
return FadeContainer.Colour == Color4.White;
|
2019-02-15 15:17:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|