1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:02:55 +08:00

Add joystick/gamepad deadzone setting

Also splits joystick/gamepad into a new sub-section.
This commit is contained in:
maromalo 2022-04-23 00:17:00 -03:00
parent 71e4c4f752
commit 27f3499330
3 changed files with 87 additions and 1 deletions

View File

@ -0,0 +1,21 @@
using osu.Framework.Localisation;
namespace osu.Game.Localisation
{
public static class JoystickSettingsStrings
{
private const string prefix = @"osu.Game.Resources.Localisation.JoystickSettings";
/// <summary>
/// "Joystick / Gamepad"
/// </summary>
public static LocalisableString JoystickGamepad => new TranslatableString(getKey(@"joystick_gamepad"), @"Joystick / Gamepad");
/// <summary>
/// "Deadzone Threshold"
/// </summary>
public static LocalisableString DeadzoneThreshold => new TranslatableString(getKey(@"deadzone_threshold"), @"Deadzone Threshold");
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -0,0 +1,62 @@
using osu.Framework.Allocation;
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 Bindable<bool> enabled = new BindableBool(true);
public JoystickSettings(JoystickHandler joystickHandler)
{
this.joystickHandler = joystickHandler;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new SettingsCheckbox
{
LabelText = CommonStrings.Enabled,
Current = enabled
},
new DeadzoneSetting
{
LabelText = JoystickSettingsStrings.DeadzoneThreshold,
Current = deadzoneThreshold
},
};
}
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.005f;
TransferValueOnCommit = true;
}
}
private class DeadzoneSlider : OsuSliderBar<float>
{
public override LocalisableString TooltipText => Current.Disabled ? "" : base.TooltipText;
}
}
}

View File

@ -68,7 +68,10 @@ namespace osu.Game.Overlays.Settings.Sections
break;
// whitelist the handlers which should be displayed to avoid any weird cases of users touching settings they shouldn't.
case JoystickHandler _:
case JoystickHandler jh:
section = new JoystickSettings(jh);
break;
case MidiHandler _:
section = new HandlerSection(handler);
break;