Android: new overlay button to swap screens (#51)
Co-authored-by: gperrio <guillaume.perrio@ingenico.com> Co-authored-by: OpenSauce04 <opensauce04@gmail.com>
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
|
BIN
src/android/app/src/main/res/drawable-hdpi/button_swap.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 4.2 KiB |
BIN
src/android/app/src/main/res/drawable-xhdpi/button_swap.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 5.6 KiB |
BIN
src/android/app/src/main/res/drawable-xxhdpi/button_swap.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
After Width: | Height: | Size: 8.3 KiB |
BIN
src/android/app/src/main/res/drawable-xxxhdpi/button_swap.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.3 KiB |
@ -78,6 +78,7 @@
|
||||
<item>@string/controller_circlepad</item>
|
||||
<item>@string/controller_c</item>
|
||||
<item>@string/button_home</item>
|
||||
<item>@string/button_swap</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="cameraImageSourceNames">
|
||||
|
@ -31,6 +31,8 @@
|
||||
<integer name="N3DS_BUTTON_START_Y">850</integer>
|
||||
<integer name="N3DS_BUTTON_HOME_X">510</integer>
|
||||
<integer name="N3DS_BUTTON_HOME_Y">850</integer>
|
||||
<integer name="N3DS_BUTTON_SWAP_X">370</integer>
|
||||
<integer name="N3DS_BUTTON_SWAP_Y">850</integer>
|
||||
|
||||
<!-- Default N3DS portrait layout -->
|
||||
<integer name="N3DS_BUTTON_A_PORTRAIT_X">810</integer>
|
||||
@ -61,5 +63,7 @@
|
||||
<integer name="N3DS_BUTTON_SELECT_PORTRAIT_Y">794</integer>
|
||||
<integer name="N3DS_BUTTON_START_PORTRAIT_X">520</integer>
|
||||
<integer name="N3DS_BUTTON_START_PORTRAIT_Y">794</integer>
|
||||
<integer name="N3DS_BUTTON_SWAP_PORTRAIT_X">460</integer>
|
||||
<integer name="N3DS_BUTTON_SWAP_PORTRAIT_Y">675</integer>
|
||||
|
||||
</resources>
|
||||
|
@ -121,6 +121,7 @@
|
||||
<string name="button_select" translatable="false">SELECT</string>
|
||||
<string name="button_start" translatable="false">START</string>
|
||||
<string name="button_home">HOME</string>
|
||||
<string name="button_swap">Swap Screens</string>
|
||||
<string name="button_x" translatable="false">X</string>
|
||||
<string name="button_y" translatable="false">Y</string>
|
||||
<string name="button_l" translatable="false">L</string>
|
||||
|