android: Add turbo speed hotkey touch controls overlay button (#911)

* android: Add turbo speed hotkey touch controls overlay

* Adjusted default controller overlay location of turbo button

* Changed "Turbo Speed" overlay button to simply be referred to as "Turbo"

---------

Co-authored-by: OpenSauce04 <opensauce04@gmail.com>
This commit is contained in:
Briar 2025-04-12 23:59:53 +02:00 committed by GitHub
parent 14413d896f
commit 8dcef46a11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 50 additions and 6 deletions

View File

@ -773,6 +773,7 @@ object NativeLibrary {
const val BUTTON_DEBUG = 781 const val BUTTON_DEBUG = 781
const val BUTTON_GPIO14 = 782 const val BUTTON_GPIO14 = 782
const val BUTTON_SWAP = 800 const val BUTTON_SWAP = 800
const val BUTTON_TURBO = 801
} }
/** /**

View File

@ -52,7 +52,7 @@ class EmulationActivity : AppCompatActivity() {
get() = PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext) get() = PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
var isActivityRecreated = false var isActivityRecreated = false
private val emulationViewModel: EmulationViewModel by viewModels() private val emulationViewModel: EmulationViewModel by viewModels()
private val settingsViewModel: SettingsViewModel by viewModels() val settingsViewModel: SettingsViewModel by viewModels()
private lateinit var binding: ActivityEmulationBinding private lateinit var binding: ActivityEmulationBinding
private lateinit var screenAdjustmentUtil: ScreenAdjustmentUtil private lateinit var screenAdjustmentUtil: ScreenAdjustmentUtil

View File

@ -954,12 +954,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
private fun showToggleControlsDialog() { private fun showToggleControlsDialog() {
val editor = preferences.edit() val editor = preferences.edit()
val enabledButtons = BooleanArray(15) val enabledButtons = BooleanArray(16)
enabledButtons.forEachIndexed { i: Int, _: Boolean -> enabledButtons.forEachIndexed { i: Int, _: Boolean ->
// Buttons that are disabled by default // Buttons that are disabled by default
var defaultValue = true var defaultValue = true
when (i) { when (i) {
6, 7, 12, 13, 14 -> defaultValue = false 6, 7, 12, 13, 14, 15 -> defaultValue = false
} }
enabledButtons[i] = preferences.getBoolean("buttonToggle$i", defaultValue) enabledButtons[i] = preferences.getBoolean("buttonToggle$i", defaultValue)
} }
@ -1137,10 +1137,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
.apply() .apply()
val editor = preferences.edit() val editor = preferences.edit()
for (i in 0 until 15) { for (i in 0 until 16) {
var defaultValue = true var defaultValue = true
when (i) { when (i) {
6, 7, 12, 13, 14 -> defaultValue = false 6, 7, 12, 13, 14, 15 -> defaultValue = false
} }
editor.putBoolean("buttonToggle$i", defaultValue) editor.putBoolean("buttonToggle$i", defaultValue)
} }

View File

@ -1,4 +1,4 @@
// Copyright 2023 Citra Emulator Project // Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -24,6 +24,7 @@ import androidx.preference.PreferenceManager
import org.citra.citra_emu.CitraApplication import org.citra.citra_emu.CitraApplication
import org.citra.citra_emu.NativeLibrary import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.R import org.citra.citra_emu.R
import org.citra.citra_emu.features.hotkeys.HotkeyFunctions
import org.citra.citra_emu.utils.EmulationMenuSettings import org.citra.citra_emu.utils.EmulationMenuSettings
import java.lang.NullPointerException import java.lang.NullPointerException
import kotlin.math.min import kotlin.math.min
@ -44,6 +45,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
private var buttonBeingConfigured: InputOverlayDrawableButton? = null private var buttonBeingConfigured: InputOverlayDrawableButton? = null
private var dpadBeingConfigured: InputOverlayDrawableDpad? = null private var dpadBeingConfigured: InputOverlayDrawableDpad? = null
private var joystickBeingConfigured: InputOverlayDrawableJoystick? = null private var joystickBeingConfigured: InputOverlayDrawableJoystick? = null
private val settingsViewModel = NativeLibrary.sEmulationActivity.get()!!.settingsViewModel
private val hotkeyFunctions = HotkeyFunctions(settingsViewModel.settings)
// Stores the ID of the pointer that interacted with the 3DS touchscreen. // Stores the ID of the pointer that interacted with the 3DS touchscreen.
private var touchscreenPointerId = -1 private var touchscreenPointerId = -1
@ -104,6 +107,11 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
swapScreen() swapScreen()
} }
if (button.id == NativeLibrary.ButtonType.BUTTON_TURBO && button.status == NativeLibrary.ButtonState.PRESSED) {
hotkeyFunctions.setTurboSpeed((!hotkeyFunctions.isTurboSpeedEnabled))
}
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.id, button.status) NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.id, button.status)
shouldUpdateView = true shouldUpdateView = true
} }
@ -468,6 +476,18 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
) )
) )
} }
if (preferences.getBoolean("buttonToggle15", false)) {
overlayButtons.add(
initializeOverlayButton(
context,
R.drawable.button_turbo,
R.drawable.button_turbo_pressed,
NativeLibrary.ButtonType.BUTTON_TURBO,
orientation
)
)
}
} }
fun refreshControls() { fun refreshControls() {
@ -673,6 +693,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
NativeLibrary.ButtonType.BUTTON_SWAP.toString() + "-Y", NativeLibrary.ButtonType.BUTTON_SWAP.toString() + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_SWAP_Y).toFloat() / 1000 * maxY resources.getInteger(R.integer.N3DS_BUTTON_SWAP_Y).toFloat() / 1000 * maxY
) )
.putFloat(
NativeLibrary.ButtonType.BUTTON_TURBO.toString() + "-X",
resources.getInteger(R.integer.N3DS_BUTTON_TURBO_X).toFloat() / 1000 * maxX
)
.putFloat(
NativeLibrary.ButtonType.BUTTON_TURBO.toString() + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_TURBO_Y).toFloat() / 1000 * maxY
)
.apply() .apply()
} }
@ -816,6 +844,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
NativeLibrary.ButtonType.BUTTON_SWAP.toString() + portrait + "-Y", NativeLibrary.ButtonType.BUTTON_SWAP.toString() + portrait + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_SWAP_PORTRAIT_Y).toFloat() / 1000 * maxY resources.getInteger(R.integer.N3DS_BUTTON_SWAP_PORTRAIT_Y).toFloat() / 1000 * maxY
) )
.putFloat(
NativeLibrary.ButtonType.BUTTON_TURBO.toString() + portrait + "-X",
resources.getInteger(R.integer.N3DS_BUTTON_TURBO_PORTRAIT_X).toFloat() / 1000 * maxX
)
.putFloat(
NativeLibrary.ButtonType.BUTTON_TURBO.toString() + portrait + "-Y",
resources.getInteger(R.integer.N3DS_BUTTON_TURBO_PORTRAIT_Y).toFloat() / 1000 * maxY
)
.apply() .apply()
} }
@ -928,6 +964,7 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
NativeLibrary.ButtonType.BUTTON_START, NativeLibrary.ButtonType.BUTTON_START,
NativeLibrary.ButtonType.BUTTON_SELECT, NativeLibrary.ButtonType.BUTTON_SELECT,
NativeLibrary.ButtonType.BUTTON_SWAP -> 0.08f NativeLibrary.ButtonType.BUTTON_SWAP -> 0.08f
NativeLibrary.ButtonType.BUTTON_TURBO -> 0.10f
NativeLibrary.ButtonType.TRIGGER_L, NativeLibrary.ButtonType.TRIGGER_L,
NativeLibrary.ButtonType.TRIGGER_R, NativeLibrary.ButtonType.TRIGGER_R,

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -131,6 +131,7 @@
<item>@string/controller_c</item> <item>@string/controller_c</item>
<item>@string/button_home</item> <item>@string/button_home</item>
<item>@string/button_swap</item> <item>@string/button_swap</item>
<item>@string/button_turbo</item>
</string-array> </string-array>
<string-array name="cameraImageSourceNames"> <string-array name="cameraImageSourceNames">

View File

@ -33,6 +33,8 @@
<integer name="N3DS_BUTTON_HOME_Y">850</integer> <integer name="N3DS_BUTTON_HOME_Y">850</integer>
<integer name="N3DS_BUTTON_SWAP_X">370</integer> <integer name="N3DS_BUTTON_SWAP_X">370</integer>
<integer name="N3DS_BUTTON_SWAP_Y">850</integer> <integer name="N3DS_BUTTON_SWAP_Y">850</integer>
<integer name="N3DS_BUTTON_TURBO_X">630</integer>
<integer name="N3DS_BUTTON_TURBO_Y">850</integer>
<!-- Default N3DS portrait layout --> <!-- Default N3DS portrait layout -->
<integer name="N3DS_BUTTON_A_PORTRAIT_X">810</integer> <integer name="N3DS_BUTTON_A_PORTRAIT_X">810</integer>
@ -65,5 +67,7 @@
<integer name="N3DS_BUTTON_START_PORTRAIT_Y">794</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_X">460</integer>
<integer name="N3DS_BUTTON_SWAP_PORTRAIT_Y">675</integer> <integer name="N3DS_BUTTON_SWAP_PORTRAIT_Y">675</integer>
<integer name="N3DS_BUTTON_TURBO_PORTRAIT_X">453</integer>
<integer name="N3DS_BUTTON_TURBO_PORTRAIT_Y">720</integer>
</resources> </resources>

View File

@ -137,6 +137,7 @@
<string name="button_start" translatable="false">START</string> <string name="button_start" translatable="false">START</string>
<string name="button_home">HOME</string> <string name="button_home">HOME</string>
<string name="button_swap">Swap Screens</string> <string name="button_swap">Swap Screens</string>
<string name="button_turbo">Turbo</string>
<string name="button_x" translatable="false">X</string> <string name="button_x" translatable="false">X</string>
<string name="button_y" translatable="false">Y</string> <string name="button_y" translatable="false">Y</string>
<string name="button_l" translatable="false">L</string> <string name="button_l" translatable="false">L</string>