1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 01:32:55 +08:00

Make gradient in NewsArticleCover be effected by hover (#7509)

Make gradient in NewsArticleCover be effected by hover
This commit is contained in:
Dean Herbert 2020-01-13 15:34:46 +08:00 committed by GitHub
commit 8059922aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK.Graphics; using osuTK.Graphics;
@ -19,6 +20,10 @@ namespace osu.Game.Overlays.News
{ {
public class NewsArticleCover : Container public class NewsArticleCover : Container
{ {
private const int hover_duration = 300;
private readonly Box gradient;
public NewsArticleCover(ArticleInfo info) public NewsArticleCover(ArticleInfo info)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -47,11 +52,11 @@ namespace osu.Game.Overlays.News
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
new Box gradient = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.6f)), Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.1f), Color4.Black.Opacity(0.7f)),
Alpha = 1f, Alpha = 0
}, },
new DateContainer(info.Time) new DateContainer(info.Time)
{ {
@ -90,6 +95,18 @@ namespace osu.Game.Overlays.News
bg.OnLoadComplete += d => d.FadeIn(250, Easing.In); bg.OnLoadComplete += d => d.FadeIn(250, Easing.In);
} }
protected override bool OnHover(HoverEvent e)
{
gradient.FadeIn(hover_duration, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
gradient.FadeOut(hover_duration, Easing.OutQuint);
}
[LongRunningLoad] [LongRunningLoad]
private class NewsBackground : Sprite private class NewsBackground : Sprite
{ {