mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-25 15:27:02 +02:00
fixes joypad overlay autohide during holding actions (#3337)
fixes joypad overlay autohide during holding actions suppose holding right to move character. that wouldn't clear autohide countdown, and it also would deny other touches to do so. i guess this was buried coz those who truly use joypad overlay don't use autohide. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3337 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: xbzk <xbzk@eden-emu.dev> Co-committed-by: xbzk <xbzk@eden-emu.dev>
This commit is contained in:
parent
291b5febec
commit
d72553f519
2 changed files with 47 additions and 20 deletions
|
|
@ -134,6 +134,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
private var amiiboLoadJob: Job? = null
|
private var amiiboLoadJob: Job? = null
|
||||||
|
|
||||||
private var wasInputOverlayAutoHidden = false
|
private var wasInputOverlayAutoHidden = false
|
||||||
|
private var overlayTouchActive = false
|
||||||
|
|
||||||
private val loadAmiiboLauncher =
|
private val loadAmiiboLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
|
||||||
|
|
@ -1123,6 +1124,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
amiiboLoadJob?.cancel()
|
amiiboLoadJob?.cancel()
|
||||||
amiiboLoadJob = null
|
amiiboLoadJob = null
|
||||||
|
_binding?.surfaceInputOverlay?.touchEventListener = null
|
||||||
_binding = null
|
_binding = null
|
||||||
isAmiiboPickerOpen = false
|
isAmiiboPickerOpen = false
|
||||||
}
|
}
|
||||||
|
|
@ -1173,10 +1175,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
}
|
}
|
||||||
binding.showStatsOverlayText.setVisible(showPerfOverlay)
|
binding.showStatsOverlayText.setVisible(showPerfOverlay)
|
||||||
if (showPerfOverlay) {
|
if (showPerfOverlay) {
|
||||||
val SYSTEM_FPS = 0
|
//val SYSTEM_FPS = 0
|
||||||
val FPS = 1
|
val FPS = 1
|
||||||
val FRAMETIME = 2
|
val FRAMETIME = 2
|
||||||
val SPEED = 3
|
//val SPEED = 3
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
perfStatsUpdater = {
|
perfStatsUpdater = {
|
||||||
if (emulationViewModel.emulationStarted.value &&
|
if (emulationViewModel.emulationStarted.value &&
|
||||||
|
|
@ -2000,46 +2002,63 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
|
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
if (showInputOverlay && isAdded && _binding != null) {
|
if (showInputOverlay && isAdded && _binding != null) {
|
||||||
autoHideOverlay()
|
if (overlayTouchActive) {
|
||||||
|
startOverlayAutoHideTimer(seconds)
|
||||||
|
} else {
|
||||||
|
autoHideOverlay()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, seconds * 1000L)
|
}, seconds * 1000L)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleScreenTap(isLongTap: Boolean) {
|
fun handleScreenTap(isLongTap: Boolean) {
|
||||||
|
if (!isAdded || _binding == null) return
|
||||||
if (binding.surfaceInputOverlay.isGamelessMode()) return
|
if (binding.surfaceInputOverlay.isGamelessMode()) return
|
||||||
|
if (!BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean()) return
|
||||||
val shouldProceed = BooleanSetting.ENABLE_INPUT_OVERLAY_AUTO_HIDE.getBoolean()
|
|
||||||
if (!shouldProceed) return
|
|
||||||
|
|
||||||
// failsafe
|
// failsafe
|
||||||
val autoHideSeconds = IntSetting.INPUT_OVERLAY_AUTO_HIDE.getInt()
|
val autoHideSeconds = IntSetting.INPUT_OVERLAY_AUTO_HIDE.getInt()
|
||||||
if (autoHideSeconds == 0) {
|
if (autoHideSeconds == 0) {
|
||||||
toggleOverlay(true)
|
toggleOverlay(true)
|
||||||
return
|
} else {
|
||||||
|
val showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
|
||||||
|
if (!showInputOverlay && !isLongTap && wasInputOverlayAutoHidden) {
|
||||||
|
toggleOverlay(true)
|
||||||
|
}
|
||||||
|
startOverlayAutoHideTimer(autoHideSeconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
val showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
|
|
||||||
if (!showInputOverlay && !isLongTap && wasInputOverlayAutoHidden) {
|
|
||||||
toggleOverlay(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
startOverlayAutoHideTimer(autoHideSeconds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeOverlayAutoHide() {
|
private fun initializeOverlayAutoHide() {
|
||||||
if (binding.surfaceInputOverlay.isGamelessMode()) {
|
if (!isAdded || _binding == null) return
|
||||||
return
|
if (binding.surfaceInputOverlay.isGamelessMode()) return
|
||||||
}
|
|
||||||
|
|
||||||
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 showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
|
val showInputOverlay = BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()
|
||||||
|
|
||||||
if (autoHideEnabled && showInputOverlay) {
|
if (autoHideEnabled && showInputOverlay) {
|
||||||
toggleOverlay(true)
|
toggleOverlay(true)
|
||||||
startOverlayAutoHideTimer(autoHideSeconds)
|
startOverlayAutoHideTimer(autoHideSeconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.surfaceInputOverlay.touchEventListener = { event ->
|
||||||
|
when (event.actionMasked) {
|
||||||
|
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> {
|
||||||
|
overlayTouchActive = true
|
||||||
|
handler.removeCallbacksAndMessages(null)
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> {
|
||||||
|
overlayTouchActive = event.pointerCount > 1
|
||||||
|
if (!overlayTouchActive) handleScreenTap(isLongTap = false)
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
|
overlayTouchActive = false
|
||||||
|
handleScreenTap(isLongTap = false)
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
overlayTouchActive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun autoHideOverlay() {
|
private fun autoHideOverlay() {
|
||||||
|
|
@ -2048,6 +2067,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleOverlay(enable: Boolean) {
|
fun toggleOverlay(enable: Boolean) {
|
||||||
|
if (!isAdded || _binding == null) return
|
||||||
if (enable == !BooleanSetting.SHOW_INPUT_OVERLAY.getBoolean()) {
|
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) {
|
if (!enable) {
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,9 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||||
|
|
||||||
var layout = OverlayLayout.Landscape
|
var layout = OverlayLayout.Landscape
|
||||||
|
|
||||||
|
// External listener for EmulationFragment joypad overlay auto-hide
|
||||||
|
var touchEventListener: ((MotionEvent) -> Unit)? = null
|
||||||
|
|
||||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||||
super.onLayout(changed, left, top, right, bottom)
|
super.onLayout(changed, left, top, right, bottom)
|
||||||
|
|
||||||
|
|
@ -138,6 +141,10 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
||||||
|
try {
|
||||||
|
touchEventListener?.invoke(event)
|
||||||
|
} catch (e: Exception) {}
|
||||||
|
|
||||||
if (inEditMode) {
|
if (inEditMode) {
|
||||||
return onTouchWhileEditing(event)
|
return onTouchWhileEditing(event)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue