2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-01-26 22:07:49 +08:00
|
|
|
|
|
2017-03-14 16:58:34 +08:00
|
|
|
|
using System;
|
2017-01-26 22:07:49 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-03-14 16:58:34 +08:00
|
|
|
|
using OpenTK.Input;
|
2017-01-26 22:07:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-01-26 22:07:49 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-03-14 16:58:34 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-06-27 20:05:49 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-01-26 22:07:49 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
2017-06-27 20:05:49 +08:00
|
|
|
|
public class FooterButton : OsuClickableContainer
|
2017-01-26 22:07:49 +08:00
|
|
|
|
{
|
|
|
|
|
private static readonly Vector2 shearing = new Vector2(0.15f, 0);
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get { return spriteText?.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (spriteText != null)
|
|
|
|
|
spriteText.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 deselectedColour;
|
|
|
|
|
public Color4 DeselectedColour
|
|
|
|
|
{
|
|
|
|
|
get { return deselectedColour; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
deselectedColour = value;
|
2017-03-14 16:58:34 +08:00
|
|
|
|
if (light.Colour != SelectedColour)
|
2017-01-26 22:07:49 +08:00
|
|
|
|
light.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 selectedColour;
|
|
|
|
|
public Color4 SelectedColour
|
|
|
|
|
{
|
|
|
|
|
get { return selectedColour; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
selectedColour = value;
|
|
|
|
|
box.Colour = selectedColour;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly SpriteText spriteText;
|
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly Box light;
|
2017-01-26 22:07:49 +08:00
|
|
|
|
|
|
|
|
|
public FooterButton()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
},
|
2017-01-31 17:53:52 +08:00
|
|
|
|
spriteText = new OsuSpriteText
|
2017-01-26 22:07:49 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Action Hovered;
|
|
|
|
|
public Action HoverLost;
|
2017-03-14 16:58:34 +08:00
|
|
|
|
public Key? Hotkey;
|
2017-01-26 22:07:49 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
Hovered?.Invoke();
|
2017-07-23 02:50:25 +08:00
|
|
|
|
light.ScaleTo(new Vector2(1, 2), Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
light.FadeColour(SelectedColour, Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
2017-01-26 22:07:49 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
HoverLost?.Invoke();
|
2017-07-23 02:50:25 +08:00
|
|
|
|
light.ScaleTo(new Vector2(1, 1), Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
light.FadeColour(DeselectedColour, Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
2017-01-26 22:07:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
box.FadeTo(0.3f, Footer.TRANSITION_LENGTH * 2, Easing.OutQuint);
|
2017-01-26 22:07:49 +08:00
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 19:46:53 +08:00
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
box.FadeOut(Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
2017-02-06 19:46:53 +08:00
|
|
|
|
return base.OnMouseUp(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 22:07:49 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
2017-02-25 20:12:39 +08:00
|
|
|
|
box.ClearTransforms();
|
2017-01-26 22:07:49 +08:00
|
|
|
|
box.Alpha = 1;
|
2017-07-23 02:50:25 +08:00
|
|
|
|
box.FadeOut(Footer.TRANSITION_LENGTH * 3, Easing.OutQuint);
|
2017-01-26 22:07:49 +08:00
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 16:58:34 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.Repeat && args.Key == Hotkey)
|
|
|
|
|
{
|
|
|
|
|
OnClick(state);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
2017-01-26 22:07:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|