From 280cd048f662090d5bdde09191daa9ff978190dc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 26 Apr 2022 17:30:28 +0900 Subject: [PATCH] Fix joystick settings changing enabled state of config level bindables Just copied what we had in place for the mouse sensitivity setting. For tablet settings I believe I avoided this by just hiding the settings when not enabled. Might be a better way forward, but this is simplest for now. Run `TestSceneSettingsPanel` twice to get a crash without this change. --- .../Sections/Input/JoystickSettings.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/Sections/Input/JoystickSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/JoystickSettings.cs index c136ca6a19..60849cd6d4 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/JoystickSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/JoystickSettings.cs @@ -20,6 +20,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input private SettingsSlider deadzoneSlider; + private Bindable handlerDeadzone; + + private Bindable localDeadzone; + public JoystickSettings(JoystickHandler joystickHandler) { this.joystickHandler = joystickHandler; @@ -28,6 +32,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input [BackgroundDependencyLoader] private void load() { + // use local bindable to avoid changing enabled state of game host's bindable. + handlerDeadzone = joystickHandler.DeadzoneThreshold.GetBoundCopy(); + localDeadzone = handlerDeadzone.GetUnboundCopy(); + Children = new Drawable[] { new SettingsCheckbox @@ -40,7 +48,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input LabelText = JoystickSettingsStrings.DeadzoneThreshold, KeyboardStep = 0.01f, DisplayAsPercentage = true, - Current = joystickHandler.DeadzoneThreshold, + Current = localDeadzone, }, }; } @@ -51,6 +59,17 @@ namespace osu.Game.Overlays.Settings.Sections.Input enabled.BindTo(joystickHandler.Enabled); enabled.BindValueChanged(e => deadzoneSlider.Current.Disabled = !e.NewValue, true); + + handlerDeadzone.BindValueChanged(val => + { + bool disabled = localDeadzone.Disabled; + + localDeadzone.Disabled = false; + localDeadzone.Value = val.NewValue; + localDeadzone.Disabled = disabled; + }, true); + + localDeadzone.BindValueChanged(val => handlerDeadzone.Value = val.NewValue); } } }