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
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
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;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.Match.Components
|
|
|
|
{
|
2019-12-03 15:10:25 +08:00
|
|
|
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIUserScoreAggregate>
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2019-02-05 18:00:01 +08:00
|
|
|
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
|
|
|
private Bindable<int?> roomId { get; set; }
|
2019-01-08 18:24:55 +08:00
|
|
|
|
2018-12-14 18:52:03 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
roomId.BindValueChanged(id =>
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
if (id.NewValue == null)
|
2018-12-25 12:57:25 +08:00
|
|
|
return;
|
|
|
|
|
2018-12-14 18:52:03 +08:00
|
|
|
Scores = null;
|
|
|
|
UpdateScores();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2019-07-21 09:42:40 +08:00
|
|
|
protected override bool IsOnlineScope => true;
|
2019-07-21 08:07:27 +08:00
|
|
|
|
2019-12-03 15:10:25 +08:00
|
|
|
protected override APIRequest FetchScores(Action<IEnumerable<APIUserScoreAggregate>> scoresCallback)
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2019-02-05 18:00:01 +08:00
|
|
|
if (roomId.Value == null)
|
2018-12-14 18:52:03 +08:00
|
|
|
return null;
|
|
|
|
|
2020-08-31 18:54:41 +08:00
|
|
|
var req = new GetRoomLeaderboardRequest(roomId.Value ?? 0);
|
2018-12-14 18:52:03 +08:00
|
|
|
|
2018-12-21 17:22:13 +08:00
|
|
|
req.Success += r =>
|
|
|
|
{
|
2020-08-31 18:54:57 +08:00
|
|
|
scoresCallback?.Invoke(r.Leaderboard);
|
2020-09-01 14:42:47 +08:00
|
|
|
TopScore = r.UserScore;
|
2018-12-21 17:22:13 +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);
|
2018-12-14 18:52:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum MatchLeaderboardScope
|
|
|
|
{
|
|
|
|
Overall
|
|
|
|
}
|
|
|
|
}
|