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>
@ -773,6 +773,7 @@ object NativeLibrary {
|
||||
const val BUTTON_DEBUG = 781
|
||||
const val BUTTON_GPIO14 = 782
|
||||
const val BUTTON_SWAP = 800
|
||||
const val BUTTON_TURBO = 801
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -52,7 +52,7 @@ class EmulationActivity : AppCompatActivity() {
|
||||
get() = PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
||||
var isActivityRecreated = false
|
||||
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 screenAdjustmentUtil: ScreenAdjustmentUtil
|
||||
|
||||
@ -954,12 +954,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
|
||||
private fun showToggleControlsDialog() {
|
||||
val editor = preferences.edit()
|
||||
val enabledButtons = BooleanArray(15)
|
||||
val enabledButtons = BooleanArray(16)
|
||||
enabledButtons.forEachIndexed { i: Int, _: Boolean ->
|
||||
// Buttons that are disabled by default
|
||||
var defaultValue = true
|
||||
when (i) {
|
||||
6, 7, 12, 13, 14 -> defaultValue = false
|
||||
6, 7, 12, 13, 14, 15 -> defaultValue = false
|
||||
}
|
||||
enabledButtons[i] = preferences.getBoolean("buttonToggle$i", defaultValue)
|
||||
}
|
||||
@ -1137,10 +1137,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
.apply()
|
||||
|
||||
val editor = preferences.edit()
|
||||
for (i in 0 until 15) {
|
||||
for (i in 0 until 16) {
|
||||
var defaultValue = true
|
||||
when (i) {
|
||||
6, 7, 12, 13, 14 -> defaultValue = false
|
||||
6, 7, 12, 13, 14, 15 -> defaultValue = false
|
||||
}
|
||||
editor.putBoolean("buttonToggle$i", defaultValue)
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Copyright 2023 Citra Emulator Project
|
||||
// Copyright Citra Emulator Project / Azahar Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// 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.NativeLibrary
|
||||
import org.citra.citra_emu.R
|
||||
import org.citra.citra_emu.features.hotkeys.HotkeyFunctions
|
||||
import org.citra.citra_emu.utils.EmulationMenuSettings
|
||||
import java.lang.NullPointerException
|
||||
import kotlin.math.min
|
||||
@ -44,6 +45,8 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
private var buttonBeingConfigured: InputOverlayDrawableButton? = null
|
||||
private var dpadBeingConfigured: InputOverlayDrawableDpad? = 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.
|
||||
private var touchscreenPointerId = -1
|
||||
@ -104,6 +107,11 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
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)
|
||||
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() {
|
||||
@ -673,6 +693,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
NativeLibrary.ButtonType.BUTTON_SWAP.toString() + "-Y",
|
||||
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()
|
||||
}
|
||||
|
||||
@ -816,6 +844,14 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
NativeLibrary.ButtonType.BUTTON_SWAP.toString() + portrait + "-Y",
|
||||
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()
|
||||
}
|
||||
|
||||
@ -928,6 +964,7 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
|
||||
NativeLibrary.ButtonType.BUTTON_START,
|
||||
NativeLibrary.ButtonType.BUTTON_SELECT,
|
||||
NativeLibrary.ButtonType.BUTTON_SWAP -> 0.08f
|
||||
NativeLibrary.ButtonType.BUTTON_TURBO -> 0.10f
|
||||
|
||||
NativeLibrary.ButtonType.TRIGGER_L,
|
||||
NativeLibrary.ButtonType.TRIGGER_R,
|
||||
|
||||
BIN
src/android/app/src/main/res/drawable-hdpi/button_turbo.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
BIN
src/android/app/src/main/res/drawable-xhdpi/button_turbo.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
BIN
src/android/app/src/main/res/drawable-xxhdpi/button_turbo.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
BIN
src/android/app/src/main/res/drawable-xxxhdpi/button_turbo.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
@ -131,6 +131,7 @@
|
||||
<item>@string/controller_c</item>
|
||||
<item>@string/button_home</item>
|
||||
<item>@string/button_swap</item>
|
||||
<item>@string/button_turbo</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="cameraImageSourceNames">
|
||||
|
||||
@ -33,6 +33,8 @@
|
||||
<integer name="N3DS_BUTTON_HOME_Y">850</integer>
|
||||
<integer name="N3DS_BUTTON_SWAP_X">370</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 -->
|
||||
<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_SWAP_PORTRAIT_X">460</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>
|
||||
|
||||
@ -137,6 +137,7 @@
|
||||
<string name="button_start" translatable="false">START</string>
|
||||
<string name="button_home">HOME</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_y" translatable="false">Y</string>
|
||||
<string name="button_l" translatable="false">L</string>
|
||||
|
||||