2020-08-16 10:08:35 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-08-16 10:08:35 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Input;
|
|
|
|
using osu.Game.Configuration;
|
2021-08-17 15:13:45 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2020-08-16 10:08:35 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Input
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-10-06 20:09:35 +08:00
|
|
|
/// Connects <see cref="OsuSetting.ConfineMouseMode"/> with <see cref="FrameworkSetting.ConfineMouseMode"/>.
|
2020-10-07 13:44:49 +08:00
|
|
|
/// If <see cref="OsuGame.LocalUserPlaying"/> is true, we should also confine the mouse cursor if it has been
|
2020-10-06 20:09:35 +08:00
|
|
|
/// requested with <see cref="OsuConfineMouseMode.DuringGameplay"/>.
|
2020-08-16 10:08:35 +08:00
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class ConfineMouseTracker : Component
|
2020-08-16 10:08:35 +08:00
|
|
|
{
|
|
|
|
private Bindable<ConfineMouseMode> frameworkConfineMode;
|
2020-12-04 19:49:18 +08:00
|
|
|
private Bindable<WindowMode> frameworkWindowMode;
|
|
|
|
|
2020-08-16 10:08:35 +08:00
|
|
|
private Bindable<OsuConfineMouseMode> osuConfineMode;
|
2020-10-07 13:44:49 +08:00
|
|
|
private IBindable<bool> localUserPlaying;
|
2020-08-16 10:08:35 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-08-17 15:13:45 +08:00
|
|
|
private void load(ILocalUserPlayInfo localUserInfo, FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
|
2020-08-16 10:08:35 +08:00
|
|
|
{
|
|
|
|
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
|
2020-12-04 19:49:18 +08:00
|
|
|
frameworkWindowMode = frameworkConfigManager.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
|
|
|
|
frameworkWindowMode.BindValueChanged(_ => updateConfineMode());
|
|
|
|
|
2020-08-16 10:08:35 +08:00
|
|
|
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
|
2021-08-17 15:13:45 +08:00
|
|
|
localUserPlaying = localUserInfo.IsPlaying.GetBoundCopy();
|
2020-10-06 20:09:35 +08:00
|
|
|
|
2020-10-05 08:41:46 +08:00
|
|
|
osuConfineMode.ValueChanged += _ => updateConfineMode();
|
2020-10-07 13:44:49 +08:00
|
|
|
localUserPlaying.BindValueChanged(_ => updateConfineMode(), true);
|
2020-08-16 10:08:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateConfineMode()
|
|
|
|
{
|
2020-10-07 13:32:35 +08:00
|
|
|
// confine mode is unavailable on some platforms
|
|
|
|
if (frameworkConfineMode.Disabled)
|
|
|
|
return;
|
|
|
|
|
2020-12-04 19:49:18 +08:00
|
|
|
if (frameworkWindowMode.Value == WindowMode.Fullscreen)
|
|
|
|
{
|
|
|
|
frameworkConfineMode.Value = ConfineMouseMode.Fullscreen;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-16 10:08:35 +08:00
|
|
|
switch (osuConfineMode.Value)
|
|
|
|
{
|
|
|
|
case OsuConfineMouseMode.Never:
|
|
|
|
frameworkConfineMode.Value = ConfineMouseMode.Never;
|
|
|
|
break;
|
|
|
|
|
2020-10-06 20:09:35 +08:00
|
|
|
case OsuConfineMouseMode.DuringGameplay:
|
2020-10-07 13:44:49 +08:00
|
|
|
frameworkConfineMode.Value = localUserPlaying.Value ? ConfineMouseMode.Always : ConfineMouseMode.Never;
|
2020-08-16 10:08:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OsuConfineMouseMode.Always:
|
|
|
|
frameworkConfineMode.Value = ConfineMouseMode.Always;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|