1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 06:45:37 +08:00

Merge branch 'apply-screen-suspension-changes' into multiplayer-spectator-screen

This commit is contained in:
smoogipoo 2021-04-07 22:28:44 +09:00
commit 65014d9596

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -19,6 +18,8 @@ namespace osu.Game.Screens.Play
private readonly GameplayClockContainer gameplayClockContainer;
private Bindable<bool> isPaused;
private readonly Bindable<bool> disableSuspensionBindable = new Bindable<bool>();
[Resolved]
private GameHost host { get; set; }
@ -31,12 +32,14 @@ namespace osu.Game.Screens.Play
{
base.LoadComplete();
// This is the only usage game-wide of suspension changes.
// Assert to ensure we don't accidentally forget this in the future.
Debug.Assert(host.AllowScreenSuspension.Value);
isPaused = gameplayClockContainer.IsPaused.GetBoundCopy();
isPaused.BindValueChanged(paused => host.AllowScreenSuspension.Value = paused.NewValue, true);
isPaused.BindValueChanged(paused =>
{
if (paused.NewValue)
host.AllowScreenSuspension.RemoveSource(disableSuspensionBindable);
else
host.AllowScreenSuspension.AddSource(disableSuspensionBindable);
}, true);
}
protected override void Dispose(bool isDisposing)
@ -44,9 +47,7 @@ namespace osu.Game.Screens.Play
base.Dispose(isDisposing);
isPaused?.UnbindAll();
if (host != null)
host.AllowScreenSuspension.Value = true;
host?.AllowScreenSuspension.RemoveSource(disableSuspensionBindable);
}
}
}