android: Gamepads can now control the in-game menu

This commit is contained in:
OpenSauce04 2024-06-22 20:47:54 +01:00 committed by OpenSauce
parent 461c8c9574
commit 277914a873
2 changed files with 26 additions and 7 deletions

View File

@ -35,6 +35,7 @@ import io.github.lime3ds.android.display.ScreenAdjustmentUtil
import io.github.lime3ds.android.features.hotkeys.HotkeyUtility
import io.github.lime3ds.android.features.settings.model.SettingsViewModel
import io.github.lime3ds.android.features.settings.model.view.InputBindingSetting
import io.github.lime3ds.android.fragments.EmulationFragment
import io.github.lime3ds.android.fragments.MessageDialogFragment
import io.github.lime3ds.android.utils.ControllerMappingHelper
import io.github.lime3ds.android.utils.FileBrowserHelper
@ -49,14 +50,20 @@ class EmulationActivity : AppCompatActivity() {
get() = PreferenceManager.getDefaultSharedPreferences(LimeApplication.appContext)
private var foregroundService: Intent? = null
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?) {
@ -198,6 +205,10 @@ class EmulationActivity : AppCompatActivity() {
return false
}
if (emulationFragment.isDrawerOpen()) {
return super.dispatchKeyEvent(event)
}
val button =
preferences.getInt(InputBindingSetting.getInputButtonKey(event.keyCode), event.keyCode)
val action: Int = when (event.action) {
@ -236,11 +247,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)
}

View File

@ -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()