1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

Use nullable in PlayerLoader

This commit is contained in:
Dean Herbert 2022-03-17 19:36:33 +09:00
parent da76358ee0
commit dae5569e36

View File

@ -1,10 +1,11 @@
// 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 enable
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using ManagedBass.Fx; using ManagedBass.Fx;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -48,31 +49,31 @@ namespace osu.Game.Screens.Play
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
// We show the previous screen status // We show the previous screen status
protected override UserActivity InitialActivity => null; protected override UserActivity? InitialActivity => null;
protected override bool PlayResumeSound => false; protected override bool PlayResumeSound => false;
protected BeatmapMetadataDisplay MetadataInfo { get; private set; } protected BeatmapMetadataDisplay MetadataInfo { get; private set; } = null!;
/// <summary> /// <summary>
/// A fill flow containing the player settings groups, exposed for the ability to hide it from inheritors of the player loader. /// A fill flow containing the player settings groups, exposed for the ability to hide it from inheritors of the player loader.
/// </summary> /// </summary>
protected FillFlowContainer<PlayerSettingsGroup> PlayerSettings { get; private set; } protected FillFlowContainer<PlayerSettingsGroup> PlayerSettings { get; private set; } = null!;
protected VisualSettings VisualSettings { get; private set; } protected VisualSettings VisualSettings { get; private set; } = null!;
protected AudioSettings AudioSettings { get; private set; } protected AudioSettings AudioSettings { get; private set; } = null!;
protected Task LoadTask { get; private set; } protected Task? LoadTask { get; private set; }
protected Task DisposalTask { get; private set; } protected Task? DisposalTask { get; private set; }
private bool backgroundBrightnessReduction; private bool backgroundBrightnessReduction;
private readonly BindableDouble volumeAdjustment = new BindableDouble(1); private readonly BindableDouble volumeAdjustment = new BindableDouble(1);
private AudioFilter lowPassFilter; private AudioFilter lowPassFilter = null!;
private AudioFilter highPassFilter; private AudioFilter highPassFilter = null!;
protected bool BackgroundBrightnessReduction protected bool BackgroundBrightnessReduction
{ {
@ -94,47 +95,45 @@ namespace osu.Game.Screens.Play
// don't push if the user is hovering one of the panes, unless they are idle. // don't push if the user is hovering one of the panes, unless they are idle.
&& (IsHovered || idleTracker.IsIdle.Value) && (IsHovered || idleTracker.IsIdle.Value)
// don't push if the user is dragging a slider or otherwise. // don't push if the user is dragging a slider or otherwise.
&& inputManager?.DraggedDrawable == null && inputManager.DraggedDrawable == null
// don't push if a focused overlay is visible, like settings. // don't push if a focused overlay is visible, like settings.
&& inputManager?.FocusedDrawable == null; && inputManager.FocusedDrawable == null;
private readonly Func<Player> createPlayer; private readonly Func<Player> createPlayer;
/// <summary> /// <summary>
/// The <see cref="Player"/> instance being loaded by this screen. /// The <see cref="Player"/> instance being loaded by this screen.
/// </summary> /// </summary>
[CanBeNull] public Player? CurrentPlayer { get; private set; }
public Player CurrentPlayer { get; private set; }
/// <summary> /// <summary>
/// Whether the current player instance has been consumed via <see cref="consumePlayer"/>. /// Whether the current player instance has been consumed via <see cref="consumePlayer"/>.
/// </summary> /// </summary>
private bool playerConsumed; private bool playerConsumed;
private LogoTrackingContainer content; private LogoTrackingContainer content = null!;
private bool hideOverlays; private bool hideOverlays;
private InputManager inputManager; private InputManager inputManager = null!;
private IdleTracker idleTracker; private IdleTracker idleTracker = null!;
private ScheduledDelegate scheduledPushPlayer; private ScheduledDelegate? scheduledPushPlayer;
[CanBeNull] private EpilepsyWarning? epilepsyWarning;
private EpilepsyWarning epilepsyWarning;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private NotificationOverlay notificationOverlay { get; set; } private NotificationOverlay? notificationOverlay { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private VolumeOverlay volumeOverlay { get; set; } private VolumeOverlay? volumeOverlay { get; set; }
[Resolved] [Resolved]
private AudioManager audioManager { get; set; } private AudioManager audioManager { get; set; } = null!;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private BatteryInfo batteryInfo { get; set; } private BatteryInfo? batteryInfo { get; set; }
public PlayerLoader(Func<Player> createPlayer) public PlayerLoader(Func<Player> createPlayer)
{ {
@ -241,6 +240,8 @@ namespace osu.Game.Screens.Play
{ {
base.OnResuming(last); base.OnResuming(last);
Debug.Assert(CurrentPlayer != null);
var lastScore = CurrentPlayer.Score; var lastScore = CurrentPlayer.Score;
AudioSettings.ReferenceScore.Value = lastScore?.ScoreInfo; AudioSettings.ReferenceScore.Value = lastScore?.ScoreInfo;
@ -348,6 +349,7 @@ namespace osu.Game.Screens.Play
private Player consumePlayer() private Player consumePlayer()
{ {
Debug.Assert(!playerConsumed); Debug.Assert(!playerConsumed);
Debug.Assert(CurrentPlayer != null);
playerConsumed = true; playerConsumed = true;
return CurrentPlayer; return CurrentPlayer;
@ -484,7 +486,7 @@ namespace osu.Game.Screens.Play
#region Mute warning #region Mute warning
private Bindable<bool> muteWarningShownOnce; private Bindable<bool> muteWarningShownOnce = null!;
private int restartCount; private int restartCount;
@ -539,7 +541,7 @@ namespace osu.Game.Screens.Play
#region Low battery warning #region Low battery warning
private Bindable<bool> batteryWarningShownOnce; private Bindable<bool> batteryWarningShownOnce = null!;
private void showBatteryWarningIfNeeded() private void showBatteryWarningIfNeeded()
{ {