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

@ -279,7 +279,8 @@ namespace osu.Game.Online.Chat
JoinMultiplayerMatch, JoinMultiplayerMatch,
Spectate, Spectate,
OpenUserProfile, OpenUserProfile,
Custom Custom,
OpenDirectWithSearch
} }
public class Link : IComparable<Link> public class Link : IComparable<Link>

View File

@ -244,6 +244,10 @@ namespace osu.Game
ShowChannel(link.Argument); ShowChannel(link.Argument);
break; break;
case LinkAction.OpenDirectWithSearch:
ShowDirectWithSearch(link.Argument);
break;
case LinkAction.OpenEditorTimestamp: case LinkAction.OpenEditorTimestamp:
case LinkAction.JoinMultiplayerMatch: case LinkAction.JoinMultiplayerMatch:
case LinkAction.Spectate: case LinkAction.Spectate:
@ -310,6 +314,12 @@ namespace osu.Game
/// <param name="beatmapId">The beatmap to show.</param> /// <param name="beatmapId">The beatmap to show.</param>
public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId)); public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId));
/// <summary>
/// Show Direct with a query.
/// </summary>
/// <param name="query">The query to search for.null</param>
public void ShowDirectWithSearch(string query) => waitForReady(() => direct, _ => direct.ShowWithSearch(query));
/// <summary> /// <summary>
/// Present a beatmap at song select immediately. /// Present a beatmap at song select immediately.
/// The user should have already requested this interactively. /// The user should have already requested this interactively.

View File

@ -8,10 +8,13 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
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;
using osu.Game.Online.Chat;
using osu.Game.Screens.Select;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -68,7 +71,7 @@ namespace osu.Game.Overlays.BeatmapSet
Child = new Container Child = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new MetadataSection("Description"), Child = new MetadataSection(MetadataType.Description),
}, },
}, },
new Container new Container
@ -86,10 +89,10 @@ namespace osu.Game.Overlays.BeatmapSet
Direction = FillDirection.Full, Direction = FillDirection.Full,
Children = new[] Children = new[]
{ {
source = new MetadataSection("Source"), source = new MetadataSection(MetadataType.Source),
genre = new MetadataSection("Genre") { Width = 0.5f }, genre = new MetadataSection(MetadataType.Genre) { Width = 0.5f },
language = new MetadataSection("Language") { Width = 0.5f }, language = new MetadataSection(MetadataType.Language) { Width = 0.5f },
tags = new MetadataSection("Tags"), tags = new MetadataSection(MetadataType.Tags),
}, },
}, },
}, },
@ -133,8 +136,9 @@ namespace osu.Game.Overlays.BeatmapSet
private class MetadataSection : FillFlowContainer private class MetadataSection : FillFlowContainer
{ {
private readonly MetadataType type;
private readonly OsuSpriteText header; private readonly OsuSpriteText header;
private readonly TextFlowContainer textFlow; private readonly LinkFlowContainer textFlow;
public string Text public string Text
{ {
@ -147,13 +151,32 @@ namespace osu.Game.Overlays.BeatmapSet
} }
this.FadeIn(transition_duration); this.FadeIn(transition_duration);
textFlow.Clear(); textFlow.Clear();
textFlow.AddText(value, s => s.Font = s.Font.With(size: 14)); static void format(SpriteText t) => t.Font = t.Font.With(size: 14);
switch(type)
{
case MetadataType.Tags:
foreach (string tag in value.Split(" "))
textFlow.AddLink(tag + " ", LinkAction.OpenDirectWithSearch, tag, null, format);
break;
case MetadataType.Source:
textFlow.AddLink(value, LinkAction.OpenDirectWithSearch, value, null, format);
break;
default:
textFlow.AddText(value, format);
break;
}
} }
} }
public MetadataSection(string title) public MetadataSection(MetadataType type)
{ {
this.type = type;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Spacing = new Vector2(5f); Spacing = new Vector2(5f);
@ -162,12 +185,12 @@ namespace osu.Game.Overlays.BeatmapSet
{ {
header = new OsuSpriteText header = new OsuSpriteText
{ {
Text = title, Text = this.type.ToString(),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
Shadow = false, Shadow = false,
Margin = new MarginPadding { Top = 20 }, Margin = new MarginPadding { Top = 20 },
}, },
textFlow = new OsuTextFlowContainer textFlow = new LinkFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,

View File

@ -154,6 +154,12 @@ namespace osu.Game.Overlays
updateResultCounts(); updateResultCounts();
} }
public void ShowWithSearch(string query)
{
currentQuery.Value = query;
Show();
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, RulesetStore rulesets, PreviewTrackManager previewTrackManager) private void load(OsuColour colours, RulesetStore rulesets, PreviewTrackManager previewTrackManager)
{ {

View File

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