From 0ddc5db96790707687a14d35a1d4da45c550ed89 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Sun, 6 Jun 2021 10:13:40 +0200 Subject: [PATCH] - Reset state will now only send an input when necesarry. --- .../customcontrols/gamepad/GamepadButton.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java index f7f513ce6..f502ff60f 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java @@ -5,12 +5,12 @@ import android.view.KeyEvent; public class GamepadButton { /* - Just a simple button, that auto deal with the great habit from android to just SPAAAM input events + Just a simple button, that auto deal with the great habit from android to just SPAAAMS input events */ public int[] keycodes; public boolean isToggleable = false; private boolean isDown = false; - private boolean toggled = false; + private boolean isToggled = false; public void update(KeyEvent event){ boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN); @@ -22,23 +22,25 @@ public class GamepadButton { isDown = isKeyDown; if(isToggleable){ if(isKeyDown){ - toggled = !toggled; - Gamepad.sendInput(keycodes, toggled); + isToggled = !isToggled; + Gamepad.sendInput(keycodes, isToggled); } return; } - Gamepad.sendInput(keycodes, isDown); } } public void resetButtonState(){ + if(isDown || isToggled){ + Gamepad.sendInput(keycodes, false); + } isDown = false; - toggled = false; - Gamepad.sendInput(keycodes, false); + isToggled = false; } + public boolean isDown(){ - return isToggleable ? toggled : isDown; + return isToggleable ? isToggled : isDown; } }