Maintain the current gameplay state in OsuGame

This commit is contained in:
Shane Woolcock
2020-10-06 22:39:35 +10:30
parent 782fc1d60f
commit 478f2dec96
5 changed files with 33 additions and 25 deletions

View File

@ -7,30 +7,29 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Game.Configuration;
using osu.Game.Overlays;
namespace osu.Game.Input
{
/// <summary>
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>,
/// while binding <see cref="OsuGame.OverlayActivationMode"/>.
/// It is assumed that while overlay activation is <see cref="OverlayActivation.Disabled"/>, we should also confine the
/// mouse cursor if it has been requested with <see cref="OsuConfineMouseMode.WhenOverlaysDisabled"/>.
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>.
/// If <see cref="OsuGame.IsGameplay"/> is true, we should also confine the mouse cursor if it has been
/// requested with <see cref="OsuConfineMouseMode.DuringGameplay"/>.
/// </summary>
public class ConfineMouseTracker : Component
{
private Bindable<ConfineMouseMode> frameworkConfineMode;
private Bindable<OsuConfineMouseMode> osuConfineMode;
private IBindable<OverlayActivation> overlayActivationMode;
private IBindable<bool> isGameplay;
[BackgroundDependencyLoader]
private void load(OsuGame game, FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
{
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
isGameplay = game.IsGameplay.GetBoundCopy();
osuConfineMode.ValueChanged += _ => updateConfineMode();
overlayActivationMode = game.OverlayActivationMode.GetBoundCopy();
overlayActivationMode.BindValueChanged(_ => updateConfineMode(), true);
isGameplay.BindValueChanged(_ => updateConfineMode(), true);
}
private void updateConfineMode()
@ -45,8 +44,8 @@ namespace osu.Game.Input
frameworkConfineMode.Value = ConfineMouseMode.Fullscreen;
break;
case OsuConfineMouseMode.WhenOverlaysDisabled:
frameworkConfineMode.Value = overlayActivationMode?.Value == OverlayActivation.Disabled ? ConfineMouseMode.Always : ConfineMouseMode.Never;
case OsuConfineMouseMode.DuringGameplay:
frameworkConfineMode.Value = isGameplay.Value ? ConfineMouseMode.Always : ConfineMouseMode.Never;
break;
case OsuConfineMouseMode.Always: