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