From fb34c4a469190cbcd436a10c8cf3102562d97faf Mon Sep 17 00:00:00 2001 From: fredboy Date: Wed, 24 Apr 2024 04:47:26 +0700 Subject: [PATCH] Fix touch controls --- .../mouse/CreativeInventoryScrollMouseInputHandler.kt | 10 ++++++---- .../SelectCreativeInventoryItemMouseInputHandler.kt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CreativeInventoryScrollMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CreativeInventoryScrollMouseInputHandler.kt index 52e9f62..01cc4e2 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CreativeInventoryScrollMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/CreativeInventoryScrollMouseInputHandler.kt @@ -1,6 +1,7 @@ package ru.deadsoftware.cavedroid.game.input.handler.mouse import com.badlogic.gdx.math.MathUtils +import ru.deadsoftware.cavedroid.MainConfig import ru.deadsoftware.cavedroid.game.GameItemsHolder import ru.deadsoftware.cavedroid.game.GameScope import ru.deadsoftware.cavedroid.game.GameUiWindow @@ -15,6 +16,7 @@ import kotlin.math.abs @GameScope class CreativeInventoryScrollMouseInputHandler @Inject constructor( + private val mainConfig: MainConfig, private val gameWindowsManager: GameWindowsManager, private val gameItemsHolder: GameItemsHolder, ) : IGameInputHandler { @@ -32,17 +34,17 @@ class CreativeInventoryScrollMouseInputHandler @Inject constructor( } private fun checkStartDragConditions(action: MouseInputAction): Boolean { - return action.actionKey is MouseInputActionKey.Left && + return (action.actionKey is MouseInputActionKey.Touch) && !action.actionKey.touchUp && !gameWindowsManager.isDragging } private fun checkEndDragConditions(action: MouseInputAction): Boolean { - return action.actionKey is MouseInputActionKey.Left && + return action.actionKey is MouseInputActionKey.Touch && action.actionKey.touchUp && gameWindowsManager.isDragging } private fun checkDragConditions(action: MouseInputAction): Boolean { - return action.actionKey is MouseInputActionKey.Dragged && + return mainConfig.isTouch && action.actionKey is MouseInputActionKey.Dragged && abs(action.screenY - dragStartY) >= DRAG_SENSITIVITY } @@ -73,7 +75,7 @@ class CreativeInventoryScrollMouseInputHandler @Inject constructor( override fun handle(action: MouseInputAction) { when (action.actionKey) { - is MouseInputActionKey.Left -> handleStartOrEndDrag(action) + is MouseInputActionKey.Touch -> handleStartOrEndDrag(action) is MouseInputActionKey.Dragged -> handleDrag(action) is MouseInputActionKey.Scroll -> handleScroll(action) else -> return diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCreativeInventoryItemMouseInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCreativeInventoryItemMouseInputHandler.kt index ddd71c4..e6fb732 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCreativeInventoryItemMouseInputHandler.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/input/handler/mouse/SelectCreativeInventoryItemMouseInputHandler.kt @@ -25,7 +25,7 @@ class SelectCreativeInventoryItemMouseInputHandler @Inject constructor( override fun checkConditions(action: MouseInputAction): Boolean { return gameWindowsManager.getCurrentWindow() == GameUiWindow.CREATIVE_INVENTORY && !gameWindowsManager.isDragging && - action.actionKey is MouseInputActionKey.Left && + (action.actionKey is MouseInputActionKey.Left || action.actionKey is MouseInputActionKey.Touch) && action.actionKey.touchUp && isInsideWindow(action, creativeInventoryTexture) } -- 2.29.2