mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 14:51:51 -04:00
Fix[input]: make scroll gesture and swap hand more consistent
This commit is contained in:
parent
0725de8386
commit
251e90c4b3
@ -93,8 +93,8 @@ public class Touchpad extends FrameLayout implements GrabListener{
|
||||
case MotionEvent.ACTION_MOVE: // 2
|
||||
//Scrolling feature
|
||||
if (!LauncherPreferences.PREF_DISABLE_GESTURES && !CallbackBridge.isGrabbing() && event.getPointerCount() >= 2) {
|
||||
int hScroll = ((int) (event.getX() - mScrollLastInitialX)) / FINGER_SCROLL_THRESHOLD;
|
||||
int vScroll = ((int) (event.getY() - mScrollLastInitialY)) / FINGER_SCROLL_THRESHOLD;
|
||||
int hScroll = (int) ((event.getX() - mScrollLastInitialX) / FINGER_SCROLL_THRESHOLD);
|
||||
int vScroll = (int) ((event.getY() - mScrollLastInitialY) / FINGER_SCROLL_THRESHOLD);
|
||||
|
||||
if(vScroll != 0 || hScroll != 0){
|
||||
CallbackBridge.sendScroll(hScroll, vScroll);
|
||||
|
@ -87,9 +87,7 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if(!CallbackBridge.isGrabbing()) return false;
|
||||
// Check if we are double-tapping to swap hands
|
||||
boolean hasDoubleTapped = mDoubleTapDetector.onTouchEvent(event);
|
||||
if(hasDoubleTapped && !LauncherPreferences.PREF_DISABLE_SWAP_HAND) CallbackBridge.sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_F);
|
||||
|
||||
// Check if we need to cancel the drop event
|
||||
int actionMasked = event.getActionMasked();
|
||||
@ -100,12 +98,16 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
|
||||
if(x < 0 || x > mWidth) return true;
|
||||
int hotbarIndex = (int)MathUtils.map(x, 0, mWidth, 0, HOTBAR_KEYS.length);
|
||||
// Check if the slot changed and we need to make a key press
|
||||
if(hotbarIndex == mLastIndex) return true;
|
||||
if(hotbarIndex == mLastIndex) {
|
||||
// Only check for doubletapping if the slot has not changed
|
||||
if(hasDoubleTapped && !LauncherPreferences.PREF_DISABLE_SWAP_HAND) CallbackBridge.sendKeyPress(LwjglGlfwKeycode.GLFW_KEY_F);
|
||||
return true;
|
||||
}
|
||||
mLastIndex = hotbarIndex;
|
||||
int hotbarKey = HOTBAR_KEYS[hotbarIndex];
|
||||
CallbackBridge.sendKeyPress(hotbarKey);
|
||||
// Cancel the event since we changed hotbar slots.
|
||||
mDropGesture.cancel();
|
||||
mDropGesture.cancel();
|
||||
// Only resubmit the gesture only if it isn't the last event we will receive.
|
||||
if(!isLastEventInGesture(actionMasked)) mDropGesture.submit();
|
||||
return true;
|
||||
|
@ -12,7 +12,7 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
||||
private final PointerTracker mTracker = new PointerTracker();
|
||||
private boolean mIsMouseDown = false;
|
||||
private final float mScaleFactor;
|
||||
public static final int FINGER_SCROLL_THRESHOLD = (int) Tools.dpToPx(6);
|
||||
public static final float FINGER_SCROLL_THRESHOLD = Tools.dpToPx(6);
|
||||
public InGUIEventProcessor(float scaleFactor) {
|
||||
mScaleFactor = scaleFactor;
|
||||
}
|
||||
@ -34,8 +34,8 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
||||
if(!mIsMouseDown) enableMouse();
|
||||
} else {
|
||||
float[] motionVector = mTracker.getMotionVector();
|
||||
int hScroll = ((int) motionVector[0]) / FINGER_SCROLL_THRESHOLD;
|
||||
int vScroll = ((int) motionVector[1]) / FINGER_SCROLL_THRESHOLD;
|
||||
int hScroll = (int)(motionVector[0] / FINGER_SCROLL_THRESHOLD);
|
||||
int vScroll = (int)(motionVector[1] / FINGER_SCROLL_THRESHOLD);
|
||||
if(hScroll != 0 | vScroll != 0) CallbackBridge.sendScroll(hScroll, vScroll);
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user