1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 07:53:38 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Components/BeatmapTitle.cs

83 lines
2.3 KiB
C#
Raw Normal View History

// 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.
2020-02-13 17:48:28 +08:00
using System.Linq;
2018-12-26 16:07:59 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
2018-12-26 16:07:59 +08:00
using osu.Game.Graphics;
2018-12-20 19:03:39 +08:00
using osu.Game.Graphics.Containers;
using osu.Game.Online.Chat;
namespace osu.Game.Screens.OnlinePlay.Components
{
public class BeatmapTitle : OnlinePlayComposite
{
2018-12-20 19:03:39 +08:00
private readonly LinkFlowContainer textFlow;
public BeatmapTitle()
{
AutoSizeAxes = Axes.Both;
2018-12-20 19:03:39 +08:00
InternalChild = textFlow = new LinkFlowContainer { AutoSizeAxes = Axes.Both };
}
2019-02-05 18:00:01 +08:00
[BackgroundDependencyLoader]
private void load()
{
Playlist.CollectionChanged += (_, __) => updateText();
2020-02-13 17:48:28 +08:00
updateText();
}
private float textSize = OsuFont.DEFAULT_FONT_SIZE;
2018-12-22 13:01:06 +08:00
public float TextSize
{
get => textSize;
set
{
if (textSize == value)
return;
2019-02-28 12:31:40 +08:00
2018-12-22 13:01:06 +08:00
textSize = value;
updateText();
}
}
2018-12-26 16:07:59 +08:00
[Resolved]
private OsuColour colours { get; set; }
private void updateText()
{
2019-02-13 13:57:40 +08:00
if (LoadState < LoadState.Loading)
return;
2018-12-20 19:03:39 +08:00
textFlow.Clear();
2020-02-13 17:48:28 +08:00
var beatmap = Playlist.FirstOrDefault()?.Beatmap;
2019-02-11 18:11:34 +08:00
if (beatmap == null)
2019-11-11 19:53:22 +08:00
{
2018-12-26 16:07:59 +08:00
textFlow.AddText("No beatmap selected", s =>
{
s.Font = s.Font.With(size: TextSize);
2018-12-26 16:07:59 +08:00
s.Colour = colours.PinkLight;
});
2019-11-11 19:53:22 +08:00
}
else
{
var metadataInfo = beatmap.Metadata;
string artistUnicode = string.IsNullOrEmpty(metadataInfo.ArtistUnicode) ? metadataInfo.Artist : metadataInfo.ArtistUnicode;
string titleUnicode = string.IsNullOrEmpty(metadataInfo.TitleUnicode) ? metadataInfo.Title : metadataInfo.TitleUnicode;
var title = new RomanisableString($"{artistUnicode} - {titleUnicode}".Trim(), $"{metadataInfo.Artist} - {metadataInfo.Title}".Trim());
textFlow.AddLink(title, LinkAction.OpenBeatmap, beatmap.OnlineID.ToString(), "Open beatmap");
}
}
}
}