1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 21:43:21 +08:00
osu-lazer/osu.Game/Screens/Select/FooterButton.cs

147 lines
4.2 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
using System;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Select
{
public class FooterButton : OsuClickableContainer
{
private static readonly Vector2 shearing = new Vector2(0.15f, 0);
public string Text
{
2019-04-14 07:55:15 +08:00
get => SpriteText?.Text;
2018-04-13 17:19:50 +08:00
set
{
2019-04-14 07:55:15 +08:00
if (SpriteText != null)
SpriteText.Text = value;
2018-04-13 17:19:50 +08:00
}
}
private Color4 deselectedColour;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
public Color4 DeselectedColour
{
get => deselectedColour;
2018-04-13 17:19:50 +08:00
set
{
deselectedColour = value;
if (light.Colour != SelectedColour)
light.Colour = value;
}
}
private Color4 selectedColour;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
public Color4 SelectedColour
{
get => selectedColour;
2018-04-13 17:19:50 +08:00
set
{
selectedColour = value;
box.Colour = selectedColour;
}
}
2019-04-14 07:55:15 +08:00
protected readonly Container TextContainer;
protected readonly SpriteText SpriteText;
2018-04-13 17:19:50 +08:00
private readonly Box box;
private readonly Box light;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => box.ReceivePositionalInputAt(screenSpacePos);
2018-07-03 13:03:17 +08:00
2018-04-13 17:19:50 +08:00
public FooterButton()
{
AutoSizeAxes = Axes.Both;
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
2019-04-14 07:55:15 +08:00
TextContainer = new Container
{
Size = new Vector2(100, 50),
2019-04-14 07:55:15 +08:00
Child = SpriteText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
},
2018-04-13 17:19:50 +08:00
box = new Box
{
RelativeSizeAxes = Axes.Both,
Shear = shearing,
EdgeSmoothness = new Vector2(2, 0),
Colour = Color4.White,
Alpha = 0,
},
light = new Box
{
Shear = shearing,
Height = 4,
EdgeSmoothness = new Vector2(2, 0),
RelativeSizeAxes = Axes.X,
},
};
}
public Action Hovered;
public Action HoverLost;
public Key? Hotkey;
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-04-13 17:19:50 +08:00
{
Hovered?.Invoke();
light.ScaleTo(new Vector2(1, 2), Footer.TRANSITION_LENGTH, Easing.OutQuint);
light.FadeColour(SelectedColour, Footer.TRANSITION_LENGTH, Easing.OutQuint);
return true;
}
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
2018-04-13 17:19:50 +08:00
{
HoverLost?.Invoke();
light.ScaleTo(new Vector2(1, 1), Footer.TRANSITION_LENGTH, Easing.OutQuint);
light.FadeColour(DeselectedColour, Footer.TRANSITION_LENGTH, Easing.OutQuint);
}
2018-10-02 11:02:47 +08:00
protected override bool OnMouseDown(MouseDownEvent e)
2018-04-13 17:19:50 +08:00
{
box.FadeTo(0.3f, Footer.TRANSITION_LENGTH * 2, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
return base.OnMouseDown(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnMouseUp(MouseUpEvent e)
2018-04-13 17:19:50 +08:00
{
box.FadeOut(Footer.TRANSITION_LENGTH, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
return base.OnMouseUp(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnClick(ClickEvent e)
2018-04-13 17:19:50 +08:00
{
box.ClearTransforms();
box.Alpha = 1;
box.FadeOut(Footer.TRANSITION_LENGTH * 3, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
return base.OnClick(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
2018-04-13 17:19:50 +08:00
{
2018-10-02 11:02:47 +08:00
if (!e.Repeat && e.Key == Hotkey)
2018-04-13 17:19:50 +08:00
{
Click();
2018-04-13 17:19:50 +08:00
return true;
}
2018-10-02 11:02:47 +08:00
return base.OnKeyDown(e);
2018-04-13 17:19:50 +08:00
}
}
}