1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 04:49:40 +08:00
osu-lazer/osu.Game/Screens/Select/Leaderboards/BeatmapLeaderboard.cs

123 lines
3.5 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.
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;
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.Rulesets.Mods;
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
{
get => beatmap;
set
{
if (beatmap == value)
return;
beatmap = value;
Scores = null;
UpdateScores();
}
}
private bool filterMods;
public bool FilterMods
{
get => filterMods;
set
{
if (value == filterMods)
return;
filterMods = value;
UpdateScores();
}
}
[Resolved]
private ScoreManager scoreManager { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
[BackgroundDependencyLoader]
private void load()
{
ruleset.ValueChanged += _ => UpdateScores();
mods.ValueChanged += _ =>
{
if (filterMods)
UpdateScores();
};
}
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
if (Scope == BeatmapLeaderboardScope.Local)
{
Scores = scoreManager
.QueryScores(s => !s.DeletePending && s.Beatmap.ID == Beatmap.ID && s.Ruleset.ID == ruleset.Value.ID)
.OrderByDescending(s => s.TotalScore).ToArray();
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;
}
IReadOnlyList<Mod> requestMods = null;
if (filterMods && mods.Value.Count == 0)
// add nomod for the request
requestMods = new Mod[] { new ModNoMod() };
else if (filterMods)
requestMods = mods.Value;
var req = new GetScoresRequest(Beatmap, ruleset.Value ?? Beatmap.Ruleset, Scope, requestMods);
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)
{
Action = () => ScoreSelected?.Invoke(model)
};
}
}