1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:22:56 +08:00

Make DrawableRoom look up the online beatmap

This commit is contained in:
Dan Balasescu 2022-02-15 22:44:20 +09:00
parent ccd265ebe7
commit 73ce1b324e

View File

@ -2,8 +2,10 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
@ -12,6 +14,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -328,6 +331,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
[Resolved]
private OsuColour colours { get; set; }
[Resolved]
private BeatmapLookupCache beatmapLookupCache { get; set; }
private SpriteText statusText;
private LinkFlowContainer beatmapText;
@ -385,8 +391,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
SelectedItem.BindValueChanged(onSelectedItemChanged, true);
}
private CancellationTokenSource beatmapLookupCancellation;
private void onSelectedItemChanged(ValueChangedEvent<PlaylistItem> item)
{
beatmapLookupCancellation?.Cancel();
beatmapText.Clear();
if (Type.Value == MatchType.Playlists)
@ -395,17 +404,25 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
return;
}
if (item.NewValue?.Beatmap.Value != null)
{
statusText.Text = "Currently playing ";
beatmapText.AddLink(item.NewValue.Beatmap.Value.GetDisplayTitleRomanisable(),
LinkAction.OpenBeatmap,
item.NewValue.Beatmap.Value.OnlineID.ToString(),
creationParameters: s =>
{
s.Truncate = true;
});
}
var beatmap = item.NewValue?.Beatmap;
if (beatmap == null)
return;
var cancellationSource = beatmapLookupCancellation = new CancellationTokenSource();
beatmapLookupCache.GetBeatmapAsync(beatmap.Value.OnlineID, cancellationSource.Token)
.ContinueWith(task => Schedule(() =>
{
if (cancellationSource.IsCancellationRequested)
return;
var retrievedBeatmap = task.GetResultSafely();
statusText.Text = "Currently playing ";
beatmapText.AddLink(retrievedBeatmap.GetDisplayTitleRomanisable(),
LinkAction.OpenBeatmap,
retrievedBeatmap.OnlineID.ToString(),
creationParameters: s => s.Truncate = true);
}), cancellationSource.Token);
}
}