2022-12-01 12:13:37 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2022-12-02 17:44:21 +00:00
|
|
|
using osu.Framework.Bindables;
|
2022-12-01 21:07:28 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-12-01 12:13:37 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-12-01 14:34:09 +00:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2022-12-01 12:13:37 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-12-01 14:34:09 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-12-01 12:13:37 +00:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-12-01 15:29:52 +00:00
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
2022-12-01 12:13:37 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-12-01 14:34:09 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-12-01 12:13:37 +00:00
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.FooterV2
|
|
|
|
{
|
|
|
|
public partial class FooterButtonV2 : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
|
|
|
|
{
|
2022-12-19 10:30:23 +00:00
|
|
|
private const int button_height = 90;
|
2022-12-01 12:13:37 +00:00
|
|
|
private const int button_width = 140;
|
|
|
|
private const int corner_radius = 10;
|
2022-12-02 17:44:21 +00:00
|
|
|
private const int transition_length = 500;
|
2022-12-01 12:13:37 +00:00
|
|
|
|
2022-12-19 10:30:23 +00:00
|
|
|
//Accounts for corner radius margin on bottom, would be 12
|
|
|
|
public const float SHEAR_WIDTH = 13.5f;
|
2022-12-01 12:13:37 +00:00
|
|
|
|
2022-12-02 17:44:21 +00:00
|
|
|
public Bindable<Visibility> OverlayState = new Bindable<Visibility>();
|
|
|
|
|
2022-12-01 14:34:09 +00:00
|
|
|
protected static readonly Vector2 SHEAR = new Vector2(SHEAR_WIDTH / button_height, 0);
|
|
|
|
|
2022-12-01 12:13:37 +00:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
|
2022-12-01 14:34:09 +00: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 15:29:52 +00:00
|
|
|
protected LocalisableString Text
|
2022-12-01 14:34:09 +00:00
|
|
|
{
|
|
|
|
set => text.Text = value;
|
|
|
|
}
|
|
|
|
|
2022-12-19 15:35:20 +00: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 12:13:37 +00:00
|
|
|
{
|
2022-12-01 14:34:09 +00:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = 5,
|
|
|
|
Roundness = 10,
|
|
|
|
Colour = Colour4.Black.Opacity(0.25f)
|
|
|
|
};
|
2022-12-01 12:13:37 +00:00
|
|
|
Shear = SHEAR;
|
|
|
|
Size = new Vector2(button_width, button_height);
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = corner_radius;
|
2023-01-30 11:56:39 +00:00
|
|
|
Children = new Drawable[]
|
2022-12-01 12:13:37 +00:00
|
|
|
{
|
2022-12-19 10:30:23 +00:00
|
|
|
backgroundBox = new Box
|
2022-12-01 12:13:37 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
|
|
|
|
//For elements that should not be sheared.
|
|
|
|
new Container
|
|
|
|
{
|
2022-12-19 10:30:23 +00:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-12-01 14:34:09 +00:00
|
|
|
Shear = -SHEAR,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-12-01 15:29:52 +00:00
|
|
|
TextContainer = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2022-12-19 10:30:23 +00:00
|
|
|
Y = 42,
|
2022-12-01 15:29:52 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Child = text = new OsuSpriteText
|
|
|
|
{
|
2022-12-19 10:30:23 +00:00
|
|
|
//figma design says the size is 16, but due to the issues with font sizes 19 matches better
|
|
|
|
Font = OsuFont.TorusAlternate.With(size: 19),
|
2022-12-01 15:29:52 +00:00
|
|
|
AlwaysPresent = true
|
|
|
|
}
|
|
|
|
},
|
2022-12-01 14:34:09 +00:00
|
|
|
icon = new SpriteIcon
|
|
|
|
{
|
2022-12-19 10:30:23 +00:00
|
|
|
Y = 12,
|
2022-12-01 14:34:09 +00:00
|
|
|
Size = new Vector2(20),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
},
|
2023-01-17 21:16:59 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Shear = -SHEAR,
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Y = -10,
|
|
|
|
Size = new Vector2(120, 6),
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 3,
|
|
|
|
Child = bar = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-12-01 14:34:09 +00:00
|
|
|
}
|
2022-12-01 12:13:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-01 21:31:14 +00:00
|
|
|
protected override void LoadComplete()
|
2022-12-01 15:29:52 +00:00
|
|
|
{
|
2022-12-01 21:31:14 +00:00
|
|
|
base.LoadComplete();
|
2022-12-19 10:30:23 +00:00
|
|
|
|
2023-01-30 11:56:39 +00:00
|
|
|
// We want the first colour assignment for the background to be instantaneous
|
|
|
|
backgroundBox.Colour = Enabled.Value ? colourProvider.Background3 : colourProvider.Background3.Darken(0.3f);
|
|
|
|
|
2022-12-01 21:31:14 +00:00
|
|
|
Enabled.BindValueChanged(_ => updateDisplay(), true);
|
2022-12-02 17:44:21 +00:00
|
|
|
OverlayState.BindValueChanged(_ => updateDisplay());
|
2022-12-01 15:29:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 21:31:14 +00:00
|
|
|
public GlobalAction? Hotkey;
|
|
|
|
|
2022-12-01 15:29:52 +00:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
2022-12-01 12:13:37 +00:00
|
|
|
{
|
2022-12-01 21:31:14 +00:00
|
|
|
updateDisplay();
|
2022-12-01 15:29:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-17 21:16:59 +00:00
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => updateDisplay();
|
2022-12-01 15:29:52 +00:00
|
|
|
|
|
|
|
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
2022-12-19 15:35:20 +00:00
|
|
|
if (e.Action != Hotkey || e.Repeat) return false;
|
2022-12-01 15:29:52 +00:00
|
|
|
|
2022-12-19 15:35:20 +00:00
|
|
|
TriggerClick();
|
|
|
|
return true;
|
2022-12-01 12:13:37 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 15:29:52 +00:00
|
|
|
public virtual void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) { }
|
2022-12-01 21:07:28 +00:00
|
|
|
|
2022-12-01 21:31:14 +00:00
|
|
|
private void updateDisplay()
|
2022-12-01 21:07:28 +00:00
|
|
|
{
|
2022-12-01 21:31:14 +00:00
|
|
|
if (!Enabled.Value)
|
|
|
|
{
|
2022-12-19 10:30:23 +00:00
|
|
|
backgroundBox.FadeColour(colourProvider.Background3.Darken(0.3f), transition_length, Easing.OutQuint);
|
2022-12-01 21:31:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-12-01 21:07:28 +00:00
|
|
|
|
2022-12-19 15:35:20 +00:00
|
|
|
if (OverlayState.Value == Visibility.Visible)
|
2022-12-02 17:44:21 +00:00
|
|
|
{
|
2022-12-19 15:35:20 +00:00
|
|
|
backgroundBox.FadeColour(buttonAccentColour.Darken(0.5f), transition_length, Easing.OutQuint);
|
|
|
|
return;
|
|
|
|
}
|
2022-12-02 17:44:21 +00:00
|
|
|
|
2022-12-19 15:35:20 +00:00
|
|
|
if (IsHovered)
|
|
|
|
{
|
|
|
|
backgroundBox.FadeColour(colourProvider.Background3.Lighten(0.3f), transition_length, Easing.OutQuint);
|
|
|
|
return;
|
2022-12-02 17:44:21 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 15:35:20 +00:00
|
|
|
backgroundBox.FadeColour(colourProvider.Background3, transition_length, Easing.OutQuint);
|
2022-12-01 21:07:28 +00:00
|
|
|
}
|
2022-12-01 12:13:37 +00:00
|
|
|
}
|
|
|
|
}
|