From 6d1203a5993a0faec79e1ba4076522e11acc9cba Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 30 Jul 2019 12:00:04 +0900 Subject: [PATCH] Move screen pushes into function, rename receptor --- .../Visual/Menus/TestSceneExitingScreens.cs | 27 +++++++++---------- .../UserInterface/TestSceneBackButton.cs | 2 +- osu.Game/Graphics/UserInterface/BackButton.cs | 6 ++--- osu.Game/OsuGame.cs | 7 +++-- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/osu.Game.Tests/Visual/Menus/TestSceneExitingScreens.cs b/osu.Game.Tests/Visual/Menus/TestSceneExitingScreens.cs index 377d7b60fb..4780111e66 100644 --- a/osu.Game.Tests/Visual/Menus/TestSceneExitingScreens.cs +++ b/osu.Game.Tests/Visual/Menus/TestSceneExitingScreens.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; @@ -43,7 +44,7 @@ namespace osu.Game.Tests.Visual.Menus public void SetUpSteps() { AddUntilStep("wait for load", () => osuGame.IsLoaded); - AddUntilStep("wait for main menu", () => + AddUntilStep("exit to main menu", () => { var current = osuGame.ScreenStack.CurrentScreen; @@ -69,8 +70,7 @@ namespace osu.Game.Tests.Visual.Menus { TestSongSelect songSelect = null; - AddStep("Push song select", () => osuGame.ScreenStack.Push(songSelect = new TestSongSelect())); - AddUntilStep("Wait for song select", () => songSelect.IsCurrentScreen()); + pushAndConfirm(() => songSelect = new TestSongSelect(), "song select"); AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show()); AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible); AddStep("Press escape", () => pressAndRelease(Key.Escape)); @@ -83,8 +83,7 @@ namespace osu.Game.Tests.Visual.Menus { TestSongSelect songSelect = null; - AddStep("Push song select", () => osuGame.ScreenStack.Push(songSelect = new TestSongSelect())); - AddUntilStep("Wait for song select", () => songSelect.IsCurrentScreen()); + pushAndConfirm(() => songSelect = new TestSongSelect(), "song select"); AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show()); AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible); AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(osuGame.BackButton)); @@ -100,24 +99,24 @@ namespace osu.Game.Tests.Visual.Menus [Test] public void TestExitMultiWithEscape() { - Screens.Multi.Multiplayer multiplayer = null; - - AddStep("Push multiplayer", () => osuGame.ScreenStack.Push(multiplayer = new Screens.Multi.Multiplayer())); - AddUntilStep("Wait for multiplayer", () => multiplayer.IsCurrentScreen()); + pushAndConfirm(() => new Screens.Multi.Multiplayer(), "multiplayer"); exitViaEscapeAndConfirm(); } [Test] public void TestExitMultiWithBackButton() { - Screens.Multi.Multiplayer multiplayer = null; - - AddStep("Push multiplayer", () => osuGame.ScreenStack.Push(multiplayer = new Screens.Multi.Multiplayer())); - AddUntilStep("Wait for multiplayer", () => multiplayer.IsCurrentScreen()); - + pushAndConfirm(() => new Screens.Multi.Multiplayer(), "multiplayer"); exitViaBackButtonAndConfirm(); } + private void pushAndConfirm(Func newScreen, string screenName) + { + Screen screen = null; + AddStep($"Push new {screenName}", () => osuGame.ScreenStack.Push(screen = newScreen())); + AddUntilStep($"Wait for new {screenName}", () => screen.IsCurrentScreen()); + } + private void exitViaEscapeAndConfirm() { AddStep("Press escape", () => pressAndRelease(Key.Escape)); diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs index 05d14abe30..b7d7053dcd 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBackButton.cs @@ -22,7 +22,7 @@ namespace osu.Game.Tests.Visual.UserInterface public TestSceneBackButton() { BackButton button; - BackButton.BackButtonReceptor receptor = new BackButton.BackButtonReceptor(); + BackButton.Receptor receptor = new BackButton.Receptor(); Child = new Container { diff --git a/osu.Game/Graphics/UserInterface/BackButton.cs b/osu.Game/Graphics/UserInterface/BackButton.cs index fe82a5d8e2..9808eda4df 100644 --- a/osu.Game/Graphics/UserInterface/BackButton.cs +++ b/osu.Game/Graphics/UserInterface/BackButton.cs @@ -16,9 +16,9 @@ namespace osu.Game.Graphics.UserInterface private readonly TwoLayerButton button; - public BackButton(BackButtonReceptor receptor) + public BackButton(Receptor receptor) { - receptor.OnBackPressed += () => Action.Invoke(); + receptor.OnBackPressed = () => Action.Invoke(); Size = TwoLayerButton.SIZE_EXTENDED; @@ -51,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface button.FadeOut(400, Easing.OutQuint); } - public class BackButtonReceptor : Drawable, IKeyBindingHandler + public class Receptor : Drawable, IKeyBindingHandler { public Action OnBackPressed; diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 3018cea276..a889af94eb 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -84,8 +84,6 @@ namespace osu.Game protected OsuScreenStack ScreenStack; protected BackButton BackButton; - private BackButton.BackButtonReceptor backButtonReceptor; - private VolumeOverlay volume; private OsuLogo osuLogo; @@ -393,6 +391,7 @@ namespace osu.Game ScoreManager.PresentImport = items => PresentScore(items.First()); Container logoContainer; + BackButton.Receptor receptor; dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); @@ -409,9 +408,9 @@ namespace osu.Game RelativeSizeAxes = Axes.Both, Children = new Drawable[] { - backButtonReceptor = new BackButton.BackButtonReceptor(), + receptor = new BackButton.Receptor(), ScreenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both }, - BackButton = new BackButton(backButtonReceptor) + BackButton = new BackButton(receptor) { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft,