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:51:27 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-14 18:51:27 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Online.Leaderboards;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Leaderboards
|
|
|
|
{
|
|
|
|
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
|
|
|
|
{
|
|
|
|
public Action<ScoreInfo> ScoreSelected;
|
|
|
|
|
|
|
|
private BeatmapInfo beatmap;
|
|
|
|
|
|
|
|
public BeatmapInfo Beatmap
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
get => beatmap;
|
2018-12-14 18:51:27 +08:00
|
|
|
set
|
|
|
|
{
|
|
|
|
if (beatmap == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
beatmap = value;
|
|
|
|
Scores = null;
|
|
|
|
|
|
|
|
UpdateScores();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private ScoreManager scoreManager { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
2019-03-13 11:56:47 +08:00
|
|
|
private IAPIProvider api { get; set; }
|
2018-12-14 18:51:27 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
ruleset.ValueChanged += _ => UpdateScores();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
|
|
|
{
|
|
|
|
if (Scope == BeatmapLeaderboardScope.Local)
|
|
|
|
{
|
2019-04-07 19:26:35 +08:00
|
|
|
Scores = scoreManager.QueryScores(s => !s.DeletePending && s.Beatmap.ID == Beatmap.ID).OrderByDescending(s => s.TotalScore).ToArray();
|
2018-12-14 18:51:27 +08:00
|
|
|
PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Beatmap?.OnlineBeatmapID == null)
|
|
|
|
{
|
|
|
|
PlaceholderState = PlaceholderState.Unavailable;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Scope != BeatmapLeaderboardScope.Global && !api.LocalUser.Value.IsSupporter)
|
|
|
|
{
|
|
|
|
PlaceholderState = PlaceholderState.NotSupporter;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var req = new GetScoresRequest(Beatmap, ruleset.Value ?? Beatmap.Ruleset, Scope);
|
|
|
|
|
|
|
|
req.Success += r => scoresCallback?.Invoke(r.Scores);
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2018-12-22 14:20:35 +08:00
|
|
|
protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index)
|
2018-12-14 18:51:27 +08:00
|
|
|
{
|
|
|
|
Action = () => ScoreSelected?.Invoke(model)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|