Skip to content

Commit

Permalink
android: Gamepads can now control the in-game menu
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenSauce04 authored and Gamer64ytb committed Jul 26, 2024
1 parent e9673fa commit 68360b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.citra.citra_emu.features.hotkeys.HotkeyUtility
import org.citra.citra_emu.features.settings.model.BooleanSetting
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
Expand All @@ -48,14 +49,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
}

override fun onCreate(savedInstanceState: Bundle?) {
ThemeUtil.setTheme(this)

Expand Down Expand Up @@ -183,6 +190,10 @@ class EmulationActivity : AppCompatActivity() {
return false
}

if (emulationFragment.isDrawerOpen()) {
return super.dispatchKeyEvent(event)
}

val button = preferences.getInt(InputBindingSetting.getInputButtonKey(event), event.scanCode)
val action: Int = when (event.action) {
KeyEvent.ACTION_DOWN -> {
Expand Down Expand Up @@ -220,11 +231,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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,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) {
Expand Down Expand Up @@ -413,6 +419,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
setInsets()
}

fun isDrawerOpen(): Boolean {
return binding.drawerLayout.isOpen
}

private fun togglePause() {
if(emulationState.isPaused) {
emulationState.unpause()
Expand Down

0 comments on commit 68360b5

Please sign in to comment.