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