mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:52:55 +08:00
Make news cards clickable
This commit is contained in:
parent
dac98c8914
commit
2d9909cdd8
@ -31,15 +31,16 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
new NewsCard(new APINewsPost
|
new NewsCard(new APINewsPost
|
||||||
{
|
{
|
||||||
Title = "This post has an image which starts with \"/\" and has many authors!",
|
Title = "This post has an image which starts with \"/\" and has many authors! (clickable)",
|
||||||
Preview = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
Preview = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||||
Author = "someone, someone1, someone2, someone3, someone4",
|
Author = "someone, someone1, someone2, someone3, someone4",
|
||||||
FirstImage = "/help/wiki/shared/news/banners/monthly-beatmapping-contest.png",
|
FirstImage = "/help/wiki/shared/news/banners/monthly-beatmapping-contest.png",
|
||||||
PublishedAt = DateTimeOffset.Now
|
PublishedAt = DateTimeOffset.Now,
|
||||||
|
Slug = "2020-07-16-summer-theme-park-2020-voting-open"
|
||||||
}),
|
}),
|
||||||
new NewsCard(new APINewsPost
|
new NewsCard(new APINewsPost
|
||||||
{
|
{
|
||||||
Title = "This post has a full-url image! (HTML entity: &)",
|
Title = "This post has a full-url image! (HTML entity: &) (non-clickable)",
|
||||||
Preview = "boom (HTML entity: &)",
|
Preview = "boom (HTML entity: &)",
|
||||||
Author = "user (HTML entity: &)",
|
Author = "user (HTML entity: &)",
|
||||||
FirstImage = "https://assets.ppy.sh/artists/88/header.jpg",
|
FirstImage = "https://assets.ppy.sh/artists/88/header.jpg",
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -10,18 +11,17 @@ 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.Framework.Platform;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.News
|
namespace osu.Game.Overlays.News
|
||||||
{
|
{
|
||||||
public class NewsCard : CompositeDrawable
|
public class NewsCard : OsuHoverContainer
|
||||||
{
|
{
|
||||||
[Resolved]
|
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
||||||
private OverlayColourProvider colourProvider { get; set; }
|
|
||||||
|
|
||||||
private readonly APINewsPost post;
|
private readonly APINewsPost post;
|
||||||
|
|
||||||
@ -31,24 +31,28 @@ namespace osu.Game.Overlays.News
|
|||||||
public NewsCard(APINewsPost post)
|
public NewsCard(APINewsPost post)
|
||||||
{
|
{
|
||||||
this.post = post;
|
this.post = post;
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
Masking = true;
|
Masking = true;
|
||||||
CornerRadius = 6;
|
CornerRadius = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider, GameHost host)
|
||||||
|
{
|
||||||
|
if (post.Slug != null)
|
||||||
|
{
|
||||||
|
TooltipText = "view in browser";
|
||||||
|
Action = () => host.OpenUrlExternally("https://osu.ppy.sh/home/news/" + post.Slug);
|
||||||
|
}
|
||||||
|
|
||||||
NewsBackground bg;
|
NewsBackground bg;
|
||||||
|
AddRange(new Drawable[]
|
||||||
InternalChildren = new Drawable[]
|
|
||||||
{
|
{
|
||||||
background = new Box
|
background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both
|
||||||
Colour = colourProvider.Background4
|
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -104,9 +108,11 @@ namespace osu.Game.Overlays.News
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
new HoverClickSounds()
|
});
|
||||||
};
|
|
||||||
|
IdleColour = colourProvider.Background4;
|
||||||
|
HoverColour = colourProvider.Background3;
|
||||||
|
|
||||||
bg.OnLoadComplete += d => d.FadeIn(250, Easing.In);
|
bg.OnLoadComplete += d => d.FadeIn(250, Easing.In);
|
||||||
|
|
||||||
@ -116,18 +122,6 @@ namespace osu.Game.Overlays.News
|
|||||||
main.AddText(post.Author, t => t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold));
|
main.AddText(post.Author, t => t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
|
||||||
{
|
|
||||||
background.FadeColour(colourProvider.Background3, 200, Easing.OutQuint);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
|
||||||
{
|
|
||||||
background.FadeColour(colourProvider.Background4, 200, Easing.OutQuint);
|
|
||||||
base.OnHoverLost(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
[LongRunningLoad]
|
[LongRunningLoad]
|
||||||
private class NewsBackground : Sprite
|
private class NewsBackground : Sprite
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user