2018-12-14 18:52:03 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Online.API;
|
2018-12-22 14:45:16 +08:00
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
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;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.Match.Components
|
|
|
|
{
|
2018-12-22 14:45:16 +08:00
|
|
|
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, APIRoomScoreInfo>
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2018-12-22 14:45:16 +08:00
|
|
|
public Action<IEnumerable<APIRoomScoreInfo>> ScoresLoaded;
|
2018-12-21 17:22:13 +08:00
|
|
|
|
2018-12-14 18:52:03 +08:00
|
|
|
private readonly Room room;
|
|
|
|
|
|
|
|
public MatchLeaderboard(Room room)
|
|
|
|
{
|
|
|
|
this.room = room;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
room.RoomID.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
Scores = null;
|
|
|
|
UpdateScores();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2018-12-22 14:45:16 +08:00
|
|
|
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
|
|
|
if (room.RoomID == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var req = new GetRoomScoresRequest(room.RoomID.Value ?? 0);
|
|
|
|
|
2018-12-21 17:22:13 +08:00
|
|
|
req.Success += r =>
|
|
|
|
{
|
|
|
|
scoresCallback?.Invoke(r);
|
|
|
|
ScoresLoaded?.Invoke(r);
|
|
|
|
};
|
2018-12-14 18:52:03 +08:00
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2018-12-22 14:45:16 +08:00
|
|
|
protected override LeaderboardScore CreateDrawableScore(APIRoomScoreInfo model, int index) => new MatchLeaderboardScore(model, index);
|
2018-12-14 18:52:03 +08:00
|
|
|
}
|
|
|
|
|
2018-12-22 14:35:22 +08:00
|
|
|
public class MatchLeaderboardScore : LeaderboardScore
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2018-12-22 14:45:16 +08:00
|
|
|
public MatchLeaderboardScore(APIRoomScoreInfo score, int rank)
|
2018-12-14 18:52:03 +08:00
|
|
|
: base(score, rank)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RankContainer.Alpha = 0;
|
|
|
|
}
|
|
|
|
|
2018-12-22 14:35:22 +08:00
|
|
|
protected override IEnumerable<LeaderboardScoreStatistic> GetStatistics(ScoreInfo model) => new[]
|
2018-12-14 18:52:03 +08:00
|
|
|
{
|
2018-12-22 14:35:22 +08:00
|
|
|
new LeaderboardScoreStatistic(FontAwesome.fa_crosshairs, "Accuracy", string.Format(model.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", model.Accuracy)),
|
2018-12-22 14:45:16 +08:00
|
|
|
new LeaderboardScoreStatistic(FontAwesome.fa_refresh, "Total Attempts", ((APIRoomScoreInfo)model).TotalAttempts.ToString()),
|
|
|
|
new LeaderboardScoreStatistic(FontAwesome.fa_check, "Completed Beatmaps", ((APIRoomScoreInfo)model).CompletedAttempts.ToString()),
|
2018-12-14 18:52:03 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum MatchLeaderboardScope
|
|
|
|
{
|
|
|
|
Overall
|
|
|
|
}
|
|
|
|
}
|