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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-04-23 11:17:00 +08:00
|
|
|
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 partial class JoystickSettings : SettingsSubsection
|
|
|
|
{
|
2022-04-23 12:52:59 +08:00
|
|
|
protected override LocalisableString Header => JoystickSettingsStrings.JoystickGamepad;
|
2022-04-24 15:31:20 +08:00
|
|
|
|
|
|
|
private readonly JoystickHandler joystickHandler;
|
|
|
|
|
2022-04-23 12:52:59 +08:00
|
|
|
private readonly Bindable<bool> enabled = new BindableBool(true);
|
2022-04-23 13:14:41 +08:00
|
|
|
|
2022-04-24 15:31:20 +08:00
|
|
|
private SettingsSlider<float> deadzoneSlider;
|
|
|
|
|
2022-04-26 16:30:28 +08:00
|
|
|
private Bindable<float> handlerDeadzone;
|
|
|
|
|
|
|
|
private Bindable<float> localDeadzone;
|
|
|
|
|
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()
|
|
|
|
{
|
2022-04-26 16:30:28 +08:00
|
|
|
// use local bindable to avoid changing enabled state of game host's bindable.
|
|
|
|
handlerDeadzone = joystickHandler.DeadzoneThreshold.GetBoundCopy();
|
|
|
|
localDeadzone = handlerDeadzone.GetUnboundCopy();
|
|
|
|
|
2022-04-23 12:52:59 +08:00
|
|
|
Children = new Drawable[]
|
2022-04-23 11:17:00 +08:00
|
|
|
{
|
2022-04-23 12:52:59 +08:00
|
|
|
new SettingsCheckbox
|
2022-04-23 11:17:00 +08:00
|
|
|
{
|
2022-04-23 12:52:59 +08:00
|
|
|
LabelText = CommonStrings.Enabled,
|
|
|
|
Current = enabled
|
|
|
|
},
|
2022-04-24 15:31:20 +08:00
|
|
|
deadzoneSlider = new SettingsSlider<float>
|
2022-04-23 12:52:59 +08:00
|
|
|
{
|
|
|
|
LabelText = JoystickSettingsStrings.DeadzoneThreshold,
|
2022-04-24 15:31:20 +08:00
|
|
|
KeyboardStep = 0.01f,
|
|
|
|
DisplayAsPercentage = true,
|
2022-04-26 16:30:28 +08:00
|
|
|
Current = localDeadzone,
|
2022-04-23 12:52:59 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-04-23 11:17:00 +08:00
|
|
|
|
2022-04-23 12:52:59 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-04-23 11:17:00 +08:00
|
|
|
|
2022-04-24 15:31:20 +08:00
|
|
|
enabled.BindTo(joystickHandler.Enabled);
|
|
|
|
enabled.BindValueChanged(e => deadzoneSlider.Current.Disabled = !e.NewValue, true);
|
2022-04-26 16:30:28 +08:00
|
|
|
|
|
|
|
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);
|
2022-04-23 12:52:59 +08:00
|
|
|
}
|
2022-04-23 11:17:00 +08:00
|
|
|
}
|
2022-04-24 15:31:20 +08:00
|
|
|
}
|