2019-01-24 16:43:03 +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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2021-07-26 15:59:59 +08:00
using osu.Framework ;
2016-11-11 06:40:42 +08:00
using osu.Framework.Allocation ;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables ;
2017-05-02 16:45:42 +08:00
using osu.Framework.Configuration ;
2016-11-09 11:38:40 +08:00
using osu.Framework.Graphics ;
2021-03-12 17:38:16 +08:00
using osu.Framework.Input.Handlers.Mouse ;
2021-06-26 01:10:04 +08:00
using osu.Framework.Localisation ;
2016-11-09 11:38:40 +08:00
using osu.Game.Configuration ;
2017-01-31 17:37:11 +08:00
using osu.Game.Graphics.UserInterface ;
2020-08-16 09:34:28 +08:00
using osu.Game.Input ;
2021-07-15 11:50:34 +08:00
using osu.Game.Localisation ;
2018-04-13 17:19:50 +08:00
2017-05-15 09:55:29 +08:00
namespace osu.Game.Overlays.Settings.Sections.Input
2016-11-11 06:40:42 +08:00
{
2017-05-15 09:55:29 +08:00
public partial class MouseSettings : SettingsSubsection
2016-11-11 06:40:42 +08:00
{
2021-03-12 17:38:16 +08:00
private readonly MouseHandler mouseHandler ;
2018-04-13 17:19:50 +08:00
2021-07-15 11:50:34 +08:00
protected override LocalisableString Header = > MouseSettingsStrings . Mouse ;
2021-03-03 15:47:42 +08:00
2021-03-12 17:38:16 +08:00
private Bindable < double > handlerSensitivity ;
2021-03-03 15:47:42 +08:00
2021-03-03 19:36:41 +08:00
private Bindable < double > localSensitivity ;
2021-03-03 15:47:42 +08:00
2020-12-06 05:13:51 +08:00
private Bindable < WindowMode > windowMode ;
2023-12-27 23:54:01 +08:00
private Bindable < bool > minimiseOnFocusLoss ;
2020-12-06 05:13:51 +08:00
private SettingsEnumDropdown < OsuConfineMouseMode > confineMouseModeSetting ;
2021-03-12 17:38:16 +08:00
private Bindable < bool > relativeMode ;
2021-07-26 15:59:59 +08:00
private SettingsCheckbox highPrecisionMouse ;
2021-03-12 17:38:16 +08:00
public MouseSettings ( MouseHandler mouseHandler )
{
this . mouseHandler = mouseHandler ;
}
2020-12-06 05:13:51 +08:00
2016-11-12 18:44:16 +08:00
[BackgroundDependencyLoader]
2017-05-02 16:45:42 +08:00
private void load ( OsuConfigManager osuConfig , FrameworkConfigManager config )
2016-11-09 11:38:40 +08:00
{
2020-05-15 16:31:06 +08:00
// use local bindable to avoid changing enabled state of game host's bindable.
2021-03-12 17:38:16 +08:00
handlerSensitivity = mouseHandler . Sensitivity . GetBoundCopy ( ) ;
localSensitivity = handlerSensitivity . GetUnboundCopy ( ) ;
2021-03-03 15:47:42 +08:00
2021-03-12 17:38:16 +08:00
relativeMode = mouseHandler . UseRelativeMode . GetBoundCopy ( ) ;
2021-03-03 15:47:42 +08:00
windowMode = config . GetBindable < WindowMode > ( FrameworkSetting . WindowMode ) ;
2023-12-27 23:54:01 +08:00
minimiseOnFocusLoss = config . GetBindable < bool > ( FrameworkSetting . MinimiseOnFocusLossInFullscreen ) ;
2020-05-15 16:31:06 +08:00
2016-11-11 06:40:42 +08:00
Children = new Drawable [ ]
2016-11-09 11:38:40 +08:00
{
2021-07-26 15:59:59 +08:00
highPrecisionMouse = new SettingsCheckbox
2017-06-05 11:13:15 +08:00
{
2021-07-15 12:07:35 +08:00
LabelText = MouseSettingsStrings . HighPrecisionMouse ,
TooltipText = MouseSettingsStrings . HighPrecisionMouseTooltip ,
2021-07-15 11:37:52 +08:00
Current = relativeMode ,
2021-07-15 12:07:35 +08:00
Keywords = new [ ] { @"raw" , @"input" , @"relative" , @"cursor" }
2017-06-05 11:13:15 +08:00
} ,
2020-05-16 10:03:27 +08:00
new SensitivitySetting
2017-06-05 11:13:15 +08:00
{
2021-07-15 12:07:35 +08:00
LabelText = MouseSettingsStrings . CursorSensitivity ,
2021-03-03 15:47:42 +08:00
Current = localSensitivity
2017-06-05 11:13:15 +08:00
} ,
2020-12-06 05:13:51 +08:00
confineMouseModeSetting = new SettingsEnumDropdown < OsuConfineMouseMode >
2016-12-02 06:28:20 +08:00
{
2021-07-15 12:07:35 +08:00
LabelText = MouseSettingsStrings . ConfineMouseMode ,
2020-10-07 08:37:00 +08:00
Current = osuConfig . GetBindable < OsuConfineMouseMode > ( OsuSetting . ConfineMouseMode )
2016-12-02 06:28:20 +08:00
} ,
2017-05-15 09:55:29 +08:00
new SettingsCheckbox
2016-11-11 06:40:42 +08:00
{
2021-12-03 15:56:14 +08:00
LabelText = MouseSettingsStrings . DisableMouseWheelVolumeAdjust ,
TooltipText = MouseSettingsStrings . DisableMouseWheelVolumeAdjustTooltip ,
2020-10-06 16:18:41 +08:00
Current = osuConfig . GetBindable < bool > ( OsuSetting . MouseDisableWheel )
2016-11-11 06:40:42 +08:00
} ,
2017-05-15 09:55:29 +08:00
new SettingsCheckbox
2016-11-11 06:40:42 +08:00
{
2023-11-05 19:43:14 +08:00
LabelText = MouseSettingsStrings . DisableClicksDuringGameplay ,
2020-10-06 16:18:41 +08:00
Current = osuConfig . GetBindable < bool > ( OsuSetting . MouseDisableButtons )
2016-11-11 06:40:42 +08:00
} ,
} ;
2021-03-03 15:47:42 +08:00
}
protected override void LoadComplete ( )
{
base . LoadComplete ( ) ;
2021-03-12 17:38:16 +08:00
relativeMode . BindValueChanged ( relative = > localSensitivity . Disabled = ! relative . NewValue , true ) ;
handlerSensitivity . BindValueChanged ( val = >
2021-03-04 20:00:46 +08:00
{
2021-10-27 12:04:41 +08:00
bool disabled = localSensitivity . Disabled ;
2021-03-04 20:00:46 +08:00
localSensitivity . Disabled = false ;
localSensitivity . Value = val . NewValue ;
localSensitivity . Disabled = disabled ;
} , true ) ;
2021-03-12 17:38:16 +08:00
localSensitivity . BindValueChanged ( val = > handlerSensitivity . Value = val . NewValue ) ;
2018-04-13 17:19:50 +08:00
2023-12-27 23:54:01 +08:00
windowMode . BindValueChanged ( _ = > updateConfineMouseModeSettingVisibility ( ) ) ;
minimiseOnFocusLoss . BindValueChanged ( _ = > updateConfineMouseModeSettingVisibility ( ) , true ) ;
2021-07-26 15:59:59 +08:00
highPrecisionMouse . Current . BindValueChanged ( highPrecision = >
{
2021-07-26 16:24:43 +08:00
if ( RuntimeInfo . OS ! = RuntimeInfo . Platform . Windows )
2021-07-26 15:59:59 +08:00
{
if ( highPrecision . NewValue )
2022-06-01 15:51:34 +08:00
highPrecisionMouse . SetNoticeText ( MouseSettingsStrings . HighPrecisionPlatformWarning , true ) ;
2021-07-26 15:59:59 +08:00
else
2022-06-01 15:51:34 +08:00
highPrecisionMouse . ClearNoticeText ( ) ;
2021-07-26 15:59:59 +08:00
}
} , true ) ;
2016-11-11 06:40:42 +08:00
}
2018-04-13 17:19:50 +08:00
2023-12-27 23:54:01 +08:00
/// <summary>
/// Updates disabled state and tooltip of <see cref="confineMouseModeSetting"/> to match when <see cref="ConfineMouseTracker"/> is overriding the confine mode.
/// </summary>
private void updateConfineMouseModeSettingVisibility ( )
{
bool confineModeOverriden = windowMode . Value = = WindowMode . Fullscreen & & minimiseOnFocusLoss . Value ;
if ( confineModeOverriden )
{
confineMouseModeSetting . Current . Disabled = true ;
confineMouseModeSetting . TooltipText = MouseSettingsStrings . NotApplicableFullscreen ;
}
else
{
confineMouseModeSetting . Current . Disabled = false ;
confineMouseModeSetting . TooltipText = string . Empty ;
}
}
2022-01-15 21:38:38 +08:00
public partial class SensitivitySetting : SettingsSlider < double , SensitivitySlider >
2017-06-05 12:24:54 +08:00
{
2017-12-07 19:53:28 +08:00
public SensitivitySetting ( )
{
KeyboardStep = 0.01f ;
2019-01-17 18:18:40 +08:00
TransferValueOnCommit = true ;
2017-12-07 19:53:28 +08:00
}
2017-06-05 12:24:54 +08:00
}
2018-04-13 17:19:50 +08:00
2023-02-03 00:24:45 +08:00
public partial class SensitivitySlider : RoundedSliderBar < double >
2017-04-21 19:59:04 +08:00
{
2021-07-15 12:07:35 +08:00
public override LocalisableString TooltipText = > Current . Disabled ? MouseSettingsStrings . EnableHighPrecisionForSensitivityAdjust : $"{base.TooltipText}x" ;
2017-04-21 19:59:04 +08:00
}
2016-11-11 06:40:42 +08:00
}
2017-11-30 15:03:26 +08:00
}