diff --git a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs index 64148fa0cb..970c3b5947 100644 --- a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs +++ b/osu.Game.Tournament/Components/TournamentBeatmapPanel.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.Specialized; using System.Linq; @@ -11,6 +9,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics; @@ -21,19 +20,18 @@ namespace osu.Game.Tournament.Components { public partial class TournamentBeatmapPanel : CompositeDrawable { - public readonly TournamentBeatmap Beatmap; + public readonly TournamentBeatmap? Beatmap; private readonly string mod; public const float HEIGHT = 50; - private readonly Bindable currentMatch = new Bindable(); - private Box flash; + private readonly Bindable currentMatch = new Bindable(); - public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = null) + private Box flash = null!; + + public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = "") { - ArgumentNullException.ThrowIfNull(beatmap); - Beatmap = beatmap; this.mod = mod; @@ -73,7 +71,7 @@ namespace osu.Game.Tournament.Components { new TournamentSpriteText { - Text = Beatmap.GetDisplayTitleRomanisable(false, false), + Text = Beatmap?.GetDisplayTitleRomanisable(false, false) ?? (LocalisableString)@"unknown", Font = OsuFont.Torus.With(weight: FontWeight.Bold), }, new FillFlowContainer @@ -90,7 +88,7 @@ namespace osu.Game.Tournament.Components }, new TournamentSpriteText { - Text = Beatmap.Metadata.Author.Username, + Text = Beatmap?.Metadata.Author.Username ?? "unknown", Padding = new MarginPadding { Right = 20 }, Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14) }, @@ -102,7 +100,7 @@ namespace osu.Game.Tournament.Components }, new TournamentSpriteText { - Text = Beatmap.DifficultyName, + Text = Beatmap?.DifficultyName ?? "unknown", Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14) }, } @@ -131,36 +129,37 @@ namespace osu.Game.Tournament.Components } } - private void matchChanged(ValueChangedEvent match) + private void matchChanged(ValueChangedEvent match) { if (match.OldValue != null) match.OldValue.PicksBans.CollectionChanged -= picksBansOnCollectionChanged; - match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged; + if (match.NewValue != null) + match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged; + updateState(); } - private void picksBansOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void picksBansOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) => updateState(); - private BeatmapChoice choice; + private BeatmapChoice? choice; private void updateState() { - var found = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap.OnlineID); + var newChoice = currentMatch.Value?.PicksBans.FirstOrDefault(p => p.BeatmapID == Beatmap?.OnlineID); - bool doFlash = found != choice; - choice = found; + bool shouldFlash = newChoice != choice; - if (found != null) + if (newChoice != null) { - if (doFlash) - flash?.FadeOutFromOne(500).Loop(0, 10); + if (shouldFlash) + flash.FadeOutFromOne(500).Loop(0, 10); BorderThickness = 6; - BorderColour = TournamentGame.GetTeamColour(found.Team); + BorderColour = TournamentGame.GetTeamColour(newChoice.Team); - switch (found.Type) + switch (newChoice.Type) { case ChoiceType.Pick: Colour = Color4.White; @@ -179,6 +178,8 @@ namespace osu.Game.Tournament.Components BorderThickness = 0; Alpha = 1; } + + choice = newChoice; } private partial class NoUnloadBeatmapSetCover : UpdateableOnlineBeatmapSetCover diff --git a/osu.Game.Tournament/Models/RoundBeatmap.cs b/osu.Game.Tournament/Models/RoundBeatmap.cs index 65ef77e53d..f2ec261246 100644 --- a/osu.Game.Tournament/Models/RoundBeatmap.cs +++ b/osu.Game.Tournament/Models/RoundBeatmap.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 Newtonsoft.Json; namespace osu.Game.Tournament.Models @@ -10,9 +8,10 @@ namespace osu.Game.Tournament.Models public class RoundBeatmap { public int ID; - public string Mods; + + public string Mods = string.Empty; [JsonProperty("BeatmapInfo")] - public TournamentBeatmap Beatmap; + public TournamentBeatmap? Beatmap; } } diff --git a/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs b/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs index 4a3b5c0846..1c6e59aeaa 100644 --- a/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs +++ b/osu.Game.Tournament/Screens/Editors/RoundEditorScreen.cs @@ -134,9 +134,11 @@ namespace osu.Game.Tournament.Screens.Editors public void CreateNew() { - var user = new RoundBeatmap(); - round.Beatmaps.Add(user); - flow.Add(new RoundBeatmapRow(round, user)); + var b = new RoundBeatmap(); + + round.Beatmaps.Add(b); + + flow.Add(new RoundBeatmapRow(round, b)); } public partial class RoundBeatmapRow : CompositeDrawable