2019-08-08 12:08:51 +08: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.
|
|
|
|
|
|
2019-08-13 16:57:16 +08:00
|
|
|
|
using System.Threading;
|
2019-08-08 12:08:51 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2019-08-13 16:57:16 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2019-08-08 12:08:51 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Overlays.Direct;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.Match.Components
|
|
|
|
|
{
|
|
|
|
|
public class MatchBeatmapPanel : MultiplayerComposite
|
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
|
2019-08-13 16:57:16 +08:00
|
|
|
|
private CancellationTokenSource loadCancellation;
|
2019-08-08 12:08:51 +08:00
|
|
|
|
private GetBeatmapSetRequest request;
|
2019-08-08 17:08:51 +08:00
|
|
|
|
private DirectGridPanel panel;
|
2019-08-08 12:08:51 +08:00
|
|
|
|
|
|
|
|
|
public MatchBeatmapPanel()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2019-08-13 16:57:16 +08:00
|
|
|
|
CurrentItem.BindValueChanged(item => loadNewPanel(item.NewValue?.Beatmap), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadNewPanel(BeatmapInfo beatmap)
|
|
|
|
|
{
|
|
|
|
|
loadCancellation?.Cancel();
|
|
|
|
|
request?.Cancel();
|
|
|
|
|
|
|
|
|
|
panel?.FadeOut(200);
|
|
|
|
|
panel?.Expire();
|
|
|
|
|
panel = null;
|
|
|
|
|
|
|
|
|
|
if (beatmap?.OnlineBeatmapID == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
loadCancellation = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
request = new GetBeatmapSetRequest(beatmap.OnlineBeatmapID.Value, BeatmapSetLookupType.BeatmapId);
|
|
|
|
|
request.Success += res => Schedule(() =>
|
2019-08-08 12:08:51 +08:00
|
|
|
|
{
|
2019-08-13 16:57:16 +08:00
|
|
|
|
panel = new DirectGridPanel(res.ToBeatmapSet(rulesets));
|
|
|
|
|
LoadComponentAsync(panel, AddInternal, loadCancellation.Token);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
api.Queue(request);
|
2019-08-08 12:08:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|