1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 12:45:09 +08:00

Add hover box to beatmap card icon button

This commit is contained in:
Salman Ahmed 2022-10-13 15:52:06 +03:00
parent ebc1088457
commit aa8040d696

View File

@ -4,13 +4,16 @@
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
@ -59,6 +62,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
protected override Container<Drawable> Content => content;
private readonly Container content;
private readonly Box hover;
protected BeatmapCardIconButton()
{
@ -69,6 +73,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = BeatmapCard.CORNER_RADIUS,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
@ -76,8 +81,14 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
Icon = new SpriteIcon
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre
}
Anchor = Anchor.Centre,
},
hover = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White.Opacity(0.1f),
Blending = BlendingParameters.Additive,
},
}
});
@ -116,8 +127,9 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
bool isHovered = IsHovered && Enabled.Value;
content.ScaleTo(isHovered ? 1.2f : 1, 500, Easing.OutQuint);
content.FadeColour(isHovered ? HoverColour : IdleColour, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
hover.FadeTo(isHovered ? 1f : 0f, 500, Easing.OutQuint);
Icon.ScaleTo(isHovered ? 1.2f : 1, 500, Easing.OutQuint);
Icon.FadeColour(isHovered ? HoverColour : IdleColour, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
}
}
}