Fix test screen loading

This commit is contained in:
Dean Herbert 2019-01-31 11:00:44 +09:00
parent beab367e6d
commit e8c39b9c37

View File

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