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