// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Game.Configuration; using osu.Game.Screens.Play; namespace osu.Game.Input { /// /// Connects with /// while providing a property for to indicate whether gameplay is currently active. /// public class ConfineMouseTracker : Component { private Bindable frameworkConfineMode; private Bindable osuConfineMode; private bool gameplayActive; /// /// Indicates whether osu! is currently considered "in gameplay" for the /// purposes of . /// public bool GameplayActive { get => gameplayActive; set { if (gameplayActive == value) return; gameplayActive = value; updateConfineMode(); } } [BackgroundDependencyLoader] private void load(FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager) { frameworkConfineMode = frameworkConfigManager.GetBindable(FrameworkSetting.ConfineMouseMode); osuConfineMode = osuConfigManager.GetBindable(OsuSetting.ConfineMouseMode); osuConfineMode.BindValueChanged(_ => updateConfineMode(), true); } private void updateConfineMode() { switch (osuConfineMode.Value) { case OsuConfineMouseMode.Never: frameworkConfineMode.Value = ConfineMouseMode.Never; break; case OsuConfineMouseMode.Fullscreen: frameworkConfineMode.Value = ConfineMouseMode.Fullscreen; break; case OsuConfineMouseMode.DuringGameplay: frameworkConfineMode.Value = GameplayActive ? ConfineMouseMode.Always : ConfineMouseMode.Never; break; case OsuConfineMouseMode.Always: frameworkConfineMode.Value = ConfineMouseMode.Always; break; } } } }