mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 16:43:52 +09:00
Use current OverlayActivationMode to determine confine logic
This commit is contained in:
@ -7,44 +7,37 @@ using osu.Framework.Configuration;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
namespace osu.Game.Input
|
namespace osu.Game.Input
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>
|
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>,
|
||||||
/// while providing a property for <see cref="Player"/> to indicate whether gameplay is currently active.
|
/// while optionally binding an <see cref="OverlayActivation"/> mode, usually that of the current <see cref="Player"/>.
|
||||||
|
/// 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.DuringGameplay"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConfineMouseTracker : Component
|
public class ConfineMouseTracker : Component
|
||||||
{
|
{
|
||||||
private Bindable<ConfineMouseMode> frameworkConfineMode;
|
private Bindable<ConfineMouseMode> frameworkConfineMode;
|
||||||
private Bindable<OsuConfineMouseMode> osuConfineMode;
|
private Bindable<OsuConfineMouseMode> osuConfineMode;
|
||||||
|
|
||||||
private bool gameplayActive;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether osu! is currently considered "in gameplay" for the
|
/// The bindable used to indicate whether gameplay is active.
|
||||||
/// purposes of <see cref="OsuConfineMouseMode.DuringGameplay"/>.
|
/// 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>
|
/// </summary>
|
||||||
public bool GameplayActive
|
public IBindable<OverlayActivation> OverlayActivationMode { get; } = new Bindable<OverlayActivation>(OverlayActivation.All);
|
||||||
{
|
|
||||||
get => gameplayActive;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (gameplayActive == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gameplayActive = value;
|
|
||||||
updateConfineMode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
|
private void load(FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
|
||||||
{
|
{
|
||||||
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
|
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
|
||||||
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
|
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
|
||||||
osuConfineMode.BindValueChanged(_ => updateConfineMode(), true);
|
osuConfineMode.ValueChanged += _ => updateConfineMode();
|
||||||
|
|
||||||
|
OverlayActivationMode.BindValueChanged(_ => updateConfineMode(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateConfineMode()
|
private void updateConfineMode()
|
||||||
@ -60,7 +53,7 @@ namespace osu.Game.Input
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OsuConfineMouseMode.DuringGameplay:
|
case OsuConfineMouseMode.DuringGameplay:
|
||||||
frameworkConfineMode.Value = GameplayActive ? ConfineMouseMode.Always : ConfineMouseMode.Never;
|
frameworkConfineMode.Value = OverlayActivationMode.Value == OverlayActivation.Disabled ? ConfineMouseMode.Always : ConfineMouseMode.Never;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OsuConfineMouseMode.Always:
|
case OsuConfineMouseMode.Always:
|
||||||
|
@ -229,6 +229,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
|
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
|
||||||
|
|
||||||
|
confineMouseTracker.OverlayActivationMode.BindTo(OverlayActivationMode);
|
||||||
|
|
||||||
// bind clock into components that require it
|
// bind clock into components that require it
|
||||||
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
|
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
|
||||||
|
|
||||||
@ -365,9 +367,6 @@ namespace osu.Game.Screens.Play
|
|||||||
OverlayActivationMode.Value = OverlayActivation.UserTriggered;
|
OverlayActivationMode.Value = OverlayActivation.UserTriggered;
|
||||||
else
|
else
|
||||||
OverlayActivationMode.Value = OverlayActivation.Disabled;
|
OverlayActivationMode.Value = OverlayActivation.Disabled;
|
||||||
|
|
||||||
if (confineMouseTracker != null)
|
|
||||||
confineMouseTracker.GameplayActive = !GameplayClockContainer.IsPaused.Value && !DrawableRuleset.HasReplayLoaded.Value && !HasFailed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePauseOnFocusLostState() =>
|
private void updatePauseOnFocusLostState() =>
|
||||||
|
Reference in New Issue
Block a user