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
)
val dPadKeys = listOf(
KEY_DPAD_AXIS_VERTICAL,
KEY_DPAD_AXIS_HORIZONTAL
// KEY_DPAD_AXIS_VERTICAL,
// KEY_DPAD_AXIS_HORIZONTAL,
KEY_BUTTON_UP,
KEY_BUTTON_DOWN,
KEY_BUTTON_LEFT,
KEY_BUTTON_RIGHT
)
val axisTitles = listOf(
R.string.controller_axis_vertical,
R.string.controller_axis_vertical,
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(
KEY_BUTTON_L,
KEY_BUTTON_R,

View File

@ -79,6 +79,14 @@ class InputBindingSetting(
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
* 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))
Settings.dPadKeys.forEachIndexed { i: Int, key: String ->
val button = getInputObject(key)
add(InputBindingSetting(button, Settings.axisTitles[i]))
add(InputBindingSetting(button, Settings.dPadTitles[i]))
}
add(HeaderSetting(R.string.controller_triggers))

View File

@ -110,6 +110,10 @@
<string name="controller_dpad">D-Pad</string>
<string name="controller_axis_vertical">Up/Down 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_description">Press or move an input.</string>
<string name="input_binding">Input Binding</string>