diff --git a/osu.Game/Graphics/UserInterface/BackButton.cs b/osu.Game/Graphics/UserInterface/BackButton.cs index 10e8227f16..a5d85d9338 100644 --- a/osu.Game/Graphics/UserInterface/BackButton.cs +++ b/osu.Game/Graphics/UserInterface/BackButton.cs @@ -3,10 +3,12 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Input.Bindings; +using osu.Game.Input.Bindings; namespace osu.Game.Graphics.UserInterface { - public class BackButton : TwoLayerButton + public class BackButton : TwoLayerButton, IKeyBindingHandler { public BackButton() { @@ -22,5 +24,18 @@ namespace osu.Game.Graphics.UserInterface BackgroundColour = colours.Pink; HoverColour = colours.PinkDark; } + + public bool OnPressed(GlobalAction action) + { + if (action == GlobalAction.Back) + { + Action?.Invoke(); + return true; + } + + return false; + } + + public bool OnReleased(GlobalAction action) => action == GlobalAction.Back; } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index eeeaefeadf..83fd049ea0 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -406,6 +406,11 @@ namespace osu.Game Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Alpha = 0, + Action = () => + { + if ((screenStack.CurrentScreen as IOsuScreen)?.AllowBackButton == true) + screenStack.Exit(); + } }, logoContainer = new Container { RelativeSizeAxes = Axes.Both }, } diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index 8e40c72ac6..d38baf1ae8 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -8,10 +8,8 @@ using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Input.Bindings; using osu.Framework.Screens; using osu.Game.Beatmaps; -using osu.Game.Input.Bindings; using osu.Game.Rulesets; using osu.Game.Screens.Menu; using osu.Game.Overlays; @@ -21,7 +19,7 @@ using osu.Game.Rulesets.Mods; namespace osu.Game.Screens { - public abstract class OsuScreen : Screen, IOsuScreen, IKeyBindingHandler, IHasDescription + public abstract class OsuScreen : Screen, IOsuScreen, IHasDescription { /// /// The amount of negative padding that should be applied to game background content which touches both the left and right sides of the screen. @@ -133,21 +131,6 @@ namespace osu.Game.Screens sampleExit = audio.Samples.Get(@"UI/screen-back"); } - public virtual bool OnPressed(GlobalAction action) - { - if (!this.IsCurrentScreen()) return false; - - if (action == GlobalAction.Back && AllowBackButton) - { - this.Exit(); - return true; - } - - return false; - } - - public bool OnReleased(GlobalAction action) => action == GlobalAction.Back && AllowBackButton; - public override void OnResuming(IScreen last) { if (PlayResumeSound) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index c9cc5233aa..4c55eee21b 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -34,10 +34,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Bindings; namespace osu.Game.Screens.Select { - public abstract class SongSelect : OsuScreen + public abstract class SongSelect : OsuScreen, IKeyBindingHandler { private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245); @@ -645,7 +646,7 @@ namespace osu.Game.Screens.Select Schedule(() => BeatmapDetails.Leaderboard.RefreshScores()))); } - public override bool OnPressed(GlobalAction action) + public virtual bool OnPressed(GlobalAction action) { if (!this.IsCurrentScreen()) return false; @@ -656,9 +657,11 @@ namespace osu.Game.Screens.Select return true; } - return base.OnPressed(action); + return false; } + public bool OnReleased(GlobalAction action) => action == GlobalAction.Select; + protected override bool OnKeyDown(KeyDownEvent e) { if (e.Repeat) return false;