Skip to content

Commit

Permalink
Feat[input]: interrupt dropping when switching hotbar slots + endless…
Browse files Browse the repository at this point in the history
… dropping
  • Loading branch information
artdeell committed Apr 6, 2024
1 parent 925690d commit e5c0555
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@
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();
}

@Override
public boolean checkAndTrigger() {
if(mGuiBarHit) sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_Q);
return true;
public void cancel() {
mActive = false;
mHandler.removeCallbacks(this);
}

@Override
public void onGestureCancelled(boolean isSwitching) {}
public void run() {
if(!mActive) return;
sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_Q);
mHandler.postDelayed(this, 250);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void checkGestures(boolean hasGuiBarHit) {
private void cancelGestures(boolean isSwitching) {
mLeftClickGesture.cancel(isSwitching);
mRightClickGesture.cancel(isSwitching);
mDropGesture.cancel(isSwitching);
mDropGesture.cancel();
}

private boolean handleGuiBar(MotionEvent motionEvent) {
Expand All @@ -106,6 +106,9 @@ private boolean handleGuiBar(MotionEvent motionEvent) {
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;
Expand Down

0 comments on commit e5c0555

Please sign in to comment.