Fix test screen loading

This commit is contained in:
Dean Herbert 2019-01-31 11:00:44 +09:00
parent beab367e6d
commit e8c39b9c37
1 changed files with 10 additions and 26 deletions

View File

@ -1,6 +1,7 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Screens;
@ -11,38 +12,21 @@ namespace osu.Game.Tests.Visual
/// </summary>
public abstract class ScreenTestCase : OsuTestCase
{
private readonly TestOsuScreen baseScreen;
private readonly ScreenStack stack;
protected ScreenTestCase()
{
Add(baseScreen = new TestOsuScreen());
Add(stack = new ScreenStack
{
RelativeSizeAxes = Axes.Both,
});
}
protected void LoadScreen(OsuScreen screen) => baseScreen.LoadScreen(screen);
public class TestOsuScreen : OsuScreen
protected void LoadScreen(OsuScreen screen)
{
private OsuScreen nextScreen;
public void LoadScreen(OsuScreen screen) => Schedule(() =>
{
nextScreen = screen;
if (this.IsCurrentScreen())
{
this.Push(screen);
nextScreen = null;
}
else
this.MakeCurrent();
});
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
if (nextScreen != null)
LoadScreen(nextScreen);
}
if (stack.CurrentScreen != null)
stack.Exit();
stack.Push(screen);
}
}
}