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
|
|
|
|
|
|
|
|
|
using System;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-04-10 13:53:13 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
|
|
|
|
public class FooterButton : OsuClickableContainer
|
|
|
|
|
{
|
2019-08-06 00:57:04 +00:00
|
|
|
|
public static readonly float SHEAR_WIDTH = 7.5f;
|
|
|
|
|
|
2019-08-07 03:20:49 +00:00
|
|
|
|
protected static readonly Vector2 SHEAR = new Vector2(SHEAR_WIDTH / Footer.HEIGHT, 0);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
2019-04-13 23:55:15 +00:00
|
|
|
|
get => SpriteText?.Text;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-04-13 23:55:15 +00:00
|
|
|
|
if (SpriteText != null)
|
|
|
|
|
SpriteText.Text = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 deselectedColour;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Color4 DeselectedColour
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => deselectedColour;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
deselectedColour = value;
|
|
|
|
|
if (light.Colour != SelectedColour)
|
|
|
|
|
light.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 selectedColour;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Color4 SelectedColour
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => selectedColour;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
selectedColour = value;
|
|
|
|
|
box.Colour = selectedColour;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-13 23:55:15 +00:00
|
|
|
|
protected readonly Container TextContainer;
|
|
|
|
|
protected readonly SpriteText SpriteText;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly Box light;
|
|
|
|
|
|
|
|
|
|
public FooterButton()
|
|
|
|
|
{
|
2019-04-10 13:53:13 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2019-08-07 03:20:49 +00:00
|
|
|
|
Shear = SHEAR;
|
2018-04-13 09:19:50 +00: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 01:14:41 +00:00
|
|
|
|
TextContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(100 - SHEAR_WIDTH, 50),
|
2019-08-07 03:20:49 +00:00
|
|
|
|
Shear = -SHEAR,
|
2019-08-06 01:14:41 +00:00
|
|
|
|
Child = SpriteText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Action Hovered;
|
|
|
|
|
public Action HoverLost;
|
|
|
|
|
public Key? Hotkey;
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00: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 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00: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 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
box.FadeTo(0.3f, Footer.TRANSITION_LENGTH * 2, Easing.OutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnMouseDown(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseUp(MouseUpEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
box.FadeOut(Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnMouseUp(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
box.ClearTransforms();
|
|
|
|
|
box.Alpha = 1;
|
|
|
|
|
box.FadeOut(Footer.TRANSITION_LENGTH * 3, Easing.OutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnClick(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
if (!e.Repeat && e.Key == Hotkey)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-09-19 11:52:57 +00:00
|
|
|
|
Click();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnKeyDown(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|