2022-12-01 20:13:37 +08: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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2022-12-03 01:44:21 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-12-02 05:07:28 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-12-01 20:13:37 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-12-01 22:34:09 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2022-12-01 20:13:37 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-12-01 22:34:09 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-12-01 20:13:37 +08:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-12-01 23:29:52 +08:00
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
2022-12-01 20:13:37 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-12-01 22:34:09 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-12-01 20:13:37 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
2023-02-03 15:24:19 +08:00
|
|
|
using osuTK.Graphics;
|
2022-12-01 20:13:37 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.FooterV2
|
|
|
|
{
|
|
|
|
public partial class FooterButtonV2 : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
|
|
|
|
{
|
2022-12-03 01:44:21 +08:00
|
|
|
private const int transition_length = 500;
|
2022-12-01 20:13:37 +08:00
|
|
|
|
2023-02-03 15:26:54 +08:00
|
|
|
// This should be 12 by design, but an extra allowance is added due to the corner radius specification.
|
2024-05-10 11:47:48 +08:00
|
|
|
private const float shear_width = 13.5f;
|
2022-12-01 20:13:37 +08:00
|
|
|
|
2024-05-10 11:47:48 +08:00
|
|
|
protected const int CORNER_RADIUS = 10;
|
|
|
|
protected const int BUTTON_HEIGHT = 90;
|
|
|
|
protected const int BUTTON_WIDTH = 140;
|
2024-05-08 08:58:10 +08:00
|
|
|
|
2022-12-03 01:44:21 +08:00
|
|
|
public Bindable<Visibility> OverlayState = new Bindable<Visibility>();
|
|
|
|
|
2024-05-10 11:47:48 +08:00
|
|
|
protected static readonly Vector2 BUTTON_SHEAR = new Vector2(shear_width / BUTTON_HEIGHT, 0);
|
2022-12-01 22:34:09 +08:00
|
|
|
|
2023-02-14 05:17:02 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
2022-12-01 20:13:37 +08:00
|
|
|
|
2022-12-01 22:34:09 +08:00
|
|
|
private Colour4 buttonAccentColour;
|
|
|
|
|
|
|
|
protected Colour4 AccentColour
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
buttonAccentColour = value;
|
|
|
|
bar.Colour = buttonAccentColour;
|
|
|
|
icon.Colour = buttonAccentColour;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected IconUsage Icon
|
|
|
|
{
|
|
|
|
set => icon.Icon = value;
|
|
|
|
}
|
|
|
|
|
2022-12-01 23:29:52 +08:00
|
|
|
protected LocalisableString Text
|
2022-12-01 22:34:09 +08:00
|
|
|
{
|
|
|
|
set => text.Text = value;
|
|
|
|
}
|
|
|
|
|
2022-12-19 23:35:20 +08:00
|
|
|
private readonly SpriteText text;
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
|
|
|
protected Container TextContainer;
|
|
|
|
private readonly Box bar;
|
|
|
|
private readonly Box backgroundBox;
|
|
|
|
|
|
|
|
public FooterButtonV2()
|
2022-12-01 20:13:37 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
Size = new Vector2(BUTTON_WIDTH, BUTTON_HEIGHT);
|
|
|
|
|
|
|
|
Child = new Container
|
2022-12-01 20:13:37 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2022-12-01 20:13:37 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = 4,
|
|
|
|
// Figma says 50% opacity, but it does not match up visually if taken at face value, and looks bad.
|
|
|
|
Colour = Colour4.Black.Opacity(0.25f),
|
|
|
|
Offset = new Vector2(0, 2),
|
2022-12-01 20:13:37 +08:00
|
|
|
},
|
2024-05-08 08:58:10 +08:00
|
|
|
Shear = BUTTON_SHEAR,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = CORNER_RADIUS,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2022-12-01 20:13:37 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
backgroundBox = new Box
|
2022-12-01 22:34:09 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
// For elements that should not be sheared.
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Shear = -BUTTON_SHEAR,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2022-12-01 23:29:52 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
TextContainer = new Container
|
2022-12-01 23:29:52 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Y = 42,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Child = text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
// figma design says the size is 16, but due to the issues with font sizes 19 matches better
|
|
|
|
Font = OsuFont.TorusAlternate.With(size: 19),
|
|
|
|
AlwaysPresent = true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
icon = new SpriteIcon
|
|
|
|
{
|
|
|
|
Y = 12,
|
|
|
|
Size = new Vector2(20),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Container
|
2023-01-18 05:16:59 +08:00
|
|
|
{
|
2024-05-08 08:58:10 +08:00
|
|
|
Shear = -BUTTON_SHEAR,
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Y = -CORNER_RADIUS,
|
|
|
|
Size = new Vector2(120, 6),
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 3,
|
|
|
|
Child = bar = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
2022-12-01 22:34:09 +08:00
|
|
|
}
|
2022-12-01 20:13:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-02 05:31:14 +08:00
|
|
|
protected override void LoadComplete()
|
2022-12-01 23:29:52 +08:00
|
|
|
{
|
2022-12-02 05:31:14 +08:00
|
|
|
base.LoadComplete();
|
2022-12-19 18:30:23 +08:00
|
|
|
|
2022-12-03 01:44:21 +08:00
|
|
|
OverlayState.BindValueChanged(_ => updateDisplay());
|
2023-02-03 15:25:54 +08:00
|
|
|
Enabled.BindValueChanged(_ => updateDisplay(), true);
|
|
|
|
|
|
|
|
FinishTransforms(true);
|
2022-12-01 23:29:52 +08:00
|
|
|
}
|
|
|
|
|
2022-12-02 05:31:14 +08:00
|
|
|
public GlobalAction? Hotkey;
|
|
|
|
|
2023-02-03 15:24:19 +08:00
|
|
|
private bool handlingMouse;
|
|
|
|
|
2022-12-01 23:29:52 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
2022-12-01 20:13:37 +08:00
|
|
|
{
|
2022-12-02 05:31:14 +08:00
|
|
|
updateDisplay();
|
2022-12-01 23:29:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-03 15:24:19 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
handlingMouse = true;
|
|
|
|
updateDisplay();
|
|
|
|
return base.OnMouseDown(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
handlingMouse = false;
|
|
|
|
updateDisplay();
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
}
|
|
|
|
|
2023-01-18 05:16:59 +08:00
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => updateDisplay();
|
2022-12-01 23:29:52 +08:00
|
|
|
|
|
|
|
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
2022-12-19 23:35:20 +08:00
|
|
|
if (e.Action != Hotkey || e.Repeat) return false;
|
2022-12-01 23:29:52 +08:00
|
|
|
|
2022-12-19 23:35:20 +08:00
|
|
|
TriggerClick();
|
|
|
|
return true;
|
2022-12-01 20:13:37 +08:00
|
|
|
}
|
|
|
|
|
2022-12-01 23:29:52 +08:00
|
|
|
public virtual void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) { }
|
2022-12-02 05:07:28 +08:00
|
|
|
|
2022-12-02 05:31:14 +08:00
|
|
|
private void updateDisplay()
|
2022-12-02 05:07:28 +08:00
|
|
|
{
|
2023-02-03 15:24:19 +08:00
|
|
|
Color4 backgroundColour = colourProvider.Background3;
|
|
|
|
|
2022-12-02 05:31:14 +08:00
|
|
|
if (!Enabled.Value)
|
|
|
|
{
|
2023-02-03 15:24:19 +08:00
|
|
|
backgroundColour = colourProvider.Background3.Darken(0.4f);
|
2022-12-02 05:31:14 +08:00
|
|
|
}
|
2023-02-03 15:24:19 +08:00
|
|
|
else
|
2022-12-03 01:44:21 +08:00
|
|
|
{
|
2023-02-03 15:24:19 +08:00
|
|
|
if (OverlayState.Value == Visibility.Visible)
|
|
|
|
backgroundColour = buttonAccentColour.Darken(0.5f);
|
2022-12-03 01:44:21 +08:00
|
|
|
|
2023-02-03 15:24:19 +08:00
|
|
|
if (IsHovered)
|
|
|
|
{
|
|
|
|
backgroundColour = backgroundColour.Lighten(0.3f);
|
|
|
|
|
|
|
|
if (handlingMouse)
|
|
|
|
backgroundColour = backgroundColour.Lighten(0.3f);
|
|
|
|
}
|
2022-12-03 01:44:21 +08:00
|
|
|
}
|
|
|
|
|
2023-02-03 15:24:19 +08:00
|
|
|
backgroundBox.FadeColour(backgroundColour, transition_length, Easing.OutQuint);
|
2022-12-02 05:07:28 +08:00
|
|
|
}
|
2022-12-01 20:13:37 +08:00
|
|
|
}
|
|
|
|
}
|