2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-25 09:30:43 +00:00
|
|
|
|
using System;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2019-06-25 09:30:43 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-06-25 08:17:29 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-06-25 08:17:29 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2019-07-29 09:45:16 +00:00
|
|
|
|
public class BackButton : VisibilityContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-25 09:30:43 +00:00
|
|
|
|
public Action Action;
|
|
|
|
|
|
|
|
|
|
private readonly TwoLayerButton button;
|
|
|
|
|
|
2020-05-17 08:35:10 +00:00
|
|
|
|
public BackButton(Receptor receptor = null)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-25 09:30:43 +00:00
|
|
|
|
Size = TwoLayerButton.SIZE_EXTENDED;
|
|
|
|
|
|
2021-07-30 12:25:44 +00:00
|
|
|
|
Child = button = new TwoLayerButton(HoverSampleSet.Submit)
|
2019-06-25 09:30:43 +00:00
|
|
|
|
{
|
2019-08-06 03:43:30 +00:00
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
2019-06-25 09:30:43 +00:00
|
|
|
|
Text = @"back",
|
|
|
|
|
Icon = OsuIcon.LeftCircle,
|
|
|
|
|
Action = () => Action?.Invoke()
|
|
|
|
|
};
|
2020-05-17 08:35:10 +00:00
|
|
|
|
|
2020-05-17 08:35:18 +00:00
|
|
|
|
if (receptor == null)
|
|
|
|
|
{
|
|
|
|
|
// if a receptor wasn't provided, create our own locally.
|
|
|
|
|
Add(receptor = new Receptor());
|
|
|
|
|
}
|
2020-05-17 08:35:10 +00:00
|
|
|
|
|
2021-08-04 08:27:44 +00:00
|
|
|
|
receptor.OnBackPressed = () => button.TriggerClick();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2019-06-25 09:30:43 +00:00
|
|
|
|
button.BackgroundColour = colours.Pink;
|
|
|
|
|
button.HoverColour = colours.PinkDark;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-06-25 08:17:29 +00:00
|
|
|
|
|
2019-06-25 09:30:43 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
button.MoveToX(0, 400, Easing.OutQuint);
|
|
|
|
|
button.FadeIn(150, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2019-06-25 11:23:34 +00:00
|
|
|
|
button.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400, Easing.OutQuint);
|
|
|
|
|
button.FadeOut(400, Easing.OutQuint);
|
2019-06-25 09:30:43 +00:00
|
|
|
|
}
|
2019-07-29 09:45:16 +00:00
|
|
|
|
|
2019-07-30 03:00:04 +00:00
|
|
|
|
public class Receptor : Drawable, IKeyBindingHandler<GlobalAction>
|
2019-07-29 09:45:16 +00:00
|
|
|
|
{
|
|
|
|
|
public Action OnBackPressed;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2019-07-29 09:45:16 +00:00
|
|
|
|
{
|
2021-11-18 03:35:47 +00:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2019-07-29 09:45:16 +00:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Back:
|
2019-09-25 13:14:42 +00:00
|
|
|
|
OnBackPressed?.Invoke();
|
2019-07-29 09:45:16 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2020-01-22 04:22:34 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2019-07-29 09:45:16 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|