Use OsuGame.OverlayActivationMode rather than per-Player

This commit is contained in:
Shane Woolcock
2020-10-06 20:11:48 +10:30
parent 1877312a91
commit 782fc1d60f
3 changed files with 7 additions and 20 deletions

View File

@ -8,13 +8,12 @@ using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Game.Configuration;
using osu.Game.Overlays;
using osu.Game.Screens.Play;
namespace osu.Game.Input
{
/// <summary>
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>,
/// while optionally binding an <see cref="OverlayActivation"/> mode, usually that of the current <see cref="Player"/>.
/// 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"/>.
/// </summary>
@ -22,22 +21,16 @@ namespace osu.Game.Input
{
private Bindable<ConfineMouseMode> frameworkConfineMode;
private Bindable<OsuConfineMouseMode> osuConfineMode;
/// <summary>
/// The bindable used to indicate whether gameplay is active.
/// Should be bound to the corresponding bindable of the current <see cref="Player"/>.
/// Defaults to <see cref="OverlayActivation.All"/> to assume that all other screens are considered "not gameplay".
/// </summary>
public IBindable<OverlayActivation> OverlayActivationMode { get; } = new Bindable<OverlayActivation>(OverlayActivation.All);
private IBindable<OverlayActivation> overlayActivationMode;
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
private void load(OsuGame game, FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
{
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
osuConfineMode.ValueChanged += _ => updateConfineMode();
OverlayActivationMode.BindValueChanged(_ => updateConfineMode(), true);
overlayActivationMode = game.OverlayActivationMode.GetBoundCopy();
overlayActivationMode.BindValueChanged(_ => updateConfineMode(), true);
}
private void updateConfineMode()
@ -53,7 +46,7 @@ namespace osu.Game.Input
break;
case OsuConfineMouseMode.WhenOverlaysDisabled:
frameworkConfineMode.Value = OverlayActivationMode.Value == OverlayActivation.Disabled ? ConfineMouseMode.Always : ConfineMouseMode.Never;
frameworkConfineMode.Value = overlayActivationMode?.Value == OverlayActivation.Disabled ? ConfineMouseMode.Always : ConfineMouseMode.Never;
break;
case OsuConfineMouseMode.Always: