1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:07:26 +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
{
2019-11-12 20:07:01 +08:00
public const float SHEAR_WIDTH = 7.5f;
2019-08-07 11:20:49 +08:00
protected static readonly Vector2 SHEAR = new Vector2(SHEAR_WIDTH / Footer.HEIGHT, 0);
2018-04-13 17:19:50 +08:00
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 FooterButton()
{
AutoSizeAxes = Axes.Both;
2019-08-07 11:20:49 +08:00
Shear = SHEAR;
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
box = new Box
{
RelativeSizeAxes = Axes.Both,
EdgeSmoothness = new Vector2(2, 0),
Colour = Color4.White,
Alpha = 0,
},
light = new Box
{
Height = 4,
EdgeSmoothness = new Vector2(2, 0),
RelativeSizeAxes = Axes.X,
},
2019-08-06 09:14:41 +08:00
TextContainer = new Container
{
Size = new Vector2(100 - SHEAR_WIDTH, 50),
2019-08-07 11:20:49 +08:00
Shear = -SHEAR,
2019-08-06 09:14:41 +08:00
Child = SpriteText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
},
2018-04-13 17:19:50 +08:00
};
}
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
}
}
}