- Reset state will now only send an input when necesarry.

This commit is contained in:
SerpentSpirale 2021-06-06 10:13:40 +02:00 committed by SerpentSpirale
parent 95fd415f94
commit 0ddc5db967

View File

@ -5,12 +5,12 @@ import android.view.KeyEvent;
public class GamepadButton { 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 int[] keycodes;
public boolean isToggleable = false; public boolean isToggleable = false;
private boolean isDown = false; private boolean isDown = false;
private boolean toggled = false; private boolean isToggled = false;
public void update(KeyEvent event){ public void update(KeyEvent event){
boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN); boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN);
@ -22,23 +22,25 @@ public class GamepadButton {
isDown = isKeyDown; isDown = isKeyDown;
if(isToggleable){ if(isToggleable){
if(isKeyDown){ if(isKeyDown){
toggled = !toggled; isToggled = !isToggled;
Gamepad.sendInput(keycodes, toggled); Gamepad.sendInput(keycodes, isToggled);
} }
return; return;
} }
Gamepad.sendInput(keycodes, isDown); Gamepad.sendInput(keycodes, isDown);
} }
} }
public void resetButtonState(){ public void resetButtonState(){
if(isDown || isToggled){
Gamepad.sendInput(keycodes, false);
}
isDown = false; isDown = false;
toggled = false; isToggled = false;
Gamepad.sendInput(keycodes, false);
} }
public boolean isDown(){ public boolean isDown(){
return isToggleable ? toggled : isDown; return isToggleable ? isToggled : isDown;
} }
} }