From da953b34a721540e266b33d495ce11525bf1c8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 25 Apr 2024 09:52:26 +0200 Subject: [PATCH] Apply nullability annotations to `ResultsScreen` & inheritors --- .../Visual/Ranking/TestSceneResultsScreen.cs | 2 +- .../MultiplayerTeamResultsScreen.cs | 8 ++-- .../Spectate/MultiSpectatorResultsScreen.cs | 6 +-- .../Playlists/PlaylistsResultsScreen.cs | 35 +++++++--------- osu.Game/Screens/Ranking/ResultsScreen.cs | 42 +++++++++---------- osu.Game/Screens/Ranking/SoloResultsScreen.cs | 4 +- 6 files changed, 43 insertions(+), 54 deletions(-) diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs b/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs index ffc5dbc8fb..fca1d0f82a 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs @@ -424,7 +424,7 @@ namespace osu.Game.Tests.Visual.Ranking scores.Add(score); } - scoresCallback?.Invoke(scores); + scoresCallback.Invoke(scores); return null; } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerTeamResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerTeamResultsScreen.cs index a8c513603c..ab83860ba7 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerTeamResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerTeamResultsScreen.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . 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; @@ -28,8 +26,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer { private readonly SortedDictionary teamScores; - private Container winnerBackground; - private Drawable winnerText; + private Container winnerBackground = null!; + private Drawable winnerText = null!; public MultiplayerTeamResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, SortedDictionary teamScores) : base(score, roomId, playlistItem) @@ -41,7 +39,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer } [Resolved] - private OsuColour colours { get; set; } + private OsuColour colours { get; set; } = null!; [BackgroundDependencyLoader] private void load() diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs index 2afc187e40..c240bbea0c 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . 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; @@ -25,8 +23,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate Scheduler.AddDelayed(() => StatisticsPanel.ToggleVisibility(), 1000); } - protected override APIRequest FetchScores(Action> scoresCallback) => null; + protected override APIRequest? FetchScores(Action> scoresCallback) => null; - protected override APIRequest FetchNextPage(int direction, Action> scoresCallback) => null; + protected override APIRequest? FetchNextPage(int direction, Action> scoresCallback) => null; } } diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs index add7aee8cd..fdb83b5ae8 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsResultsScreen.cs @@ -1,13 +1,10 @@ // Copyright (c) ppy Pty Ltd . 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; @@ -25,23 +22,23 @@ namespace osu.Game.Screens.OnlinePlay.Playlists 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; @@ -123,11 +120,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists return userScoreReq; } - protected override APIRequest FetchNextPage(int direction, Action> scoresCallback) + protected override APIRequest? FetchNextPage(int direction, Action> 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; @@ -147,7 +144,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// The callback to perform with the resulting scores. /// An optional score pivot to retrieve scores around. Can be null to retrieve scores from the highest score. /// The indexing . - private APIRequest createIndexRequest(Action> scoresCallback, [CanBeNull] MultiplayerScores pivot = null) + private APIRequest createIndexRequest(Action> scoresCallback, MultiplayerScores? pivot = null) { var indexReq = pivot != null ? new IndexPlaylistScoresRequest(roomId, playlistItem.ID, pivot.Cursor, pivot.Params) @@ -180,7 +177,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// The callback to invoke with the final s. /// The s that were retrieved from s. /// An optional pivot around which the scores were retrieved. - private void performSuccessCallback([NotNull] Action> callback, [NotNull] List scores, [CanBeNull] MultiplayerScores pivot = null) => Schedule(() => + private void performSuccessCallback(Action> callback, List scores, MultiplayerScores? pivot = null) => Schedule(() => { var scoreInfos = scores.Select(s => s.CreateScoreInfo(scoreManager, rulesets, playlistItem, Beatmap.Value.BeatmapInfo)).OrderByTotalScore().ToArray(); @@ -201,7 +198,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists hideLoadingSpinners(pivot); }); - private void hideLoadingSpinners([CanBeNull] MultiplayerScores pivot = null) + private void hideLoadingSpinners(MultiplayerScores? pivot = null) { CentreSpinner.Hide(); @@ -217,7 +214,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// The to set positions on. /// The pivot. /// The amount to increment the pivot position by for each in . - 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); /// @@ -226,7 +223,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// The to set positions on. /// The pivot position. /// The amount to increment the pivot position by for each in . - 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) { diff --git a/osu.Game/Screens/Ranking/ResultsScreen.cs b/osu.Game/Screens/Ranking/ResultsScreen.cs index ebb0530046..1c3518909d 100644 --- a/osu.Game/Screens/Ranking/ResultsScreen.cs +++ b/osu.Game/Screens/Ranking/ResultsScreen.cs @@ -1,12 +1,9 @@ // Copyright (c) ppy Pty Ltd . 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; @@ -45,25 +42,24 @@ namespace osu.Game.Screens.Ranking protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered; - public readonly Bindable SelectedScore = new Bindable(); + public readonly Bindable SelectedScore = new Bindable(); - [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; } - - [Resolved(CanBeNull = true)] - private Player player { get; set; } + protected VerticalScrollContainer VerticalScrollContent { get; private set; } = null!; [Resolved] - private IAPIProvider api { get; set; } + private Player? player { get; set; } - protected StatisticsPanel StatisticsPanel { get; private set; } + [Resolved] + private IAPIProvider api { get; set; } = null!; - private Drawable bottomPanel; - private Container detachedPanelContainer; + protected StatisticsPanel StatisticsPanel { get; private set; } = null!; + + private Drawable bottomPanel = null!; + private Container detachedPanelContainer = null!; private bool lastFetchCompleted; @@ -84,9 +80,9 @@ namespace osu.Game.Screens.Ranking /// public bool ShowUserStatistics { get; init; } - private Sample popInSample; + private Sample? popInSample; - protected ResultsScreen([CanBeNull] ScoreInfo score) + protected ResultsScreen(ScoreInfo? score) { Score = score; @@ -182,11 +178,11 @@ namespace osu.Game.Screens.Ranking 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 }); } @@ -225,7 +221,7 @@ namespace osu.Game.Screens.Ranking if (lastFetchCompleted) { - APIRequest nextPageRequest = null; + APIRequest? nextPageRequest = null; if (ScorePanelList.IsScrolledToStart) nextPageRequest = FetchNextPage(-1, fetchScoresCallback); @@ -245,7 +241,7 @@ namespace osu.Game.Screens.Ranking /// /// A callback which should be called when fetching is completed. Scheduling is not required. /// An responsible for the fetch operation. This will be queued and performed automatically. - protected virtual APIRequest FetchScores(Action> scoresCallback) => null; + protected virtual APIRequest? FetchScores(Action> scoresCallback) => null; /// /// Performs a fetch of the next page of scores. This is invoked every frame until a non-null is returned. @@ -253,7 +249,7 @@ namespace osu.Game.Screens.Ranking /// 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. /// A callback which should be called when fetching is completed. Scheduling is not required. /// An responsible for the fetch operation. This will be queued and performed automatically. - protected virtual APIRequest FetchNextPage(int direction, Action> scoresCallback) => null; + protected virtual APIRequest? FetchNextPage(int direction, Action> scoresCallback) => null; /// /// Creates the to be used to display extended information about scores. @@ -327,7 +323,7 @@ namespace osu.Game.Screens.Ranking panel.Alpha = 0; } - private ScorePanel detachedPanel; + private ScorePanel? detachedPanel; private void onStatisticsStateChanged(ValueChangedEvent state) { diff --git a/osu.Game/Screens/Ranking/SoloResultsScreen.cs b/osu.Game/Screens/Ranking/SoloResultsScreen.cs index ee0251b5ac..33b4bf976b 100644 --- a/osu.Game/Screens/Ranking/SoloResultsScreen.cs +++ b/osu.Game/Screens/Ranking/SoloResultsScreen.cs @@ -27,7 +27,7 @@ namespace osu.Game.Screens.Ranking { } - protected override APIRequest? FetchScores(Action>? scoresCallback) + protected override APIRequest? FetchScores(Action> scoresCallback) { Debug.Assert(Score != null); @@ -35,7 +35,7 @@ namespace osu.Game.Screens.Ranking 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; }