mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Use a receptor model instead
This commit is contained in:
@ -22,6 +22,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public TestSceneBackButton()
|
public TestSceneBackButton()
|
||||||
{
|
{
|
||||||
BackButton button;
|
BackButton button;
|
||||||
|
BackButton.BackButtonReceptor receptor = new BackButton.BackButtonReceptor();
|
||||||
|
|
||||||
Child = new Container
|
Child = new Container
|
||||||
{
|
{
|
||||||
@ -31,12 +32,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Masking = true,
|
Masking = true,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
receptor,
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = Color4.SlateGray
|
Colour = Color4.SlateGray
|
||||||
},
|
},
|
||||||
button = new BackButton
|
button = new BackButton(receptor)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
|
@ -10,14 +10,16 @@ using osu.Game.Input.Bindings;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class BackButton : VisibilityContainer, IKeyBindingHandler<GlobalAction>
|
public class BackButton : VisibilityContainer
|
||||||
{
|
{
|
||||||
public Action Action;
|
public Action Action;
|
||||||
|
|
||||||
private readonly TwoLayerButton button;
|
private readonly TwoLayerButton button;
|
||||||
|
|
||||||
public BackButton()
|
public BackButton(BackButtonReceptor receptor)
|
||||||
{
|
{
|
||||||
|
receptor.OnBackPressed += () => Action.Invoke();
|
||||||
|
|
||||||
Size = TwoLayerButton.SIZE_EXTENDED;
|
Size = TwoLayerButton.SIZE_EXTENDED;
|
||||||
|
|
||||||
Child = button = new TwoLayerButton
|
Child = button = new TwoLayerButton
|
||||||
@ -37,19 +39,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
button.HoverColour = colours.PinkDark;
|
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()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
button.MoveToX(0, 400, Easing.OutQuint);
|
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.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400, Easing.OutQuint);
|
||||||
button.FadeOut(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.Graphics;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
|
|
||||||
namespace osu.Game.Input.Bindings
|
namespace osu.Game.Input.Bindings
|
||||||
{
|
{
|
||||||
@ -56,32 +55,8 @@ namespace osu.Game.Input.Bindings
|
|||||||
new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, GlobalAction.DecreaseScrollSpeed),
|
new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, GlobalAction.DecreaseScrollSpeed),
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override IEnumerable<Drawable> KeyBindingInputQueue
|
protected override IEnumerable<Drawable> KeyBindingInputQueue =>
|
||||||
{
|
handler == null ? base.KeyBindingInputQueue : base.KeyBindingInputQueue.Prepend(handler);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum GlobalAction
|
public enum GlobalAction
|
||||||
|
@ -84,6 +84,8 @@ namespace osu.Game
|
|||||||
protected OsuScreenStack ScreenStack;
|
protected OsuScreenStack ScreenStack;
|
||||||
protected BackButton BackButton;
|
protected BackButton BackButton;
|
||||||
|
|
||||||
|
private BackButton.BackButtonReceptor backButtonReceptor;
|
||||||
|
|
||||||
private VolumeOverlay volume;
|
private VolumeOverlay volume;
|
||||||
private OsuLogo osuLogo;
|
private OsuLogo osuLogo;
|
||||||
|
|
||||||
@ -407,8 +409,9 @@ namespace osu.Game
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
backButtonReceptor = new BackButton.BackButtonReceptor(),
|
||||||
ScreenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
|
ScreenStack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
|
||||||
BackButton = new BackButton
|
BackButton = new BackButton(backButtonReceptor)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
|
Reference in New Issue
Block a user