1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 14:07:27 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Input/JoystickSettings.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.2 KiB
C#
Raw Normal View History

2022-04-23 12:52:59 +08: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.
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;
2022-04-23 12:52:59 +08:00
protected override LocalisableString Header => JoystickSettingsStrings.JoystickGamepad;
private readonly BindableNumber<float> deadzoneThreshold = new BindableNumber<float>();
private readonly Bindable<bool> enabled = new BindableBool(true);
2022-04-23 13:14:41 +08:00
2022-04-23 12:52:59 +08:00
public JoystickSettings(JoystickHandler joystickHandler)
{
this.joystickHandler = joystickHandler;
}
2022-04-23 13:14:41 +08:00
2022-04-23 12:52:59 +08:00
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
2022-04-23 12:52:59 +08:00
new SettingsCheckbox
{
2022-04-23 12:52:59 +08:00
LabelText = CommonStrings.Enabled,
Current = enabled
},
new DeadzoneSetting
{
LabelText = JoystickSettingsStrings.DeadzoneThreshold,
Current = deadzoneThreshold
},
};
}
2022-04-23 12:52:59 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
enabled.BindTo(joystickHandler.Enabled);
deadzoneThreshold.BindTo(joystickHandler.DeadzoneThreshold);
enabled.BindValueChanged(e => deadzoneThreshold.Disabled = !e.NewValue, true);
}
2022-04-23 12:52:59 +08:00
private class DeadzoneSetting : SettingsSlider<float, DeadzoneSlider>
{
public DeadzoneSetting()
{
2022-04-23 12:52:59 +08:00
KeyboardStep = 0.005f;
TransferValueOnCommit = true;
}
2022-04-23 12:52:59 +08:00
}
2022-04-23 13:14:41 +08:00
2022-04-23 12:52:59 +08:00
private class DeadzoneSlider : OsuSliderBar<float>
{
public override LocalisableString TooltipText => Current.Disabled ? "" : base.TooltipText;
}
}
}