Revert "android: Gross disgusting awful workaround for #1267"

This reverts commit 106e994dbf31bfae503551326a1a4b0c48647fab.
This commit is contained in:
OpenSauce04 2025-08-10 23:38:30 +01:00 committed by OpenSauce
parent 2087f96e90
commit a964e63722
2 changed files with 58 additions and 78 deletions

View File

@ -97,82 +97,42 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
return onTouchWhileEditing(event) return onTouchWhileEditing(event)
} }
var hasActiveButtons = false
val pointerIndex = event.actionIndex val pointerIndex = event.actionIndex
val pointerId = event.getPointerId(pointerIndex) val pointerId = event.getPointerId(pointerIndex)
val xPosition = event.getX(pointerIndex).toInt()
val yPosition = event.getY(pointerIndex).toInt()
val motionEvent = event.action and MotionEvent.ACTION_MASK
val isActionDown =
motionEvent == MotionEvent.ACTION_DOWN || motionEvent == MotionEvent.ACTION_POINTER_DOWN
val isActionMove = motionEvent == MotionEvent.ACTION_MOVE
val isActionUp =
motionEvent == MotionEvent.ACTION_UP || motionEvent == MotionEvent.ACTION_POINTER_UP
var hasActiveButtons = false
var isAnyButtonSliding = false
for (button in overlayButtons) { for (button in overlayButtons) {
if (button.trackId == pointerId) { if (button.trackId == pointerId) {
hasActiveButtons = true hasActiveButtons = true
} break
if (button.isButtonSliding) {
if (isActionUp) {
// A touch event ended, so tell any buttons tracking sliding to stop
button.isButtonSliding = false
} else {
isAnyButtonSliding = true
}
} }
} }
var hasActiveDpad = false var hasActiveDpad = false
for (dpad in overlayDpads) { if (!hasActiveButtons) {
if (dpad.trackId == pointerId) { for (dpad in overlayDpads) {
hasActiveDpad = true if (dpad.trackId == pointerId) {
break hasActiveDpad = true
break
}
} }
} }
var hasActiveJoystick = false var hasActiveJoystick = false
for (joystick in overlayJoysticks) { if(!hasActiveButtons && !hasActiveDpad){
if (joystick.trackId == pointerId) { for (joystick in overlayJoysticks) {
hasActiveJoystick = true if (joystick.trackId == pointerId) {
break hasActiveJoystick = true
break
}
} }
} }
var shouldUpdateView = false var shouldUpdateView = false
if (!preferences.getBoolean("isTouchEnabled", true)) {
return true
}
if (isActionMove) {
var noneConsumed = true
for (i in 0 until event.pointerCount) {
val fingerId = event.getPointerId(i)
if (isTouchInputConsumed(fingerId)) {
noneConsumed = false
continue
}
NativeLibrary.onTouchMoved(xPosition.toFloat(), yPosition.toFloat())
}
if (noneConsumed && !isAnyButtonSliding) {
return true
}
}
if (isActionUp && !isTouchInputConsumed(pointerId)) {
NativeLibrary.onTouchEvent(0f, 0f, false)
}
var anyStateChanged = false
if(!hasActiveDpad && !hasActiveJoystick) { if(!hasActiveDpad && !hasActiveJoystick) {
for (button in overlayButtons) { for (button in overlayButtons) {
val stateChanged = button.updateStatus(event, hasActiveButtons, this) val stateChanged = button.updateStatus(event, hasActiveButtons, this)
if (!stateChanged) { if (!stateChanged) {
continue continue
} }
anyStateChanged = true
if (button.id == NativeLibrary.ButtonType.BUTTON_SWAP && button.status == NativeLibrary.ButtonState.PRESSED) { if (button.id == NativeLibrary.ButtonType.BUTTON_SWAP && button.status == NativeLibrary.ButtonState.PRESSED) {
swapScreen() swapScreen()
@ -202,7 +162,6 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
if (!stateChanged) { if (!stateChanged) {
continue continue
} }
anyStateChanged = true
NativeLibrary.onGamePadEvent( NativeLibrary.onGamePadEvent(
NativeLibrary.TouchScreenDevice, NativeLibrary.TouchScreenDevice,
@ -229,32 +188,56 @@ class InputOverlay(context: Context?, attrs: AttributeSet?) : SurfaceView(contex
} }
} }
for (joystick in overlayJoysticks) { if(!hasActiveDpad && !hasActiveButtons) {
val stateChanged = joystick.updateStatus(event, true, this) for (joystick in overlayJoysticks) {
if (!stateChanged) { val stateChanged = joystick.updateStatus(event, hasActiveJoystick, this)
continue if (!stateChanged) {
continue
}
val axisID = joystick.joystickId
NativeLibrary.onGamePadMoveEvent(
NativeLibrary.TouchScreenDevice,
axisID,
joystick.xAxis,
joystick.yAxis
)
shouldUpdateView = true
} }
anyStateChanged = true
val axisID = joystick.joystickId
NativeLibrary.onGamePadMoveEvent(
NativeLibrary.TouchScreenDevice,
axisID,
joystick.xAxis,
joystick.yAxis
)
shouldUpdateView = true
} }
if (shouldUpdateView) { if (shouldUpdateView) {
invalidate() invalidate()
} }
if (!anyStateChanged && isActionDown && !isTouchInputConsumed(pointerId)) { if (!preferences.getBoolean("isTouchEnabled", true)) {
NativeLibrary.onTouchEvent(xPosition.toFloat(), yPosition.toFloat(), true) return true
} }
val xPosition = event.getX(pointerIndex).toInt()
val yPosition = event.getY(pointerIndex).toInt()
val motionEvent = event.action and MotionEvent.ACTION_MASK
val isActionDown =
motionEvent == MotionEvent.ACTION_DOWN || motionEvent == MotionEvent.ACTION_POINTER_DOWN
val isActionMove = motionEvent == MotionEvent.ACTION_MOVE
val isActionUp =
motionEvent == MotionEvent.ACTION_UP || motionEvent == MotionEvent.ACTION_POINTER_UP
if (isActionDown && !isTouchInputConsumed(pointerId)) {
NativeLibrary.onTouchEvent(xPosition.toFloat(), yPosition.toFloat(), true)
}
if (isActionMove) {
for (i in 0 until event.pointerCount) {
val fingerId = event.getPointerId(i)
if (isTouchInputConsumed(fingerId)) {
continue
}
NativeLibrary.onTouchMoved(xPosition.toFloat(), yPosition.toFloat())
}
}
if (isActionUp && !isTouchInputConsumed(pointerId)) {
NativeLibrary.onTouchEvent(0f, 0f, false)
}
return true return true
} }

View File

@ -44,7 +44,6 @@ class InputOverlayDrawableButton(
val opacity: Int val opacity: Int
) { ) {
var trackId: Int var trackId: Int
var isButtonSliding: Boolean
private var isMotionFirstButton = false // mark the first activated button with the current motion private var isMotionFirstButton = false // mark the first activated button with the current motion
@ -62,7 +61,6 @@ class InputOverlayDrawableButton(
this.defaultStateBitmap = BitmapDrawable(res, defaultStateBitmap) this.defaultStateBitmap = BitmapDrawable(res, defaultStateBitmap)
this.pressedStateBitmap = BitmapDrawable(res, pressedStateBitmap) this.pressedStateBitmap = BitmapDrawable(res, pressedStateBitmap)
trackId = -1 trackId = -1
isButtonSliding = false
width = this.defaultStateBitmap.intrinsicWidth width = this.defaultStateBitmap.intrinsicWidth
height = this.defaultStateBitmap.intrinsicHeight height = this.defaultStateBitmap.intrinsicHeight
} }
@ -94,7 +92,7 @@ class InputOverlayDrawableButton(
if (trackId != pointerId) { if (trackId != pointerId) {
return false return false
} }
buttonUp(overlay, false) buttonUp(overlay)
return true return true
} }
@ -111,7 +109,7 @@ class InputOverlayDrawableButton(
if (buttonSliding == ButtonSlidingMode.Alternative.int && isMotionFirstButton) { if (buttonSliding == ButtonSlidingMode.Alternative.int && isMotionFirstButton) {
return false return false
} }
buttonUp(overlay, true) buttonUp(overlay)
return true return true
} else { } else {
// button was not yet pressed // button was not yet pressed
@ -134,11 +132,10 @@ class InputOverlayDrawableButton(
overlay.hapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) overlay.hapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
} }
private fun buttonUp(overlay: InputOverlay, _isButtonSliding: Boolean) { private fun buttonUp(overlay: InputOverlay) {
pressedState = false pressedState = false
isMotionFirstButton = false isMotionFirstButton = false
trackId = -1 trackId = -1
isButtonSliding = _isButtonSliding
overlay.hapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY_RELEASE) overlay.hapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY_RELEASE)
} }