Relieve OsuScreen of back button input duties

This commit is contained in:
smoogipoo
2019-06-25 17:17:29 +09:00
parent f53d2fbe76
commit d9927204f8
4 changed files with 28 additions and 22 deletions

View File

@ -3,10 +3,12 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
public class BackButton : TwoLayerButton public class BackButton : TwoLayerButton, IKeyBindingHandler<GlobalAction>
{ {
public BackButton() public BackButton()
{ {
@ -22,5 +24,18 @@ namespace osu.Game.Graphics.UserInterface
BackgroundColour = colours.Pink; BackgroundColour = colours.Pink;
HoverColour = colours.PinkDark; 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;
} }
} }

View File

@ -406,6 +406,11 @@ namespace osu.Game
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Alpha = 0, Alpha = 0,
Action = () =>
{
if ((screenStack.CurrentScreen as IOsuScreen)?.AllowBackButton == true)
screenStack.Exit();
}
}, },
logoContainer = new Container { RelativeSizeAxes = Axes.Both }, logoContainer = new Container { RelativeSizeAxes = Axes.Both },
} }

View File

@ -8,10 +8,8 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -21,7 +19,7 @@ using osu.Game.Rulesets.Mods;
namespace osu.Game.Screens namespace osu.Game.Screens
{ {
public abstract class OsuScreen : Screen, IOsuScreen, IKeyBindingHandler<GlobalAction>, IHasDescription public abstract class OsuScreen : Screen, IOsuScreen, IHasDescription
{ {
/// <summary> /// <summary>
/// The amount of negative padding that should be applied to game background content which touches both the left and right sides of the screen. /// 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"); 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) public override void OnResuming(IScreen last)
{ {
if (PlayResumeSound) if (PlayResumeSound)

View File

@ -34,10 +34,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
{ {
public abstract class SongSelect : OsuScreen public abstract class SongSelect : OsuScreen, IKeyBindingHandler<GlobalAction>
{ {
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245); 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()))); Schedule(() => BeatmapDetails.Leaderboard.RefreshScores())));
} }
public override bool OnPressed(GlobalAction action) public virtual bool OnPressed(GlobalAction action)
{ {
if (!this.IsCurrentScreen()) return false; if (!this.IsCurrentScreen()) return false;
@ -656,9 +657,11 @@ namespace osu.Game.Screens.Select
return true; return true;
} }
return base.OnPressed(action); return false;
} }
public bool OnReleased(GlobalAction action) => action == GlobalAction.Select;
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
if (e.Repeat) return false; if (e.Repeat) return false;