mirror of
https://git.ryujinx.app/kenji-nx/ryujinx.git
synced 2025-12-13 22:37:07 +00:00
removed old L3/R3 settings on virtual controllers (doubletab+hold)
This commit is contained in:
parent
0cf2b1fbda
commit
e4d2dea201
1 changed files with 59 additions and 140 deletions
|
|
@ -33,6 +33,10 @@ import org.kenjinx.android.viewmodels.QuickSettings
|
||||||
typealias GamePad = RadialGamePad
|
typealias GamePad = RadialGamePad
|
||||||
typealias GamePadConfig = RadialGamePadConfig
|
typealias GamePadConfig = RadialGamePadConfig
|
||||||
|
|
||||||
|
// --- Dummy IDs to disconnect legacy L3/R3 (stick double tap/tap) ---
|
||||||
|
private const val DUMMY_LEFT_STICK_PRESS_ID = 10001
|
||||||
|
private const val DUMMY_RIGHT_STICK_PRESS_ID = 10002
|
||||||
|
|
||||||
class GameController(var activity: Activity) {
|
class GameController(var activity: Activity) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -41,14 +45,14 @@ class GameController(var activity: Activity) {
|
||||||
val view = inflater.inflate(R.layout.game_layout, null)
|
val view = inflater.inflate(R.layout.game_layout, null)
|
||||||
view.findViewById<FrameLayout>(R.id.leftcontainer)!!.addView(controller.leftGamePad)
|
view.findViewById<FrameLayout>(R.id.leftcontainer)!!.addView(controller.leftGamePad)
|
||||||
view.findViewById<FrameLayout>(R.id.rightcontainer)!!.addView(controller.rightGamePad)
|
view.findViewById<FrameLayout>(R.id.rightcontainer)!!.addView(controller.rightGamePad)
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Compose(viewModel: MainViewModel): Unit {
|
fun Compose(viewModel: MainViewModel): Unit {
|
||||||
AndroidView(
|
AndroidView(
|
||||||
modifier = Modifier.fillMaxSize(), factory = { context ->
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
factory = { context ->
|
||||||
val controller = GameController(viewModel.activity)
|
val controller = GameController(viewModel.activity)
|
||||||
val c = init(context, controller)
|
val c = init(context, controller)
|
||||||
viewModel.activity.lifecycleScope.apply {
|
viewModel.activity.lifecycleScope.apply {
|
||||||
|
|
@ -56,8 +60,7 @@ class GameController(var activity: Activity) {
|
||||||
val events = merge(
|
val events = merge(
|
||||||
controller.leftGamePad.events(),
|
controller.leftGamePad.events(),
|
||||||
controller.rightGamePad.events()
|
controller.rightGamePad.events()
|
||||||
)
|
).shareIn(viewModel.activity.lifecycleScope, SharingStarted.Lazily)
|
||||||
.shareIn(viewModel.activity.lifecycleScope, SharingStarted.Lazily)
|
|
||||||
events.safeCollect {
|
events.safeCollect {
|
||||||
controller.handleEvent(it)
|
controller.handleEvent(it)
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +70,8 @@ class GameController(var activity: Activity) {
|
||||||
viewModel.setGameController(controller)
|
viewModel.setGameController(controller)
|
||||||
controller.setVisible(QuickSettings(viewModel.activity).useVirtualController)
|
controller.setVisible(QuickSettings(viewModel.activity).useVirtualController)
|
||||||
c
|
c
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,13 +80,7 @@ class GameController(var activity: Activity) {
|
||||||
var rightGamePad: GamePad
|
var rightGamePad: GamePad
|
||||||
var controllerId: Int = -1
|
var controllerId: Int = -1
|
||||||
val isVisible: Boolean
|
val isVisible: Boolean
|
||||||
get() {
|
get() = controllerView?.isVisible ?: false
|
||||||
controllerView?.apply {
|
|
||||||
return this.isVisible
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
leftGamePad = GamePad(generateConfig(true), 16f, activity)
|
leftGamePad = GamePad(generateConfig(true), 16f, activity)
|
||||||
|
|
@ -100,9 +98,7 @@ class GameController(var activity: Activity) {
|
||||||
fun setVisible(isVisible: Boolean) {
|
fun setVisible(isVisible: Boolean) {
|
||||||
controllerView?.apply {
|
controllerView?.apply {
|
||||||
this.isVisible = isVisible
|
this.isVisible = isVisible
|
||||||
|
if (isVisible) connect()
|
||||||
if (isVisible)
|
|
||||||
connect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,78 +114,40 @@ class GameController(var activity: Activity) {
|
||||||
controllerId.apply {
|
controllerId.apply {
|
||||||
when (ev) {
|
when (ev) {
|
||||||
is Event.Button -> {
|
is Event.Button -> {
|
||||||
val action = ev.action
|
// Ignore legacy L3/R3 via stick press (double tap)
|
||||||
when (action) {
|
if (ev.id == DUMMY_LEFT_STICK_PRESS_ID || ev.id == DUMMY_RIGHT_STICK_PRESS_ID) {
|
||||||
KeyEvent.ACTION_UP -> {
|
return
|
||||||
KenjinxNative.inputSetButtonReleased(ev.id, this)
|
}
|
||||||
}
|
when (ev.action) {
|
||||||
|
KeyEvent.ACTION_UP -> KenjinxNative.inputSetButtonReleased(ev.id, this)
|
||||||
KeyEvent.ACTION_DOWN -> {
|
KeyEvent.ACTION_DOWN -> KenjinxNative.inputSetButtonPressed(ev.id, this)
|
||||||
KenjinxNative.inputSetButtonPressed(ev.id, this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is Event.Direction -> {
|
is Event.Direction -> {
|
||||||
val direction = ev.id
|
when (ev.id) {
|
||||||
|
|
||||||
when (direction) {
|
|
||||||
GamePadButtonInputId.DpadUp.ordinal -> {
|
GamePadButtonInputId.DpadUp.ordinal -> {
|
||||||
|
// Horizontal
|
||||||
if (ev.xAxis > 0) {
|
if (ev.xAxis > 0) {
|
||||||
KenjinxNative.inputSetButtonPressed(
|
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadRight.ordinal, this)
|
||||||
GamePadButtonInputId.DpadRight.ordinal,
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadLeft.ordinal, this)
|
||||||
this
|
|
||||||
)
|
|
||||||
KenjinxNative.inputSetButtonReleased(
|
|
||||||
GamePadButtonInputId.DpadLeft.ordinal,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
} else if (ev.xAxis < 0) {
|
} else if (ev.xAxis < 0) {
|
||||||
KenjinxNative.inputSetButtonPressed(
|
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadLeft.ordinal, this)
|
||||||
GamePadButtonInputId.DpadLeft.ordinal,
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadRight.ordinal, this)
|
||||||
this
|
|
||||||
)
|
|
||||||
KenjinxNative.inputSetButtonReleased(
|
|
||||||
GamePadButtonInputId.DpadRight.ordinal,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
KenjinxNative.inputSetButtonReleased(
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadLeft.ordinal, this)
|
||||||
GamePadButtonInputId.DpadLeft.ordinal,
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadRight.ordinal, this)
|
||||||
this
|
|
||||||
)
|
|
||||||
KenjinxNative.inputSetButtonReleased(
|
|
||||||
GamePadButtonInputId.DpadRight.ordinal,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
// Vertical
|
||||||
if (ev.yAxis < 0) {
|
if (ev.yAxis < 0) {
|
||||||
KenjinxNative.inputSetButtonPressed(
|
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadUp.ordinal, this)
|
||||||
GamePadButtonInputId.DpadUp.ordinal,
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadDown.ordinal, this)
|
||||||
this
|
|
||||||
)
|
|
||||||
KenjinxNative.inputSetButtonReleased(
|
|
||||||
GamePadButtonInputId.DpadDown.ordinal,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
} else if (ev.yAxis > 0) {
|
} else if (ev.yAxis > 0) {
|
||||||
KenjinxNative.inputSetButtonPressed(
|
KenjinxNative.inputSetButtonPressed(GamePadButtonInputId.DpadDown.ordinal, this)
|
||||||
GamePadButtonInputId.DpadDown.ordinal,
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadUp.ordinal, this)
|
||||||
this
|
|
||||||
)
|
|
||||||
KenjinxNative.inputSetButtonReleased(
|
|
||||||
GamePadButtonInputId.DpadUp.ordinal,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
KenjinxNative.inputSetButtonReleased(
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadDown.ordinal, this)
|
||||||
GamePadButtonInputId.DpadDown.ordinal,
|
KenjinxNative.inputSetButtonReleased(GamePadButtonInputId.DpadUp.ordinal, this)
|
||||||
this
|
|
||||||
)
|
|
||||||
KenjinxNative.inputSetButtonReleased(
|
|
||||||
GamePadButtonInputId.DpadUp.ordinal,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,24 +155,14 @@ class GameController(var activity: Activity) {
|
||||||
val setting = QuickSettings(activity)
|
val setting = QuickSettings(activity)
|
||||||
val x = MathUtils.clamp(ev.xAxis * setting.controllerStickSensitivity, -1f, 1f)
|
val x = MathUtils.clamp(ev.xAxis * setting.controllerStickSensitivity, -1f, 1f)
|
||||||
val y = MathUtils.clamp(ev.yAxis * setting.controllerStickSensitivity, -1f, 1f)
|
val y = MathUtils.clamp(ev.yAxis * setting.controllerStickSensitivity, -1f, 1f)
|
||||||
KenjinxNative.inputSetStickAxis(
|
KenjinxNative.inputSetStickAxis(1, x, -y, this)
|
||||||
1,
|
|
||||||
x,
|
|
||||||
-y,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GamePadButtonInputId.RightStick.ordinal -> {
|
GamePadButtonInputId.RightStick.ordinal -> {
|
||||||
val setting = QuickSettings(activity)
|
val setting = QuickSettings(activity)
|
||||||
val x = MathUtils.clamp(ev.xAxis * setting.controllerStickSensitivity, -1f, 1f)
|
val x = MathUtils.clamp(ev.xAxis * setting.controllerStickSensitivity, -1f, 1f)
|
||||||
val y = MathUtils.clamp(ev.yAxis * setting.controllerStickSensitivity, -1f, 1f)
|
val y = MathUtils.clamp(ev.yAxis * setting.controllerStickSensitivity, -1f, 1f)
|
||||||
KenjinxNative.inputSetStickAxis(
|
KenjinxNative.inputSetStickAxis(2, x, -y, this)
|
||||||
2,
|
|
||||||
x,
|
|
||||||
-y,
|
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -223,13 +171,9 @@ class GameController(var activity: Activity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun <T> Flow<T>.safeCollect(
|
suspend fun <T> Flow<T>.safeCollect(block: suspend (T) -> Unit) {
|
||||||
block: suspend (T) -> Unit
|
this.catch { }
|
||||||
) {
|
.collect { block(it) }
|
||||||
this.catch {}
|
|
||||||
.collect {
|
|
||||||
block(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
|
|
@ -239,15 +183,17 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
if (isLeft) {
|
if (isLeft) {
|
||||||
return GamePadConfig(
|
return GamePadConfig(
|
||||||
/* ringSegments = */ 12,
|
/* ringSegments = */ 12,
|
||||||
/* Primary (Stick) */ PrimaryDialConfig.Stick(
|
/* Primary (Stick) */
|
||||||
|
// IMPORTANT: pressButtonId -> DUMMY_LEFT_STICK_PRESS_ID, so that double tap does not trigger L3
|
||||||
|
PrimaryDialConfig.Stick(
|
||||||
GamePadButtonInputId.LeftStick.ordinal,
|
GamePadButtonInputId.LeftStick.ordinal,
|
||||||
GamePadButtonInputId.LeftStickButton.ordinal,
|
DUMMY_LEFT_STICK_PRESS_ID,
|
||||||
setOf(),
|
setOf(),
|
||||||
"LeftStick",
|
"LeftStick",
|
||||||
null
|
null
|
||||||
),
|
),
|
||||||
listOf(
|
listOf(
|
||||||
// D-Pad (unchanged)
|
// D-Pad
|
||||||
SecondaryDialConfig.Cross(
|
SecondaryDialConfig.Cross(
|
||||||
/* sector */ 10,
|
/* sector */ 10,
|
||||||
/* size */ 3,
|
/* size */ 3,
|
||||||
|
|
@ -265,7 +211,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// Minus (unchanged)
|
// Minus
|
||||||
SecondaryDialConfig.SingleButton(
|
SecondaryDialConfig.SingleButton(
|
||||||
/* sector */ 1,
|
/* sector */ 1,
|
||||||
buttonScale,
|
buttonScale,
|
||||||
|
|
@ -284,7 +230,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// L-Bumper (unchanged, DoubleButton means wider target)
|
// L-Bumper
|
||||||
SecondaryDialConfig.DoubleButton(
|
SecondaryDialConfig.DoubleButton(
|
||||||
/* sector */ 2,
|
/* sector */ 2,
|
||||||
distance,
|
distance,
|
||||||
|
|
@ -302,7 +248,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// ZL-Trigger (unchanged)
|
// ZL-Trigger
|
||||||
SecondaryDialConfig.SingleButton(
|
SecondaryDialConfig.SingleButton(
|
||||||
/* sector */ 9,
|
/* sector */ 9,
|
||||||
buttonScale,
|
buttonScale,
|
||||||
|
|
@ -321,7 +267,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// *** NEW: L3 as a separate button (top of the left pad) ***
|
// NEW (remains): L3 as a separate button
|
||||||
SecondaryDialConfig.SingleButton(
|
SecondaryDialConfig.SingleButton(
|
||||||
/* sector */ 1,
|
/* sector */ 1,
|
||||||
buttonScale,
|
buttonScale,
|
||||||
|
|
@ -344,47 +290,20 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
} else {
|
} else {
|
||||||
return GamePadConfig(
|
return GamePadConfig(
|
||||||
/* ringSegments = */ 12,
|
/* ringSegments = */ 12,
|
||||||
/* Primary (ABXY) */ PrimaryDialConfig.PrimaryButtons(
|
/* Primary (ABXY) */
|
||||||
|
PrimaryDialConfig.PrimaryButtons(
|
||||||
listOf(
|
listOf(
|
||||||
ButtonConfig(
|
ButtonConfig(
|
||||||
GamePadButtonInputId.A.ordinal,
|
GamePadButtonInputId.A.ordinal, "A", true, null, "A", setOf(), true, null
|
||||||
"A",
|
|
||||||
true,
|
|
||||||
null,
|
|
||||||
"A",
|
|
||||||
setOf(),
|
|
||||||
true,
|
|
||||||
null
|
|
||||||
),
|
),
|
||||||
ButtonConfig(
|
ButtonConfig(
|
||||||
GamePadButtonInputId.X.ordinal,
|
GamePadButtonInputId.X.ordinal, "X", true, null, "X", setOf(), true, null
|
||||||
"X",
|
|
||||||
true,
|
|
||||||
null,
|
|
||||||
"X",
|
|
||||||
setOf(),
|
|
||||||
true,
|
|
||||||
null
|
|
||||||
),
|
),
|
||||||
ButtonConfig(
|
ButtonConfig(
|
||||||
GamePadButtonInputId.Y.ordinal,
|
GamePadButtonInputId.Y.ordinal, "Y", true, null, "Y", setOf(), true, null
|
||||||
"Y",
|
|
||||||
true,
|
|
||||||
null,
|
|
||||||
"Y",
|
|
||||||
setOf(),
|
|
||||||
true,
|
|
||||||
null
|
|
||||||
),
|
),
|
||||||
ButtonConfig(
|
ButtonConfig(
|
||||||
GamePadButtonInputId.B.ordinal,
|
GamePadButtonInputId.B.ordinal, "B", true, null, "B", setOf(), true, null
|
||||||
"B",
|
|
||||||
true,
|
|
||||||
null,
|
|
||||||
"B",
|
|
||||||
setOf(),
|
|
||||||
true,
|
|
||||||
null
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
|
|
@ -394,20 +313,21 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
),
|
),
|
||||||
listOf(
|
listOf(
|
||||||
// Right stick (unchanged)
|
// Right stick (unchanged)
|
||||||
|
// IMPORTANT: pressButtonId -> DUMMY_RIGHT_STICK_PRESS_ID, so that double tap does not trigger R3
|
||||||
SecondaryDialConfig.Stick(
|
SecondaryDialConfig.Stick(
|
||||||
/* sector */ 7,
|
/* sector */ 7,
|
||||||
/* size */ 2,
|
/* size */ 2,
|
||||||
/* gap */ 2f,
|
/* gap */ 2f,
|
||||||
distance,
|
distance,
|
||||||
GamePadButtonInputId.RightStick.ordinal,
|
GamePadButtonInputId.RightStick.ordinal,
|
||||||
GamePadButtonInputId.RightStickButton.ordinal,
|
DUMMY_RIGHT_STICK_PRESS_ID,
|
||||||
null,
|
null,
|
||||||
setOf(),
|
setOf(),
|
||||||
"RightStick",
|
"RightStick",
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// Plus (unchanged)
|
// Plus
|
||||||
SecondaryDialConfig.SingleButton(
|
SecondaryDialConfig.SingleButton(
|
||||||
/* sector */ 6,
|
/* sector */ 6,
|
||||||
buttonScale,
|
buttonScale,
|
||||||
|
|
@ -426,7 +346,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// R-Bumper (unchanged)
|
// R-Bumper
|
||||||
SecondaryDialConfig.DoubleButton(
|
SecondaryDialConfig.DoubleButton(
|
||||||
/* sector */ 3,
|
/* sector */ 3,
|
||||||
distance,
|
distance,
|
||||||
|
|
@ -444,7 +364,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// ZR-Trigger (unchanged)
|
// ZR-Trigger
|
||||||
SecondaryDialConfig.SingleButton(
|
SecondaryDialConfig.SingleButton(
|
||||||
/* sector */ 9,
|
/* sector */ 9,
|
||||||
buttonScale,
|
buttonScale,
|
||||||
|
|
@ -463,7 +383,7 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
SecondaryDialConfig.RotationProcessor()
|
SecondaryDialConfig.RotationProcessor()
|
||||||
),
|
),
|
||||||
|
|
||||||
// *** NEW: R3 as a separate button (top of the right pad) ***
|
// NEW (remains): R3 as a separate button
|
||||||
SecondaryDialConfig.SingleButton(
|
SecondaryDialConfig.SingleButton(
|
||||||
/* sector */ 5,
|
/* sector */ 5,
|
||||||
buttonScale,
|
buttonScale,
|
||||||
|
|
@ -485,4 +405,3 @@ private fun generateConfig(isLeft: Boolean): GamePadConfig {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue