Feat[input]: interrupt dropping when switching hotbar slots + endless dropping

This commit is contained in:
artdeell 2024-04-06 12:22:03 -04:00 committed by Maksim Belov
parent 1fdb483c1f
commit e89c409807
2 changed files with 24 additions and 12 deletions

View File

@ -5,24 +5,33 @@ import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
import android.os.Handler;
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
public class DropGesture implements Runnable{
private final Handler mHandler;
private boolean mActive;
public class DropGesture extends ValidatorGesture {
public DropGesture(Handler mHandler) {
super(mHandler, 250);
this.mHandler = mHandler;
}
boolean mGuiBarHit;
public void submit(boolean hasGuiBarHit) {
submit();
mGuiBarHit = hasGuiBarHit;
if(hasGuiBarHit && !mActive) {
mActive = true;
mHandler.postDelayed(this, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
}
if(!hasGuiBarHit && mActive) cancel();
}
public void cancel() {
mActive = false;
mHandler.removeCallbacks(this);
}
@Override
public boolean checkAndTrigger() {
if(mGuiBarHit) sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_Q);
return true;
public void run() {
if(!mActive) return;
sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_Q);
mHandler.postDelayed(this, 250);
}
@Override
public void onGestureCancelled(boolean isSwitching) {}
}

View File

@ -92,7 +92,7 @@ public class InGameEventProcessor implements TouchEventProcessor {
private void cancelGestures(boolean isSwitching) {
mLeftClickGesture.cancel(isSwitching);
mRightClickGesture.cancel(isSwitching);
mDropGesture.cancel(isSwitching);
mDropGesture.cancel();
}
private boolean handleGuiBar(MotionEvent motionEvent) {
@ -106,6 +106,9 @@ public class InGameEventProcessor implements TouchEventProcessor {
boolean hasGuiBarHit = hudKeyHandled != -1;
if(hasGuiBarHit && hudKeyHandled != mLastHudKey) {
CallbackBridge.sendKeyPress(hudKeyHandled);
// The GUI bar is handled before the gesture will be submitted, so this
// will be resubmitted again soon (with the timer restarted)
mDropGesture.cancel();
mLastHudKey = hudKeyHandled;
}
return hasGuiBarHit;