From af6ae1cce560faa31fd4033c4678054050e99a7c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 03:49:11 +0300 Subject: [PATCH 01/10] Remove hacky code with explicit pragma disable --- osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs | 5 ++--- osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs b/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs index 97105b6b6a..8d83fe7452 100644 --- a/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs +++ b/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs @@ -79,8 +79,10 @@ namespace osu.Game.Tests.NonVisual public List HitObjects; public override IEnumerable Objects => HitObjects; +#pragma warning disable 67 public override event Action NewResult; public override event Action RevertResult; +#pragma warning restore 67 public override Playfield Playfield { get; } public override Container Overlays { get; } @@ -95,9 +97,6 @@ namespace osu.Game.Tests.NonVisual public TestDrawableRuleset() : base(new OsuRuleset()) { - // won't compile without this. - NewResult?.Invoke(null); - RevertResult?.Invoke(null); } public override void SetReplayScore(Score replayScore) => throw new NotImplementedException(); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs index 1ba0965ceb..aa29f1386c 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs @@ -235,8 +235,10 @@ namespace osu.Game.Tests.Visual.Gameplay public override IEnumerable Objects => new[] { new HitCircle { HitWindows = HitWindows } }; +#pragma warning disable 67 public override event Action NewResult; public override event Action RevertResult; +#pragma warning restore 67 public override Playfield Playfield { get; } public override Container Overlays { get; } @@ -251,9 +253,6 @@ namespace osu.Game.Tests.Visual.Gameplay public TestDrawableRuleset() : base(new OsuRuleset()) { - // won't compile without this. - NewResult?.Invoke(null); - RevertResult?.Invoke(null); } public override void SetReplayScore(Score replayScore) => throw new NotImplementedException(); From 6197ef426dd1a70e1240e7a9ea0eb83b837f61df Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 03:50:17 +0300 Subject: [PATCH 02/10] Disable another "code heurstically unreachable" with comment --- osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs b/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs index 84cf796835..fd620a0e95 100644 --- a/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs +++ b/osu.Game.Tests/Mods/ModDifficultyAdjustTest.cs @@ -105,6 +105,9 @@ namespace osu.Game.Tests.Mods testMod.ResetSettingsToDefaults(); Assert.That(testMod.DrainRate.Value, Is.Null); + + // ReSharper disable once HeuristicUnreachableCode + // see https://youtrack.jetbrains.com/issue/RIDER-70159. Assert.That(testMod.OverallDifficulty.Value, Is.Null); var applied = applyDifficulty(new BeatmapDifficulty From 36d99a2e34297f1a2c7f0dacb2704ab8e61a463f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 03:51:08 +0300 Subject: [PATCH 03/10] Move action to private named method to avoid null inspection --- osu.Game/Overlays/OverlayScrollContainer.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/OverlayScrollContainer.cs b/osu.Game/Overlays/OverlayScrollContainer.cs index ca5fc90027..7fe188eb04 100644 --- a/osu.Game/Overlays/OverlayScrollContainer.cs +++ b/osu.Game/Overlays/OverlayScrollContainer.cs @@ -37,11 +37,7 @@ namespace osu.Game.Overlays Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, Margin = new MarginPadding(20), - Action = () => - { - ScrollToStart(); - Button.State = Visibility.Hidden; - } + Action = scrollToTop }); } @@ -58,6 +54,12 @@ namespace osu.Game.Overlays Button.State = Target > button_scroll_position ? Visibility.Visible : Visibility.Hidden; } + private void scrollToTop() + { + ScrollToStart(); + Button.State = Visibility.Hidden; + } + public class ScrollToTopButton : OsuHoverContainer { private const int fade_duration = 500; From 4245af28e1a3b1d953e391d29c65d535779c70be Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 04:50:52 +0300 Subject: [PATCH 04/10] Disable other false-positive null inspections with comment --- .../BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs | 2 ++ osu.Game/Overlays/Changelog/ChangelogHeader.cs | 2 ++ osu.Game/Overlays/Comments/CommentEditor.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs b/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs index e0632ace58..845190f285 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs @@ -23,6 +23,8 @@ namespace osu.Game.Overlays.BeatmapListing public BeatmapSearchMultipleSelectionFilterRow(LocalisableString header) : base(header) { + // ReSharper disable once PossibleNullReferenceException + // see https://youtrack.jetbrains.com/issue/RSRP-486768 Current.BindTo(filter.Current); } diff --git a/osu.Game/Overlays/Changelog/ChangelogHeader.cs b/osu.Game/Overlays/Changelog/ChangelogHeader.cs index 52dea63ab7..69a8cb2ce0 100644 --- a/osu.Game/Overlays/Changelog/ChangelogHeader.cs +++ b/osu.Game/Overlays/Changelog/ChangelogHeader.cs @@ -39,6 +39,8 @@ namespace osu.Game.Overlays.Changelog Build.ValueChanged += showBuild; + // ReSharper disable once PossibleNullReferenceException + // see https://youtrack.jetbrains.com/issue/RSRP-486768 Streams.Current.ValueChanged += e => { if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream)) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 20a8ab64f7..1f3931901c 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -187,6 +187,8 @@ namespace osu.Game.Overlays.Comments AutoSizeAxes = Axes.Both; LoadingAnimationSize = new Vector2(10); + // ReSharper disable once PossibleNullReferenceException + // see https://youtrack.jetbrains.com/issue/RSRP-486768 drawableText.Text = text; } From f528488aa2ddea3979ca35c4da2bedb1e2761910 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 05:36:04 +0300 Subject: [PATCH 05/10] Mark as non-null and move current bind to BDL instead --- .../BeatmapSearchMultipleSelectionFilterRow.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs b/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs index 845190f285..461a06a634 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapSearchMultipleSelectionFilterRow.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -23,8 +24,11 @@ namespace osu.Game.Overlays.BeatmapListing public BeatmapSearchMultipleSelectionFilterRow(LocalisableString header) : base(header) { - // ReSharper disable once PossibleNullReferenceException - // see https://youtrack.jetbrains.com/issue/RSRP-486768 + } + + [BackgroundDependencyLoader] + private void load() + { Current.BindTo(filter.Current); } @@ -33,6 +37,7 @@ namespace osu.Game.Overlays.BeatmapListing /// /// Creates a filter control that can be used to simultaneously select multiple values of type . /// + [NotNull] protected virtual MultipleSelectionFilter CreateMultipleSelectionFilter() => new MultipleSelectionFilter(); protected class MultipleSelectionFilter : FillFlowContainer From b7239757670ee73f41cf797df4d910a6ab9b9e93 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 09:10:38 +0300 Subject: [PATCH 06/10] Replace pragma with `add/remove => throw` --- .../NonVisual/FirstAvailableHitWindowsTest.cs | 15 +++++++++++---- .../Visual/Gameplay/TestSceneHitErrorMeter.cs | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs b/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs index 8d83fe7452..8386a10ebb 100644 --- a/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs +++ b/osu.Game.Tests/NonVisual/FirstAvailableHitWindowsTest.cs @@ -79,10 +79,17 @@ namespace osu.Game.Tests.NonVisual public List HitObjects; public override IEnumerable Objects => HitObjects; -#pragma warning disable 67 - public override event Action NewResult; - public override event Action RevertResult; -#pragma warning restore 67 + public override event Action NewResult + { + add => throw new InvalidOperationException(); + remove => throw new InvalidOperationException(); + } + + public override event Action RevertResult + { + add => throw new InvalidOperationException(); + remove => throw new InvalidOperationException(); + } public override Playfield Playfield { get; } public override Container Overlays { get; } diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs index aa29f1386c..c1260f0231 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs @@ -235,10 +235,17 @@ namespace osu.Game.Tests.Visual.Gameplay public override IEnumerable Objects => new[] { new HitCircle { HitWindows = HitWindows } }; -#pragma warning disable 67 - public override event Action NewResult; - public override event Action RevertResult; -#pragma warning restore 67 + public override event Action NewResult + { + add => throw new InvalidOperationException(); + remove => throw new InvalidOperationException(); + } + + public override event Action RevertResult + { + add => throw new InvalidOperationException(); + remove => throw new InvalidOperationException(); + } public override Playfield Playfield { get; } public override Container Overlays { get; } From 3a3ec1436b8a35323d6b731f3c6575214ffb8557 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 09:14:50 +0300 Subject: [PATCH 07/10] Re-enable possible null refernece exception inspections and move code --- .../Overlays/Changelog/ChangelogHeader.cs | 53 ++++++++++--------- osu.Game/Overlays/Comments/CommentEditor.cs | 12 +++-- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/osu.Game/Overlays/Changelog/ChangelogHeader.cs b/osu.Game/Overlays/Changelog/ChangelogHeader.cs index 69a8cb2ce0..1b120ef57c 100644 --- a/osu.Game/Overlays/Changelog/ChangelogHeader.cs +++ b/osu.Game/Overlays/Changelog/ChangelogHeader.cs @@ -38,14 +38,6 @@ namespace osu.Game.Overlays.Changelog }; Build.ValueChanged += showBuild; - - // ReSharper disable once PossibleNullReferenceException - // see https://youtrack.jetbrains.com/issue/RSRP-486768 - Streams.Current.ValueChanged += e => - { - if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream)) - Build.Value = e.NewValue.LatestBuild; - }; } [BackgroundDependencyLoader] @@ -75,29 +67,40 @@ namespace osu.Game.Overlays.Changelog protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog"); - protected override Drawable CreateContent() => new Container + protected override Drawable CreateContent() { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Children = new Drawable[] + var content = new Container { - streamsBackground = new Box + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both - }, - new Container - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Padding = new MarginPadding + streamsBackground = new Box { - Horizontal = 65, - Vertical = 20 + RelativeSizeAxes = Axes.Both }, - Child = Streams = new ChangelogUpdateStreamControl() + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding + { + Horizontal = 65, + Vertical = 20 + }, + Child = Streams = new ChangelogUpdateStreamControl() + } } - } - }; + }; + + Streams.Current.ValueChanged += e => + { + if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream)) + Build.Value = e.NewValue.LatestBuild; + }; + + return content; + } protected override OverlayTitle CreateTitle() => new ChangelogHeaderTitle(); diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 1f3931901c..1847de8660 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -175,6 +175,8 @@ namespace osu.Game.Overlays.Comments protected override IEnumerable EffectTargets => new[] { background }; + private readonly string text; + [Resolved] private OverlayColourProvider colourProvider { get; set; } @@ -184,12 +186,10 @@ namespace osu.Game.Overlays.Comments public CommitButton(string text) { + this.text = text; + AutoSizeAxes = Axes.Both; LoadingAnimationSize = new Vector2(10); - - // ReSharper disable once PossibleNullReferenceException - // see https://youtrack.jetbrains.com/issue/RSRP-486768 - drawableText.Text = text; } [BackgroundDependencyLoader] @@ -198,6 +198,8 @@ namespace osu.Game.Overlays.Comments IdleColour = colourProvider.Light4; HoverColour = colourProvider.Light3; blockedBackground.Colour = colourProvider.Background5; + + drawableText.Text = text; } protected override void LoadComplete() @@ -234,7 +236,7 @@ namespace osu.Game.Overlays.Comments Anchor = Anchor.Centre, Origin = Anchor.Centre, Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), - Margin = new MarginPadding { Horizontal = 20 } + Margin = new MarginPadding { Horizontal = 20 }, } } }; From f013a1e37fd8f9184bbaa6e6c13841d611aa06e7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 10:12:41 +0300 Subject: [PATCH 08/10] Move `CreateContent()` to BDL --- .../Graphics/UserInterface/LoadingButton.cs | 40 ++++++++++++------- osu.Game/Overlays/Comments/CommentEditor.cs | 3 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/LoadingButton.cs b/osu.Game/Graphics/UserInterface/LoadingButton.cs index 81dc023d7e..a75cf0639c 100644 --- a/osu.Game/Graphics/UserInterface/LoadingButton.cs +++ b/osu.Game/Graphics/UserInterface/LoadingButton.cs @@ -1,7 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; using osu.Game.Graphics.Containers; using osuTK; @@ -22,15 +24,9 @@ namespace osu.Game.Graphics.UserInterface Enabled.Value = !isLoading; if (value) - { loading.Show(); - OnLoadStarted(); - } else - { loading.Hide(); - OnLoadFinished(); - } } } @@ -44,18 +40,34 @@ namespace osu.Game.Graphics.UserInterface protected LoadingButton() { - AddRange(new[] + Add(loading = new LoadingSpinner { - CreateContent(), - loading = new LoadingSpinner - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(12) - } + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(12), + Depth = -1, }); } + [BackgroundDependencyLoader] + private void load() + { + Add(CreateContent()); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + loading.State.BindValueChanged(s => + { + if (s.NewValue == Visibility.Visible) + OnLoadStarted(); + else + OnLoadFinished(); + }, true); + } + protected override bool OnClick(ClickEvent e) { if (!Enabled.Value) diff --git a/osu.Game/Overlays/Comments/CommentEditor.cs b/osu.Game/Overlays/Comments/CommentEditor.cs index 1847de8660..3ff4cfad4a 100644 --- a/osu.Game/Overlays/Comments/CommentEditor.cs +++ b/osu.Game/Overlays/Comments/CommentEditor.cs @@ -198,8 +198,6 @@ namespace osu.Game.Overlays.Comments IdleColour = colourProvider.Light4; HoverColour = colourProvider.Light3; blockedBackground.Colour = colourProvider.Background5; - - drawableText.Text = text; } protected override void LoadComplete() @@ -237,6 +235,7 @@ namespace osu.Game.Overlays.Comments Origin = Anchor.Centre, Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), Margin = new MarginPadding { Horizontal = 20 }, + Text = text, } } }; From 51e7b9950e1bcedb85a97315616c486b3b3b75e7 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 5 Nov 2021 18:07:12 +0300 Subject: [PATCH 09/10] Define local current bindable to bind value change instead --- .../Overlays/Changelog/ChangelogHeader.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Changelog/ChangelogHeader.cs b/osu.Game/Overlays/Changelog/ChangelogHeader.cs index 1b120ef57c..4a94666031 100644 --- a/osu.Game/Overlays/Changelog/ChangelogHeader.cs +++ b/osu.Game/Overlays/Changelog/ChangelogHeader.cs @@ -26,6 +26,8 @@ namespace osu.Game.Overlays.Changelog public static LocalisableString ListingString => LayoutStrings.HeaderChangelogIndex; + private readonly Bindable currentStream = new Bindable(); + private Box streamsBackground; public ChangelogHeader() @@ -38,6 +40,12 @@ namespace osu.Game.Overlays.Changelog }; Build.ValueChanged += showBuild; + + currentStream.ValueChanged += e => + { + if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream)) + Build.Value = e.NewValue.LatestBuild; + }; } [BackgroundDependencyLoader] @@ -61,7 +69,7 @@ namespace osu.Game.Overlays.Changelog else { Current.Value = ListingString; - Streams.Current.Value = null; + currentStream.Value = null; } } @@ -88,17 +96,11 @@ namespace osu.Game.Overlays.Changelog Horizontal = 65, Vertical = 20 }, - Child = Streams = new ChangelogUpdateStreamControl() + Child = Streams = new ChangelogUpdateStreamControl { Current = currentStream }, } } }; - Streams.Current.ValueChanged += e => - { - if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream)) - Build.Value = e.NewValue.LatestBuild; - }; - return content; } @@ -115,7 +117,7 @@ namespace osu.Game.Overlays.Changelog if (Build.Value == null) return; - Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name); + currentStream.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name); } private class ChangelogHeaderTitle : OverlayTitle From c40f88749209b7cfd06b9f67a74c345fda3186bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 6 Nov 2021 15:20:29 +0100 Subject: [PATCH 10/10] Remove unnecessary local variable --- .../Overlays/Changelog/ChangelogHeader.cs | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/osu.Game/Overlays/Changelog/ChangelogHeader.cs b/osu.Game/Overlays/Changelog/ChangelogHeader.cs index 4a94666031..49a33ee5d6 100644 --- a/osu.Game/Overlays/Changelog/ChangelogHeader.cs +++ b/osu.Game/Overlays/Changelog/ChangelogHeader.cs @@ -75,34 +75,29 @@ namespace osu.Game.Overlays.Changelog protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog"); - protected override Drawable CreateContent() + protected override Drawable CreateContent() => new Container { - var content = new Container + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Children = new Drawable[] + streamsBackground = new Box { - streamsBackground = new Box + RelativeSizeAxes = Axes.Both + }, + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding { - RelativeSizeAxes = Axes.Both + Horizontal = 65, + Vertical = 20 }, - new Container - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Padding = new MarginPadding - { - Horizontal = 65, - Vertical = 20 - }, - Child = Streams = new ChangelogUpdateStreamControl { Current = currentStream }, - } + Child = Streams = new ChangelogUpdateStreamControl { Current = currentStream }, } - }; - - return content; - } + } + }; protected override OverlayTitle CreateTitle() => new ChangelogHeaderTitle();