mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:02:55 +08:00
Use a receptor model instead
This commit is contained in:
parent
8742ed8a9c
commit
e8c039bb8a
@ -22,6 +22,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
public TestSceneBackButton()
|
||||
{
|
||||
BackButton button;
|
||||
BackButton.BackButtonReceptor receptor = new BackButton.BackButtonReceptor();
|
||||
|
||||
Child = new Container
|
||||
{
|
||||
@ -31,12 +32,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
Masking = true,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
receptor,
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.SlateGray
|
||||
},
|
||||
button = new BackButton
|
||||
button = new BackButton(receptor)
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
|
@ -10,14 +10,16 @@ using osu.Game.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class BackButton : VisibilityContainer, IKeyBindingHandler<GlobalAction>
|
||||
public class BackButton : VisibilityContainer
|
||||
{
|
||||
public Action Action;
|
||||
|
||||
private readonly TwoLayerButton button;
|
||||
|
||||
public BackButton()
|
||||
public BackButton(BackButtonReceptor receptor)
|
||||
{
|
||||
receptor.OnBackPressed += () => Action.Invoke();
|
||||
|
||||
Size = TwoLayerButton.SIZE_EXTENDED;
|
||||
|
||||
Child = button = new TwoLayerButton
|
||||
@ -37,19 +39,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
button.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;
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
button.MoveToX(0, 400, Easing.OutQuint);
|
||||
@ -61,5 +50,24 @@ namespace osu.Game.Graphics.UserInterface
|
||||
button.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400, Easing.OutQuint);
|
||||
button.FadeOut(400, Easing.OutQuint);
|
||||
}
|
||||
|
||||
public class BackButtonReceptor : Drawable, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
public Action OnBackPressed;
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
OnBackPressed.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Input.Bindings
|
||||
{
|
||||
@ -56,32 +55,8 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, GlobalAction.DecreaseScrollSpeed),
|
||||
};
|
||||
|
||||
protected override IEnumerable<Drawable> KeyBindingInputQueue
|
||||
{
|
||||
get
|
||||
{
|
||||
var queue = base.KeyBindingInputQueue.ToList();
|
||||
|
||||
if (handler != null)
|
||||
yield return handler;
|
||||
|
||||
BackButton backButton = null;
|
||||
|
||||
foreach (var drawable in queue)
|
||||
{
|
||||
if (drawable is BackButton button)
|
||||
{
|
||||
backButton = button;
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return drawable;
|
||||
}
|
||||
|
||||
if (backButton != null)
|
||||
yield return backButton;
|
||||
}
|
||||
}
|
||||
protected override IEnumerable<Drawable> KeyBindingInputQueue =>
|
||||
handler == null ? base.KeyBindingInputQueue : base.KeyBindingInputQueue.Prepend(handler);
|
||||
}
|
||||
|
||||
public enum GlobalAction
|
||||
|
@ -84,6 +84,8 @@ namespace osu.Game
|
||||
protected OsuScreenStack ScreenStack;
|
||||
protected BackButton BackButton;
|
||||
|
||||
private BackButton.BackButtonReceptor backButtonReceptor;
|
||||
|
||||
private VolumeOverlay volume;
|
||||
private OsuLogo osuLogo;
|
||||
|
||||
@ -407,8 +409,9 @@ namespace osu.Game
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
backButtonReceptor = new BackButton.BackButtonReceptor(),
|
||||
ScreenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
|
||||
BackButton = new BackButton
|
||||
BackButton = new BackButton(backButtonReceptor)
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
|
Loading…
Reference in New Issue
Block a user