fixed L3+R3 on physical controllers, added L3/R3 on virtual Controllers

This commit is contained in:
BeZide93 2025-09-06 02:13:53 -05:00 committed by KeatonTheBot
parent 8707fd5232
commit 92c3b72b17
2 changed files with 137 additions and 109 deletions

View file

@ -238,8 +238,8 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
if (isLeft) { if (isLeft) {
return GamePadConfig( return GamePadConfig(
12, /* ringSegments = */ 12,
PrimaryDialConfig.Stick( /* Primary (Stick) */ PrimaryDialConfig.Stick(
GamePadButtonInputId.LeftStick.ordinal, GamePadButtonInputId.LeftStick.ordinal,
GamePadButtonInputId.LeftStickButton.ordinal, GamePadButtonInputId.LeftStickButton.ordinal,
setOf(), setOf(),
@ -247,10 +247,11 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null null
), ),
listOf( listOf(
// D-Pad (unchanged)
SecondaryDialConfig.Cross( SecondaryDialConfig.Cross(
10, /* sector */ 10,
3, /* size */ 3,
2.5f, /* gap */ 2.5f,
distance, distance,
CrossConfig( CrossConfig(
GamePadButtonInputId.DpadUp.ordinal, GamePadButtonInputId.DpadUp.ordinal,
@ -263,8 +264,10 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
), ),
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// Minus (unchanged)
SecondaryDialConfig.SingleButton( SecondaryDialConfig.SingleButton(
1, /* sector */ 1,
buttonScale, buttonScale,
distance, distance,
ButtonConfig( ButtonConfig(
@ -280,8 +283,10 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null, null,
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// L-Bumper (unchanged, DoubleButton means wider target)
SecondaryDialConfig.DoubleButton( SecondaryDialConfig.DoubleButton(
2, /* sector */ 2,
distance, distance,
ButtonConfig( ButtonConfig(
GamePadButtonInputId.LeftShoulder.ordinal, GamePadButtonInputId.LeftShoulder.ordinal,
@ -296,8 +301,10 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null, null,
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// ZL-Trigger (unchanged)
SecondaryDialConfig.SingleButton( SecondaryDialConfig.SingleButton(
9, /* sector */ 9,
buttonScale, buttonScale,
distance, distance,
ButtonConfig( ButtonConfig(
@ -313,12 +320,31 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null, null,
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// *** NEW: L3 as a separate button (top of the left pad) ***
SecondaryDialConfig.SingleButton(
/* sector */ 1,
buttonScale,
1.5f,
ButtonConfig(
GamePadButtonInputId.LeftStickButton.ordinal,
"L3",
true,
null,
"LeftStickButton",
setOf(),
true,
null
),
null,
SecondaryDialConfig.RotationProcessor()
),
) )
) )
} else { } else {
return GamePadConfig( return GamePadConfig(
12, /* ringSegments = */ 12,
PrimaryDialConfig.PrimaryButtons( /* Primary (ABXY) */ PrimaryDialConfig.PrimaryButtons(
listOf( listOf(
ButtonConfig( ButtonConfig(
GamePadButtonInputId.A.ordinal, GamePadButtonInputId.A.ordinal,
@ -367,10 +393,11 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null null
), ),
listOf( listOf(
// Right stick (unchanged)
SecondaryDialConfig.Stick( SecondaryDialConfig.Stick(
7, /* sector */ 7,
2, /* size */ 2,
2f, /* gap */ 2f,
distance, distance,
GamePadButtonInputId.RightStick.ordinal, GamePadButtonInputId.RightStick.ordinal,
GamePadButtonInputId.RightStickButton.ordinal, GamePadButtonInputId.RightStickButton.ordinal,
@ -379,8 +406,10 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
"RightStick", "RightStick",
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// Plus (unchanged)
SecondaryDialConfig.SingleButton( SecondaryDialConfig.SingleButton(
6, /* sector */ 6,
buttonScale, buttonScale,
distance, distance,
ButtonConfig( ButtonConfig(
@ -396,8 +425,10 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null, null,
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// R-Bumper (unchanged)
SecondaryDialConfig.DoubleButton( SecondaryDialConfig.DoubleButton(
3, /* sector */ 3,
distance, distance,
ButtonConfig( ButtonConfig(
GamePadButtonInputId.RightShoulder.ordinal, GamePadButtonInputId.RightShoulder.ordinal,
@ -412,8 +443,10 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
null, null,
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
), ),
// ZR-Trigger (unchanged)
SecondaryDialConfig.SingleButton( SecondaryDialConfig.SingleButton(
9, /* sector */ 9,
buttonScale, buttonScale,
distance, distance,
ButtonConfig( ButtonConfig(
@ -428,8 +461,28 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
), ),
null, null,
SecondaryDialConfig.RotationProcessor() SecondaryDialConfig.RotationProcessor()
) ),
// *** NEW: R3 as a separate button (top of the right pad) ***
SecondaryDialConfig.SingleButton(
/* sector */ 5,
buttonScale,
1.5f,
ButtonConfig(
GamePadButtonInputId.RightStickButton.ordinal,
"R3",
true,
null,
"RightStickButton",
setOf(),
true,
null
),
null,
SecondaryDialConfig.RotationProcessor()
),
) )
) )
} }
} }

View file

@ -9,119 +9,80 @@ class PhysicalControllerManager(val activity: MainActivity) {
private var controllerId: Int = -1 private var controllerId: Int = -1
fun onKeyEvent(event: KeyEvent): Boolean { fun onKeyEvent(event: KeyEvent): Boolean {
// Make sure we are connected
if (controllerId == -1) {
controllerId = KenjinxNative.inputConnectGamepad(0)
}
val id = getGamePadButtonInputId(event.keyCode) val id = getGamePadButtonInputId(event.keyCode)
if (id != GamePadButtonInputId.None) { if (id != GamePadButtonInputId.None) {
val isNotFallback = (event.flags and KeyEvent.FLAG_FALLBACK) == 0 val isNotFallback = (event.flags and KeyEvent.FLAG_FALLBACK) == 0
if (/*controllerId != -1 &&*/ isNotFallback) { // Many gamepads send additional fallback events we suppress them.
if (isNotFallback) {
when (event.action) { when (event.action) {
KeyEvent.ACTION_UP -> { KeyEvent.ACTION_UP -> {
KenjinxNative.inputSetButtonReleased(id.ordinal, controllerId) KenjinxNative.inputSetButtonReleased(id.ordinal, controllerId)
} }
KeyEvent.ACTION_DOWN -> { KeyEvent.ACTION_DOWN -> {
KenjinxNative.inputSetButtonPressed(id.ordinal, controllerId) KenjinxNative.inputSetButtonPressed(id.ordinal, controllerId)
} }
} }
return true }
} //else if (!isNotFallback) { return true
return true
// }
} }
return false return false
} }
fun onMotionEvent(ev: MotionEvent) { fun onMotionEvent(ev: MotionEvent) {
// if (true) { if (ev.action == MotionEvent.ACTION_MOVE) {
if (ev.action == MotionEvent.ACTION_MOVE) { if (controllerId == -1) {
val leftStickX = ev.getAxisValue(MotionEvent.AXIS_X) controllerId = KenjinxNative.inputConnectGamepad(0)
val leftStickY = ev.getAxisValue(MotionEvent.AXIS_Y) }
val rightStickX = ev.getAxisValue(MotionEvent.AXIS_Z)
val rightStickY = ev.getAxisValue(MotionEvent.AXIS_RZ)
KenjinxNative.inputSetStickAxis(
1,
leftStickX,
-leftStickY,
controllerId
)
KenjinxNative.inputSetStickAxis(
2,
rightStickX,
-rightStickY,
controllerId
)
ev.device?.apply { val leftStickX = ev.getAxisValue(MotionEvent.AXIS_X)
if (sources and InputDevice.SOURCE_DPAD != InputDevice.SOURCE_DPAD) { val leftStickY = ev.getAxisValue(MotionEvent.AXIS_Y)
// Controller uses HAT val rightStickX = ev.getAxisValue(MotionEvent.AXIS_Z)
val dPadHor = ev.getAxisValue(MotionEvent.AXIS_HAT_X) val rightStickY = ev.getAxisValue(MotionEvent.AXIS_RZ)
val dPadVert = ev.getAxisValue(MotionEvent.AXIS_HAT_Y)
if (dPadVert == 0.0f) {
KenjinxNative.inputSetButtonReleased(
GamePadButtonInputId.DpadUp.ordinal,
controllerId
)
KenjinxNative.inputSetButtonReleased(
GamePadButtonInputId.DpadDown.ordinal,
controllerId
)
}
if (dPadHor == 0.0f) {
KenjinxNative.inputSetButtonReleased(
GamePadButtonInputId.DpadLeft.ordinal,
controllerId
)
KenjinxNative.inputSetButtonReleased(
GamePadButtonInputId.DpadRight.ordinal,
controllerId
)
}
if (dPadVert < 0.0f) { KenjinxNative.inputSetStickAxis(1, leftStickX, -leftStickY, controllerId)
KenjinxNative.inputSetButtonPressed( KenjinxNative.inputSetStickAxis(2, rightStickX, -rightStickY, controllerId)
GamePadButtonInputId.DpadUp.ordinal,
controllerId
)
KenjinxNative.inputSetButtonReleased(
GamePadButtonInputId.DpadDown.ordinal,
controllerId
)
}
if (dPadHor < 0.0f) {
KenjinxNative.inputSetButtonPressed(
GamePadButtonInputId.DpadLeft.ordinal,
controllerId
)
KenjinxNative.inputSetButtonReleased(
GamePadButtonInputId.DpadRight.ordinal,
controllerId
)
}
if (dPadVert > 0.0f) { ev.device?.apply {
KenjinxNative.inputSetButtonReleased( if (sources and InputDevice.SOURCE_DPAD != InputDevice.SOURCE_DPAD) {
GamePadButtonInputId.DpadUp.ordinal, // Controller uses HAT instead of “real” DPAD
controllerId val dPadHor = ev.getAxisValue(MotionEvent.AXIS_HAT_X)
) val dPadVert = ev.getAxisValue(MotionEvent.AXIS_HAT_Y)
KenjinxNative.inputSetButtonPressed(
GamePadButtonInputId.DpadDown.ordinal, if (dPadVert == 0.0f) {
controllerId KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadUp.ordinal, controllerId)
) KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadDown.ordinal, controllerId)
} }
if (dPadHor > 0.0f) { if (dPadHor == 0.0f) {
KenjinxNative.inputSetButtonReleased( KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadLeft.ordinal, controllerId)
GamePadButtonInputId.DpadLeft.ordinal, KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadRight.ordinal, controllerId)
controllerId }
)
KenjinxNative.inputSetButtonPressed( if (dPadVert < 0.0f) {
GamePadButtonInputId.DpadRight.ordinal, KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadUp.ordinal, controllerId)
controllerId KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadDown.ordinal, controllerId)
) }
} if (dPadHor < 0.0f) {
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadLeft.ordinal, controllerId)
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadRight.ordinal, controllerId)
}
if (dPadVert > 0.0f) {
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadUp.ordinal, controllerId)
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadDown.ordinal, controllerId)
}
if (dPadHor > 0.0f) {
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadLeft.ordinal, controllerId)
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadRight.ordinal, controllerId)
} }
} }
} }
// } }
} }
fun connect(): Int { fun connect(): Int {
@ -136,22 +97,36 @@ class PhysicalControllerManager(val activity: MainActivity) {
private fun getGamePadButtonInputId(keycode: Int): GamePadButtonInputId { private fun getGamePadButtonInputId(keycode: Int): GamePadButtonInputId {
val quickSettings = QuickSettings(activity) val quickSettings = QuickSettings(activity)
return when (keycode) { return when (keycode) {
// ABXY (Switch/Xbox layout switchable)
KeyEvent.KEYCODE_BUTTON_A -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.A else GamePadButtonInputId.B KeyEvent.KEYCODE_BUTTON_A -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.A else GamePadButtonInputId.B
KeyEvent.KEYCODE_BUTTON_B -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.B else GamePadButtonInputId.A KeyEvent.KEYCODE_BUTTON_B -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.B else GamePadButtonInputId.A
KeyEvent.KEYCODE_BUTTON_X -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.X else GamePadButtonInputId.Y KeyEvent.KEYCODE_BUTTON_X -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.X else GamePadButtonInputId.Y
KeyEvent.KEYCODE_BUTTON_Y -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.Y else GamePadButtonInputId.X KeyEvent.KEYCODE_BUTTON_Y -> if (!quickSettings.useSwitchLayout) GamePadButtonInputId.Y else GamePadButtonInputId.X
// Shoulder buttons
KeyEvent.KEYCODE_BUTTON_L1 -> GamePadButtonInputId.LeftShoulder KeyEvent.KEYCODE_BUTTON_L1 -> GamePadButtonInputId.LeftShoulder
KeyEvent.KEYCODE_BUTTON_L2 -> GamePadButtonInputId.LeftTrigger KeyEvent.KEYCODE_BUTTON_L2 -> GamePadButtonInputId.LeftTrigger
KeyEvent.KEYCODE_BUTTON_R1 -> GamePadButtonInputId.RightShoulder KeyEvent.KEYCODE_BUTTON_R1 -> GamePadButtonInputId.RightShoulder
KeyEvent.KEYCODE_BUTTON_R2 -> GamePadButtonInputId.RightTrigger KeyEvent.KEYCODE_BUTTON_R2 -> GamePadButtonInputId.RightTrigger
KeyEvent.KEYCODE_BUTTON_THUMBL -> GamePadButtonInputId.LeftStick
KeyEvent.KEYCODE_BUTTON_THUMBR -> GamePadButtonInputId.RightStick // **L3 / R3 (Stick-Click) CORRECT: *_Button**
KeyEvent.KEYCODE_BUTTON_THUMBL -> GamePadButtonInputId.LeftStickButton
KeyEvent.KEYCODE_BUTTON_THUMBR -> GamePadButtonInputId.RightStickButton
// Additional fallback keycodes for some pads (optional)
KeyEvent.KEYCODE_BUTTON_11 -> GamePadButtonInputId.LeftStickButton // isolated L3
KeyEvent.KEYCODE_BUTTON_12 -> GamePadButtonInputId.RightStickButton // isolated R3
// D-Pad
KeyEvent.KEYCODE_DPAD_UP -> GamePadButtonInputId.DpadUp KeyEvent.KEYCODE_DPAD_UP -> GamePadButtonInputId.DpadUp
KeyEvent.KEYCODE_DPAD_DOWN -> GamePadButtonInputId.DpadDown KeyEvent.KEYCODE_DPAD_DOWN -> GamePadButtonInputId.DpadDown
KeyEvent.KEYCODE_DPAD_LEFT -> GamePadButtonInputId.DpadLeft KeyEvent.KEYCODE_DPAD_LEFT -> GamePadButtonInputId.DpadLeft
KeyEvent.KEYCODE_DPAD_RIGHT -> GamePadButtonInputId.DpadRight KeyEvent.KEYCODE_DPAD_RIGHT -> GamePadButtonInputId.DpadRight
// Plus/Minus
KeyEvent.KEYCODE_BUTTON_START -> GamePadButtonInputId.Plus KeyEvent.KEYCODE_BUTTON_START -> GamePadButtonInputId.Plus
KeyEvent.KEYCODE_BUTTON_SELECT -> GamePadButtonInputId.Minus KeyEvent.KEYCODE_BUTTON_SELECT -> GamePadButtonInputId.Minus
else -> GamePadButtonInputId.None else -> GamePadButtonInputId.None
} }
} }