mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 03:33:19 +08:00
Merge pull request #19131 from Susko3/android-joystick-settings
Add joystick settings on Android
This commit is contained in:
commit
288fdbd06f
76
osu.Android/AndroidJoystickSettings.cs
Normal file
76
osu.Android/AndroidJoystickSettings.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// 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.Android.Input;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Localisation;
|
||||||
|
using osu.Game.Overlays.Settings;
|
||||||
|
|
||||||
|
namespace osu.Android
|
||||||
|
{
|
||||||
|
public class AndroidJoystickSettings : SettingsSubsection
|
||||||
|
{
|
||||||
|
protected override LocalisableString Header => JoystickSettingsStrings.JoystickGamepad;
|
||||||
|
|
||||||
|
private readonly AndroidJoystickHandler joystickHandler;
|
||||||
|
|
||||||
|
private readonly Bindable<bool> enabled = new BindableBool(true);
|
||||||
|
|
||||||
|
private SettingsSlider<float> deadzoneSlider = null!;
|
||||||
|
|
||||||
|
private Bindable<float> handlerDeadzone = null!;
|
||||||
|
|
||||||
|
private Bindable<float> localDeadzone = null!;
|
||||||
|
|
||||||
|
public AndroidJoystickSettings(AndroidJoystickHandler joystickHandler)
|
||||||
|
{
|
||||||
|
this.joystickHandler = joystickHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
// use local bindable to avoid changing enabled state of game host's bindable.
|
||||||
|
handlerDeadzone = joystickHandler.DeadzoneThreshold.GetBoundCopy();
|
||||||
|
localDeadzone = handlerDeadzone.GetUnboundCopy();
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SettingsCheckbox
|
||||||
|
{
|
||||||
|
LabelText = CommonStrings.Enabled,
|
||||||
|
Current = enabled
|
||||||
|
},
|
||||||
|
deadzoneSlider = new SettingsSlider<float>
|
||||||
|
{
|
||||||
|
LabelText = JoystickSettingsStrings.DeadzoneThreshold,
|
||||||
|
KeyboardStep = 0.01f,
|
||||||
|
DisplayAsPercentage = true,
|
||||||
|
Current = localDeadzone,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
enabled.BindTo(joystickHandler.Enabled);
|
||||||
|
enabled.BindValueChanged(e => deadzoneSlider.Current.Disabled = !e.NewValue, true);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -96,6 +96,9 @@ namespace osu.Android
|
|||||||
case AndroidMouseHandler mh:
|
case AndroidMouseHandler mh:
|
||||||
return new AndroidMouseSettings(mh);
|
return new AndroidMouseSettings(mh);
|
||||||
|
|
||||||
|
case AndroidJoystickHandler jh:
|
||||||
|
return new AndroidJoystickSettings(jh);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return base.CreateSettingsSubsectionFor(handler);
|
return base.CreateSettingsSubsectionFor(handler);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
|
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AndroidJoystickSettings.cs" />
|
||||||
<Compile Include="AndroidMouseSettings.cs" />
|
<Compile Include="AndroidMouseSettings.cs" />
|
||||||
<Compile Include="GameplayScreenRotationLocker.cs" />
|
<Compile Include="GameplayScreenRotationLocker.cs" />
|
||||||
<Compile Include="OsuGameActivity.cs" />
|
<Compile Include="OsuGameActivity.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user