1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Enable nullability for song select

This commit is contained in:
mk56-spn 2023-01-13 00:52:14 +01:00
parent b3d4da8fc9
commit 403ca05e5e
3 changed files with 87 additions and 72 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -105,6 +106,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
Schedule(() => Schedule(() =>
{ {
Debug.Assert(Carousel != null);
Carousel.AllowSelection = true; Carousel.AllowSelection = true;
}); });
}); });

View File

@ -173,7 +173,7 @@ namespace osu.Game.Screens.OnlinePlay
IsValidMod = IsValidMod IsValidMod = IsValidMod
}; };
protected override IEnumerable<(FooterButton, OverlayContainer)> CreateFooterButtons() protected override IEnumerable<(FooterButton, OverlayContainer?)> CreateFooterButtons()
{ {
var buttons = base.CreateFooterButtons().ToList(); var buttons = base.CreateFooterButtons().ToList();
buttons.Insert(buttons.FindIndex(b => b.Item1 is FooterButtonMods) + 1, (new FooterButtonFreeMods { Current = FreeMods }, freeModSelectOverlay)); buttons.Insert(buttons.FindIndex(b => b.Item1 is FooterButtonMods) + 1, (new FooterButtonFreeMods { Current = FreeMods }, freeModSelectOverlay));

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 osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
@ -36,7 +34,6 @@ using osu.Framework.Input.Bindings;
using osu.Game.Collections; using osu.Game.Collections;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -49,7 +46,7 @@ namespace osu.Game.Screens.Select
protected const float BACKGROUND_BLUR = 20; protected const float BACKGROUND_BLUR = 20;
private const float left_area_padding = 20; private const float left_area_padding = 20;
public FilterControl FilterControl { get; private set; } public FilterControl FilterControl { get; private set; } = null!;
/// <summary> /// <summary>
/// Whether this song select instance should take control of the global track, /// Whether this song select instance should take control of the global track,
@ -64,18 +61,18 @@ namespace osu.Game.Screens.Select
/// <summary> /// <summary>
/// Can be null if <see cref="ShowFooter"/> is false. /// Can be null if <see cref="ShowFooter"/> is false.
/// </summary> /// </summary>
protected BeatmapOptionsOverlay BeatmapOptions { get; private set; } protected BeatmapOptionsOverlay BeatmapOptions { get; private set; } = null!;
/// <summary> /// <summary>
/// Can be null if <see cref="ShowFooter"/> is false. /// Can be null if <see cref="ShowFooter"/> is false.
/// </summary> /// </summary>
protected Footer Footer { get; private set; } protected Footer? Footer { get; private set; }
/// <summary> /// <summary>
/// Contains any panel which is triggered by a footer button. /// Contains any panel which is triggered by a footer button.
/// Helps keep them located beneath the footer itself. /// Helps keep them located beneath the footer itself.
/// </summary> /// </summary>
protected Container FooterPanels { get; private set; } protected Container FooterPanels { get; private set; } = null!;
/// <summary> /// <summary>
/// Whether entering editor mode should be allowed. /// Whether entering editor mode should be allowed.
@ -85,50 +82,49 @@ namespace osu.Game.Screens.Select
public bool BeatmapSetsLoaded => IsLoaded && Carousel?.BeatmapSetsLoaded == true; public bool BeatmapSetsLoaded => IsLoaded && Carousel?.BeatmapSetsLoaded == true;
[Resolved] [Resolved]
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
protected BeatmapCarousel Carousel { get; private set; } protected BeatmapCarousel? Carousel { get; private set; }
private ParallaxContainer wedgeBackground; private ParallaxContainer wedgeBackground = null!;
protected Container LeftArea { get; private set; } protected Container LeftArea { get; private set; } = null!;
private BeatmapInfoWedge beatmapInfoWedge; private BeatmapInfoWedge beatmapInfoWedge = null!;
[Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; }
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private IDialogOverlay? dialogOverlay { get; set; }
protected ModSelectOverlay ModSelect { get; private set; } [Resolved]
private BeatmapManager beatmaps { get; set; } = null!;
protected Sample SampleConfirm { get; private set; } protected ModSelectOverlay ModSelect { get; private set; } = null!;
private Sample sampleChangeDifficulty; protected Sample? SampleConfirm { get; private set; }
private Sample sampleChangeBeatmap;
private Container carouselContainer; private Sample sampleChangeDifficulty = null!;
private Sample sampleChangeBeatmap = null!;
protected BeatmapDetailArea BeatmapDetails { get; private set; } private Container carouselContainer = null!;
private FooterButtonOptions beatmapOptionsButton; protected BeatmapDetailArea BeatmapDetails { get; private set; } = null!;
private FooterButtonOptions beatmapOptionsButton = null!;
private readonly Bindable<RulesetInfo> decoupledRuleset = new Bindable<RulesetInfo>(); private readonly Bindable<RulesetInfo> decoupledRuleset = new Bindable<RulesetInfo>();
private double audioFeedbackLastPlaybackTime; private double audioFeedbackLastPlaybackTime;
[CanBeNull] private IDisposable? modSelectOverlayRegistration;
private IDisposable modSelectOverlayRegistration;
[Resolved] [Resolved]
private MusicController music { get; set; } private MusicController? music { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
internal IOverlayManager OverlayManager { get; private set; } internal IOverlayManager? OverlayManager { get; private set; }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuColour colours, ManageCollectionsDialog manageCollectionsDialog, DifficultyRecommender recommender) private void load(AudioManager audio, OsuColour colours, ManageCollectionsDialog? manageCollectionsDialog, DifficultyRecommender? recommender)
{ {
// initial value transfer is required for FilterControl (it uses our re-cached bindables in its async load for the initial filter). // initial value transfer is required for FilterControl (it uses our re-cached bindables in its async load for the initial filter).
transferRulesetValue(); transferRulesetValue();
@ -273,7 +269,7 @@ namespace osu.Game.Screens.Select
BeatmapOptions = new BeatmapOptionsOverlay(), BeatmapOptions = new BeatmapOptionsOverlay(),
} }
}, },
Footer = new Footer(), Footer = new Footer()
}); });
} }
@ -318,16 +314,20 @@ namespace osu.Game.Screens.Select
/// Creates the buttons to be displayed in the footer. /// Creates the buttons to be displayed in the footer.
/// </summary> /// </summary>
/// <returns>A set of <see cref="FooterButton"/> and an optional <see cref="OverlayContainer"/> which the button opens when pressed.</returns> /// <returns>A set of <see cref="FooterButton"/> and an optional <see cref="OverlayContainer"/> which the button opens when pressed.</returns>
protected virtual IEnumerable<(FooterButton, OverlayContainer)> CreateFooterButtons() => new (FooterButton, OverlayContainer)[] protected virtual IEnumerable<(FooterButton, OverlayContainer?)> CreateFooterButtons()
{ {
(new FooterButtonMods { Current = Mods }, ModSelect), Debug.Assert(Carousel != null);
(new FooterButtonRandom return new (FooterButton, OverlayContainer?)[]
{ {
NextRandom = () => Carousel.SelectNextRandom(), (new FooterButtonMods { Current = Mods }, ModSelect),
PreviousRandom = Carousel.SelectPreviousRandom (new FooterButtonRandom
}, null), {
(beatmapOptionsButton = new FooterButtonOptions(), BeatmapOptions) NextRandom = () => Carousel.SelectNextRandom(),
}; PreviousRandom = Carousel.SelectPreviousRandom
}, null),
(beatmapOptionsButton = new FooterButtonOptions(), BeatmapOptions)
};
}
protected virtual ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay(); protected virtual ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay();
@ -336,10 +336,11 @@ namespace osu.Game.Screens.Select
// if not the current screen, we want to get carousel in a good presentation state before displaying (resume or enter). // if not the current screen, we want to get carousel in a good presentation state before displaying (resume or enter).
bool shouldDebounce = this.IsCurrentScreen(); bool shouldDebounce = this.IsCurrentScreen();
Debug.Assert(Carousel != null);
Carousel.Filter(criteria, shouldDebounce); Carousel.Filter(criteria, shouldDebounce);
} }
private DependencyContainer dependencies; private DependencyContainer dependencies = null!;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
@ -357,7 +358,7 @@ namespace osu.Game.Screens.Select
/// </summary> /// </summary>
protected abstract BeatmapDetailArea CreateBeatmapDetailArea(); protected abstract BeatmapDetailArea CreateBeatmapDetailArea();
public void Edit(BeatmapInfo beatmapInfo = null) public void Edit(BeatmapInfo? beatmapInfo = null)
{ {
if (!AllowEditing) if (!AllowEditing)
throw new InvalidOperationException($"Attempted to edit when {nameof(AllowEditing)} is disabled"); throw new InvalidOperationException($"Attempted to edit when {nameof(AllowEditing)} is disabled");
@ -372,8 +373,10 @@ namespace osu.Game.Screens.Select
/// <param name="beatmapInfo">An optional beatmap to override the current carousel selection.</param> /// <param name="beatmapInfo">An optional beatmap to override the current carousel selection.</param>
/// <param name="ruleset">An optional ruleset to override the current carousel selection.</param> /// <param name="ruleset">An optional ruleset to override the current carousel selection.</param>
/// <param name="customStartAction">An optional custom action to perform instead of <see cref="OnStart"/>.</param> /// <param name="customStartAction">An optional custom action to perform instead of <see cref="OnStart"/>.</param>
public void FinaliseSelection(BeatmapInfo beatmapInfo = null, RulesetInfo ruleset = null, Action customStartAction = null) public void FinaliseSelection(BeatmapInfo? beatmapInfo = null, RulesetInfo? ruleset = null, Action? customStartAction = null)
{ {
Debug.Assert(Carousel != null);
// This is very important as we have not yet bound to screen-level bindables before the carousel load is completed. // This is very important as we have not yet bound to screen-level bindables before the carousel load is completed.
if (!Carousel.BeatmapSetsLoaded) if (!Carousel.BeatmapSetsLoaded)
{ {
@ -419,43 +422,44 @@ namespace osu.Game.Screens.Select
/// <returns>If a resultant action occurred that takes the user away from SongSelect.</returns> /// <returns>If a resultant action occurred that takes the user away from SongSelect.</returns>
protected abstract bool OnStart(); protected abstract bool OnStart();
private ScheduledDelegate selectionChangedDebounce; private ScheduledDelegate? selectionChangedDebounce;
private void updateCarouselSelection(ValueChangedEvent<WorkingBeatmap> e = null) private void updateCarouselSelection(ValueChangedEvent<WorkingBeatmap>? e = null)
{ {
var beatmap = e?.NewValue ?? Beatmap.Value; var beatmap = e?.NewValue ?? Beatmap.Value;
if (beatmap is DummyWorkingBeatmap || !this.IsCurrentScreen()) return; if (beatmap is DummyWorkingBeatmap || !this.IsCurrentScreen()) return;
Logger.Log($"Song select working beatmap updated to {beatmap}"); Logger.Log($"Song select working beatmap updated to {beatmap}");
if (!Carousel.SelectBeatmap(beatmap.BeatmapInfo, false)) Debug.Assert(Carousel != null);
if (Carousel.SelectBeatmap(beatmap.BeatmapInfo, false)) return;
// A selection may not have been possible with filters applied.
// There was possibly a ruleset mismatch. This is a case we can help things along by updating the game-wide ruleset to match.
if (!beatmap.BeatmapInfo.Ruleset.Equals(decoupledRuleset.Value))
{ {
// A selection may not have been possible with filters applied. Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
transferRulesetValue();
// There was possibly a ruleset mismatch. This is a case we can help things along by updating the game-wide ruleset to match.
if (!beatmap.BeatmapInfo.Ruleset.Equals(decoupledRuleset.Value))
{
Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
transferRulesetValue();
}
// Even if a ruleset mismatch was not the cause (ie. a text filter is applied),
// we still want to temporarily show the new beatmap, bypassing filters.
// This will be undone the next time the user changes the filter.
var criteria = FilterControl.CreateCriteria();
criteria.SelectedBeatmapSet = beatmap.BeatmapInfo.BeatmapSet;
Carousel.Filter(criteria);
Carousel.SelectBeatmap(beatmap.BeatmapInfo);
} }
// Even if a ruleset mismatch was not the cause (ie. a text filter is applied),
// we still want to temporarily show the new beatmap, bypassing filters.
// This will be undone the next time the user changes the filter.
var criteria = FilterControl.CreateCriteria();
criteria.SelectedBeatmapSet = beatmap.BeatmapInfo.BeatmapSet;
Carousel.Filter(criteria);
Carousel.SelectBeatmap(beatmap.BeatmapInfo);
} }
// We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds. // We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds.
private BeatmapInfo beatmapInfoPrevious; private BeatmapInfo? beatmapInfoPrevious;
private BeatmapInfo beatmapInfoNoDebounce; private BeatmapInfo? beatmapInfoNoDebounce;
private RulesetInfo rulesetNoDebounce; private RulesetInfo? rulesetNoDebounce;
private void updateSelectedBeatmap(BeatmapInfo beatmapInfo) private void updateSelectedBeatmap(BeatmapInfo? beatmapInfo)
{ {
if (beatmapInfo == null && beatmapInfoNoDebounce == null) if (beatmapInfo == null && beatmapInfoNoDebounce == null)
return; return;
@ -467,7 +471,7 @@ namespace osu.Game.Screens.Select
performUpdateSelected(); performUpdateSelected();
} }
private void updateSelectedRuleset(RulesetInfo ruleset) private void updateSelectedRuleset(RulesetInfo? ruleset)
{ {
if (ruleset == null && rulesetNoDebounce == null) if (ruleset == null && rulesetNoDebounce == null)
return; return;
@ -485,7 +489,7 @@ namespace osu.Game.Screens.Select
private void performUpdateSelected() private void performUpdateSelected()
{ {
var beatmap = beatmapInfoNoDebounce; var beatmap = beatmapInfoNoDebounce;
var ruleset = rulesetNoDebounce; RulesetInfo? ruleset = rulesetNoDebounce;
selectionChangedDebounce?.Cancel(); selectionChangedDebounce?.Cancel();
@ -518,6 +522,7 @@ namespace osu.Game.Screens.Select
if (transferRulesetValue()) if (transferRulesetValue())
{ {
Debug.Assert(Carousel != null);
// transferRulesetValue() may trigger a re-filter. If the current selection does not match the new ruleset, we want to switch away from it. // transferRulesetValue() may trigger a re-filter. If the current selection does not match the new ruleset, we want to switch away from it.
// The default logic on WorkingBeatmap change is to switch to a matching ruleset (see workingBeatmapChanged()), but we don't want that here. // The default logic on WorkingBeatmap change is to switch to a matching ruleset (see workingBeatmapChanged()), but we don't want that here.
// We perform an early selection attempt and clear out the beatmap selection to avoid a second ruleset change (revert). // We perform an early selection attempt and clear out the beatmap selection to avoid a second ruleset change (revert).
@ -604,6 +609,7 @@ namespace osu.Game.Screens.Select
ModSelect.SelectedMods.Disabled = false; ModSelect.SelectedMods.Disabled = false;
ModSelect.SelectedMods.BindTo(selectedMods); ModSelect.SelectedMods.BindTo(selectedMods);
Debug.Assert(Carousel != null);
Carousel.AllowSelection = true; Carousel.AllowSelection = true;
BeatmapDetails.Refresh(); BeatmapDetails.Refresh();
@ -620,6 +626,7 @@ namespace osu.Game.Screens.Select
{ {
// restart playback on returning to song select, regardless. // restart playback on returning to song select, regardless.
// not sure this should be a permanent thing (we may want to leave a user pause paused even on returning) // not sure this should be a permanent thing (we may want to leave a user pause paused even on returning)
Debug.Assert(music != null);
music.ResetTrackAdjustments(); music.ResetTrackAdjustments();
music.Play(requestedByUser: true); music.Play(requestedByUser: true);
} }
@ -665,6 +672,7 @@ namespace osu.Game.Screens.Select
BeatmapOptions.Hide(); BeatmapOptions.Hide();
Debug.Assert(Carousel != null);
Carousel.AllowSelection = false; Carousel.AllowSelection = false;
endLooping(); endLooping();
@ -694,6 +702,8 @@ namespace osu.Game.Screens.Select
isHandlingLooping = true; isHandlingLooping = true;
ensureTrackLooping(Beatmap.Value, TrackChangeDirection.None); ensureTrackLooping(Beatmap.Value, TrackChangeDirection.None);
Debug.Assert(music != null);
music.TrackChanged += ensureTrackLooping; music.TrackChanged += ensureTrackLooping;
} }
@ -703,6 +713,7 @@ namespace osu.Game.Screens.Select
if (!isHandlingLooping) if (!isHandlingLooping)
return; return;
Debug.Assert(music != null);
music.CurrentTrack.Looping = isHandlingLooping = false; music.CurrentTrack.Looping = isHandlingLooping = false;
music.TrackChanged -= ensureTrackLooping; music.TrackChanged -= ensureTrackLooping;
@ -763,7 +774,7 @@ namespace osu.Game.Screens.Select
} }
} }
private readonly WeakReference<ITrack> lastTrack = new WeakReference<ITrack>(null); private readonly WeakReference<ITrack?> lastTrack = new WeakReference<ITrack?>(null);
/// <summary> /// <summary>
/// Ensures some music is playing for the current track. /// Ensures some music is playing for the current track.
@ -774,6 +785,7 @@ namespace osu.Game.Screens.Select
if (!ControlGlobalMusic) if (!ControlGlobalMusic)
return; return;
Debug.Assert(music != null);
ITrack track = music.CurrentTrack; ITrack track = music.CurrentTrack;
bool isNewTrack = !lastTrack.TryGetTarget(out var last) || last != track; bool isNewTrack = !lastTrack.TryGetTarget(out var last) || last != track;
@ -791,6 +803,7 @@ namespace osu.Game.Screens.Select
{ {
bindBindables(); bindBindables();
Debug.Assert(Carousel != null);
Carousel.AllowSelection = true; Carousel.AllowSelection = true;
// If a selection was already obtained, do not attempt to update the selected beatmap. // If a selection was already obtained, do not attempt to update the selected beatmap.
@ -868,14 +881,14 @@ namespace osu.Game.Screens.Select
return true; return true;
} }
private void delete(BeatmapSetInfo beatmap) private void delete(BeatmapSetInfo? beatmap)
{ {
if (beatmap == null) return; if (beatmap == null) return;
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap)); dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
} }
private void clearScores(BeatmapInfo beatmapInfo) private void clearScores(BeatmapInfo? beatmapInfo)
{ {
if (beatmapInfo == null) return; if (beatmapInfo == null) return;
@ -950,7 +963,7 @@ namespace osu.Game.Screens.Select
private partial class ResetScrollContainer : Container private partial class ResetScrollContainer : Container
{ {
private readonly Action onHoverAction; private readonly Action? onHoverAction;
public ResetScrollContainer(Action onHoverAction) public ResetScrollContainer(Action onHoverAction)
{ {