Display deadzone as percentage and simplify surrounding code

This commit is contained in:
Dean Herbert
2022-04-24 16:31:20 +09:00
parent 5addcbf460
commit 2200067c52

View File

@ -6,18 +6,20 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input.Handlers.Joystick;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
namespace osu.Game.Overlays.Settings.Sections.Input
{
public class JoystickSettings : SettingsSubsection
{
private readonly JoystickHandler joystickHandler;
protected override LocalisableString Header => JoystickSettingsStrings.JoystickGamepad;
private readonly BindableNumber<float> deadzoneThreshold = new BindableNumber<float>();
private readonly JoystickHandler joystickHandler;
private readonly Bindable<bool> enabled = new BindableBool(true);
private SettingsSlider<float> deadzoneSlider;
public JoystickSettings(JoystickHandler joystickHandler)
{
this.joystickHandler = joystickHandler;
@ -33,10 +35,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
LabelText = CommonStrings.Enabled,
Current = enabled
},
new DeadzoneSetting
deadzoneSlider = new SettingsSlider<float>
{
LabelText = JoystickSettingsStrings.DeadzoneThreshold,
Current = deadzoneThreshold
KeyboardStep = 0.01f,
DisplayAsPercentage = true,
Current = joystickHandler.DeadzoneThreshold,
},
};
}
@ -44,23 +48,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
protected override void LoadComplete()
{
base.LoadComplete();
enabled.BindTo(joystickHandler.Enabled);
deadzoneThreshold.BindTo(joystickHandler.DeadzoneThreshold);
enabled.BindValueChanged(e => deadzoneThreshold.Disabled = !e.NewValue, true);
}
private class DeadzoneSetting : SettingsSlider<float, DeadzoneSlider>
{
public DeadzoneSetting()
{
KeyboardStep = 0.01f;
TransferValueOnCommit = true;
}
}
private class DeadzoneSlider : OsuSliderBar<float>
{
public override LocalisableString TooltipText => Current.Disabled ? "" : base.TooltipText;
enabled.BindValueChanged(e => deadzoneSlider.Current.Disabled = !e.NewValue, true);
}
}
}
}