Browse Source

[android, ui] joypad overlay show/hide overhaul + touchpad fix (#3315)

As stated by @PavelBARABANOV when joypad overlay was being hidden via quick toggle or autohides (time/input), touchpad was being disabled along (hiding via original show/hide checkbox was working ok).

This PR fixes this by centering all joypad overlay toggling paths, and using correct method to not disable touchpad.
Additionally, mirror state variable was removed for better sync, and also touching screen will only unhide if hiding was triggered via autohides.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3315
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: DraVee <dravee@eden-emu.dev>
Co-authored-by: xbzk <xbzk@eden-emu.dev>
Co-committed-by: xbzk <xbzk@eden-emu.dev>
pull/3331/head
xbzk 2 months ago
committed by crueter
parent
commit
8df41f06c7
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 2
      src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
  2. 81
      src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt

2
src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt

@ -582,7 +582,7 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener, InputManager
BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean() && BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean() &&
!BooleanSetting.HIDE_OVERLAY_ON_CONTROLLER_INPUT.getBoolean()) { !BooleanSetting.HIDE_OVERLAY_ON_CONTROLLER_INPUT.getBoolean()) {
fragment.handler.removeCallbacksAndMessages(null) fragment.handler.removeCallbacksAndMessages(null)
fragment.showOverlay()
fragment.toggleOverlay(true)
} }
} }
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {

81
src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt

@ -105,7 +105,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
private var socUpdater: (() -> Unit)? = null private var socUpdater: (() -> Unit)? = null
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
private var isOverlayVisible = true
private var controllerInputReceived = false private var controllerInputReceived = false
private var _binding: FragmentEmulationBinding? = null private var _binding: FragmentEmulationBinding? = null
@ -133,6 +133,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
private var isAmiiboPickerOpen = false private var isAmiiboPickerOpen = false
private var amiiboLoadJob: Job? = null private var amiiboLoadJob: Job? = null
private var wasInputOverlayAutoHidden = false
private val loadAmiiboLauncher = private val loadAmiiboLauncher =
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri -> registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
isAmiiboPickerOpen = false isAmiiboPickerOpen = false
@ -712,11 +714,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
updateQuickOverlayMenuEntry(newState) updateQuickOverlayMenuEntry(newState)
binding.surfaceInputOverlay.refreshControls() binding.surfaceInputOverlay.refreshControls()
// Sync view visibility with the setting // Sync view visibility with the setting
if (newState) {
showOverlay()
} else {
hideOverlay()
}
toggleOverlay(newState)
NativeConfig.saveGlobalConfig() NativeConfig.saveGlobalConfig()
true true
} }
@ -1164,7 +1162,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
private fun updateShowStatsOverlay() { private fun updateShowStatsOverlay() {
val showOverlay = BooleanSetting.SHOW_PERFORMANCE_OVERLAY.getBoolean()
val showPerfOverlay = BooleanSetting.SHOW_PERFORMANCE_OVERLAY.getBoolean()
binding.showStatsOverlayText.apply { binding.showStatsOverlayText.apply {
setTextColor( setTextColor(
MaterialColors.getColor( MaterialColors.getColor(
@ -1173,8 +1171,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
) )
) )
} }
binding.showStatsOverlayText.setVisible(showOverlay)
if (showOverlay) {
binding.showStatsOverlayText.setVisible(showPerfOverlay)
if (showPerfOverlay) {
val SYSTEM_FPS = 0 val SYSTEM_FPS = 0
val FPS = 1 val FPS = 1
val FRAMETIME = 2 val FRAMETIME = 2
@ -1351,7 +1349,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
} }
private fun updateSocOverlay() { private fun updateSocOverlay() {
val showOverlay = BooleanSetting.SHOW_SOC_OVERLAY.getBoolean()
val showSOCOverlay = BooleanSetting.SHOW_SOC_OVERLAY.getBoolean()
binding.showSocOverlayText.apply { binding.showSocOverlayText.apply {
setTextColor( setTextColor(
MaterialColors.getColor( MaterialColors.getColor(
@ -1360,9 +1358,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
) )
) )
} }
binding.showSocOverlayText.setVisible(showOverlay)
binding.showSocOverlayText.setVisible(showSOCOverlay)
if (showOverlay) {
if (showSOCOverlay) {
val sb = StringBuilder() val sb = StringBuilder()
socUpdater = { socUpdater = {
@ -1674,9 +1672,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
R.id.menu_show_overlay -> { R.id.menu_show_overlay -> {
it.isChecked = !it.isChecked it.isChecked = !it.isChecked
BooleanSetting.SHOW_INPUT_OVERLAY.setBoolean(it.isChecked)
updateQuickOverlayMenuEntry(it.isChecked)
binding.surfaceInputOverlay.refreshControls()
toggleOverlay(it.isChecked)
true true
} }
@ -2000,34 +1996,32 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
private fun startOverlayAutoHideTimer(seconds: Int) { private fun startOverlayAutoHideTimer(seconds: Int) {
handler.removeCallbacksAndMessages(null) handler.removeCallbacksAndMessages(null)
val showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
handler.postDelayed({ handler.postDelayed({
if (isOverlayVisible && isAdded && _binding != null) {
hideOverlay()
if (showInputOverlay && isAdded && _binding != null) {
autoHideOverlay()
} }
}, seconds * 1000L) }, seconds * 1000L)
} }
fun handleScreenTap(isLongTap: Boolean) { fun handleScreenTap(isLongTap: Boolean) {
if (binding.surfaceInputOverlay.isGamelessMode()) {
return
}
val autoHideSeconds = IntSetting.INPUT_OVERLAY_AUTO_HIDE.getInt()
val shouldProceed = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean() && BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean()
if (binding.surfaceInputOverlay.isGamelessMode()) return
if (!shouldProceed) {
return
}
val shouldProceed = BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean()
if (!shouldProceed) return
// failsafe // failsafe
val autoHideSeconds = IntSetting.INPUT_OVERLAY_AUTO_HIDE.getInt()
if (autoHideSeconds == 0) { if (autoHideSeconds == 0) {
showOverlay()
toggleOverlay(true)
return return
} }
if (!isOverlayVisible && !isLongTap) {
showOverlay()
val showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
if (!showInputOverlay && !isLongTap && wasInputOverlayAutoHidden) {
toggleOverlay(true)
} }
startOverlayAutoHideTimer(autoHideSeconds) startOverlayAutoHideTimer(autoHideSeconds)
@ -2040,28 +2034,31 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
val autoHideSeconds = IntSetting.INPUT_OVERLAY_AUTO_HIDE.getInt() val autoHideSeconds = IntSetting.INPUT_OVERLAY_AUTO_HIDE.getInt()
val autoHideEnabled = BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean() val autoHideEnabled = BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean()
val showOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
val showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
if (autoHideEnabled && showOverlay) {
showOverlay()
if (autoHideEnabled && showInputOverlay) {
toggleOverlay(true)
startOverlayAutoHideTimer(autoHideSeconds) startOverlayAutoHideTimer(autoHideSeconds)
} }
} }
private fun autoHideOverlay() {
toggleOverlay(false)
wasInputOverlayAutoHidden = true
}
fun showOverlay() {
if (!isOverlayVisible) {
isOverlayVisible = true
fun toggleOverlay(enable: Boolean) {
if (enable == !BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()) {
// Reset controller input flag so controller can hide overlay again // Reset controller input flag so controller can hide overlay again
if (!enable) {
controllerInputReceived = false controllerInputReceived = false
ViewUtils.showView(binding.surfaceInputOverlay, 500)
} }
if (enable) {
wasInputOverlayAutoHidden = false
} }
private fun hideOverlay() {
if (isOverlayVisible) {
isOverlayVisible = false
ViewUtils.hideView(binding.surfaceInputOverlay)
BooleanSetting.SHOW_INPUT_OVERLAY.setBoolean(enable)
updateQuickOverlayMenuEntry(enable)
binding.surfaceInputOverlay.refreshControls()
} }
} }
@ -2070,7 +2067,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
if (!BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()) return if (!BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()) return
if (controllerInputReceived) return if (controllerInputReceived) return
controllerInputReceived = true controllerInputReceived = true
hideOverlay()
autoHideOverlay()
} }
fun onControllerConnected() { fun onControllerConnected() {
@ -2081,6 +2078,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
if (!BooleanSetting.HIDE_OVERLAY_ON_CONTROLLER_INPUT.getBoolean()) return if (!BooleanSetting.HIDE_OVERLAY_ON_CONTROLLER_INPUT.getBoolean()) return
if (!BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()) return if (!BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()) return
controllerInputReceived = false controllerInputReceived = false
showOverlay()
toggleOverlay(true)
} }
} }
Loading…
Cancel
Save