mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 07:05:40 -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
|
case MotionEvent.ACTION_MOVE: // 2
|
||||||
//Scrolling feature
|
//Scrolling feature
|
||||||
if (!LauncherPreferences.PREF_DISABLE_GESTURES && !CallbackBridge.isGrabbing() && event.getPointerCount() >= 2) {
|
if (!LauncherPreferences.PREF_DISABLE_GESTURES && !CallbackBridge.isGrabbing() && event.getPointerCount() >= 2) {
|
||||||
int hScroll = ((int) (event.getX() - mScrollLastInitialX)) / FINGER_SCROLL_THRESHOLD;
|
int hScroll = (int) ((event.getX() - mScrollLastInitialX) / FINGER_SCROLL_THRESHOLD);
|
||||||
int vScroll = ((int) (event.getY() - mScrollLastInitialY)) / FINGER_SCROLL_THRESHOLD;
|
int vScroll = (int) ((event.getY() - mScrollLastInitialY) / FINGER_SCROLL_THRESHOLD);
|
||||||
|
|
||||||
if(vScroll != 0 || hScroll != 0){
|
if(vScroll != 0 || hScroll != 0){
|
||||||
CallbackBridge.sendScroll(hScroll, vScroll);
|
CallbackBridge.sendScroll(hScroll, vScroll);
|
||||||
|
@ -87,9 +87,7 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
|
|||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if(!CallbackBridge.isGrabbing()) return false;
|
if(!CallbackBridge.isGrabbing()) return false;
|
||||||
// Check if we are double-tapping to swap hands
|
|
||||||
boolean hasDoubleTapped = mDoubleTapDetector.onTouchEvent(event);
|
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
|
// Check if we need to cancel the drop event
|
||||||
int actionMasked = event.getActionMasked();
|
int actionMasked = event.getActionMasked();
|
||||||
@ -100,12 +98,16 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
|
|||||||
if(x < 0 || x > mWidth) return true;
|
if(x < 0 || x > mWidth) return true;
|
||||||
int hotbarIndex = (int)MathUtils.map(x, 0, mWidth, 0, HOTBAR_KEYS.length);
|
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
|
// 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;
|
mLastIndex = hotbarIndex;
|
||||||
int hotbarKey = HOTBAR_KEYS[hotbarIndex];
|
int hotbarKey = HOTBAR_KEYS[hotbarIndex];
|
||||||
CallbackBridge.sendKeyPress(hotbarKey);
|
CallbackBridge.sendKeyPress(hotbarKey);
|
||||||
// Cancel the event since we changed hotbar slots.
|
// 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.
|
// Only resubmit the gesture only if it isn't the last event we will receive.
|
||||||
if(!isLastEventInGesture(actionMasked)) mDropGesture.submit();
|
if(!isLastEventInGesture(actionMasked)) mDropGesture.submit();
|
||||||
return true;
|
return true;
|
||||||
|
@ -12,7 +12,7 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
|||||||
private final PointerTracker mTracker = new PointerTracker();
|
private final PointerTracker mTracker = new PointerTracker();
|
||||||
private boolean mIsMouseDown = false;
|
private boolean mIsMouseDown = false;
|
||||||
private final float mScaleFactor;
|
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) {
|
public InGUIEventProcessor(float scaleFactor) {
|
||||||
mScaleFactor = scaleFactor;
|
mScaleFactor = scaleFactor;
|
||||||
}
|
}
|
||||||
@ -34,8 +34,8 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
|||||||
if(!mIsMouseDown) enableMouse();
|
if(!mIsMouseDown) enableMouse();
|
||||||
} else {
|
} else {
|
||||||
float[] motionVector = mTracker.getMotionVector();
|
float[] motionVector = mTracker.getMotionVector();
|
||||||
int hScroll = ((int) motionVector[0]) / FINGER_SCROLL_THRESHOLD;
|
int hScroll = (int)(motionVector[0] / FINGER_SCROLL_THRESHOLD);
|
||||||
int vScroll = ((int) motionVector[1]) / FINGER_SCROLL_THRESHOLD;
|
int vScroll = (int)(motionVector[1] / FINGER_SCROLL_THRESHOLD);
|
||||||
if(hScroll != 0 | vScroll != 0) CallbackBridge.sendScroll(hScroll, vScroll);
|
if(hScroll != 0 | vScroll != 0) CallbackBridge.sendScroll(hScroll, vScroll);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user