osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs
/// <summary>
/// Push two screens and check that they only handle input when they are respectively loaded and current.
/// </summary>
Push two screens and check that they only handle input when they are respectively loaded and current.
Push two screens and check that they only handle input when they are respectively loaded and current .
[Test]
        public void TestNonCurrentScreenDoesNotAcceptInput()
        {
            ManualInputManager inputManager = null;
            AddStep("override stack", () =>
            {
                Clear();
                Add(inputManager = new ManualInputManager
                {
                    Child = stack = new ScreenStack(baseScreen = new TestScreen())
                    {
                        RelativeSizeAxes = Axes.Both
                    }
                });
            });
            TestScreen screen1 = null;
            TestScreenSlow screen2 = null;
            pushAndEnsureCurrent(() => screen1 = new TestScreen());
            AddStep("Click center of screen", () => clickScreen(inputManager, screen1));
            AddAssert("screen 1 clicked", () => screen1.ClickCount == 1);
            AddStep("push slow", () => screen1.Push(screen2 = new TestScreenSlow()));
            AddStep("Click center of screen", () => inputManager.Click(MouseButton.Left));
            AddAssert("screen 1 not clicked", () => screen1.ClickCount == 1);
            AddAssert("Screen 2 not clicked", () => screen2.ClickCount == 0 && !screen2.IsLoaded);
            AddStep("Allow screen to load", () => screen2.AllowLoad.Set());
            AddUntilStep("ensure current", () => screen2.IsCurrentScreen());
            AddStep("Click center of screen", () => clickScreen(inputManager, screen2));
            AddAssert("screen 1 not clicked", () => screen1.ClickCount == 1);
            AddAssert("Screen 2 clicked", () => screen2.ClickCount == 1 && screen2.IsLoaded);
        }
[ Test ] public void TestNonCurrentScreenDoesNotAcceptInput ( ) { ManualInputManager inputManager = null ; AddStep ( " " , ( ) => { Clear ( ) ; Add ( inputManager = new ManualInputManager { Child = stack = new ScreenStack ( baseScreen = new TestScreen ( ) ) { RelativeSizeAxes = Axes . Both } } ) ; } ) ; TestScreen screen1 = null ; TestScreenSlow screen2 = null ; pushAndEnsureCurrent ( ( ) => screen1 = new TestScreen ( ) ) ; AddStep ( " " , ( ) => clickScreen ( inputManager , screen1 ) ) ; AddAssert ( " " , ( ) => screen1 . ClickCount == 1 ) ; AddStep ( " " , ( ) => screen1 . Push ( screen2 = new TestScreenSlow ( ) ) ) ; AddStep ( " " , ( ) => inputManager . Click ( MouseButton . Left ) ) ; AddAssert ( " " , ( ) => screen1 . ClickCount == 1 ) ; AddAssert ( " " , ( ) => screen2 . ClickCount == 0 && ! screen2 . IsLoaded ) ; AddStep ( " " , ( ) => screen2 . AllowLoad . Set ( ) ) ; AddUntilStep ( " " , ( ) => screen2 . IsCurrentScreen ( ) ) ; AddStep ( " " , ( ) => clickScreen ( inputManager , screen2 ) ) ; AddAssert ( " " , ( ) => screen1 . ClickCount == 1 ) ; AddAssert ( " " , ( ) => screen2 . ClickCount == 1 && screen2 . IsLoaded ) ; }
Push two screens and check that they only handle input when they are respectively loaded and current.
Push two screens and check that they only handle input when they are respectively loaded and current .
// we can't use the [SetUp] screen stack as we need to change the ctor parameters.