Use buttons instead of axes for the d-pad, enabling mapping from gamepads with only digital dpad outputs (#203)

This commit is contained in:
David Griswold 2024-08-20 05:34:40 -03:00 committed by GitHub
parent e3b156bd96
commit 8656655bb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 4 deletions

View file

@ -166,13 +166,25 @@ class Settings {
KEY_CSTICK_AXIS_HORIZONTAL KEY_CSTICK_AXIS_HORIZONTAL
) )
val dPadKeys = listOf( val dPadKeys = listOf(
KEY_DPAD_AXIS_VERTICAL, // KEY_DPAD_AXIS_VERTICAL,
KEY_DPAD_AXIS_HORIZONTAL // KEY_DPAD_AXIS_HORIZONTAL,
KEY_BUTTON_UP,
KEY_BUTTON_DOWN,
KEY_BUTTON_LEFT,
KEY_BUTTON_RIGHT
) )
val axisTitles = listOf( val axisTitles = listOf(
R.string.controller_axis_vertical, R.string.controller_axis_vertical,
R.string.controller_axis_horizontal R.string.controller_axis_horizontal
) )
val dPadTitles = listOf(
R.string.direction_up,
R.string.direction_down,
R.string.direction_left,
R.string.direction_right,
)
val triggerKeys = listOf( val triggerKeys = listOf(
KEY_BUTTON_L, KEY_BUTTON_L,
KEY_BUTTON_R, KEY_BUTTON_R,

View file

@ -79,6 +79,14 @@ class InputBindingSetting(
else -> false else -> false
} }
fun isDpadButtons(): Boolean =
when (abstractSetting.key) {
Settings.KEY_BUTTON_DOWN,
Settings.KEY_BUTTON_LEFT,
Settings.KEY_BUTTON_UP,
Settings.KEY_BUTTON_RIGHT -> true
else -> false
}
/** /**
* Returns true if this key is for the 3DS L/R or ZL/ZR buttons. Note, these are not real * Returns true if this key is for the 3DS L/R or ZL/ZR buttons. Note, these are not real
* triggers on the 3DS, but we support them as such on a physical gamepad. * triggers on the 3DS, but we support them as such on a physical gamepad.

View file

@ -612,7 +612,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
add(HeaderSetting(R.string.controller_dpad)) add(HeaderSetting(R.string.controller_dpad))
Settings.dPadKeys.forEachIndexed { i: Int, key: String -> Settings.dPadKeys.forEachIndexed { i: Int, key: String ->
val button = getInputObject(key) val button = getInputObject(key)
add(InputBindingSetting(button, Settings.axisTitles[i])) add(InputBindingSetting(button, Settings.dPadTitles[i]))
} }
add(HeaderSetting(R.string.controller_triggers)) add(HeaderSetting(R.string.controller_triggers))

View file

@ -110,6 +110,10 @@
<string name="controller_dpad">D-Pad</string> <string name="controller_dpad">D-Pad</string>
<string name="controller_axis_vertical">Up/Down Axis</string> <string name="controller_axis_vertical">Up/Down Axis</string>
<string name="controller_axis_horizontal">Left/Right Axis</string> <string name="controller_axis_horizontal">Left/Right Axis</string>
<string name="direction_up">Up</string>
<string name="direction_down">Down</string>
<string name="direction_left">Left</string>
<string name="direction_right">Right</string>
<string name="input_dialog_title">Bind %1$s %2$s</string> <string name="input_dialog_title">Bind %1$s %2$s</string>
<string name="input_dialog_description">Press or move an input.</string> <string name="input_dialog_description">Press or move an input.</string>
<string name="input_binding">Input Binding</string> <string name="input_binding">Input Binding</string>