-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17942 from maromalo/master
Add joystick/gamepad deadzone setting
- Loading branch information
Showing
6 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
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"); | ||
|
||
private static string getKey(string key) => $@"{prefix}:{key}"; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
osu.Game/Overlays/Settings/Sections/Input/JoystickSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
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.Localisation; | ||
|
||
namespace osu.Game.Overlays.Settings.Sections.Input | ||
{ | ||
public class JoystickSettings : SettingsSubsection | ||
{ | ||
protected override LocalisableString Header => JoystickSettingsStrings.JoystickGamepad; | ||
|
||
private readonly JoystickHandler joystickHandler; | ||
|
||
private readonly Bindable<bool> enabled = new BindableBool(true); | ||
|
||
private SettingsSlider<float> deadzoneSlider; | ||
|
||
public JoystickSettings(JoystickHandler joystickHandler) | ||
{ | ||
this.joystickHandler = joystickHandler; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
Children = new Drawable[] | ||
{ | ||
new SettingsCheckbox | ||
{ | ||
LabelText = CommonStrings.Enabled, | ||
Current = enabled | ||
}, | ||
deadzoneSlider = new SettingsSlider<float> | ||
{ | ||
LabelText = JoystickSettingsStrings.DeadzoneThreshold, | ||
KeyboardStep = 0.01f, | ||
DisplayAsPercentage = true, | ||
Current = joystickHandler.DeadzoneThreshold, | ||
}, | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
enabled.BindTo(joystickHandler.Enabled); | ||
enabled.BindValueChanged(e => deadzoneSlider.Current.Disabled = !e.NewValue, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters