osu/osu.Game/Screens/Ranking/SoloResultsScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.7 KiB
C#
Raw Normal View History

2020-05-26 08:00:41 +00: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.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2020-06-03 02:06:47 +00:00
using osu.Game.Beatmaps;
2020-05-26 08:00:41 +00:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Solo;
2020-05-26 08:00:41 +00:00
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
2020-05-26 08:00:41 +00:00
namespace osu.Game.Screens.Ranking
{
public partial class SoloResultsScreen : ResultsScreen
{
/// <summary>
/// Whether the user's personal statistics should be shown on the extended statistics panel
/// after clicking the score panel associated with the <see cref="ResultsScreen.Score"/> being presented.
/// </summary>
public bool ShowUserStatistics { get; init; }
2022-12-28 06:49:09 +00:00
private GetScoresRequest? getScoreRequest;
2020-05-26 08:00:41 +00:00
[Resolved]
2022-12-28 06:49:09 +00:00
private RulesetStore rulesets { get; set; } = null!;
2020-05-26 08:00:41 +00:00
[Resolved]
2022-12-28 06:49:09 +00:00
private SoloStatisticsWatcher soloStatisticsWatcher { get; set; } = null!;
2022-12-28 06:49:09 +00:00
private readonly Bindable<SoloStatisticsUpdate?> statisticsUpdate = new Bindable<SoloStatisticsUpdate?>();
public SoloResultsScreen(ScoreInfo score, bool allowRetry)
2020-05-26 08:00:41 +00:00
: base(score, allowRetry)
{
}
protected override void LoadComplete()
{
base.LoadComplete();
if (ShowUserStatistics)
soloStatisticsWatcher.RegisterForStatisticsUpdateAfter(Score, update => statisticsUpdate.Value = update);
}
protected override StatisticsPanel CreateStatisticsPanel()
{
if (ShowUserStatistics)
{
return new SoloStatisticsPanel(Score)
{
StatisticsUpdate = { BindTarget = statisticsUpdate }
};
}
return base.CreateStatisticsPanel();
}
2022-12-28 06:49:09 +00:00
protected override APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>>? scoresCallback)
2020-05-26 08:00:41 +00:00
{
if (Score.BeatmapInfo.OnlineID <= 0 || Score.BeatmapInfo.Status <= BeatmapOnlineStatus.Pending)
2020-06-03 02:06:47 +00:00
return null;
getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset);
getScoreRequest.Success += r => scoresCallback?.Invoke(r.Scores.Where(s => s.OnlineID != Score.OnlineID).Select(s => s.ToScoreInfo(rulesets, Beatmap.Value.BeatmapInfo)));
return getScoreRequest;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
getScoreRequest?.Cancel();
2020-05-26 08:00:41 +00:00
}
}
}