mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Make DrawableRoom look up the online beatmap
This commit is contained in:
parent
ccd265ebe7
commit
73ce1b324e
@ -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)
|
||||||
statusText.Text = "Currently playing ";
|
return;
|
||||||
beatmapText.AddLink(item.NewValue.Beatmap.Value.GetDisplayTitleRomanisable(),
|
|
||||||
LinkAction.OpenBeatmap,
|
var cancellationSource = beatmapLookupCancellation = new CancellationTokenSource();
|
||||||
item.NewValue.Beatmap.Value.OnlineID.ToString(),
|
beatmapLookupCache.GetBeatmapAsync(beatmap.Value.OnlineID, cancellationSource.Token)
|
||||||
creationParameters: s =>
|
.ContinueWith(task => Schedule(() =>
|
||||||
{
|
{
|
||||||
s.Truncate = true;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user