From 804b59ee8073cf54fa475e8dc9780edab842a18d Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Sun, 29 Apr 2018 20:15:09 +0300 Subject: [PATCH] Handle GlobalAction.Back --- osu.Game/Screens/Menu/ButtonSystem.cs | 42 +++++++++++++++++++++------ osu.Game/Screens/OsuScreen.cs | 35 +++++++++++++--------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/osu.Game/Screens/Menu/ButtonSystem.cs b/osu.Game/Screens/Menu/ButtonSystem.cs index f48e1925c5..8cf0d24f7d 100644 --- a/osu.Game/Screens/Menu/ButtonSystem.cs +++ b/osu.Game/Screens/Menu/ButtonSystem.cs @@ -6,22 +6,24 @@ using System.Linq; using osu.Framework; using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; +using osu.Framework.Input.Bindings; +using osu.Framework.Threading; using osu.Game.Graphics; +using osu.Game.Input.Bindings; using OpenTK; using OpenTK.Graphics; using OpenTK.Input; -using osu.Framework.Audio.Sample; -using osu.Framework.Audio; -using osu.Framework.Configuration; -using osu.Framework.Threading; namespace osu.Game.Screens.Menu { - public class ButtonSystem : Container, IStateful + public class ButtonSystem : Container, IStateful, IKeyBindingHandler { public event Action StateChanged; @@ -146,7 +148,16 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) case Key.Space: logo?.TriggerOnClick(state); return true; - case Key.Escape: + } + + return false; + } + + public bool OnPressed(GlobalAction action) + { + switch (action) + { + case GlobalAction.Back: switch (State) { case MenuState.TopLevel: @@ -155,14 +166,26 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) case MenuState.Play: backButton.TriggerOnClick(); return true; + default: + return false; } - + default: return false; } - - return false; } + public bool OnReleased(GlobalAction action) + { + switch (action) + { + case GlobalAction.Back: + return true; + default: + return false; + } + } + + private void onPlay() { State = MenuState.Play; @@ -337,6 +360,7 @@ private void updateLogoState(MenuState lastState = MenuState.Initial) logo.ScaleTo(0.5f, 200, Easing.OutQuint); break; } + break; case MenuState.EnteringMode: logoTracking = true; diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index 7a910574e0..5d2c46f438 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -3,22 +3,22 @@ using System; using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Input.Bindings; using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; -using OpenTK; -using osu.Framework.Audio.Sample; -using osu.Framework.Audio; -using osu.Framework.Graphics; +using osu.Game.Input.Bindings; using osu.Game.Rulesets; using osu.Game.Screens.Menu; -using osu.Framework.Input; -using OpenTK.Input; +using OpenTK; namespace osu.Game.Screens { - public abstract class OsuScreen : Screen + public abstract class OsuScreen : Screen, IKeyBindingHandler { public BackgroundScreen Background { get; private set; } @@ -90,18 +90,27 @@ private void load(OsuGameBase game, OsuGame osuGame, AudioManager audio) sampleExit = audio.Sample.Get(@"UI/screen-back"); } - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + public bool OnPressed(GlobalAction action) { - if (args.Repeat || !IsCurrentScreen) return false; - - switch (args.Key) + switch (action) { - case Key.Escape: + case GlobalAction.Back: Exit(); return true; + default: + return false; } + } - return base.OnKeyDown(state, args); + public bool OnReleased(GlobalAction action) + { + switch (action) + { + case GlobalAction.Back: + return true; + default: + return false; + } } protected override void OnResuming(Screen last)