2020-05-26 17:00:41 +09: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;
|
2024-01-29 16:13:30 +09:00
|
|
|
using System.Diagnostics;
|
2025-02-25 21:54:13 +09:00
|
|
|
using System.Threading.Tasks;
|
2020-05-26 17:00:41 +09:00
|
|
|
using osu.Framework.Allocation;
|
2025-02-26 18:00:16 +09:00
|
|
|
using osu.Framework.Logging;
|
2020-06-03 11:36:47 +09:30
|
|
|
using osu.Game.Beatmaps;
|
2023-10-26 15:09:59 +02:00
|
|
|
using osu.Game.Extensions;
|
2020-05-26 17:00:41 +09:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
2025-02-25 21:54:13 +09:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-05-26 17:00:41 +09:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking
|
|
|
|
{
|
|
|
|
public partial class SoloResultsScreen : ResultsScreen
|
|
|
|
{
|
2022-12-28 07:49:09 +01:00
|
|
|
private GetScoresRequest? getScoreRequest;
|
2021-02-24 19:54:52 +09:00
|
|
|
|
2020-05-26 17:00:41 +09:00
|
|
|
[Resolved]
|
2022-12-28 07:49:09 +01:00
|
|
|
private RulesetStore rulesets { get; set; } = null!;
|
2020-05-26 17:00:41 +09:00
|
|
|
|
2025-02-25 21:54:13 +09:00
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
|
|
|
|
2024-02-22 19:15:02 +01:00
|
|
|
public SoloResultsScreen(ScoreInfo score)
|
|
|
|
: base(score)
|
2020-05-26 17:00:41 +09:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-02-25 22:55:55 +09:00
|
|
|
protected override async Task<ScoreInfo[]> FetchScores()
|
2020-05-26 17:00:41 +09:00
|
|
|
{
|
2024-01-29 16:13:30 +09:00
|
|
|
Debug.Assert(Score != null);
|
|
|
|
|
2023-07-04 14:50:34 +09:00
|
|
|
if (Score.BeatmapInfo!.OnlineID <= 0 || Score.BeatmapInfo.Status <= BeatmapOnlineStatus.Pending)
|
2025-02-25 21:54:13 +09:00
|
|
|
return [];
|
|
|
|
|
|
|
|
var requestTaskSource = new TaskCompletionSource<APIScoresCollection>();
|
2020-06-03 11:36:47 +09:30
|
|
|
|
2021-10-04 17:35:53 +09:00
|
|
|
getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset);
|
2025-02-25 21:54:13 +09:00
|
|
|
getScoreRequest.Success += requestTaskSource.SetResult;
|
|
|
|
getScoreRequest.Failure += requestTaskSource.SetException;
|
|
|
|
api.Queue(getScoreRequest);
|
|
|
|
|
|
|
|
try
|
2025-02-10 12:13:46 +01:00
|
|
|
{
|
2025-02-25 22:56:38 +09:00
|
|
|
var scores = await requestTaskSource.Task.ConfigureAwait(false);
|
2025-02-10 12:13:46 +01:00
|
|
|
var toDisplay = new List<ScoreInfo>();
|
|
|
|
|
2025-02-25 21:54:13 +09:00
|
|
|
for (int i = 0; i < scores.Scores.Count; ++i)
|
2025-02-10 12:13:46 +01:00
|
|
|
{
|
2025-02-25 21:54:13 +09:00
|
|
|
var score = scores.Scores[i];
|
2025-02-10 12:13:46 +01:00
|
|
|
int position = i + 1;
|
|
|
|
|
|
|
|
if (score.MatchesOnlineID(Score))
|
|
|
|
{
|
|
|
|
// we don't want to add the same score twice, but also setting any properties of `Score` this late will have no visible effect,
|
|
|
|
// so we have to fish out the actual drawable panel and set the position to it directly.
|
|
|
|
var panel = ScorePanelList.GetPanelForScore(Score);
|
|
|
|
Score.Position = panel.ScorePosition.Value = position;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var converted = score.ToScoreInfo(rulesets, Beatmap.Value.BeatmapInfo);
|
|
|
|
converted.Position = position;
|
|
|
|
toDisplay.Add(converted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-25 22:55:55 +09:00
|
|
|
return toDisplay.ToArray();
|
2025-02-25 21:54:13 +09:00
|
|
|
}
|
2025-02-26 18:00:16 +09:00
|
|
|
catch (Exception ex)
|
2025-02-25 21:54:13 +09:00
|
|
|
{
|
2025-02-26 18:00:16 +09:00
|
|
|
Logger.Log($"Failed to fetch scores (beatmap: {Score.BeatmapInfo}, ruleset: {Score.Ruleset}): {ex}");
|
2025-02-25 21:54:13 +09:00
|
|
|
return [];
|
|
|
|
}
|
2021-02-24 19:54:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
getScoreRequest?.Cancel();
|
2020-05-26 17:00:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|