1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 17:17:24 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/BackButton.cs

66 lines
1.8 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
2019-06-25 17:30:43 +08:00
using System;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2019-06-25 17:30:43 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.UserInterface
{
2019-06-25 17:30:43 +08:00
public class BackButton : VisibilityContainer, IKeyBindingHandler<GlobalAction>
2018-04-13 17:19:50 +08:00
{
2019-06-25 17:30:43 +08:00
public Action Action;
private readonly TwoLayerButton button;
2018-04-13 17:19:50 +08:00
public BackButton()
{
2019-06-25 17:30:43 +08:00
Size = TwoLayerButton.SIZE_EXTENDED;
Child = button = new TwoLayerButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = @"back",
Icon = OsuIcon.LeftCircle,
Action = () => Action?.Invoke()
};
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2019-06-25 17:30:43 +08:00
button.BackgroundColour = colours.Pink;
button.HoverColour = colours.PinkDark;
2018-04-13 17:19:50 +08:00
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
Action?.Invoke();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back;
2019-06-25 17:30:43 +08:00
protected override void PopIn()
{
button.MoveToX(0, 400, Easing.OutQuint);
button.FadeIn(150, Easing.OutQuint);
}
protected override void PopOut()
{
2019-06-25 19:23:34 +08:00
button.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400, Easing.OutQuint);
button.FadeOut(400, Easing.OutQuint);
2019-06-25 17:30:43 +08:00
}
2018-04-13 17:19:50 +08:00
}
}