mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:03:11 +08:00
linkify metadata
This commit is contained in:
parent
7f59576f13
commit
c5995acfff
@ -279,7 +279,8 @@ namespace osu.Game.Online.Chat
|
||||
JoinMultiplayerMatch,
|
||||
Spectate,
|
||||
OpenUserProfile,
|
||||
Custom
|
||||
Custom,
|
||||
OpenDirectWithSearch
|
||||
}
|
||||
|
||||
public class Link : IComparable<Link>
|
||||
|
@ -244,6 +244,10 @@ namespace osu.Game
|
||||
ShowChannel(link.Argument);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenDirectWithSearch:
|
||||
ShowDirectWithSearch(link.Argument);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenEditorTimestamp:
|
||||
case LinkAction.JoinMultiplayerMatch:
|
||||
case LinkAction.Spectate:
|
||||
@ -310,6 +314,12 @@ namespace osu.Game
|
||||
/// <param name="beatmapId">The beatmap to show.</param>
|
||||
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>
|
||||
/// Present a beatmap at song select immediately.
|
||||
/// The user should have already requested this interactively.
|
||||
|
@ -8,10 +8,13 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Screens.Select;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -68,7 +71,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new MetadataSection("Description"),
|
||||
Child = new MetadataSection(MetadataType.Description),
|
||||
},
|
||||
},
|
||||
new Container
|
||||
@ -86,10 +89,10 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Direction = FillDirection.Full,
|
||||
Children = new[]
|
||||
{
|
||||
source = new MetadataSection("Source"),
|
||||
genre = new MetadataSection("Genre") { Width = 0.5f },
|
||||
language = new MetadataSection("Language") { Width = 0.5f },
|
||||
tags = new MetadataSection("Tags"),
|
||||
source = new MetadataSection(MetadataType.Source),
|
||||
genre = new MetadataSection(MetadataType.Genre) { Width = 0.5f },
|
||||
language = new MetadataSection(MetadataType.Language) { Width = 0.5f },
|
||||
tags = new MetadataSection(MetadataType.Tags),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -133,8 +136,9 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
private class MetadataSection : FillFlowContainer
|
||||
{
|
||||
private readonly MetadataType type;
|
||||
private readonly OsuSpriteText header;
|
||||
private readonly TextFlowContainer textFlow;
|
||||
private readonly LinkFlowContainer textFlow;
|
||||
|
||||
public string Text
|
||||
{
|
||||
@ -147,13 +151,32 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
}
|
||||
|
||||
this.FadeIn(transition_duration);
|
||||
|
||||
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;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Spacing = new Vector2(5f);
|
||||
@ -162,12 +185,12 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
header = new OsuSpriteText
|
||||
{
|
||||
Text = title,
|
||||
Text = this.type.ToString(),
|
||||
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
|
||||
Shadow = false,
|
||||
Margin = new MarginPadding { Top = 20 },
|
||||
},
|
||||
textFlow = new OsuTextFlowContainer
|
||||
textFlow = new LinkFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
|
@ -154,6 +154,12 @@ namespace osu.Game.Overlays
|
||||
updateResultCounts();
|
||||
}
|
||||
|
||||
public void ShowWithSearch(string query)
|
||||
{
|
||||
currentQuery.Value = query;
|
||||
Show();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, RulesetStore rulesets, PreviewTrackManager previewTrackManager)
|
||||
{
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user