mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2026-04-28 05:55:11 -06:00
Android: Keep track of the axis direction when mapping axes (also allows inversion for external pads) (#1483)
This commit is contained in:
parent
8c53dcef31
commit
b1717b6fc2
@ -342,6 +342,7 @@ class EmulationActivity : AppCompatActivity() {
|
||||
preferences.getInt(InputBindingSetting.getInputAxisButtonKey(axis), -1)
|
||||
val guestOrientation =
|
||||
preferences.getInt(InputBindingSetting.getInputAxisOrientationKey(axis), -1)
|
||||
val inverted = preferences.getBoolean(InputBindingSetting.getInputAxisInvertedKey(axis),false);
|
||||
if (nextMapping == -1 || guestOrientation == -1) {
|
||||
// Axis is unmapped
|
||||
continue
|
||||
@ -350,6 +351,8 @@ class EmulationActivity : AppCompatActivity() {
|
||||
// Skip joystick wobble
|
||||
value = 0f
|
||||
}
|
||||
if (inverted) value = -value;
|
||||
|
||||
when (nextMapping) {
|
||||
NativeLibrary.ButtonType.STICK_LEFT -> {
|
||||
axisValuesCirclePad[guestOrientation] = value
|
||||
|
||||
@ -169,6 +169,7 @@ class InputBindingSetting(
|
||||
.remove(oldKey) // Used for button mapping
|
||||
.remove(oldKey + "_GuestOrientation") // Used for axis orientation
|
||||
.remove(oldKey + "_GuestButton") // Used for axis button
|
||||
.remove(oldKey + "_Inverted") // used for axis inversion
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
@ -202,7 +203,7 @@ class InputBindingSetting(
|
||||
/**
|
||||
* Helper function to write a gamepad axis mapping for the setting.
|
||||
*/
|
||||
private fun writeAxisMapping(axis: Int, value: Int) {
|
||||
private fun writeAxisMapping(axis: Int, value: Int, inverted: Boolean) {
|
||||
// Cleanup old mapping
|
||||
removeOldMapping()
|
||||
|
||||
@ -210,6 +211,7 @@ class InputBindingSetting(
|
||||
preferences.edit()
|
||||
.putInt(getInputAxisOrientationKey(axis), if (isHorizontalOrientation()) 0 else 1)
|
||||
.putInt(getInputAxisButtonKey(axis), value)
|
||||
.putBoolean(getInputAxisInvertedKey(axis),inverted)
|
||||
// Write next reverse mapping for future cleanup
|
||||
.putString(reverseKey, getInputAxisKey(axis))
|
||||
.apply()
|
||||
@ -237,7 +239,7 @@ class InputBindingSetting(
|
||||
*
|
||||
* @param device InputDevice from which the input event originated.
|
||||
* @param motionRange MotionRange of the movement
|
||||
* @param axisDir Either '-' or '+' (currently unused)
|
||||
* @param axisDir Either '-' or '+'
|
||||
*/
|
||||
fun onMotionInput(device: InputDevice, motionRange: MotionRange, axisDir: Char) {
|
||||
if (!isAxisMappingSupported()) {
|
||||
@ -253,8 +255,8 @@ class InputBindingSetting(
|
||||
} else {
|
||||
buttonCode
|
||||
}
|
||||
writeAxisMapping(motionRange.axis, button)
|
||||
val uiString = "${device.name}: Axis ${motionRange.axis}"
|
||||
writeAxisMapping(motionRange.axis, button, axisDir == '-')
|
||||
val uiString = "${device.name}: Axis ${motionRange.axis}" + axisDir
|
||||
value = uiString
|
||||
}
|
||||
|
||||
@ -309,6 +311,11 @@ class InputBindingSetting(
|
||||
*/
|
||||
fun getInputAxisButtonKey(axis: Int): String = "${getInputAxisKey(axis)}_GuestButton"
|
||||
|
||||
/**
|
||||
* Helper function to get the settings key for an whether a gamepad axis is inverted.
|
||||
*/
|
||||
fun getInputAxisInvertedKey(axis: Int): String = "${getInputAxisKey(axis)}_Inverted"
|
||||
|
||||
/**
|
||||
* Helper function to get the settings key for an gamepad axis orientation.
|
||||
*/
|
||||
|
||||
@ -140,8 +140,8 @@
|
||||
<string name="input_dialog_description">Press or move an input.</string>
|
||||
<string name="input_binding">Input Binding</string>
|
||||
<string name="input_binding_description">Press or move an input to bind it to %1$s.</string>
|
||||
<string name="input_binding_description_vertical_axis">Move your joystick up or down.</string>
|
||||
<string name="input_binding_description_horizontal_axis">Move your joystick left or right.</string>
|
||||
<string name="input_binding_description_vertical_axis">Move your joystick down</string>
|
||||
<string name="input_binding_description_horizontal_axis">Move your joystick right</string>
|
||||
<string name="button_a" translatable="false">A</string>
|
||||
<string name="button_b" translatable="false">B</string>
|
||||
<string name="button_select" translatable="false">SELECT</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user