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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Input;
|
|
|
|
using osu.Game.Configuration;
|
2020-10-05 00:41:46 +00:00
|
|
|
using osu.Game.Overlays;
|
2020-08-16 02:08:35 +00:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Input
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-10-05 00:41:46 +00:00
|
|
|
/// 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"/>.
|
|
|
|
/// It is assumed that while overlay activation is <see cref="OverlayActivation.Disabled"/>, we should also confine the
|
2020-10-06 09:22:18 +00:00
|
|
|
/// mouse cursor if it has been requested with <see cref="OsuConfineMouseMode.WhenOverlaysDisabled"/>.
|
2020-08-16 02:08:35 +00:00
|
|
|
/// </summary>
|
|
|
|
public class ConfineMouseTracker : Component
|
|
|
|
{
|
|
|
|
private Bindable<ConfineMouseMode> frameworkConfineMode;
|
|
|
|
private Bindable<OsuConfineMouseMode> osuConfineMode;
|
|
|
|
|
|
|
|
/// <summary>
|
2020-10-05 00:41:46 +00:00
|
|
|
/// 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".
|
2020-08-16 02:08:35 +00:00
|
|
|
/// </summary>
|
2020-10-05 00:41:46 +00:00
|
|
|
public IBindable<OverlayActivation> OverlayActivationMode { get; } = new Bindable<OverlayActivation>(OverlayActivation.All);
|
2020-08-16 02:08:35 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(FrameworkConfigManager frameworkConfigManager, OsuConfigManager osuConfigManager)
|
|
|
|
{
|
|
|
|
frameworkConfineMode = frameworkConfigManager.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode);
|
|
|
|
osuConfineMode = osuConfigManager.GetBindable<OsuConfineMouseMode>(OsuSetting.ConfineMouseMode);
|
2020-10-05 00:41:46 +00:00
|
|
|
osuConfineMode.ValueChanged += _ => updateConfineMode();
|
|
|
|
|
|
|
|
OverlayActivationMode.BindValueChanged(_ => updateConfineMode(), true);
|
2020-08-16 02:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateConfineMode()
|
|
|
|
{
|
|
|
|
switch (osuConfineMode.Value)
|
|
|
|
{
|
|
|
|
case OsuConfineMouseMode.Never:
|
|
|
|
frameworkConfineMode.Value = ConfineMouseMode.Never;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OsuConfineMouseMode.Fullscreen:
|
|
|
|
frameworkConfineMode.Value = ConfineMouseMode.Fullscreen;
|
|
|
|
break;
|
|
|
|
|
2020-10-06 09:22:18 +00:00
|
|
|
case OsuConfineMouseMode.WhenOverlaysDisabled:
|
2020-10-05 00:41:46 +00:00
|
|
|
frameworkConfineMode.Value = OverlayActivationMode.Value == OverlayActivation.Disabled ? ConfineMouseMode.Always : ConfineMouseMode.Never;
|
2020-08-16 02:08:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OsuConfineMouseMode.Always:
|
|
|
|
frameworkConfineMode.Value = ConfineMouseMode.Always;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|