mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 00:52:57 +08:00
Add test case for background preview, fix unit tests
This commit is contained in:
parent
f5d8700920
commit
ad5e81f0cd
@ -1,8 +1,11 @@
|
||||
// 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.
|
||||
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
@ -11,6 +14,7 @@ using osu.Game.Scoring;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Play.PlayerSettings;
|
||||
using osu.Game.Tests.Beatmaps;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
@ -19,20 +23,30 @@ using osuTK.Graphics;
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestCaseBackgroundScreenBeatmap : ScreenTestCase
|
||||
public class TestCaseBackgroundScreenBeatmap : ManualInputManagerTestCase
|
||||
{
|
||||
private DummySongSelect songSelect;
|
||||
protected Player Player;
|
||||
private DimAccessiblePlayerLoader playerLoader;
|
||||
private DimAccessiblePlayer player;
|
||||
|
||||
[Cached]
|
||||
private BackgroundScreenStack backgroundStack;
|
||||
|
||||
public TestCaseBackgroundScreenBeatmap()
|
||||
{
|
||||
ScreenStack screen;
|
||||
InputManager.Add(backgroundStack = new BackgroundScreenStack {RelativeSizeAxes = Axes.Both});
|
||||
InputManager.Add(screen = new ScreenStack { RelativeSizeAxes = Axes.Both });
|
||||
|
||||
AddStep("Load Song Select", () =>
|
||||
{
|
||||
LoadComponentAsync(new DummySongSelect(), p =>
|
||||
{
|
||||
songSelect = p;
|
||||
LoadScreen(p);
|
||||
screen.Push(p);
|
||||
});
|
||||
});
|
||||
|
||||
AddUntilStep(() => songSelect?.IsLoaded ?? false, "Wait for song select to load");
|
||||
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();
|
||||
songSelect.Push(Player = p);
|
||||
InputManager.MoveMouseTo(playerLoader.ScreenPos);
|
||||
InputManager.MoveMouseTo(playerLoader.VisualSettingsPos);
|
||||
});
|
||||
|
||||
AddUntilStep(() => Player?.IsLoaded ?? false, "Wait for player to load");
|
||||
AddStep("Update bindables", () => ((DimAccessiblePlayer)Player).UpdateBindables());
|
||||
AddWaitStep(5, "Wait for dim");
|
||||
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>
|
||||
@ -69,9 +99,9 @@ namespace osu.Game.Tests.Visual
|
||||
[Test]
|
||||
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");
|
||||
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
|
||||
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -80,9 +110,9 @@ namespace osu.Game.Tests.Visual
|
||||
[Test]
|
||||
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");
|
||||
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed());
|
||||
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -91,9 +121,9 @@ namespace osu.Game.Tests.Visual
|
||||
[Test]
|
||||
public void PauseTest()
|
||||
{
|
||||
AddStep("Transition to Pause", () => ((DimAccessiblePlayer)Player).Exit());
|
||||
AddStep("Transition to Pause", () => player.Exit());
|
||||
AddWaitStep(5, "Wait for dim");
|
||||
AddAssert("Screen is dimmed", () => ((DimAccessiblePlayer)Player).AssertDimmed());
|
||||
AddAssert("Screen is dimmed", () => songSelect.AssertDimmed());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -102,9 +132,9 @@ namespace osu.Game.Tests.Visual
|
||||
[Test]
|
||||
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");
|
||||
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
|
||||
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -115,16 +145,28 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
AddStep("Exit player", () =>
|
||||
{
|
||||
Player.MakeCurrent();
|
||||
Player.Exit();
|
||||
player.MakeCurrent();
|
||||
player.Exit();
|
||||
});
|
||||
AddWaitStep(5, "Wait for dim");
|
||||
AddAssert("Screen is undimmed", () => ((DimAccessiblePlayer)Player).AssertUndimmed());
|
||||
AddAssert("Screen is undimmed", () => songSelect.AssertUndimmed());
|
||||
}
|
||||
|
||||
private class DummySongSelect : OsuScreen
|
||||
{
|
||||
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
|
||||
@ -137,25 +179,35 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground();
|
||||
public VisualSettings VisualSettingsPos => VisualSettings;
|
||||
public Vector2 ScreenPos => VisualSettings.ScreenSpaceDrawQuad.BottomLeft - new Vector2(20, 20);
|
||||
|
||||
public void UpdateBindables()
|
||||
{
|
||||
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
|
||||
|
@ -37,9 +37,12 @@ namespace osu.Game.Screens.Backgrounds
|
||||
|
||||
beatmap = value;
|
||||
|
||||
FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both };
|
||||
InternalChild = FadeContainer;
|
||||
EnableUserDim = FadeContainer.EnableUserDim;
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
FadeContainer = new UserDimContainer { RelativeSizeAxes = Axes.Both };
|
||||
LoadComponentAsync(new BeatmapBackground(beatmap), b => Schedule(() =>
|
||||
{
|
||||
float newDepth = 0;
|
||||
@ -54,8 +57,6 @@ namespace osu.Game.Screens.Backgrounds
|
||||
FadeContainer.Child = Background = b;
|
||||
Background.BlurSigma = BlurTarget;
|
||||
}));
|
||||
InternalChild = FadeContainer;
|
||||
EnableUserDim = FadeContainer.EnableUserDim;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -346,6 +346,10 @@ namespace osu.Game.Screens.Play
|
||||
.Delay(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;
|
||||
|
||||
Task.Run(() =>
|
||||
|
@ -78,7 +78,7 @@ namespace osu.Game.Screens.Play
|
||||
Margin = new MarginPadding(25),
|
||||
Children = new PlayerSettingsGroup[]
|
||||
{
|
||||
visualSettings = new VisualSettings(),
|
||||
VisualSettings = new VisualSettings(),
|
||||
new InputSettings()
|
||||
}
|
||||
}
|
||||
@ -153,7 +153,7 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
|
||||
private ScheduledDelegate pushDebounce;
|
||||
private VisualSettings visualSettings;
|
||||
protected VisualSettings VisualSettings;
|
||||
|
||||
private bool readyForPush => player.LoadState == LoadState.Ready && IsHovered && GetContainingInputManager()?.DraggedDrawable == null;
|
||||
|
||||
@ -161,14 +161,14 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
// restore our screen defaults
|
||||
InitializeBackgroundElements();
|
||||
if (this.IsCurrentScreen())
|
||||
if (this.IsCurrentScreen() && (Background?.IsLoaded ?? false))
|
||||
Background.EnableUserDim.Value = false;
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
if (GetContainingInputManager()?.HoveredDrawables.Contains(visualSettings) == true)
|
||||
if (GetContainingInputManager()?.HoveredDrawables.Contains(VisualSettings) == true)
|
||||
{
|
||||
// show user setting preview
|
||||
UpdateBackgroundElements();
|
||||
@ -247,7 +247,8 @@ namespace osu.Game.Screens.Play
|
||||
this.FadeOut(150);
|
||||
cancelLoad();
|
||||
|
||||
Background.EnableUserDim.Value = false;
|
||||
if (Background != null)
|
||||
Background.EnableUserDim.Value = false;
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
@ -37,11 +37,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
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);
|
||||
DimLevel.ValueChanged += _ => UpdateBackgroundElements();
|
||||
BlurLevel.ValueChanged += _ => UpdateBackgroundElements();
|
||||
ShowStoryboard.ValueChanged += _ => UpdateBackgroundElements();
|
||||
InitializeBackgroundElements();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user