1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 16:03:01 +08:00

Add test case for background preview, fix unit tests

This commit is contained in:
David Zhao 2019-02-21 15:24:26 +09:00
parent f5d8700920
commit ad5e81f0cd
5 changed files with 93 additions and 38 deletions

View File

@ -1,8 +1,11 @@
// 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.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -11,6 +14,7 @@ using osu.Game.Scoring;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -19,20 +23,30 @@ using osuTK.Graphics;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
[TestFixture] [TestFixture]
public class TestCaseBackgroundScreenBeatmap : ScreenTestCase public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase
{ {
private DummySongSelect songSelect; private DummySongSelect songSelect;
protected Player Player; private DimAccessiblePlayerLoader playerLoader;
private DimAccessiblePlayer player;
[Cached]
private BackgroundScreenStack backgroundStack;
public TestCaseBackgroundScreenBeatmap() public TestCaseBackgroundScreenBeatmap()
{ {
ScreenStack screen;
InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both});
InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both });
AddStep("Load Song Select", () => AddStep("Load Song Select", () =>
{ {
LoadComponentAsync(new DummySongSelect(), p => LoadComponentAsync(new DummySongSelect(), p =>
{ {
songSelect = p; songSelect = p;
LoadScreen(p); screen.Push(p);
}); });
}); });
AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load"); AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load");
AddStep("Create beatmap", () => AddStep("Create beatmap", () =>
{ {
@ -53,14 +67,30 @@ namespace osu.Game.Tests.Visual
}, },
}); });
}); });
AddStep("Load Player", () =>
AddStep("Start player loader", () => songSelect.Push(playerLoader = new DimAccessiblePlayerLoader(player = new DimAccessiblePlayer())));
AddUntilStep(() => playerLoader?.IsLoaded ?? false, "Wait for Player Loader to load");
AddStep("Update bindables", () => playerLoader.UpdateBindables());
AddStep("Trigger background preview", () =>
{ {
var p = new DimAccessiblePlayer(); InputManager.MoveMouseTo(playerLoader.ScreenPos);
songSelect.Push(Player = p); InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
}); });
AddUntilStep(() => Player?.IsLoaded ?? false, "Wait for player to load"); AddWaitStep(5, "Wait for dim");
AddStep("Update bindables", () => ((DimAccessiblePlayer)Player).UpdateBindables()); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
AddStep("Allow beatmap to load", () =>
{
player.Ready = true;
InputManager.MoveMouseTo(playerLoader.ScreenPos);
});
// In the case of a user triggering the dim preview the instant player gets loaded, the user dim needs to be applied when the map starts.
AddUntilStep(() => player?.IsLoaded ?? false, "Wait for player to load");
AddStep("Trigger background preview when loaded", () => InputManager.MoveMouseTo(playerLoader.VisualSettingsPos));
AddWaitStep(5, "Wait for dim");
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
} }
/// <summary> /// <summary>
@ -69,9 +99,9 @@ namespace osu.Game.Tests.Visual
[Test] [Test]
public void DisableUserDimTest() public void DisableUserDimTest()
{ {
AddStep("Test User Undimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = false); AddStep("Test User Undimming", () => playerLoader.DimEnabled.Value = false);
AddWaitStep(5, "Wait for dim"); AddWaitStep(5, "Wait for dim");
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
} }
/// <summary> /// <summary>
@ -80,9 +110,9 @@ namespace osu.Game.Tests.Visual
[Test] [Test]
public void EnableUserDimTest() public void EnableUserDimTest()
{ {
AddStep("Test User Dimming", () => ((DimAccessiblePlayer)Player).DimEnabled.Value = true); AddStep("Test User Dimming", () => playerLoader.DimEnabled.Value = true);
AddWaitStep(5, "Wait for dim"); AddWaitStep(5, "Wait for dim");
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed()); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
} }
/// <summary> /// <summary>
@ -91,9 +121,9 @@ namespace osu.Game.Tests.Visual
[Test] [Test]
public void PauseTest() public void PauseTest()
{ {
AddStep("Transition to Pause", () => ((DimAccessiblePlayer)Player).Exit()); AddStep("Transition to Pause", () => player.Exit());
AddWaitStep(5, "Wait for dim"); AddWaitStep(5, "Wait for dim");
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed()); AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
} }
/// <summary> /// <summary>
@ -102,9 +132,9 @@ namespace osu.Game.Tests.Visual
[Test] [Test]
public void TransitionTest() public void TransitionTest()
{ {
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", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
} }
/// <summary> /// <summary>
@ -115,16 +145,28 @@ namespace osu.Game.Tests.Visual
{ {
AddStep("Exit player", () => AddStep("Exit player", () =>
{ {
Player.MakeCurrent(); player.MakeCurrent();
Player.Exit(); player.Exit();
}); });
AddWaitStep(5, "Wait for dim"); AddWaitStep(5, "Wait for dim");
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed()); AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
} }
private class DummySongSelect : OsuScreen private class DummySongSelect : OsuScreen
{ {
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
public bool BackgroundLoaded => Background?.IsLoaded ?? false;
public bool AssertDimmed()
{
return ((FadeAccessibleBackground)Background).AssertDimmed();
}
public bool AssertUndimmed()
{
return ((FadeAccessibleBackground)Background).AssertUndimmed();
}
} }
private class FadeAccesibleResults : SoloResults private class FadeAccesibleResults : SoloResults
@ -137,25 +179,35 @@ namespace osu.Game.Tests.Visual
} }
private class DimAccessiblePlayer : Player private class DimAccessiblePlayer : Player
{
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
public bool Ready;
[BackgroundDependencyLoader]
private void load()
{
while (!Ready)
Thread.Sleep(1);
}
}
private class DimAccessiblePlayerLoader : PlayerLoader
{ {
public Bindable<bool> DimEnabled; public Bindable<bool> DimEnabled;
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(); public VisualSettings VisualSettingsPos => VisualSettings;
public Vector2 ScreenPos => VisualSettings.ScreenSpaceDrawQuad.BottomLeft - new Vector2(20, 20);
public void UpdateBindables() public void UpdateBindables()
{ {
DimEnabled = Background.EnableUserDim; DimEnabled = Background.EnableUserDim;
} }
public bool AssertDimmed() public DimAccessiblePlayerLoader(Player player) : base(() => player)
{ {
return ((FadeAccessibleBackground)Background).AssertDimmed();
}
public bool AssertUndimmed()
{
return ((FadeAccessibleBackground)Background).AssertUndimmed();
} }
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
} }
private class FadeAccessibleBackground : BackgroundScreenBeatmap private class FadeAccessibleBackground : BackgroundScreenBeatmap

View File

@ -37,9 +37,12 @@ namespace osu.Game.Screens.Backgrounds
beatmap = value; beatmap = value;
FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both };
InternalChild = FadeContainer;
EnableUserDim = FadeContainer.EnableUserDim;
Schedule(() => Schedule(() =>
{ {
FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both };
LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() => LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() =>
{ {
float newDepth = 0; float newDepth = 0;
@ -54,8 +57,6 @@ namespace osu.Game.Screens.Backgrounds
FadeContainer.Child = Background = b; FadeContainer.Child = Background = b;
Background.BlurSigma = BlurTarget; Background.BlurSigma = BlurTarget;
})); }));
InternalChild = FadeContainer;
EnableUserDim = FadeContainer.EnableUserDim;
}); });
} }
} }

View File

@ -346,6 +346,10 @@ namespace osu.Game.Screens.Play
.Delay(250) .Delay(250)
.FadeIn(250); .FadeIn(250);
// We need to update background elements when the user dim gets updated
// The storyboard needs to know whether or not to completely fade at 100% dim
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
Background.EnableUserDim.Value = true; Background.EnableUserDim.Value = true;
Task.Run(() => Task.Run(() =>

View File

@ -78,7 +78,7 @@ namespace osu.Game.Screens.Play
Margin = new MarginPadding(25), Margin = new MarginPadding(25),
Children = new PlayerSettingsGroup[] Children = new PlayerSettingsGroup[]
{ {
visualSettings = new VisualSettings(), VisualSettings = new VisualSettings(),
new InputSettings() new InputSettings()
} }
} }
@ -153,7 +153,7 @@ namespace osu.Game.Screens.Play
} }
private ScheduledDelegate pushDebounce; private ScheduledDelegate pushDebounce;
private VisualSettings visualSettings; protected VisualSettings VisualSettings;
private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null; private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null;
@ -161,14 +161,14 @@ namespace osu.Game.Screens.Play
{ {
// restore our screen defaults // restore our screen defaults
InitializeBackgroundElements(); InitializeBackgroundElements();
if (this.IsCurrentScreen()) if (this.IsCurrentScreen() && (Background?.IsLoaded ?? false))
Background.EnableUserDim.Value = false; Background.EnableUserDim.Value = false;
return base.OnHover(e); return base.OnHover(e);
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
if (GetContainingInputManager()?.HoveredDrawables.Contains(visualSettings) == true) if (GetContainingInputManager()?.HoveredDrawables.Contains(VisualSettings) == true)
{ {
// show user setting preview // show user setting preview
UpdateBackgroundElements(); UpdateBackgroundElements();
@ -247,6 +247,7 @@ namespace osu.Game.Screens.Play
this.FadeOut(150); this.FadeOut(150);
cancelLoad(); cancelLoad();
if (Background != null)
Background.EnableUserDim.Value = false; Background.EnableUserDim.Value = false;
return base.OnExiting(next); return base.OnExiting(next);

View File

@ -37,11 +37,8 @@ namespace osu.Game.Screens.Play
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
{ {
// We need to update on dim here because player still needs to know if it needs to dim the storyboard
base.OnEntering(last); base.OnEntering(last);
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
BlurLevel.ValueChanged += _ => UpdateBackgroundElements(); BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
InitializeBackgroundElements(); InitializeBackgroundElements();
} }