2021-07-02 08:58:24 +00: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-07-15 03:41:03 +00:00
|
|
|
using System;
|
2021-08-12 17:17:32 +00:00
|
|
|
using osu.Framework.Extensions;
|
2021-07-02 08:58:24 +00: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 osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2021-07-02 09:09:16 +00:00
|
|
|
namespace osu.Game.Overlays.BeatmapSet
|
2021-07-02 08:58:24 +00:00
|
|
|
{
|
2022-12-21 18:18:47 +00:00
|
|
|
public abstract partial class MetadataSection : MetadataSection<string>
|
|
|
|
{
|
2022-12-23 19:11:15 +00:00
|
|
|
public override string Metadata
|
2022-12-21 18:18:47 +00:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
{
|
|
|
|
this.FadeOut(TRANSITION_DURATION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-23 19:11:15 +00:00
|
|
|
base.Metadata = value;
|
2022-12-21 18:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected MetadataSection(MetadataType type, Action<string>? searchAction = null)
|
|
|
|
: base(type, searchAction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract partial class MetadataSection<T> : Container
|
2021-07-02 08:58:24 +00:00
|
|
|
{
|
|
|
|
private readonly FillFlowContainer textContainer;
|
2022-12-21 18:18:47 +00:00
|
|
|
private TextFlowContainer? textFlow;
|
2021-07-02 08:58:24 +00:00
|
|
|
|
2022-12-21 18:18:47 +00:00
|
|
|
protected readonly Action<T>? SearchAction;
|
2022-07-15 03:41:03 +00:00
|
|
|
|
2022-12-21 18:18:47 +00:00
|
|
|
protected const float TRANSITION_DURATION = 250;
|
2021-07-02 08:58:24 +00:00
|
|
|
|
2022-12-21 18:18:47 +00:00
|
|
|
protected MetadataSection(MetadataType type, Action<T>? searchAction = null)
|
2021-07-02 08:58:24 +00:00
|
|
|
{
|
2022-12-21 18:18:47 +00:00
|
|
|
SearchAction = searchAction;
|
2021-07-02 08:58:24 +00: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
|
|
|
|
{
|
2022-12-21 18:18:47 +00:00
|
|
|
Text = type.GetLocalisableDescription(),
|
2021-07-02 08:58:24 +00:00
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-23 19:11:15 +00:00
|
|
|
public virtual T Metadata
|
2021-07-02 08:58:24 +00:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2022-12-21 18:18:47 +00:00
|
|
|
if (value == null)
|
2021-07-02 08:58:24 +00:00
|
|
|
{
|
2022-12-21 18:18:47 +00:00
|
|
|
this.FadeOut(TRANSITION_DURATION);
|
2021-07-02 08:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:18:47 +00:00
|
|
|
this.FadeIn(TRANSITION_DURATION);
|
2021-07-02 08:58:24 +00:00
|
|
|
|
2022-12-23 19:11:15 +00:00
|
|
|
setTextFlowAsync(value);
|
2021-07-02 08:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-23 19:11:15 +00:00
|
|
|
private void setTextFlowAsync(T metadata)
|
2021-07-02 08:58:24 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2022-12-23 19:11:15 +00:00
|
|
|
AddMetadata(metadata, loaded);
|
2021-07-02 08:58:24 +00:00
|
|
|
|
|
|
|
textContainer.Add(textFlow = loaded);
|
|
|
|
|
|
|
|
// fade in if we haven't yet.
|
2022-12-21 18:18:47 +00:00
|
|
|
textContainer.FadeIn(TRANSITION_DURATION);
|
2021-07-02 08:58:24 +00:00
|
|
|
});
|
|
|
|
}
|
2022-12-21 18:18:47 +00:00
|
|
|
|
2022-12-23 19:11:15 +00:00
|
|
|
protected abstract void AddMetadata(T metadata, LinkFlowContainer loaded);
|
2021-07-02 08:58:24 +00:00
|
|
|
}
|
|
|
|
}
|