2019-01-24 17:43:03 +09: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.
|
2018-12-14 19:52:03 +09:00
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
#nullable disable
|
|
|
|
|
2022-01-28 23:14:26 +09:00
|
|
|
using System.Threading;
|
2018-12-14 19:52:03 +09:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-14 19:52:03 +09:00
|
|
|
using osu.Game.Online.API;
|
2018-12-22 15:45:16 +09:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-12-14 19:52:03 +09:00
|
|
|
using osu.Game.Online.Leaderboards;
|
2020-12-25 13:38:11 +09:00
|
|
|
using osu.Game.Online.Rooms;
|
2018-12-14 19:52:03 +09:00
|
|
|
|
2020-12-25 16:50:00 +01:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Match.Components
|
2018-12-14 19:52:03 +09:00
|
|
|
{
|
2019-12-03 16:10:25 +09:00
|
|
|
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
|
2018-12-14 19:52:03 +09:00
|
|
|
{
|
2019-02-05 19:00:01 +09:00
|
|
|
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
2021-02-16 19:29:40 +09:00
|
|
|
private Bindable<long?> roomId { get; set; }
|
2019-01-08 19:24:55 +09:00
|
|
|
|
2018-12-14 19:52:03 +09:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-02-22 20:13:38 +09:00
|
|
|
roomId.BindValueChanged(id =>
|
2018-12-14 19:52:03 +09:00
|
|
|
{
|
2019-02-22 20:13:38 +09:00
|
|
|
if (id.NewValue == null)
|
2018-12-25 13:57:25 +09:00
|
|
|
return;
|
|
|
|
|
2022-01-30 16:16:00 +09:00
|
|
|
SetScores(null);
|
2022-01-28 21:22:09 +09:00
|
|
|
RefetchScores();
|
2018-12-14 19:52:03 +09:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2019-07-21 10:42:40 +09:00
|
|
|
protected override bool IsOnlineScope => true;
|
2019-07-21 03:07:27 +03:00
|
|
|
|
2022-01-28 23:14:26 +09:00
|
|
|
protected override APIRequest FetchScores(CancellationToken cancellationToken)
|
2018-12-14 19:52:03 +09:00
|
|
|
{
|
2019-02-05 19:00:01 +09:00
|
|
|
if (roomId.Value == null)
|
2018-12-14 19:52:03 +09:00
|
|
|
return null;
|
|
|
|
|
2020-08-31 19:54:41 +09:00
|
|
|
var req = new GetRoomLeaderboardRequest(roomId.Value ?? 0);
|
2018-12-14 19:52:03 +09:00
|
|
|
|
2022-05-27 20:03:30 +09:00
|
|
|
req.Success += r => Schedule(() =>
|
2018-12-21 18:22:13 +09:00
|
|
|
{
|
2022-01-28 23:14:26 +09:00
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
|
|
return;
|
|
|
|
|
2022-01-30 16:16:00 +09:00
|
|
|
SetScores(r.Leaderboard, r.UserScore);
|
2022-05-27 20:03:30 +09:00
|
|
|
});
|
2018-12-14 19:52:03 +09:00
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2019-12-03 16:10:25 +09:00
|
|
|
protected override LeaderboardScore CreateDrawableScore(APIUserScoreAggregate model, int index) => new MatchLeaderboardScore(model, index);
|
2020-08-31 19:54:22 +09:00
|
|
|
|
2020-09-02 14:28:31 +09:00
|
|
|
protected override LeaderboardScore CreateDrawableTopScore(APIUserScoreAggregate model) => new MatchLeaderboardScore(model, model.Position, false);
|
2018-12-14 19:52:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum MatchLeaderboardScope
|
|
|
|
{
|
|
|
|
Overall
|
|
|
|
}
|
|
|
|
}
|