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
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-03-14 08:58:34 +00:00
|
|
|
|
using System;
|
2017-01-26 14:07:49 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-04-10 13:53:13 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-01-26 14:07:49 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-07-02 03:58:34 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-02-22 08:14:00 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-06-27 12:05:49 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2022-07-02 03:58:34 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-06-04 03:21:13 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2022-07-02 03:58:34 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
2020-06-04 03:21:13 +00:00
|
|
|
|
public partial class FooterButton : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
|
2017-01-26 14:07:49 +00:00
|
|
|
|
{
|
2019-11-12 12:07:01 +00:00
|
|
|
|
public const float SHEAR_WIDTH = 7.5f;
|
2019-08-06 00:57:04 +00:00
|
|
|
|
|
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
|
|
|
|
|
2021-02-22 08:14:00 +00:00
|
|
|
|
public LocalisableString Text
|
2017-01-26 14:07:49 +00:00
|
|
|
|
{
|
2021-02-25 05:06:21 +00:00
|
|
|
|
get => SpriteText?.Text ?? default;
|
2017-01-26 14:07:49 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-04-13 23:55:15 +00:00
|
|
|
|
if (SpriteText != null)
|
|
|
|
|
SpriteText.Text = value;
|
2017-01-26 14:07:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
private Color4 deselectedColour;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
public Color4 DeselectedColour
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => deselectedColour;
|
2017-01-26 14:07:49 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
deselectedColour = value;
|
2017-03-14 08:58:34 +00:00
|
|
|
|
if (light.Colour != SelectedColour)
|
2017-01-26 14:07:49 +00:00
|
|
|
|
light.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
private Color4 selectedColour;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
public Color4 SelectedColour
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => selectedColour;
|
2017-01-26 14:07:49 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
selectedColour = value;
|
|
|
|
|
box.Colour = selectedColour;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-01 11:22:19 +00:00
|
|
|
|
protected FillFlowContainer ButtonContentContainer;
|
|
|
|
|
protected readonly Container TextContainer;
|
2019-04-13 23:55:15 +00:00
|
|
|
|
protected readonly SpriteText SpriteText;
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly Box light;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
public FooterButton()
|
|
|
|
|
{
|
2019-04-10 13:53:13 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2019-08-07 03:20:49 +00:00
|
|
|
|
Shear = SHEAR;
|
2017-01-26 14:07:49 +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,
|
|
|
|
|
},
|
2020-01-01 11:22:19 +00:00
|
|
|
|
new Container
|
2019-08-06 01:14:41 +00:00
|
|
|
|
{
|
2020-01-01 11:22:19 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2019-12-30 22:58:49 +00:00
|
|
|
|
Children = new Drawable[]
|
2019-08-06 01:14:41 +00:00
|
|
|
|
{
|
2020-01-01 11:22:19 +00:00
|
|
|
|
ButtonContentContainer = new FillFlowContainer
|
2019-12-30 22:58:49 +00:00
|
|
|
|
{
|
2020-01-01 11:22:19 +00:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Shear = -SHEAR,
|
2020-01-29 17:59:51 +00:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Height = 50,
|
|
|
|
|
Spacing = new Vector2(15, 0),
|
2020-01-01 11:22:19 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
TextContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-01-29 17:59:51 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-01-01 11:22:19 +00:00
|
|
|
|
Child = SpriteText = new OsuSpriteText
|
|
|
|
|
{
|
2021-04-07 09:29:45 +00:00
|
|
|
|
AlwaysPresent = true,
|
2020-01-01 11:22:19 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-12-30 22:58:49 +00:00
|
|
|
|
},
|
2019-08-06 01:14:41 +00:00
|
|
|
|
},
|
2017-01-26 14:07:49 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-11-17 00:57:27 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
Enabled.BindValueChanged(_ => updateDisplay(), true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 14:07:49 +00:00
|
|
|
|
public Action Hovered;
|
|
|
|
|
public Action HoverLost;
|
2020-06-04 03:21:13 +00:00
|
|
|
|
public GlobalAction? Hotkey;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-11-17 00:57:27 +00:00
|
|
|
|
private bool mouseDown;
|
|
|
|
|
|
2020-01-29 17:59:51 +00:00
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
float horizontalMargin = (100 - TextContainer.Width) / 2;
|
|
|
|
|
ButtonContentContainer.Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Left = horizontalMargin,
|
|
|
|
|
// right side margin offset to compensate for shear
|
|
|
|
|
Right = horizontalMargin - SHEAR_WIDTH / 2
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-01-26 14:07:49 +00:00
|
|
|
|
{
|
|
|
|
|
Hovered?.Invoke();
|
2022-11-17 00:57:27 +00:00
|
|
|
|
updateDisplay();
|
2017-01-26 14:07:49 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-01-26 14:07:49 +00:00
|
|
|
|
{
|
|
|
|
|
HoverLost?.Invoke();
|
2022-11-17 00:57:27 +00:00
|
|
|
|
updateDisplay();
|
2017-01-26 14:07:49 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2017-01-26 14:07:49 +00:00
|
|
|
|
{
|
2022-11-17 00:57:27 +00:00
|
|
|
|
if (!Enabled.Value)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
mouseDown = true;
|
|
|
|
|
updateDisplay();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnMouseDown(e);
|
2017-01-26 14:07:49 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-20 09:17:21 +00:00
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2017-02-06 11:46:53 +00:00
|
|
|
|
{
|
2022-11-17 00:57:27 +00:00
|
|
|
|
mouseDown = false;
|
|
|
|
|
updateDisplay();
|
2020-01-20 09:17:21 +00:00
|
|
|
|
base.OnMouseUp(e);
|
2017-02-06 11:46:53 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2017-01-26 14:07:49 +00:00
|
|
|
|
{
|
2022-11-17 00:57:27 +00:00
|
|
|
|
if (!Enabled.Value)
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-02-25 12:12:39 +00:00
|
|
|
|
box.ClearTransforms();
|
2017-01-26 14:07:49 +00:00
|
|
|
|
box.Alpha = 1;
|
2017-07-22 18:50:25 +00:00
|
|
|
|
box.FadeOut(Footer.TRANSITION_LENGTH * 3, Easing.OutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnClick(e);
|
2017-01-26 14:07:49 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2017-03-14 08:58:34 +00:00
|
|
|
|
{
|
2022-04-04 22:33:41 +00:00
|
|
|
|
if (e.Action == Hotkey && !e.Repeat)
|
2017-03-14 08:58:34 +00:00
|
|
|
|
{
|
2021-08-04 08:27:44 +00:00
|
|
|
|
TriggerClick();
|
2017-03-14 08:58:34 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-06-04 04:59:04 +00:00
|
|
|
|
|
2020-06-04 03:21:13 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public virtual void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) { }
|
2022-11-17 00:57:27 +00:00
|
|
|
|
|
|
|
|
|
private void updateDisplay()
|
|
|
|
|
{
|
|
|
|
|
this.FadeTo(Enabled.Value ? 1 : 0.25f, Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
light.ScaleTo(Enabled.Value && IsHovered ? new Vector2(1, 2) : new Vector2(1), Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
light.FadeColour(Enabled.Value && IsHovered ? SelectedColour : DeselectedColour, Footer.TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
box.FadeTo(Enabled.Value & mouseDown ? 0.3f : 0f, Footer.TRANSITION_LENGTH * 2, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
if (Enabled.Value && IsHovered)
|
|
|
|
|
Hovered?.Invoke();
|
|
|
|
|
else
|
|
|
|
|
HoverLost?.Invoke();
|
|
|
|
|
}
|
2017-01-26 14:07:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|