Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply nullability annotations to ResultsScreen & inheritors #27995

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresC
scores.Add(score);
}

scoresCallback?.Invoke(scores);
scoresCallback.Invoke(scores);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -28,8 +26,8 @@ public partial class MultiplayerTeamResultsScreen : MultiplayerResultsScreen
{
private readonly SortedDictionary<int, BindableLong> teamScores;

private Container winnerBackground;
private Drawable winnerText;
private Container winnerBackground = null!;
private Drawable winnerText = null!;

public MultiplayerTeamResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, SortedDictionary<int, BindableLong> teamScores)
: base(score, roomId, playlistItem)
Expand All @@ -41,7 +39,7 @@ public MultiplayerTeamResultsScreen(ScoreInfo score, long roomId, PlaylistItem p
}

[Resolved]
private OsuColour colours { get; set; }
private OsuColour colours { get; set; } = null!;

[BackgroundDependencyLoader]
private void load()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using osu.Game.Online.API;
Expand All @@ -25,8 +23,8 @@ protected override void LoadComplete()
Scheduler.AddDelayed(() => StatisticsPanel.ToggleVisibility(), 1000);
}

protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
protected override APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;

protected override APIRequest FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
protected override APIRequest? FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
}
}
35 changes: 16 additions & 19 deletions osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -25,23 +22,23 @@ public partial class PlaylistsResultsScreen : ResultsScreen
private readonly long roomId;
private readonly PlaylistItem playlistItem;

protected LoadingSpinner LeftSpinner { get; private set; }
protected LoadingSpinner CentreSpinner { get; private set; }
protected LoadingSpinner RightSpinner { get; private set; }
protected LoadingSpinner LeftSpinner { get; private set; } = null!;
protected LoadingSpinner CentreSpinner { get; private set; } = null!;
protected LoadingSpinner RightSpinner { get; private set; } = null!;

private MultiplayerScores higherScores;
private MultiplayerScores lowerScores;
private MultiplayerScores? higherScores;
private MultiplayerScores? lowerScores;

[Resolved]
private IAPIProvider api { get; set; }
private IAPIProvider api { get; set; } = null!;

[Resolved]
private ScoreManager scoreManager { get; set; }
private ScoreManager scoreManager { get; set; } = null!;

[Resolved]
private RulesetStore rulesets { get; set; }
private RulesetStore rulesets { get; set; } = null!;

public PlaylistsResultsScreen([CanBeNull] ScoreInfo score, long roomId, PlaylistItem playlistItem)
public PlaylistsResultsScreen(ScoreInfo? score, long roomId, PlaylistItem playlistItem)
: base(score)
{
this.roomId = roomId;
Expand Down Expand Up @@ -123,11 +120,11 @@ protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresC
return userScoreReq;
}

protected override APIRequest FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback)
protected override APIRequest? FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback)
{
Debug.Assert(direction == 1 || direction == -1);

MultiplayerScores pivot = direction == -1 ? higherScores : lowerScores;
MultiplayerScores? pivot = direction == -1 ? higherScores : lowerScores;

if (pivot?.Cursor == null)
return null;
Expand All @@ -147,7 +144,7 @@ protected override APIRequest FetchNextPage(int direction, Action<IEnumerable<Sc
/// <param name="scoresCallback">The callback to perform with the resulting scores.</param>
/// <param name="pivot">An optional score pivot to retrieve scores around. Can be null to retrieve scores from the highest score.</param>
/// <returns>The indexing <see cref="APIRequest"/>.</returns>
private APIRequest createIndexRequest(Action<IEnumerable<ScoreInfo>> scoresCallback, [CanBeNull] MultiplayerScores pivot = null)
private APIRequest createIndexRequest(Action<IEnumerable<ScoreInfo>> scoresCallback, MultiplayerScores? pivot = null)
{
var indexReq = pivot != null
? new IndexPlaylistScoresRequest(roomId, playlistItem.ID, pivot.Cursor, pivot.Params)
Expand Down Expand Up @@ -180,7 +177,7 @@ private APIRequest createIndexRequest(Action<IEnumerable<ScoreInfo>> scoresCallb
/// <param name="callback">The callback to invoke with the final <see cref="ScoreInfo"/>s.</param>
/// <param name="scores">The <see cref="MultiplayerScore"/>s that were retrieved from <see cref="APIRequest"/>s.</param>
/// <param name="pivot">An optional pivot around which the scores were retrieved.</param>
private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> callback, [NotNull] List<MultiplayerScore> scores, [CanBeNull] MultiplayerScores pivot = null) => Schedule(() =>
private void performSuccessCallback(Action<IEnumerable<ScoreInfo>> callback, List<MultiplayerScore> scores, MultiplayerScores? pivot = null) => Schedule(() =>
{
var scoreInfos = scores.Select(s => s.CreateScoreInfo(scoreManager, rulesets, playlistItem, Beatmap.Value.BeatmapInfo)).OrderByTotalScore().ToArray();

Expand All @@ -201,7 +198,7 @@ private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> cal
hideLoadingSpinners(pivot);
});

private void hideLoadingSpinners([CanBeNull] MultiplayerScores pivot = null)
private void hideLoadingSpinners(MultiplayerScores? pivot = null)
{
CentreSpinner.Hide();

Expand All @@ -217,7 +214,7 @@ private void hideLoadingSpinners([CanBeNull] MultiplayerScores pivot = null)
/// <param name="scores">The <see cref="MultiplayerScores"/> to set positions on.</param>
/// <param name="pivot">The pivot.</param>
/// <param name="increment">The amount to increment the pivot position by for each <see cref="MultiplayerScore"/> in <paramref name="scores"/>.</param>
private void setPositions([NotNull] MultiplayerScores scores, [CanBeNull] MultiplayerScores pivot, int increment)
private void setPositions(MultiplayerScores scores, MultiplayerScores? pivot, int increment)
=> setPositions(scores, pivot?.Scores[^1].Position ?? 0, increment);

/// <summary>
Expand All @@ -226,7 +223,7 @@ private void setPositions([NotNull] MultiplayerScores scores, [CanBeNull] Multip
/// <param name="scores">The <see cref="MultiplayerScores"/> to set positions on.</param>
/// <param name="pivotPosition">The pivot position.</param>
/// <param name="increment">The amount to increment the pivot position by for each <see cref="MultiplayerScore"/> in <paramref name="scores"/>.</param>
private void setPositions([NotNull] MultiplayerScores scores, int pivotPosition, int increment)
private void setPositions(MultiplayerScores scores, int pivotPosition, int increment)
{
foreach (var s in scores.Scores)
{
Expand Down
40 changes: 18 additions & 22 deletions osu.Game/Screens/Ranking/ResultsScreen.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
Expand Down Expand Up @@ -45,25 +42,24 @@ public abstract partial class ResultsScreen : ScreenWithBeatmapBackground, IKeyB

protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered;

public readonly Bindable<ScoreInfo> SelectedScore = new Bindable<ScoreInfo>();
public readonly Bindable<ScoreInfo?> SelectedScore = new Bindable<ScoreInfo?>();

[CanBeNull]
public readonly ScoreInfo Score;
public readonly ScoreInfo? Score;

protected ScorePanelList ScorePanelList { get; private set; }
protected ScorePanelList ScorePanelList { get; private set; } = null!;

protected VerticalScrollContainer VerticalScrollContent { get; private set; }
protected VerticalScrollContainer VerticalScrollContent { get; private set; } = null!;

[Resolved(CanBeNull = true)]
private Player player { get; set; }
[Resolved]
private Player? player { get; set; }

[Resolved]
private IAPIProvider api { get; set; }
private IAPIProvider api { get; set; } = null!;

protected StatisticsPanel StatisticsPanel { get; private set; }
protected StatisticsPanel StatisticsPanel { get; private set; } = null!;

private Drawable bottomPanel;
private Container<ScorePanel> detachedPanelContainer;
private Drawable bottomPanel = null!;
private Container<ScorePanel> detachedPanelContainer = null!;

private bool lastFetchCompleted;

Expand All @@ -84,9 +80,9 @@ public abstract partial class ResultsScreen : ScreenWithBeatmapBackground, IKeyB
/// </summary>
public bool ShowUserStatistics { get; init; }

private Sample popInSample;
private Sample? popInSample;

protected ResultsScreen([CanBeNull] ScoreInfo score)
protected ResultsScreen(ScoreInfo? score)
{
Score = score;

Expand Down Expand Up @@ -182,11 +178,11 @@ private void load(AudioManager audio)
Scheduler.AddDelayed(() => OverlayActivationMode.Value = OverlayActivation.All, shouldFlair ? AccuracyCircle.TOTAL_DURATION + 1000 : 0);
}

if (AllowWatchingReplay)
if (SelectedScore.Value != null && AllowWatchingReplay)
{
buttons.Add(new ReplayDownloadButton(SelectedScore.Value)
{
Score = { BindTarget = SelectedScore },
Score = { BindTarget = SelectedScore! },
Width = 300
});
}
Expand Down Expand Up @@ -225,7 +221,7 @@ protected override void Update()

if (lastFetchCompleted)
{
APIRequest nextPageRequest = null;
APIRequest? nextPageRequest = null;

if (ScorePanelList.IsScrolledToStart)
nextPageRequest = FetchNextPage(-1, fetchScoresCallback);
Expand All @@ -245,15 +241,15 @@ protected override void Update()
/// </summary>
/// <param name="scoresCallback">A callback which should be called when fetching is completed. Scheduling is not required.</param>
/// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns>
protected virtual APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
protected virtual APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;

/// <summary>
/// Performs a fetch of the next page of scores. This is invoked every frame until a non-null <see cref="APIRequest"/> is returned.
/// </summary>
/// <param name="direction">The fetch direction. -1 to fetch scores greater than the current start of the list, and 1 to fetch scores lower than the current end of the list.</param>
/// <param name="scoresCallback">A callback which should be called when fetching is completed. Scheduling is not required.</param>
/// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns>
protected virtual APIRequest FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
protected virtual APIRequest? FetchNextPage(int direction, Action<IEnumerable<ScoreInfo>> scoresCallback) => null;

/// <summary>
/// Creates the <see cref="Statistics.StatisticsPanel"/> to be used to display extended information about scores.
Expand Down Expand Up @@ -327,7 +323,7 @@ private void addScore(ScoreInfo score)
panel.Alpha = 0;
}

private ScorePanel detachedPanel;
private ScorePanel? detachedPanel;

private void onStatisticsStateChanged(ValueChangedEvent<Visibility> state)
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Ranking/SoloResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public SoloResultsScreen(ScoreInfo score)
{
}

protected override APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>>? scoresCallback)
protected override APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
Debug.Assert(Score != null);

if (Score.BeatmapInfo!.OnlineID <= 0 || Score.BeatmapInfo.Status <= BeatmapOnlineStatus.Pending)
return null;

getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset);
getScoreRequest.Success += r => scoresCallback?.Invoke(r.Scores.Where(s => !s.MatchesOnlineID(Score)).Select(s => s.ToScoreInfo(rulesets, Beatmap.Value.BeatmapInfo)));
getScoreRequest.Success += r => scoresCallback.Invoke(r.Scores.Where(s => !s.MatchesOnlineID(Score)).Select(s => s.ToScoreInfo(rulesets, Beatmap.Value.BeatmapInfo)));
return getScoreRequest;
}

Expand Down
Loading