1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 05:47:18 +08:00

60 lines
1.7 KiB
C#
Raw Normal View History

// 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
using System;
using System.Collections.Generic;
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;
using osu.Game.Online.API.Requests.Responses;
2018-12-14 19:52:03 +09:00
using osu.Game.Online.Leaderboards;
using osu.Game.Online.Multiplayer;
namespace osu.Game.Screens.Multi.Match.Components
{
2018-12-22 15:45:16 +09:00
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIRoomScoreInfo>
2018-12-14 19:52:03 +09:00
{
2018-12-22 15:45:16 +09:00
public Action<IEnumerable<APIRoomScoreInfo>> ScoresLoaded;
2018-12-21 18:22:13 +09:00
2019-02-05 19:00:01 +09:00
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<int?> roomId { get; set; }
2018-12-14 19:52:03 +09:00
[BackgroundDependencyLoader]
private void load()
{
roomId.BindValueChanged(id =>
2018-12-14 19:52:03 +09:00
{
if (id.NewValue == null)
return;
2018-12-14 19:52:03 +09:00
Scores = null;
UpdateScores();
}, true);
}
2018-12-22 15:45:16 +09:00
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
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;
2019-02-05 19:00:01 +09:00
var req = new GetRoomScoresRequest(roomId.Value ?? 0);
2018-12-14 19:52:03 +09:00
2018-12-21 18:22:13 +09:00
req.Success += r =>
{
scoresCallback?.Invoke(r);
ScoresLoaded?.Invoke(r);
};
2018-12-14 19:52:03 +09:00
return req;
}
2018-12-22 15:45:16 +09:00
protected override LeaderboardScore CreateDrawableScore(APIRoomScoreInfo model, int index) => new MatchLeaderboardScore(model, index);
2018-12-14 19:52:03 +09:00
}
public enum MatchLeaderboardScope
{
Overall
}
}