linkify metadata

This commit is contained in:
unknown
2020-01-30 12:30:25 +08:00
parent 7f59576f13
commit c5995acfff
5 changed files with 85 additions and 19 deletions

View File

@ -19,6 +19,8 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Overlays;
using osu.Game.Online.Chat;
namespace osu.Game.Screens.Select
{
@ -127,9 +129,9 @@ namespace osu.Game.Screens.Select
Margin = new MarginPadding { Top = spacing * 2 },
Children = new[]
{
description = new MetadataSection("Description"),
source = new MetadataSection("Source"),
tags = new MetadataSection("Tags"),
description = new MetadataSection(MetadataType.Description),
source = new MetadataSection(MetadataType.Source),
tags = new MetadataSection(MetadataType.Tags),
},
},
},
@ -299,10 +301,11 @@ namespace osu.Game.Screens.Select
private class MetadataSection : Container
{
private readonly FillFlowContainer textContainer;
private readonly MetadataType type;
private TextFlowContainer textFlow;
public MetadataSection(string title)
public MetadataSection(MetadataType type)
{
this.type = type;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
@ -320,7 +323,7 @@ namespace osu.Game.Screens.Select
AutoSizeAxes = Axes.Y,
Child = new OsuSpriteText
{
Text = title,
Text = this.type.ToString(),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
},
},
@ -346,15 +349,29 @@ namespace osu.Game.Screens.Select
private void setTextAsync(string text)
{
LoadComponentAsync(new OsuTextFlowContainer(s => s.Font = s.Font.With(size: 14))
LoadComponentAsync(new LinkFlowContainer(s => s.Font = s.Font.With(size: 14))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Colour = Color4.White.Opacity(0.75f),
Text = text
}, loaded =>
{
textFlow?.Expire();
switch(type)
{
case MetadataType.Tags:
foreach (string tag in text.Split(" "))
loaded.AddLink(tag + " ", LinkAction.OpenDirectWithSearch, tag);
break;
case MetadataType.Source:
loaded.AddLink(text, LinkAction.OpenDirectWithSearch, text);
break;
default:
loaded.AddText(text);
break;
}
textContainer.Add(textFlow = loaded);
// fade in if we haven't yet.
@ -363,4 +380,13 @@ namespace osu.Game.Screens.Select
}
}
}
public enum MetadataType
{
Tags,
Source,
Description,
Genre,
Language
}
}