1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 23:47:21 +08:00

Apply NRT and avoid throws from null RoundBeatmap.Beatmaps

This commit is contained in:
Dean Herbert 2023-07-26 17:43:45 +09:00
parent 219ba00fb2
commit fa4992f05a
3 changed files with 32 additions and 30 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
@ -11,6 +9,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -21,19 +20,18 @@ namespace osu.Game.Tournament.Components
{ {
public partial class TournamentBeatmapPanel : CompositeDrawable public partial class TournamentBeatmapPanel : CompositeDrawable
{ {
public readonly TournamentBeatmap Beatmap; public readonly TournamentBeatmap? Beatmap;
private readonly string mod; private readonly string mod;
public const float HEIGHT = 50; public const float HEIGHT = 50;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>(); private readonly Bindable<TournamentMatch?> currentMatch = new Bindable<TournamentMatch?>();
private Box flash;
public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = null) private Box flash = null!;
public TournamentBeatmapPanel(TournamentBeatmap beatmap, string mod = "")
{ {
ArgumentNullException.ThrowIfNull(beatmap);
Beatmap = beatmap; Beatmap = beatmap;
this.mod = mod; this.mod = mod;
@ -73,7 +71,7 @@ namespace osu.Game.Tournament.Components
{ {
new TournamentSpriteText new TournamentSpriteText
{ {
Text = Beatmap.GetDisplayTitleRomanisable(false, false), Text = Beatmap?.GetDisplayTitleRomanisable(false, false) ?? (LocalisableString)@"unknown",
Font = OsuFont.Torus.With(weight: FontWeight.Bold), Font = OsuFont.Torus.With(weight: FontWeight.Bold),
}, },
new FillFlowContainer new FillFlowContainer
@ -90,7 +88,7 @@ namespace osu.Game.Tournament.Components
}, },
new TournamentSpriteText new TournamentSpriteText
{ {
Text = Beatmap.Metadata.Author.Username, Text = Beatmap?.Metadata.Author.Username ?? "unknown",
Padding = new MarginPadding { Right = 20 }, Padding = new MarginPadding { Right = 20 },
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14) Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
}, },
@ -102,7 +100,7 @@ namespace osu.Game.Tournament.Components
}, },
new TournamentSpriteText new TournamentSpriteText
{ {
Text = Beatmap.DifficultyName, Text = Beatmap?.DifficultyName ?? "unknown",
Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14) Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 14)
}, },
} }
@ -131,36 +129,37 @@ namespace osu.Game.Tournament.Components
} }
} }
private void matchChanged(ValueChangedEvent<TournamentMatch> match) private void matchChanged(ValueChangedEvent<TournamentMatch?> match)
{ {
if (match.OldValue != null) if (match.OldValue != null)
match.OldValue.PicksBans.CollectionChanged -= picksBansOnCollectionChanged; match.OldValue.PicksBans.CollectionChanged -= picksBansOnCollectionChanged;
match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged; if (match.NewValue != null)
match.NewValue.PicksBans.CollectionChanged += picksBansOnCollectionChanged;
updateState(); updateState();
} }
private void picksBansOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void picksBansOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
=> updateState(); => updateState();
private BeatmapChoice choice; private BeatmapChoice? choice;
private void updateState() 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; bool shouldFlash = newChoice != choice;
choice = found;
if (found != null) if (newChoice != null)
{ {
if (doFlash) if (shouldFlash)
flash?.FadeOutFromOne(500).Loop(0, 10); flash.FadeOutFromOne(500).Loop(0, 10);
BorderThickness = 6; BorderThickness = 6;
BorderColour = TournamentGame.GetTeamColour(found.Team); BorderColour = TournamentGame.GetTeamColour(newChoice.Team);
switch (found.Type) switch (newChoice.Type)
{ {
case ChoiceType.Pick: case ChoiceType.Pick:
Colour = Color4.White; Colour = Color4.White;
@ -179,6 +178,8 @@ namespace osu.Game.Tournament.Components
BorderThickness = 0; BorderThickness = 0;
Alpha = 1; Alpha = 1;
} }
choice = newChoice;
} }
private partial class NoUnloadBeatmapSetCover : UpdateableOnlineBeatmapSetCover private partial class NoUnloadBeatmapSetCover : UpdateableOnlineBeatmapSetCover

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using Newtonsoft.Json; using Newtonsoft.Json;
namespace osu.Game.Tournament.Models namespace osu.Game.Tournament.Models
@ -10,9 +8,10 @@ namespace osu.Game.Tournament.Models
public class RoundBeatmap public class RoundBeatmap
{ {
public int ID; public int ID;
public string Mods;
public string Mods = string.Empty;
[JsonProperty("BeatmapInfo")] [JsonProperty("BeatmapInfo")]
public TournamentBeatmap Beatmap; public TournamentBeatmap? Beatmap;
} }
} }

View File

@ -134,9 +134,11 @@ namespace osu.Game.Tournament.Screens.Editors
public void CreateNew() public void CreateNew()
{ {
var user = new RoundBeatmap(); var b = new RoundBeatmap();
round.Beatmaps.Add(user);
flow.Add(new RoundBeatmapRow(round, user)); round.Beatmaps.Add(b);
flow.Add(new RoundBeatmapRow(round, b));
} }
public partial class RoundBeatmapRow : CompositeDrawable public partial class RoundBeatmapRow : CompositeDrawable