mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 17:02:58 +08:00
Merge pull request #9313 from peppy/add-screen-suspend-blocking
Block screen suspend while gameplay is active
This commit is contained in:
commit
98cd1f2a22
@ -125,6 +125,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
private GameplayBeatmap gameplayBeatmap;
|
private GameplayBeatmap gameplayBeatmap;
|
||||||
|
|
||||||
|
private ScreenSuspensionHandler screenSuspension;
|
||||||
|
|
||||||
private DependencyContainer dependencies;
|
private DependencyContainer dependencies;
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
@ -179,6 +181,7 @@ namespace osu.Game.Screens.Play
|
|||||||
InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
|
InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
|
||||||
|
|
||||||
AddInternal(gameplayBeatmap = new GameplayBeatmap(playableBeatmap));
|
AddInternal(gameplayBeatmap = new GameplayBeatmap(playableBeatmap));
|
||||||
|
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));
|
||||||
|
|
||||||
dependencies.CacheAs(gameplayBeatmap);
|
dependencies.CacheAs(gameplayBeatmap);
|
||||||
|
|
||||||
@ -628,12 +631,16 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public override void OnSuspending(IScreen next)
|
public override void OnSuspending(IScreen next)
|
||||||
{
|
{
|
||||||
|
screenSuspension?.Expire();
|
||||||
|
|
||||||
fadeOut();
|
fadeOut();
|
||||||
base.OnSuspending(next);
|
base.OnSuspending(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnExiting(IScreen next)
|
public override bool OnExiting(IScreen next)
|
||||||
{
|
{
|
||||||
|
screenSuspension?.Expire();
|
||||||
|
|
||||||
if (completionProgressDelegate != null && !completionProgressDelegate.Cancelled && !completionProgressDelegate.Completed)
|
if (completionProgressDelegate != null && !completionProgressDelegate.Cancelled && !completionProgressDelegate.Completed)
|
||||||
{
|
{
|
||||||
// proceed to result screen if beatmap already finished playing
|
// proceed to result screen if beatmap already finished playing
|
||||||
|
52
osu.Game/Screens/Play/ScreenSuspensionHandler.cs
Normal file
52
osu.Game/Screens/Play/ScreenSuspensionHandler.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Play
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ensures screen is not suspended / dimmed while gameplay is active.
|
||||||
|
/// </summary>
|
||||||
|
public class ScreenSuspensionHandler : Component
|
||||||
|
{
|
||||||
|
private readonly GameplayClockContainer gameplayClockContainer;
|
||||||
|
private Bindable<bool> isPaused;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
|
public ScreenSuspensionHandler([NotNull] GameplayClockContainer gameplayClockContainer)
|
||||||
|
{
|
||||||
|
this.gameplayClockContainer = gameplayClockContainer ?? throw new ArgumentNullException(nameof(gameplayClockContainer));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
isPaused?.UnbindAll();
|
||||||
|
|
||||||
|
if (host != null)
|
||||||
|
host.AllowScreenSuspension.Value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user