- [Custom controls] Changed some maths in calculating generated control.
- [Custom controls design] Try to fix hold issue.
- [ingame] Try to fix pointer capture issue.
This commit is contained in:
khanhduytran0 2020-11-20 20:36:46 +07:00
parent ec819ba538
commit 1373a76e74
5 changed files with 106 additions and 114 deletions

View File

@ -311,14 +311,14 @@ public abstract class HandleView extends View implements ViewPositionListener, V
return 0;
}
// MOD: Addition
// Addition
@Override
public boolean onLongClick(View view) {
showActionPopupWindow(0);
return true;
}
// MOD: Addition
// Addition
private float mDownX, mDownY;
@Override

View File

@ -83,7 +83,6 @@ public class BaseMainActivity extends LoggableActivity {
private TextView debugText;
private PointerOreoWrapper pointerSurface;
private View.OnTouchListener pointerCaptureListener;
// private String mQueueText = new String();
@ -529,112 +528,104 @@ public class BaseMainActivity extends LoggableActivity {
// return !CallbackBridge.isGrabbing();
}
};
pointerCaptureListener = new OnTouchListener(){
private int x, y;
private boolean debugErrored = false;
private String getMoving(float pos, boolean xOrY) {
if (pos == 0) {
return "STOPPED";
} else if (pos > 0) {
return xOrY ? "RIGHT" : "DOWN";
} else { // if (pos3 < 0) {
return xOrY ? "LEFT" : "UP";
}
}
@Override
public boolean onTouch(View p1, MotionEvent e)
{
x += ((int) e.getX()) / scaleFactor;
y -= ((int) e.getY()) / scaleFactor;
if (debugText.getVisibility() == View.VISIBLE && !debugErrored) {
StringBuilder builder = new StringBuilder();
try {
builder.append("PointerCapture debug\n");
builder.append("MotionEvent=" + e.getActionMasked() + "\n");
builder.append("PressingBtn=" + MotionEvent.class.getDeclaredMethod("buttonStateToString").invoke(null, e.getButtonState()) + "\n\n");
builder.append("PointerX=" + e.getX() + "\n");
builder.append("PointerY=" + e.getY() + "\n");
builder.append("RawX=" + e.getRawX() + "\n");
builder.append("RawY=" + e.getRawY() + "\n\n");
builder.append("XPos=" + x + "\n");
builder.append("YPos=" + y + "\n\n");
builder.append("MovingX=" + getMoving(e.getX(), true) + "\n");
builder.append("MovingY=" + getMoving(e.getY(), false) + "\n");
} catch (Throwable th) {
debugErrored = true;
builder.append("Error getting debug. The debug will be stopped!\n" + Log.getStackTraceString(th));
} finally {
debugText.setText(builder.toString());
builder.setLength(0);
}
}
CallbackBridge.sendCursorPos(x, y);
switch (e.getButtonState()) {
case MotionEvent.BUTTON_PRIMARY: CallbackBridge.mouseLeft = true;
break;
case MotionEvent.BUTTON_SECONDARY: CallbackBridge.mouseLeft = false;
break;
}
switch (e.getActionMasked()) {
case MotionEvent.ACTION_DOWN: // 0
case MotionEvent.ACTION_POINTER_DOWN: // 5
CallbackBridge.sendPrepareGrabInitialPos();
CallbackBridge.sendMouseKeycode(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, 0, true);
initialX = x;
initialY = y;
sendMouseButton(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);
// theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
break;
case MotionEvent.ACTION_UP: // 1
case MotionEvent.ACTION_CANCEL: // 3
case MotionEvent.ACTION_POINTER_UP: // 6
// CallbackBridge.sendCursorPos(x, y);
// CallbackBridge.sendMouseKeycode(rightOverride ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, true);
CallbackBridge.putMouseEventWithCoords(CallbackBridge.mouseLeft /* rightOverride */ ? (byte) 0 : (byte) 1, (byte) 1, x, y);
/*
if (!triggeredLeftMouseButton && Math.abs(initialX - x) < fingerStillThreshold && Math.abs(initialY - y) < fingerStillThreshold) {
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, true);
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);
}
if (triggeredLeftMouseButton) {
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, false);
}
*/
sendMouseButton(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, true);
// triggeredLeftMouseButton = false;
// theHandler.removeMessages(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK);
break;
}
debugText.setText(CallbackBridge.DEBUG_STRING.toString());
CallbackBridge.DEBUG_STRING.setLength(0);
return true;
// If onClick fail with false, change back to true
}
};
if (isPointerCaptureSupported()) {
this.pointerSurface = new PointerOreoWrapper(minecraftGLView);
this.pointerSurface.setOnCapturedPointerListener(new PointerOreoWrapper.OnCapturedPointerListener(){
private int x, y;
private boolean debugErrored = false;
private String getMoving(float pos, boolean xOrY) {
if (pos == 0) {
return "STOPPED";
} else if (pos > 0) {
return xOrY ? "RIGHT" : "DOWN";
} else { // if (pos3 < 0) {
return xOrY ? "LEFT" : "UP";
}
}
@Override
public boolean onCapturedPointer(View view, MotionEvent event) {
return pointerCaptureListener.onTouch(view, event);
public boolean onCapturedPointer(View view, MotionEvent e) {
x += ((int) e.getX()) / scaleFactor;
y -= ((int) e.getY()) / scaleFactor;
if (debugText.getVisibility() == View.VISIBLE && !debugErrored) {
StringBuilder builder = new StringBuilder();
try {
builder.append("PointerCapture debug\n");
builder.append("MotionEvent=" + e.getActionMasked() + "\n");
builder.append("PressingBtn=" + MotionEvent.class.getDeclaredMethod("buttonStateToString").invoke(null, e.getButtonState()) + "\n\n");
builder.append("PointerX=" + e.getX() + "\n");
builder.append("PointerY=" + e.getY() + "\n");
builder.append("RawX=" + e.getRawX() + "\n");
builder.append("RawY=" + e.getRawY() + "\n\n");
builder.append("XPos=" + x + "\n");
builder.append("YPos=" + y + "\n\n");
builder.append("MovingX=" + getMoving(e.getX(), true) + "\n");
builder.append("MovingY=" + getMoving(e.getY(), false) + "\n");
} catch (Throwable th) {
debugErrored = true;
builder.append("Error getting debug. The debug will be stopped!\n" + Log.getStackTraceString(th));
} finally {
debugText.setText(builder.toString());
builder.setLength(0);
}
}
CallbackBridge.sendCursorPos(x, y);
switch (e.getButtonState()) {
case MotionEvent.BUTTON_PRIMARY: CallbackBridge.mouseLeft = true;
break;
case MotionEvent.BUTTON_SECONDARY: CallbackBridge.mouseLeft = false;
break;
}
switch (e.getActionMasked()) {
case MotionEvent.ACTION_DOWN: // 0
case MotionEvent.ACTION_POINTER_DOWN: // 5
CallbackBridge.sendPrepareGrabInitialPos();
CallbackBridge.sendMouseKeycode(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, 0, true);
initialX = x;
initialY = y;
sendMouseButton(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);
// theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
break;
case MotionEvent.ACTION_UP: // 1
case MotionEvent.ACTION_CANCEL: // 3
case MotionEvent.ACTION_POINTER_UP: // 6
// CallbackBridge.sendCursorPos(x, y);
// CallbackBridge.sendMouseKeycode(rightOverride ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, true);
CallbackBridge.putMouseEventWithCoords(CallbackBridge.mouseLeft /* rightOverride */ ? (byte) 0 : (byte) 1, (byte) 1, x, y);
/*
if (!triggeredLeftMouseButton && Math.abs(initialX - x) < fingerStillThreshold && Math.abs(initialY - y) < fingerStillThreshold) {
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, true);
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);
}
if (triggeredLeftMouseButton) {
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, false);
}
*/
sendMouseButton(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, true);
// triggeredLeftMouseButton = false;
// theHandler.removeMessages(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK);
break;
}
debugText.setText(CallbackBridge.DEBUG_STRING.toString());
CallbackBridge.DEBUG_STRING.setLength(0);
return true;
// If onClick fail with false, change back to true
}
});
}

View File

@ -140,12 +140,13 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_DOWN:
mCanTriggerLongClick = true;
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
mCanTriggerLongClick = false;
moveX += event.getX() - downX;

View File

@ -40,7 +40,7 @@ public class ControlData implements Cloneable
if (SPECIAL_BUTTONS == null) {
ControlData[] specialButtons = new ControlData[]{
new ControlData("Keyboard", SPECIALBTN_KEYBOARD, "${margin} * 3 + ${width} * 2", "${margin}", false),
new ControlData("GUI", SPECIALBTN_TOGGLECTRL, "${margin}", "${bottom}"),
new ControlData("GUI", SPECIALBTN_TOGGLECTRL, "${margin}", "${bottom} - ${margin}"),
new ControlData("PRI", SPECIALBTN_MOUSEPRI, "${margin}", "${screen_height} - ${margin} * 3 - ${height} * 3"),
new ControlData("SEC", SPECIALBTN_MOUSESEC, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 3 - ${height} * 3"),
new ControlData("Mouse", SPECIALBTN_VIRTUALMOUSE, "${right}", "${margin}", false)

View File

@ -30,14 +30,14 @@ public class CustomControls
this.mControlDataList.add(new ControlData(ctx, R.string.control_listplayers, LWJGLGLFWKeycode.GLFW_KEY_TAB, "${margin} * 4 + ${width} * 3", "${margin}", false));
this.mControlDataList.add(new ControlData(ctx, R.string.control_thirdperson, LWJGLGLFWKeycode.GLFW_KEY_F5, "${margin}", "${height} + ${margin}", false));
this.mControlDataList.add(new ControlData(ctx, R.string.control_up, LWJGLGLFWKeycode.GLFW_KEY_W, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 3 - ${height} * 3", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_left, LWJGLGLFWKeycode.GLFW_KEY_A, "${margin}", "${screen_height} - ${margin} * 2 - ${height} * 2", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_down, LWJGLGLFWKeycode.GLFW_KEY_S, "${margin} * 2 + ${width}", "${screen_height} - ${margin} - ${width}", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_right, LWJGLGLFWKeycode.GLFW_KEY_D, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_up, LWJGLGLFWKeycode.GLFW_KEY_W, "${margin} * 2 + ${width}", "${bottom} - ${margin} * 3 - ${height} * 2", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_left, LWJGLGLFWKeycode.GLFW_KEY_A, "${margin}", "${bottom} - ${margin} * 2 - ${height}", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_down, LWJGLGLFWKeycode.GLFW_KEY_S, "${margin} * 2 + ${width}", "${bottom} - ${margin}", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_right, LWJGLGLFWKeycode.GLFW_KEY_D, "${margin} * 3 + ${width} * 2", "${bottom} - ${margin} * 2 - ${height}", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_inventory, LWJGLGLFWKeycode.GLFW_KEY_E, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} - ${width}", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_shift, LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_jump, LWJGLGLFWKeycode.GLFW_KEY_SPACE, "${screen_width} - ${margin} * 3 - ${width} * 2", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_inventory, LWJGLGLFWKeycode.GLFW_KEY_E, "${margin} * 3 + ${width} * 2", "${bottom} - ${margin}", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_shift, LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 2 - ${height} * 2", true));
this.mControlDataList.add(new ControlData(ctx, R.string.control_jump, LWJGLGLFWKeycode.GLFW_KEY_SPACE, "${right} - ${margin} * 2 - ${width}", "${bottom} - ${margin} * 2 - ${height}", true));
}