From 21ef27de5c34f1c615c3295f9e29ac6cc4570173 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 8 May 2023 21:46:39 +0800 Subject: [PATCH 1/5] Remove nullable disable annotation in the graphic namespace. --- .../Graphics/Containers/MessageContainer.cs | 14 ++++++-------- .../Containers/OrderRearrangeableListContainer.cs | 10 ++++------ .../Graphics/Cursor/BackgroundToolTip.cs | 2 -- .../Graphics/Cursor/LyricToolTip.cs | 4 +--- .../Graphics/Cursor/SingerToolTip.cs | 4 +--- .../Graphics/Overlays/Dialog/OkPopupDialog.cs | 4 +--- .../Graphics/Shapes/CornerBackground.cs | 2 -- .../Graphics/Sprites/DrawableCircleSingerAvatar.cs | 2 -- .../Graphics/Sprites/DrawableSingerAvatar.cs | 6 ++---- .../Graphics/Sprites/KaraokeIcon.cs | 2 -- .../Graphics/UserInterface/CircleCheckbox.cs | 6 ++---- .../UserInterface/MicrophoneSoundVisualizer.cs | 6 ++---- .../RearrangeableTextFlowListContainer.cs | 14 ++++++-------- .../Graphics/UserInterface/SingerDisplay.cs | 2 -- .../Graphics/UserInterfaceV2/FontSelector.cs | 12 +++++------- .../UserInterfaceV2/LabelledColourSelector.cs | 6 ++---- .../UserInterfaceV2/LabelledHueSelector.cs | 2 -- .../UserInterfaceV2/LabelledImageSelector.cs | 2 -- .../UserInterfaceV2/LabelledRealTimeSliderBar.cs | 2 -- 19 files changed, 32 insertions(+), 70 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Containers/MessageContainer.cs b/osu.Game.Rulesets.Karaoke/Graphics/Containers/MessageContainer.cs index 7a7830dc7..f98d6c27d 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Containers/MessageContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Containers/MessageContainer.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; @@ -15,14 +13,14 @@ namespace osu.Game.Rulesets.Karaoke.Graphics.Containers; public partial class MessageContainer : OsuTextFlowContainer { [Resolved] - private OsuColour colours { get; set; } + private OsuColour colours { get; set; } = null!; - public MessageContainer(Action defaultCreationParameters = null) + public MessageContainer(Action? defaultCreationParameters = null) : base(defaultCreationParameters) { } - public void AddSuccessParagraph(string text, Action creationParameters = null) + public void AddSuccessParagraph(string text, Action? creationParameters = null) { NewParagraph(); AddIcon(FontAwesome.Solid.Check, icon => @@ -32,7 +30,7 @@ public void AddSuccessParagraph(string text, Action creationParamete AddText($" {text}", creationParameters); } - public void AddWarningParagraph(string text, Action creationParameters = null) + public void AddWarningParagraph(string text, Action? creationParameters = null) { NewParagraph(); AddIcon(FontAwesome.Solid.ExclamationTriangle, icon => @@ -43,7 +41,7 @@ public void AddWarningParagraph(string text, Action creationParamete AddText($" {text}", creationParameters); } - public void AddAlertParagraph(string text, Action creationParameters = null) + public void AddAlertParagraph(string text, Action? creationParameters = null) { NewParagraph(); AddIcon(FontAwesome.Solid.TimesCircle, icon => @@ -53,7 +51,7 @@ public void AddAlertParagraph(string text, Action creationParameters AddText($" {text}", creationParameters); } - public void AddHighlightText(string text, Action creationParameters = null) + public void AddHighlightText(string text, Action? creationParameters = null) { AddText($" {text}", c => { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs b/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs index 576ab1cb0..e307569e6 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Specialized; using osu.Framework.Graphics; @@ -14,7 +12,7 @@ namespace osu.Game.Rulesets.Karaoke.Graphics.Containers; public abstract partial class OrderRearrangeableListContainer : OsuRearrangeableListContainer { - public event Action OnOrderChanged; + public event Action? OnOrderChanged; protected abstract Vector2 Spacing { get; } @@ -25,7 +23,7 @@ protected OrderRearrangeableListContainer() Items.CollectionChanged += collectionChanged; } - private void collectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void collectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { @@ -42,7 +40,7 @@ protected override FillFlowContainer> CreateListFi => base.CreateListFillFlowContainer().With(x => x.Spacing = Spacing); private bool displayBottomDrawable; - private Drawable bottomDrawable; + private Drawable? bottomDrawable; public bool DisplayBottomDrawable { @@ -78,5 +76,5 @@ public bool DisplayBottomDrawable } } - protected virtual Drawable CreateBottomDrawable() => null; + protected virtual Drawable? CreateBottomDrawable() => null; } diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Cursor/BackgroundToolTip.cs b/osu.Game.Rulesets.Karaoke/Graphics/Cursor/BackgroundToolTip.cs index 442de9a12..88de91741 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Cursor/BackgroundToolTip.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Cursor/BackgroundToolTip.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Cursor/LyricToolTip.cs b/osu.Game.Rulesets.Karaoke/Graphics/Cursor/LyricToolTip.cs index 1eebc0bd2..647ad2bf8 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Cursor/LyricToolTip.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Cursor/LyricToolTip.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Graphics.Sprites; @@ -12,7 +10,7 @@ namespace osu.Game.Rulesets.Karaoke.Graphics.Cursor; public partial class LyricTooltip : BackgroundToolTip { - private Lyric lastLyric; + private Lyric? lastLyric; public override void SetContent(Lyric lyric) { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Cursor/SingerToolTip.cs b/osu.Game.Rulesets.Karaoke/Graphics/Cursor/SingerToolTip.cs index 1f83f84bf..bb0fb4adb 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Cursor/SingerToolTip.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Cursor/SingerToolTip.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; @@ -134,7 +132,7 @@ public SingerToolTip() bindableDescription.BindValueChanged(e => singerDescription.Text = string.IsNullOrEmpty(e.NewValue) ? "" : e.NewValue, true); } - private ISinger lastSinger; + private ISinger? lastSinger; public override void SetContent(ISinger singer) { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Overlays/Dialog/OkPopupDialog.cs b/osu.Game.Rulesets.Karaoke/Graphics/Overlays/Dialog/OkPopupDialog.cs index 649d50dfc..e8707477c 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Overlays/Dialog/OkPopupDialog.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Overlays/Dialog/OkPopupDialog.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Game.Overlays.Dialog; @@ -10,7 +8,7 @@ namespace osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog; public partial class OkPopupDialog : PopupDialog { - public OkPopupDialog(Action okAction = null) + public OkPopupDialog(Action? okAction = null) { Buttons = new PopupDialogButton[] { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Shapes/CornerBackground.cs b/osu.Game.Rulesets.Karaoke/Graphics/Shapes/CornerBackground.cs index ead951bfa..401ed6865 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Shapes/CornerBackground.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Shapes/CornerBackground.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs index 492885367..58c96dc1f 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableSingerAvatar.cs b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableSingerAvatar.cs index fb50240ad..d66e83430 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableSingerAvatar.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableSingerAvatar.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -49,9 +47,9 @@ Texture getDefaultAvatar() => textures.Get(@"Online/avatar-guest"); } - private ISinger singer; + private ISinger? singer; - public virtual ISinger Singer + public virtual ISinger? Singer { get => singer; set diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/KaraokeIcon.cs b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/KaraokeIcon.cs index 9022c75d7..49aca0b3e 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/KaraokeIcon.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/KaraokeIcon.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/CircleCheckbox.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/CircleCheckbox.cs index d5b529dac..af4e6fa17 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/CircleCheckbox.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/CircleCheckbox.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; @@ -28,8 +26,8 @@ public partial class CircleCheckbox : Checkbox, IHasAccentColour, IHasTooltip private readonly SpriteIcon border; private readonly SpriteIcon selectedIcon; - private Sample sampleChecked; - private Sample sampleUnchecked; + private Sample? sampleChecked; + private Sample? sampleUnchecked; /// /// Whether to play sounds when the state changes as a result of user interaction. diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs index b4511efee..503e367d9 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; @@ -83,7 +81,7 @@ public MicrophoneSoundVisualizer() updateDeviceInfo(); } - private string deviceName; + private string deviceName = string.Empty; public string DeviceName { @@ -169,7 +167,7 @@ internal partial class MicrophoneInfo : CompositeDrawable private readonly OsuSpriteText deviceName; [Resolved] - private OsuColour colours { get; set; } + private OsuColour colours { get; set; } = null!; public MicrophoneInfo() { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs index 47904d15f..65e6fc581 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using osu.Framework.Allocation; @@ -26,9 +24,9 @@ public partial class RearrangeableTextFlowListContainer : OsuRearrangeab { public readonly Bindable SelectedSet = new(); - public Action RequestSelection; + public Action? RequestSelection; - private SearchContainer> searchContainer; + private SearchContainer> searchContainer = null!; protected sealed override FillFlowContainer> CreateListFillFlowContainer() => searchContainer = new SearchContainer> { @@ -56,9 +54,9 @@ public partial class DrawableTextListItem : OsuRearrangeableListItem, IF { public readonly Bindable SelectedSet = new(); - public Action RequestSelection; + public Action? RequestSelection; - private TextFlowContainer text; + private TextFlowContainer text = null!; private Color4 selectedColour; @@ -112,11 +110,11 @@ protected override bool OnClick(ClickEvent e) public virtual IEnumerable FilterTerms => new[] { - new LocalisableString(Model.ToString()) + new LocalisableString(Model?.ToString() ?? string.Empty) }; protected virtual void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, TModel model) - => textFlowContainer.AddText(model.ToString()); + => textFlowContainer.AddText(model?.ToString() ?? string.Empty); private bool matchingFilter = true; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs index 8dc0567c9..7f4ac3103 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using osu.Framework.Bindables; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs index c147fa8ef..dda6ca72b 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; using osu.Framework.Allocation; @@ -40,9 +38,9 @@ public partial class FontSelector : CompositeDrawable, IHasCurrentValue fonts = new(); [Resolved] - private FontStore fontStore { get; set; } + private FontStore fontStore { get; set; } = null!; - private KaraokeLocalFontStore localFontStore; + private KaraokeLocalFontStore localFontStore = null!; public Bindable Current { @@ -158,8 +156,8 @@ public FontSelector() // re-calculate if source changed. Schedule(() => { - string[] oldFamilies = b.OldItems?.OfType().Select(x => x.Family).Distinct().ToArray(); - string[] newFamilies = b.NewItems?.OfType().Select(x => x.Family).Distinct().ToArray(); + string[]? oldFamilies = b.OldItems?.OfType().Select(x => x.Family).Distinct().ToArray(); + string[]? newFamilies = b.NewItems?.OfType().Select(x => x.Family).Distinct().ToArray(); if (oldFamilies != null) { @@ -261,7 +259,7 @@ protected override DrawableTextListItem CreateDrawable(string item) private partial class DrawableFontFamilyListItem : DrawableTextListItem { [Resolved] - private FontManager fontManager { get; set; } + private FontManager fontManager { get; set; } = null!; public DrawableFontFamilyListItem(string item) : base(item) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledColourSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledColourSelector.cs index cca79fee9..6cf601211 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledColourSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledColourSelector.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions; @@ -34,8 +32,8 @@ public partial class ColourSelectorDisplay : CompositeDrawable, IHasCurrentValue { private readonly BindableWithCurrent current = new(); - private Box fill; - private OsuSpriteText colourHexCode; + private Box fill = null!; + private OsuSpriteText colourHexCode = null!; public Bindable Current { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledHueSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledHueSelector.cs index 0a8fb6441..ca90ab2ff 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledHueSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledHueSelector.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledImageSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledImageSelector.cs index 2ed14c7a9..23b4cd205 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledImageSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledImageSelector.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using osu.Game.Graphics.UserInterfaceV2; namespace osu.Game.Rulesets.Karaoke.Graphics.UserInterfaceV2; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledRealTimeSliderBar.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledRealTimeSliderBar.cs index 094700bad..8816d9fd7 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledRealTimeSliderBar.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/LabelledRealTimeSliderBar.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterfaceV2; From 07b7f9cabb389c383658686b2703493d6a7e0fad Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 13 Jul 2023 23:38:45 +0800 Subject: [PATCH 2/5] Fix possible null issue. --- .../Graphics/Containers/OrderRearrangeableListContainer.cs | 6 +++++- .../Graphics/UserInterfaceV2/FontSelector.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs b/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs index e307569e6..ce14b156b 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Containers/OrderRearrangeableListContainer.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Specialized; +using System.Diagnostics; +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; @@ -29,7 +31,9 @@ private void collectionChanged(object? sender, NotifyCollectionChangedEventArgs { // should get the event if user change the position. case NotifyCollectionChangedAction.Move: - var item = (TModel)e.NewItems[0]; + Debug.Assert(e.NewItems != null); + + var item = e.NewItems.OfType().First(); int newIndex = e.NewStartingIndex; OnOrderChanged?.Invoke(item, newIndex); break; diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs index dda6ca72b..d17011eb7 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs @@ -185,7 +185,7 @@ public FontSelector() performChange(); // re-calculate if family changed. - string[] weight = fonts.Where(f => f.Family == x.NewValue).Select(f => f.Weight).Where(s => !string.IsNullOrEmpty(s)).Distinct().ToArray(); + string[] weight = fonts.Where(f => f.Family == x.NewValue).Select(f => f.Weight).OfType().Distinct().ToArray(); weightProperty.Items.Clear(); weightProperty.Items.AddRange(weight); From 412a7c508e8b8da0c43d6e9ab09b5b14b2c39d2a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 13 Jul 2023 23:42:58 +0800 Subject: [PATCH 3/5] mark family and weight should be nullable because those two property in the `FontUsage` is null. --- .../Graphics/UserInterfaceV2/FontSelector.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs index d17011eb7..8e0f264ad 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs @@ -30,7 +30,7 @@ public partial class FontSelector : CompositeDrawable, IHasCurrentValue weightProperty; + private readonly FontPropertyList weightProperty; private readonly FontPropertyList fontSizeProperty; private readonly OsuCheckbox fixedWidthCheckbox; @@ -108,7 +108,7 @@ public FontSelector() Name = "Font family selection area", RelativeSizeAxes = Axes.Both }, - weightProperty = new FontPropertyList + weightProperty = new FontPropertyList { Name = "Font widget selection area", RelativeSizeAxes = Axes.Both @@ -170,7 +170,7 @@ public FontSelector() } // should reset family selection if user select the font that will be removed or added. - string currentFamily = familyProperty.Current.Value; + string? currentFamily = familyProperty.Current.Value; bool resetFamily = oldFamilies?.Contains(currentFamily) ?? false; if (resetFamily) @@ -232,8 +232,8 @@ private void performChange() private FontUsage generateFontUsage() { - string family = familyProperty.Current.Value; - string weight = weightProperty.Current.Value; + string? family = familyProperty.Current.Value; + string? weight = weightProperty.Current.Value; float size = fontSizeProperty.Current.Value; bool fixedWidth = fixedWidthCheckbox.Current.Value; return new FontUsage(family, size, weight, false, fixedWidth); @@ -246,14 +246,14 @@ protected override void Dispose(bool isDisposing) fontStore?.RemoveStore(localFontStore); } - internal partial class FontFamilyPropertyList : FontPropertyList + internal partial class FontFamilyPropertyList : FontPropertyList { - protected override RearrangeableTextFlowListContainer CreateRearrangeableListContainer() + protected override RearrangeableTextFlowListContainer CreateRearrangeableListContainer() => new RearrangeableFontFamilyListContainer(); - private partial class RearrangeableFontFamilyListContainer : RearrangeableTextFlowListContainer + private partial class RearrangeableFontFamilyListContainer : RearrangeableTextFlowListContainer { - protected override DrawableTextListItem CreateDrawable(string item) + protected override DrawableTextListItem CreateDrawable(string? item) => new DrawableFontFamilyListItem(item); private partial class DrawableFontFamilyListItem : DrawableTextListItem @@ -261,15 +261,15 @@ private partial class DrawableFontFamilyListItem : DrawableTextListItem [Resolved] private FontManager fontManager { get; set; } = null!; - public DrawableFontFamilyListItem(string item) + public DrawableFontFamilyListItem(string? item) : base(item) { } - protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, string model) + protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, string? model) { textFlowContainer.TextAnchor = Anchor.BottomLeft; - textFlowContainer.AddText(model); + textFlowContainer.AddText(model ?? string.Empty); var matchedFormat = fontManager.Fonts .Where(x => x.Family == Model).Select(x => x.FontFormat) From 877db568956fbd98912fee2cb7a206876926df1c Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 13 Jul 2023 23:43:34 +0800 Subject: [PATCH 4/5] Singer in the Singer avatar should be nullable. --- .../Graphics/Sprites/DrawableCircleSingerAvatar.cs | 8 ++++---- .../Graphics/UserInterface/SingerDisplay.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs index 58c96dc1f..be2752c0e 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/Sprites/DrawableCircleSingerAvatar.cs @@ -4,7 +4,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Graphics.Textures; +using osu.Game.Graphics; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas.Types; using osu.Game.Rulesets.Karaoke.Beatmaps.Utils; @@ -16,7 +16,7 @@ public partial class DrawableCircleSingerAvatar : DrawableSingerAvatar private readonly IBindable bindableHue = new Bindable(); [BackgroundDependencyLoader] - private void load(LargeTextureStore textures) + private void load(OsuColour colour) { Masking = true; CornerRadius = Math.Min(DrawSize.X, DrawSize.Y) / 2f; @@ -24,11 +24,11 @@ private void load(LargeTextureStore textures) bindableHue.BindValueChanged(_ => { - BorderColour = SingerUtils.GetContentColour(Singer); + BorderColour = Singer != null ? SingerUtils.GetContentColour(Singer) : colour.Gray0; }, true); } - public override ISinger Singer + public override ISinger? Singer { get => base.Singer; set diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs index 7f4ac3103..94a40cf24 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/SingerDisplay.cs @@ -133,7 +133,7 @@ private partial class DrawableSinger : DrawableCircleSingerAvatar, IHasCustomToo { public ITooltip GetCustomTooltip() => new SingerToolTip(); - public ISinger TooltipContent => Singer; + public ISinger? TooltipContent => Singer; } } From 4c516ac315b9b621652db93baee2e54d22f103cf Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 13 Jul 2023 23:56:41 +0800 Subject: [PATCH 5/5] Can use string.Empty() instead. --- .../ChangeHandlers/Lyrics/LyricTranslateChangeHandlerTest.cs | 2 +- .../Edit/Beatmaps/Components/UserInterfaceV2/LyricSelector.cs | 2 +- osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTranslateChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTranslateChangeHandlerTest.cs index 7cdb7e9d2..7e684cb2a 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTranslateChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTranslateChangeHandlerTest.cs @@ -81,7 +81,7 @@ public void TestUpdateTranslateWithNullText() } }); - TriggerHandlerChanged(c => c.UpdateTranslate(new CultureInfo(17), "")); + TriggerHandlerChanged(c => c.UpdateTranslate(new CultureInfo(17), string.Empty)); AssertSelectedHitObject(h => { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Components/UserInterfaceV2/LyricSelector.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Components/UserInterfaceV2/LyricSelector.cs index 5473ea802..541ccab8d 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Components/UserInterfaceV2/LyricSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Components/UserInterfaceV2/LyricSelector.cs @@ -117,7 +117,7 @@ public DrawableLyricListItem(Lyric? item) public override IEnumerable FilterTerms => new[] { - new LocalisableString(Model?.Text ?? ""), + new LocalisableString(Model?.Text ?? string.Empty), }; protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, Lyric? model) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs index 713b58147..404eea6a4 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs @@ -234,7 +234,7 @@ private LocalisableString getTextByIssueType(IssueType issueType) => }; private Colour4 getColourByIssueType(IssueType issueType) => - new IssueTemplate(new EmptyCheck(), issueType, "").Colour; + new IssueTemplate(new EmptyCheck(), issueType, string.Empty).Colour; [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider)