diff --git a/src/android/app/src/main/java/org/citra/citra_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/citra/citra_emu/NativeLibrary.kt index 135794d659..3d838809ac 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/NativeLibrary.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/NativeLibrary.kt @@ -762,6 +762,7 @@ object NativeLibrary { const val DPAD = 780 const val BUTTON_DEBUG = 781 const val BUTTON_GPIO14 = 782 + const val BUTTON_SWAP_SCREENS = 783 } /** diff --git a/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt index 73b331943c..82cda29975 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt @@ -722,6 +722,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram true } + R.id.menu_emulation_adjust_scale_button_swap_screens -> { + showAdjustScaleDialog("controlScale-" + NativeLibrary.ButtonType.BUTTON_SWAP_SCREENS) + true + } + R.id.menu_emulation_adjust_opacity -> { showAdjustOpacityDialog() true @@ -848,12 +853,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) } @@ -971,6 +976,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram resetScale("controlScale-" + NativeLibrary.ButtonType.STICK_LEFT) resetScale("controlScale-" + NativeLibrary.ButtonType.STICK_C) resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_HOME) + resetScale("controlScale-" + NativeLibrary.ButtonType.BUTTON_SWAP_SCREENS) binding.surfaceInputOverlay.refreshControls() } @@ -991,10 +997,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/org/citra/citra_emu/overlay/InputOverlay.kt b/src/android/app/src/main/java/org/citra/citra_emu/overlay/InputOverlay.kt index f11b8f640f..73d18145e7 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/overlay/InputOverlay.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/overlay/InputOverlay.kt @@ -81,6 +81,15 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex performHapticFeedback(type) } + private fun swapScreens() { + val isSwapScreensEnabled = !EmulationMenuSettings.swapScreens + EmulationMenuSettings.swapScreens = isSwapScreensEnabled + NativeLibrary.swapScreens( + isSwapScreensEnabled, + (context as Activity).windowManager.defaultDisplay.rotation + ) + } + override fun onTouch(v: View, event: MotionEvent): Boolean { if (isInEditMode) { return onTouchWhileEditing(event) @@ -90,6 +99,11 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex if (!button.updateStatus(event, this)) { continue } + + if (button.id == NativeLibrary.ButtonType.BUTTON_SWAP_SCREENS && button.status == NativeLibrary.ButtonState.PRESSED) { + swapScreens() + } + NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.id, button.status) shouldUpdateView = true } @@ -442,6 +456,17 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex ) ) } + if (preferences.getBoolean("buttonToggle14", false)) { + overlayButtons.add( + initializeOverlayButton( + context, + R.drawable.button_swap_screens, + R.drawable.button_swap_screens_pressed, + NativeLibrary.ButtonType.BUTTON_SWAP_SCREENS, + orientation + ) + ) + } } fun refreshControls() { @@ -639,6 +664,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_SCREENS.toString() + "-X", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_SCREENS_X).toFloat() / 1000 * maxX + ) + .putFloat( + NativeLibrary.ButtonType.BUTTON_SWAP_SCREENS.toString() + "-Y", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_SCREENS_Y).toFloat() / 1000 * maxY + ) .apply() } @@ -774,6 +807,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_SCREENS.toString() + portrait + "-X", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_SCREENS_PORTRAIT_X).toFloat() / 1000 * maxX + ) + .putFloat( + NativeLibrary.ButtonType.BUTTON_SWAP_SCREENS.toString() + portrait + "-Y", + resources.getInteger(R.integer.N3DS_BUTTON_SWAP_SCREENS_PORTRAIT_Y).toFloat() / 1000 * maxY + ) .apply() } @@ -884,7 +925,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_SCREENS -> 0.08f NativeLibrary.ButtonType.TRIGGER_L, NativeLibrary.ButtonType.TRIGGER_R, diff --git a/src/android/app/src/main/res/drawable-hdpi/button_swap_screens.png b/src/android/app/src/main/res/drawable-hdpi/button_swap_screens.png new file mode 100644 index 0000000000..6f17924e74 Binary files /dev/null and b/src/android/app/src/main/res/drawable-hdpi/button_swap_screens.png differ diff --git a/src/android/app/src/main/res/drawable-hdpi/button_swap_screens_pressed.png b/src/android/app/src/main/res/drawable-hdpi/button_swap_screens_pressed.png new file mode 100644 index 0000000000..be07c65989 Binary files /dev/null and b/src/android/app/src/main/res/drawable-hdpi/button_swap_screens_pressed.png differ diff --git a/src/android/app/src/main/res/drawable-xhdpi/button_swap_screens.png b/src/android/app/src/main/res/drawable-xhdpi/button_swap_screens.png new file mode 100644 index 0000000000..613b840c7b Binary files /dev/null and b/src/android/app/src/main/res/drawable-xhdpi/button_swap_screens.png differ diff --git a/src/android/app/src/main/res/drawable-xhdpi/button_swap_screens_pressed.png b/src/android/app/src/main/res/drawable-xhdpi/button_swap_screens_pressed.png new file mode 100644 index 0000000000..02b4e4e2f8 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xhdpi/button_swap_screens_pressed.png differ diff --git a/src/android/app/src/main/res/drawable-xxhdpi/button_swap_screens.png b/src/android/app/src/main/res/drawable-xxhdpi/button_swap_screens.png new file mode 100644 index 0000000000..f92effc581 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxhdpi/button_swap_screens.png differ diff --git a/src/android/app/src/main/res/drawable-xxhdpi/button_swap_screens_pressed.png b/src/android/app/src/main/res/drawable-xxhdpi/button_swap_screens_pressed.png new file mode 100644 index 0000000000..8092e175dc Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxhdpi/button_swap_screens_pressed.png differ diff --git a/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_screens.png b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_screens.png new file mode 100644 index 0000000000..a9fbe68828 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_screens.png differ diff --git a/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_screens_pressed.png b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_screens_pressed.png new file mode 100644 index 0000000000..b17a9fa0e0 Binary files /dev/null and b/src/android/app/src/main/res/drawable-xxxhdpi/button_swap_screens_pressed.png differ diff --git a/src/android/app/src/main/res/menu/menu_overlay_options.xml b/src/android/app/src/main/res/menu/menu_overlay_options.xml index e80f17c792..00a110d545 100644 --- a/src/android/app/src/main/res/menu/menu_overlay_options.xml +++ b/src/android/app/src/main/res/menu/menu_overlay_options.xml @@ -76,6 +76,9 @@ + diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index 3bce9c7f93..53d5e87aa6 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_screens diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml index 211234c77a..88b6c8b6cd 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 0fcee9589b..562346ef6e 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