mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 04:03:22 +08:00
Add tests to make sure the background is always the same through screen transitions
This commit is contained in:
parent
94bc552282
commit
65cdac60c3
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -26,6 +28,13 @@ namespace osu.Game.Tests.Visual
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase
|
public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase
|
||||||
{
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(ScreenWithBeatmapBackground),
|
||||||
|
typeof(PlayerLoader),
|
||||||
|
typeof(Player)
|
||||||
|
};
|
||||||
|
|
||||||
private DummySongSelect songSelect;
|
private DummySongSelect songSelect;
|
||||||
private DimAccessiblePlayerLoader playerLoader;
|
private DimAccessiblePlayerLoader playerLoader;
|
||||||
private DimAccessiblePlayer player;
|
private DimAccessiblePlayer player;
|
||||||
@ -36,11 +45,13 @@ namespace osu.Game.Tests.Visual
|
|||||||
public TestCaseBackgroundScreenBeatmap()
|
public TestCaseBackgroundScreenBeatmap()
|
||||||
{
|
{
|
||||||
ScreenStack screen;
|
ScreenStack screen;
|
||||||
|
|
||||||
InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both});
|
InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both});
|
||||||
InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
||||||
|
|
||||||
AddStep("Load Song Select", () =>
|
AddStep("Load Song Select", () =>
|
||||||
{
|
{
|
||||||
|
songSelect?.MakeCurrent();
|
||||||
songSelect?.Exit();
|
songSelect?.Exit();
|
||||||
|
|
||||||
LoadComponentAsync(new DummySongSelect(), p =>
|
LoadComponentAsync(new DummySongSelect(), p =>
|
||||||
@ -73,6 +84,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())));
|
AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())));
|
||||||
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
|
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
|
||||||
|
AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent());
|
||||||
|
|
||||||
AddStep("Update bindables", () => playerLoader.UpdateBindables());
|
AddStep("Update bindables", () => playerLoader.UpdateBindables());
|
||||||
AddStep("Trigger background preview", () =>
|
AddStep("Trigger background preview", () =>
|
||||||
{
|
{
|
||||||
@ -93,6 +106,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
// The OnHover of PlayerLoader will trigger, which could potentially trigger an undim unless checked for in PlayerLoader.
|
// The OnHover of PlayerLoader will trigger, which could potentially trigger an undim unless checked for in PlayerLoader.
|
||||||
// We need to check that in this scenario, the dim is still properly applied after entering player.
|
// We need to check that in this scenario, the dim is still properly applied after entering player.
|
||||||
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
|
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
|
||||||
|
AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent());
|
||||||
AddStep("Trigger background preview when loaded", () =>
|
AddStep("Trigger background preview when loaded", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
|
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
|
||||||
@ -142,7 +156,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
[Test]
|
[Test]
|
||||||
public void PauseTest()
|
public void PauseTest()
|
||||||
{
|
{
|
||||||
AddStep("Transition to Pause", () => player.Exit());
|
AddStep("Transition to Pause", () =>
|
||||||
|
{
|
||||||
|
if (!player.IsPaused)
|
||||||
|
player.Exit();
|
||||||
|
});
|
||||||
AddWaitStep(5, "Wait for dim");
|
AddWaitStep(5, "Wait for dim");
|
||||||
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
||||||
}
|
}
|
||||||
@ -156,6 +174,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }})));
|
AddStep("Transition to Results", () => player.Push(new FadeAccesibleResults(new ScoreInfo { User = new User { Username = "osu!" }})));
|
||||||
AddWaitStep(5, "Wait for dim");
|
AddWaitStep(5, "Wait for dim");
|
||||||
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
||||||
|
AddAssert("Background retained from song select", () => songSelect.AssertBackgroundCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -196,6 +215,15 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
return ((FadeAccessibleBackground)Background).AssertVisible();
|
return ((FadeAccessibleBackground)Background).AssertVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure every time a screen gets pushed, the background doesn't get replaced
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether or not the original background is still the current background</returns>
|
||||||
|
public bool AssertBackgroundCurrent()
|
||||||
|
{
|
||||||
|
return ((FadeAccessibleBackground)Background).IsCurrentScreen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FadeAccesibleResults : SoloResults
|
private class FadeAccesibleResults : SoloResults
|
||||||
@ -216,6 +244,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
public Bindable<bool> StoryboardEnabled;
|
public Bindable<bool> StoryboardEnabled;
|
||||||
public readonly Bindable<bool> ReplacesBackground = new Bindable<bool>();
|
public readonly Bindable<bool> ReplacesBackground = new Bindable<bool>();
|
||||||
|
|
||||||
|
public bool IsPaused => RulesetContainer.IsPaused;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
private void load(OsuConfigManager config)
|
||||||
{
|
{
|
||||||
@ -233,6 +263,9 @@ namespace osu.Game.Tests.Visual
|
|||||||
public VisualSettings VisualSettingsPos => VisualSettings;
|
public VisualSettings VisualSettingsPos => VisualSettings;
|
||||||
public BackgroundScreen ScreenPos => Background;
|
public BackgroundScreen ScreenPos => Background;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BackgroundScreenStack stack { get; set; }
|
||||||
|
|
||||||
public void UpdateBindables()
|
public void UpdateBindables()
|
||||||
{
|
{
|
||||||
DimEnabled = Background.EnableUserDim;
|
DimEnabled = Background.EnableUserDim;
|
||||||
|
@ -15,7 +15,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
|
||||||
|
|
||||||
protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap;
|
protected new BackgroundScreenBeatmap Background => (BackgroundScreenBeatmap)base.Background;
|
||||||
|
|
||||||
protected const float BACKGROUND_FADE_DURATION = 800;
|
protected const float BACKGROUND_FADE_DURATION = 800;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user