diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/NativeLibrary.kt b/src/android/app/src/main/java/io/github/lime3ds/android/NativeLibrary.kt index 9b7261977..ab9a99dd1 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/NativeLibrary.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/NativeLibrary.kt @@ -708,6 +708,7 @@ object NativeLibrary { const val DPAD = 780 const val BUTTON_DEBUG = 781 const val BUTTON_GPIO14 = 782 + const val BUTTON_SWAP = 800 } /** diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt index 0f3d77da6..a104802d6 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/fragments/EmulationFragment.kt @@ -738,12 +738,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram private fun showToggleControlsDialog() { val editor = preferences.edit() - val enabledButtons = BooleanArray(14) + val enabledButtons = BooleanArray(15) enabledButtons.forEachIndexed { i: Int, _: Boolean -> // Buttons that are disabled by default var defaultValue = true when (i) { - 6, 7, 12, 13 -> defaultValue = false + 6, 7, 12, 13, 14 -> defaultValue = false } enabledButtons[i] = preferences.getBoolean("buttonToggle$i", defaultValue) } @@ -816,10 +816,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram .apply() val editor = preferences.edit() - for (i in 0 until 14) { + for (i in 0 until 15) { var defaultValue = true when (i) { - 6, 7, 12, 13 -> defaultValue = false + 6, 7, 12, 13, 14 -> defaultValue = false } editor.putBoolean("buttonToggle$i", defaultValue) } diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt index a479d8a8a..b9b91e244 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/overlay/InputOverlay.kt @@ -76,6 +76,15 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex overlayJoysticks.forEach { it.draw(canvas) } } + private fun swapScreen() { + val isEnabled = !EmulationMenuSettings.swapScreens + EmulationMenuSettings.swapScreens = isEnabled + NativeLibrary.swapScreens( + isEnabled, + (context as Activity).windowManager.defaultDisplay.rotation + ) + } + override fun onTouch(v: View, event: MotionEvent): Boolean { if (isInEditMode) { return onTouchWhileEditing(event) @@ -85,6 +94,11 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex if (!button.updateStatus(event)) { continue } + + if (button.id == NativeLibrary.ButtonType.BUTTON_SWAP && button.status == NativeLibrary.ButtonState.PRESSED) { + swapScreen() + } + NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.id, button.status) shouldUpdateView = true } @@ -437,6 +451,18 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex ) ) } + + if (preferences.getBoolean("buttonToggle14", false)) { + overlayButtons.add( + initializeOverlayButton( + context, + R.drawable.button_swap, + R.drawable.button_swap_pressed, + NativeLibrary.ButtonType.BUTTON_SWAP, + orientation + ) + ) + } } fun refreshControls() { @@ -634,6 +660,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex NativeLibrary.ButtonType.STICK_LEFT.toString() + "-Y", resources.getInteger(R.integer.N3DS_STICK_MAIN_Y).toFloat() / 1000 * maxY ) + .putFloat( + NativeLibrary.ButtonType.BUTTON_SWAP.toString() + "-X", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_X).toFloat() / 1000 * maxX + ) + .putFloat( + NativeLibrary.ButtonType.BUTTON_SWAP.toString() + "-Y", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_Y).toFloat() / 1000 * maxY + ) .apply() } @@ -769,6 +803,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex NativeLibrary.ButtonType.STICK_LEFT.toString() + portrait + "-Y", resources.getInteger(R.integer.N3DS_STICK_MAIN_PORTRAIT_Y).toFloat() / 1000 * maxY ) + .putFloat( + NativeLibrary.ButtonType.BUTTON_SWAP.toString() + portrait + "-X", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_PORTRAIT_X).toFloat() / 1000 * maxX + ) + .putFloat( + NativeLibrary.ButtonType.BUTTON_SWAP.toString() + portrait + "-Y", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_PORTRAIT_Y).toFloat() / 1000 * maxY + ) .apply() } @@ -879,7 +921,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex var scale: Float = when (buttonId) { NativeLibrary.ButtonType.BUTTON_HOME, NativeLibrary.ButtonType.BUTTON_START, - NativeLibrary.ButtonType.BUTTON_SELECT -> 0.08f + NativeLibrary.ButtonType.BUTTON_SELECT, + NativeLibrary.ButtonType.BUTTON_SWAP -> 0.08f NativeLibrary.ButtonType.TRIGGER_L, NativeLibrary.ButtonType.TRIGGER_R, diff --git a/src/android/app/src/main/res/drawable-hdpi/button_swap.png b/src/android/app/src/main/res/drawable-hdpi/button_swap.png new file mode 100644 index 000000000..6f17924e7 Binary files /dev/null and b/src/android/app/src/main/res/drawable-hdpi/button_swap.png differ diff --git a/src/android/app/src/main/res/drawable-hdpi/button_swap_pressed.png b/src/android/app/src/main/res/drawable-hdpi/button_swap_pressed.png new file mode 100644 index 000000000..be07c6598 Binary files /dev/null and b/src/android/app/src/main/res/drawable-hdpi/button_swap_pressed.png differ diff --git a/src/android/app/src/main/res/drawable-xhdpi/button_swap.png b/src/android/app/src/main/res/drawable-xhdpi/button_swap.png new file mode 100644 index 000000000..613b840c7 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xhdpi/button_swap.png differ diff --git a/src/android/app/src/main/res/drawable-xhdpi/button_swap_pressed.png b/src/android/app/src/main/res/drawable-xhdpi/button_swap_pressed.png new file mode 100644 index 000000000..02b4e4e2f Binary files /dev/null and b/src/android/app/src/main/res/drawable-xhdpi/button_swap_pressed.png differ diff --git a/src/android/app/src/main/res/drawable-xxhdpi/button_swap.png b/src/android/app/src/main/res/drawable-xxhdpi/button_swap.png new file mode 100644 index 000000000..f92effc58 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxhdpi/button_swap.png differ diff --git a/src/android/app/src/main/res/drawable-xxhdpi/button_swap_pressed.png b/src/android/app/src/main/res/drawable-xxhdpi/button_swap_pressed.png new file mode 100644 index 000000000..8092e175d Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxhdpi/button_swap_pressed.png differ diff --git a/src/android/app/src/main/res/drawable-xxxhdpi/button_swap.png b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap.png new file mode 100644 index 000000000..a9fbe6882 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap.png differ diff --git a/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_pressed.png b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_pressed.png new file mode 100644 index 000000000..b17a9fa0e Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_pressed.png differ diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index cd542bae8..10ccfefd4 100644 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -78,6 +78,7 @@ @string/controller_circlepad @string/controller_c @string/button_home + @string/button_swap diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml index 8fee8e96f..50cde75f8 100644 --- a/src/android/app/src/main/res/values/integers.xml +++ b/src/android/app/src/main/res/values/integers.xml @@ -31,6 +31,8 @@ 850 510 850 + 370 + 850 810 @@ -61,5 +63,7 @@ 794 520 794 + 460 + 675 diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 63b6fbb69..da2b4b3ea 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -121,6 +121,7 @@ SELECT START HOME + Swap Screens X Y L