Use a receptor model instead

This commit is contained in:
David Zhao
2019-07-29 18:45:16 +09:00
parent 8742ed8a9c
commit e8c039bb8a
4 changed files with 32 additions and 44 deletions

View File

@ -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;
}
}
}