Add hotkey for 'quit to menu'

This commit is contained in:
amwatson 2024-02-12 13:16:36 -06:00
parent 70b23e1b71
commit ccb7bb207c
4 changed files with 29 additions and 5 deletions

View file

@ -41,6 +41,7 @@ import org.citra.citra_emu.utils.BirthdayMonth
import org.citra.citra_emu.utils.Log
import org.citra.citra_emu.utils.SystemSaveGame
import org.citra.citra_emu.utils.ThemeUtil
import org.citra.citra_emu.vr.utils.VRUtils
class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) {
private var menuTag: String? = null
@ -630,11 +631,11 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
}
// VR-SPECIFIC: just remove hotkeys for this version.
/* add(HeaderSetting(R.string.controller_hotkeys))
Settings.hotKeys.forEachIndexed { i: Int, key: String ->
add(HeaderSetting(R.string.controller_hotkeys))
VRUtils.hotKeys.forEachIndexed { i: Int, key: String ->
val button = getInputObject(key)
add(InputBindingSetting(button, Settings.hotkeyTitles[i]))
}*/
add(InputBindingSetting(button, VRUtils.hotkeyTitles[i]))
}
}
}

View file

@ -4,14 +4,22 @@
package org.citra.citra_emu.utils
import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.vr.VrActivity
object EmulationLifecycleUtil {
private var shutdownHooks: MutableList<Runnable> = ArrayList()
private var pauseResumeHooks: MutableList<Runnable> = ArrayList()
fun closeGame() {
val activity = NativeLibrary.sEmulationActivity.get()
if (activity != null && activity is VrActivity) {
activity.quitToMenu()
} else {
shutdownHooks.forEach(Runnable::run)
}
}
fun pauseOrResume() {
pauseResumeHooks.forEach(Runnable::run)

View file

@ -113,6 +113,12 @@ class VrActivity : EmulationActivity() {
runOnUiThread(clickRunnable)
}
fun quitToMenu() {
finish()
val relaunchMainIntent = Intent(this, MainActivity::class.java)
startActivity(relaunchMainIntent)
}
fun pauseGame() {
Log.info("VR [Java] pauseGame");
if (NativeLibrary.isRunning()) { NativeLibrary.pauseEmulation(); }

View file

@ -2,6 +2,8 @@ package org.citra.citra_emu.vr.utils
import android.view.KeyEvent
import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.R
import org.citra.citra_emu.features.settings.model.Settings
object VRUtils {
val hMDType: Int
@ -19,6 +21,13 @@ object VRUtils {
}
val hotKeys = listOf(
Settings.HOTKEY_CLOSE_GAME,
)
val hotkeyTitles = listOf(
R.string.emulation_close_game,
)
// Not really VR-related, but for some reason, Citra doesn't have default mappings for gamepad
enum class ButtonType(val nativeLibrary: Int, val android: Int) {
BUTTON_A(NativeLibrary.ButtonType.BUTTON_A, KeyEvent.KEYCODE_BUTTON_A),