Merge pull request #23606 from Joehuu/fix-news-sidebar-link-clicking-area

Fix clicking area of news sidebar post links
This commit is contained in:
Dean Herbert 2023-05-22 14:17:08 +09:00 committed by GitHub
commit 09c66bea8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 34 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -13,7 +11,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; 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.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -27,8 +24,8 @@ namespace osu.Game.Overlays.News
private readonly APINewsPost post; private readonly APINewsPost post;
private Box background; private Box background = null!;
private TextFlowContainer main; private TextFlowContainer main = null!;
public NewsCard(APINewsPost post) public NewsCard(APINewsPost post)
{ {
@ -41,12 +38,12 @@ namespace osu.Game.Overlays.News
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, GameHost host) private void load(OverlayColourProvider colourProvider, OsuGame? game)
{ {
if (post.Slug != null) if (post.Slug != null)
{ {
TooltipText = "view in browser"; TooltipText = "view in browser";
Action = () => host.OpenUrlExternally("https://osu.ppy.sh/home/news/" + post.Slug); Action = () => game?.OpenUrlExternally(@"/home/news/" + post.Slug);
} }
AddRange(new Drawable[] AddRange(new Drawable[]

View File

@ -20,7 +20,7 @@ using System.Diagnostics;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Platform; using osu.Game.Online.Chat;
namespace osu.Game.Overlays.News.Sidebar namespace osu.Game.Overlays.News.Sidebar
{ {
@ -59,7 +59,7 @@ namespace osu.Game.Overlays.News.Sidebar
new PostsContainer new PostsContainer
{ {
Expanded = { BindTarget = Expanded }, Expanded = { BindTarget = Expanded },
Children = posts.Select(p => new PostButton(p)).ToArray() Children = posts.Select(p => new PostLink(p)).ToArray()
} }
} }
}; };
@ -123,35 +123,14 @@ namespace osu.Game.Overlays.News.Sidebar
} }
} }
private partial class PostButton : OsuHoverContainer private partial class PostLink : LinkFlowContainer
{ {
protected override IEnumerable<Drawable> EffectTargets => new[] { text }; public PostLink(APINewsPost post)
: base(t => t.Font = OsuFont.GetFont(size: 12))
private readonly TextFlowContainer text;
private readonly APINewsPost post;
public PostButton(APINewsPost post)
{ {
this.post = post;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Child = text = new TextFlowContainer(t => t.Font = OsuFont.GetFont(size: 12)) AddLink(post.Title, LinkAction.External, @"/home/news/" + post.Slug, "view in browser");
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Text = post.Title
};
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider overlayColours, GameHost host)
{
IdleColour = overlayColours.Light2;
HoverColour = overlayColours.Light1;
TooltipText = "view in browser";
Action = () => host.OpenUrlExternally("https://osu.ppy.sh/home/news/" + post.Slug);
} }
} }