2019-01-24 16:43:03 +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.
|
2018-12-14 18:52:03 +08:00
|
|
|
|
2024-11-13 15:38:49 +08:00
|
|
|
using System.ComponentModel;
|
2022-01-28 22:14:26 +08:00
|
|
|
using System.Threading;
|
2018-12-14 18:52:03 +08:00
|
|
|
using osu.Game.Online.API;
|
2018-12-22 14:45:16 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-12-14 18:52:03 +08:00
|
|
|
using osu.Game.Online.Leaderboards;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2018-12-14 18:52:03 +08:00
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Match.Components
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2024-11-13 15:38:49 +08:00
|
|
|
private readonly Room room;
|
2019-01-08 18:24:55 +08:00
|
|
|
|
2024-11-13 15:38:49 +08:00
|
|
|
public MatchLeaderboard(Room room)
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2024-11-13 15:38:49 +08:00
|
|
|
this.room = room;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
room.PropertyChanged += onRoomPropertyChanged;
|
|
|
|
fetchInitialScores();
|
|
|
|
}
|
2018-12-25 12:57:25 +08:00
|
|
|
|
2024-11-13 15:38:49 +08:00
|
|
|
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.PropertyName == nameof(Room.RoomID))
|
|
|
|
fetchInitialScores();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchInitialScores()
|
|
|
|
{
|
|
|
|
if (room.RoomID == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetScores(null);
|
|
|
|
RefetchScores();
|
2018-12-14 18:52:03 +08:00
|
|
|
}
|
|
|
|
|
2019-07-21 09:42:40 +08:00
|
|
|
protected override bool IsOnlineScope => true;
|
2019-07-21 08:07:27 +08:00
|
|
|
|
2022-09-26 15:15:18 +08:00
|
|
|
protected override APIRequest? FetchScores(CancellationToken cancellationToken)
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2024-11-13 15:38:49 +08:00
|
|
|
if (room.RoomID == null)
|
2018-12-14 18:52:03 +08:00
|
|
|
return null;
|
|
|
|
|
2024-11-13 15:38:49 +08:00
|
|
|
var req = new GetRoomLeaderboardRequest(room.RoomID.Value);
|
2018-12-14 18:52:03 +08:00
|
|
|
|
2022-05-27 19:03:30 +08:00
|
|
|
req.Success += r => Schedule(() =>
|
2018-12-21 17:22:13 +08:00
|
|
|
{
|
2022-01-28 22:14:26 +08:00
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
|
|
return;
|
|
|
|
|
2022-01-30 15:16:00 +08:00
|
|
|
SetScores(r.Leaderboard, r.UserScore);
|
2022-05-27 19:03:30 +08:00
|
|
|
});
|
2018-12-14 18:52:03 +08:00
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2019-12-03 15:10:25 +08:00
|
|
|
protected override LeaderboardScore CreateDrawableScore(APIUserScoreAggregate model, int index) => new MatchLeaderboardScore(model, index);
|
2020-08-31 18:54:22 +08:00
|
|
|
|
2020-09-02 13:28:31 +08:00
|
|
|
protected override LeaderboardScore CreateDrawableTopScore(APIUserScoreAggregate model) => new MatchLeaderboardScore(model, model.Position, false);
|
2024-11-13 15:38:49 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
room.PropertyChanged -= onRoomPropertyChanged;
|
|
|
|
}
|
2018-12-14 18:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum MatchLeaderboardScope
|
|
|
|
{
|
|
|
|
Overall
|
|
|
|
}
|
|
|
|
}
|