mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2025-03-08 08:27:57 +01:00
android: Gamepads can now control the in-game menu
This commit is contained in:
parent
61c4d324a9
commit
6a8fa2c402
@ -35,6 +35,7 @@ import org.citra.citra_emu.display.ScreenAdjustmentUtil
|
||||
import org.citra.citra_emu.features.hotkeys.HotkeyUtility
|
||||
import org.citra.citra_emu.features.settings.model.SettingsViewModel
|
||||
import org.citra.citra_emu.features.settings.model.view.InputBindingSetting
|
||||
import org.citra.citra_emu.fragments.EmulationFragment
|
||||
import org.citra.citra_emu.fragments.MessageDialogFragment
|
||||
import org.citra.citra_emu.utils.ControllerMappingHelper
|
||||
import org.citra.citra_emu.utils.FileBrowserHelper
|
||||
@ -47,14 +48,20 @@ class EmulationActivity : AppCompatActivity() {
|
||||
private val preferences: SharedPreferences
|
||||
get() = PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
|
||||
var isActivityRecreated = false
|
||||
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
private val emulationViewModel: EmulationViewModel by viewModels()
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
|
||||
private lateinit var binding: ActivityEmulationBinding
|
||||
private lateinit var screenAdjustmentUtil: ScreenAdjustmentUtil
|
||||
private lateinit var hotkeyUtility: HotkeyUtility
|
||||
|
||||
private val emulationFragment: EmulationFragment
|
||||
get() {
|
||||
val navHostFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
|
||||
return navHostFragment.getChildFragmentManager().fragments.last() as EmulationFragment
|
||||
}
|
||||
|
||||
private var isEmulationRunning: Boolean = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -196,7 +203,12 @@ class EmulationActivity : AppCompatActivity() {
|
||||
return false
|
||||
}
|
||||
|
||||
val button = preferences.getInt(InputBindingSetting.getInputButtonKey(event), event.scanCode)
|
||||
if (emulationFragment.isDrawerOpen()) {
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
val button =
|
||||
preferences.getInt(InputBindingSetting.getInputButtonKey(event.keyCode), event.keyCode)
|
||||
val action: Int = when (event.action) {
|
||||
KeyEvent.ACTION_DOWN -> {
|
||||
// On some devices, the back gesture / button press is not intercepted by androidx
|
||||
@ -233,11 +245,9 @@ class EmulationActivity : AppCompatActivity() {
|
||||
|
||||
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||
// TODO: Move this check into native code - prevents crash if input pressed before starting emulation
|
||||
if (!NativeLibrary.isRunning()) {
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
if (event.source and InputDevice.SOURCE_CLASS_JOYSTICK == 0) {
|
||||
if (!NativeLibrary.isRunning() ||
|
||||
(event.source and InputDevice.SOURCE_CLASS_JOYSTICK == 0) ||
|
||||
emulationFragment.isDrawerOpen()) {
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
|
@ -190,10 +190,16 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
|
||||
override fun onDrawerOpened(drawerView: View) {
|
||||
binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
||||
binding.surfaceInputOverlay.isClickable = false
|
||||
binding.surfaceInputOverlay.isFocusable = false
|
||||
binding.surfaceInputOverlay.isFocusableInTouchMode = false
|
||||
}
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
binding.drawerLayout.setDrawerLockMode(EmulationMenuSettings.drawerLockMode)
|
||||
binding.surfaceInputOverlay.isClickable = true
|
||||
binding.surfaceInputOverlay.isFocusable = true
|
||||
binding.surfaceInputOverlay.isFocusableInTouchMode = true
|
||||
}
|
||||
|
||||
override fun onDrawerStateChanged(newState: Int) {
|
||||
@ -412,6 +418,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
||||
setInsets()
|
||||
}
|
||||
|
||||
fun isDrawerOpen(): Boolean {
|
||||
return binding.drawerLayout.isOpen
|
||||
}
|
||||
|
||||
private fun togglePause() {
|
||||
if(emulationState.isPaused) {
|
||||
emulationState.unpause()
|
||||
|
Loading…
x
Reference in New Issue
Block a user