2021-10-18 03:34:31 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-10-18 03:34:31 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2021-11-10 22:24:36 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-18 03:34:31 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-11-19 05:28:17 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2021-10-18 03:34:31 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
|
|
|
|
{
|
2021-11-19 05:28:17 +08:00
|
|
|
public abstract class BeatmapCardIconButton : OsuClickableContainer
|
2021-10-18 03:34:31 +08:00
|
|
|
{
|
2021-11-19 05:28:17 +08:00
|
|
|
private Colour4 idleColour;
|
2021-11-10 22:24:36 +08:00
|
|
|
|
2021-11-19 05:28:17 +08:00
|
|
|
public Colour4 IdleColour
|
|
|
|
{
|
|
|
|
get => idleColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
idleColour = value;
|
|
|
|
if (IsLoaded)
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Colour4 hoverColour;
|
|
|
|
|
|
|
|
public Colour4 HoverColour
|
|
|
|
{
|
|
|
|
get => hoverColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
hoverColour = value;
|
|
|
|
if (IsLoaded)
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 03:34:31 +08:00
|
|
|
|
2021-11-10 22:24:36 +08:00
|
|
|
private float iconSize;
|
2021-10-18 03:34:31 +08:00
|
|
|
|
2021-11-10 22:24:36 +08:00
|
|
|
public float IconSize
|
2021-10-18 03:34:31 +08:00
|
|
|
{
|
2021-11-10 22:24:36 +08:00
|
|
|
get => iconSize;
|
2021-10-18 03:34:31 +08:00
|
|
|
set
|
|
|
|
{
|
2021-11-10 22:24:36 +08:00
|
|
|
iconSize = value;
|
|
|
|
Icon.Size = new Vector2(iconSize);
|
2021-10-18 03:34:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 05:28:17 +08:00
|
|
|
protected readonly SpriteIcon Icon;
|
|
|
|
|
2021-11-26 14:32:33 +08:00
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
2021-11-19 14:27:51 +08:00
|
|
|
private readonly Container content;
|
|
|
|
|
2021-10-18 03:34:31 +08:00
|
|
|
protected BeatmapCardIconButton()
|
|
|
|
{
|
2021-11-19 14:27:51 +08:00
|
|
|
Origin = Anchor.Centre;
|
|
|
|
Anchor = Anchor.Centre;
|
2021-11-19 05:28:17 +08:00
|
|
|
|
2021-11-26 14:32:33 +08:00
|
|
|
base.Content.Add(content = new Container
|
2021-11-10 22:24:36 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
2021-11-19 14:27:51 +08:00
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
2021-11-10 22:24:36 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
Icon = new SpriteIcon
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre
|
|
|
|
}
|
|
|
|
}
|
2021-11-26 14:32:33 +08:00
|
|
|
});
|
2021-10-18 03:34:31 +08:00
|
|
|
|
2021-11-10 22:24:36 +08:00
|
|
|
Size = new Vector2(24);
|
|
|
|
IconSize = 12;
|
2021-10-18 03:34:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
2021-11-19 05:28:17 +08:00
|
|
|
IdleColour = colourProvider.Light1;
|
|
|
|
HoverColour = colourProvider.Content1;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Enabled.BindValueChanged(_ => updateState(), true);
|
|
|
|
FinishTransforms(true);
|
|
|
|
}
|
2021-10-18 03:34:31 +08:00
|
|
|
|
2021-11-19 05:28:17 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
2021-11-19 14:27:51 +08:00
|
|
|
bool isHovered = IsHovered && Enabled.Value;
|
|
|
|
|
|
|
|
content.ScaleTo(isHovered ? 1.2f : 1, 500, Easing.OutQuint);
|
2021-12-21 15:26:19 +08:00
|
|
|
content.FadeColour(isHovered ? HoverColour : IdleColour, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-10-18 03:34:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|