forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultsScreen.cs
More file actions
179 lines (147 loc) · 6.18 KB
/
Copy pathResultsScreen.cs
File metadata and controls
179 lines (147 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// 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.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
namespace osu.Game.Screens.OnlinePlay.Matchmaking.RankedPlay
{
public partial class ResultsScreen : RankedPlaySubScreen
{
public override LocalisableString StageHeading => "Results";
public override bool ShowBeatmapBackground => true;
[Resolved]
private IAPIProvider api { get; set; } = null!;
[Resolved]
private MultiplayerClient client { get; set; } = null!;
[Resolved]
private ScoreManager scoreManager { get; set; } = null!;
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
[Resolved]
private RankedPlayMatchInfo matchInfo { get; set; } = null!;
[Resolved]
private BeatmapLookupCache beatmapLookupCache { get; set; } = null!;
[Resolved]
private IBindable<WorkingBeatmap> globalBeatmap { get; set; } = null!;
[Resolved]
private IBindable<RulesetInfo> globalRuleset { get; set; } = null!;
[Resolved]
private IBindable<IReadOnlyList<Mod>> globalMods { get; set; } = null!;
private LoadingSpinner loadingSpinner = null!;
private MainPanel? mainPanel;
[BackgroundDependencyLoader]
private void load()
{
CornerPieceVisibility.Value = Visibility.Hidden;
AddRangeInternal(new Drawable[]
{
loadingSpinner = new LoadingSpinner
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
});
}
protected override void LoadComplete()
{
base.LoadComplete();
loadingSpinner.Show();
fetchFinalScores().FireAndForget();
}
private async Task fetchFinalScores()
{
try
{
if (client.Room == null)
return;
TaskCompletionSource<List<MultiplayerScore>> scoreLookup = new TaskCompletionSource<List<MultiplayerScore>>();
var request = new IndexPlaylistScoresRequest(client.Room.RoomID, client.Room.Settings.PlaylistItemId);
request.Success += req => scoreLookup.SetResult(req.Scores);
request.Failure += scoreLookup.SetException;
api.Queue(request);
List<MultiplayerScore> apiScores = await scoreLookup.Task.ConfigureAwait(false);
ScoreInfo[] scores = apiScores.Select(s => s.CreateScoreInfo(scoreManager, rulesets, globalBeatmap.Value.BeatmapInfo)).ToArray();
Debug.Assert(scores.Length <= 2);
int localUserId = api.LocalUser.Value.OnlineID;
int opponentId = matchInfo.RoomState.Users.Keys.Single(it => it != localUserId);
ScoreInfo playerScore = scores.SingleOrDefault(s => s.UserID == localUserId) ?? new ScoreInfo
{
Rank = ScoreRank.F,
Ruleset = globalRuleset.Value,
User = new APIUser { Id = localUserId }
};
ScoreInfo opponentScore = scores.SingleOrDefault(s => s.UserID == opponentId) ?? new ScoreInfo
{
Rank = ScoreRank.F,
Ruleset = globalRuleset.Value,
User = new APIUser { Id = opponentId }
};
// Should complete instantaneously due to prior lookups.
// GetBeatmapAsync can return null if the online ID is unknown (e.g. in tests or
// when the API is unavailable); fall back to a placeholder rather than crashing.
APIBeatmap? beatmap = await beatmapLookupCache.GetBeatmapAsync(globalBeatmap.Value.BeatmapInfo.OnlineID).ConfigureAwait(false);
beatmap ??= new APIBeatmap
{
BeatmapSet = new APIBeatmapSet
{
Title = "unknown beatmap",
TitleUnicode = "unknown beatmap",
Artist = "unknown artist",
ArtistUnicode = "unknown artist",
}
};
Schedule(() =>
{
LoadComponentAsync(new MainPanel
{
RelativeSizeAxes = Axes.Both,
// A little bit of room for the countdown timer...
Margin = new MarginPadding { Top = 45 },
PlayerScore = playerScore,
OpponentScore = opponentScore,
PlayerDamageInfo = matchInfo.RoomState.Users[localUserId].DamageInfo!,
OpponentDamageInfo = matchInfo.RoomState.Users[opponentId].DamageInfo!,
Beatmap = beatmap,
Mods = globalMods.Value.ToArray(),
}, loaded =>
{
AddInternal(loaded);
mainPanel = loaded;
});
});
}
catch (Exception e)
{
Logger.Error(e, "Failed to load scores for playlist item.");
throw;
}
finally
{
Scheduler.Add(() => loadingSpinner.Hide());
}
}
public override void OnExiting(RankedPlaySubScreen? next)
{
mainPanel?.StopAllSamples();
base.OnExiting(next);
}
}
}