2021-07-02 16:58:24 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-07-15 11:41:03 +08:00
|
|
|
using System;
|
2021-08-13 01:17:32 +08:00
|
|
|
using osu.Framework.Extensions;
|
2021-07-02 16:58:24 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2021-07-02 17:09:16 +08:00
|
|
|
namespace osu.Game.Overlays.BeatmapSet
|
2021-07-02 16:58:24 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class MetadataSection : Container
|
2021-07-02 16:58:24 +08:00
|
|
|
{
|
|
|
|
private readonly FillFlowContainer textContainer;
|
|
|
|
private readonly MetadataType type;
|
|
|
|
private TextFlowContainer textFlow;
|
|
|
|
|
2022-07-15 11:41:03 +08:00
|
|
|
private readonly Action<string> searchAction;
|
|
|
|
|
2021-07-02 16:58:24 +08:00
|
|
|
private const float transition_duration = 250;
|
|
|
|
|
2022-07-15 11:41:03 +08:00
|
|
|
public MetadataSection(MetadataType type, Action<string> searchAction = null)
|
2021-07-02 16:58:24 +08:00
|
|
|
{
|
|
|
|
this.type = type;
|
2022-07-15 11:41:03 +08:00
|
|
|
this.searchAction = searchAction;
|
2021-07-02 16:58:24 +08:00
|
|
|
|
|
|
|
Alpha = 0;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChild = textContainer = new FillFlowContainer
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
|
|
|
Margin = new MarginPadding { Top = 15 },
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Child = new OsuSpriteText
|
|
|
|
{
|
2021-08-13 01:17:32 +08:00
|
|
|
Text = this.type.GetLocalisableDescription(),
|
2021-07-02 16:58:24 +08:00
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
{
|
|
|
|
this.FadeOut(transition_duration);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.FadeIn(transition_duration);
|
|
|
|
|
|
|
|
setTextAsync(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setTextAsync(string text)
|
|
|
|
{
|
|
|
|
LoadComponentAsync(new LinkFlowContainer(s => s.Font = s.Font.With(size: 14))
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Colour = Color4.White.Opacity(0.75f),
|
|
|
|
}, loaded =>
|
|
|
|
{
|
|
|
|
textFlow?.Expire();
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case MetadataType.Tags:
|
|
|
|
string[] tags = text.Split(" ");
|
|
|
|
|
|
|
|
for (int i = 0; i <= tags.Length - 1; i++)
|
|
|
|
{
|
2022-07-15 11:41:03 +08:00
|
|
|
string tag = tags[i];
|
|
|
|
|
|
|
|
if (searchAction != null)
|
|
|
|
loaded.AddLink(tag, () => searchAction(tag));
|
|
|
|
else
|
|
|
|
loaded.AddLink(tag, LinkAction.SearchBeatmapSet, tag);
|
2021-07-02 16:58:24 +08:00
|
|
|
|
|
|
|
if (i != tags.Length - 1)
|
|
|
|
loaded.AddText(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MetadataType.Source:
|
2022-07-15 11:41:03 +08:00
|
|
|
if (searchAction != null)
|
|
|
|
loaded.AddLink(text, () => searchAction(text));
|
|
|
|
else
|
|
|
|
loaded.AddLink(text, LinkAction.SearchBeatmapSet, text);
|
|
|
|
|
2021-07-02 16:58:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
loaded.AddText(text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
textContainer.Add(textFlow = loaded);
|
|
|
|
|
|
|
|
// fade in if we haven't yet.
|
|
|
|
textContainer.FadeIn(transition_duration);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|