diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java
index 256265329..5a8561e7b 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java
@@ -3,6 +3,7 @@ package net.kdt.pojavlaunch;
import static net.kdt.pojavlaunch.Architecture.ARCH_X86;
import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
import static org.lwjgl.glfw.CallbackBridge.windowHeight;
import static org.lwjgl.glfw.CallbackBridge.windowWidth;
@@ -54,7 +55,7 @@ public class BaseMainActivity extends LoggableActivity {
private ScrollView contentScroll;
private ToggleButton toggleLog;
- private TextView debugText;
+
private NavigationView.OnNavigationItemSelectedListener gameActionListener;
public NavigationView.OnNavigationItemSelectedListener ingameControlsEditorListener;
@@ -124,7 +125,7 @@ public class BaseMainActivity extends LoggableActivity {
break;
case R.id.nav_viewlog: openLogOutput();
break;
- case R.id.nav_debug: toggleDebug();
+ case R.id.nav_debug: minecraftGLView.togglepointerDebugging();
break;
case R.id.nav_customkey: dialogSendCustomKey();
break;
@@ -153,7 +154,6 @@ public class BaseMainActivity extends LoggableActivity {
appendToLog("");
});
- this.debugText = findViewById(R.id.content_text_debug);
this.minecraftGLView = findViewById(R.id.main_game_render_view);
this.drawerLayout.closeDrawers();
@@ -267,10 +267,6 @@ public class BaseMainActivity extends LoggableActivity {
return s.toString();
}
- private void toggleDebug() {
- debugText.setVisibility(debugText.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
- }
-
private void dialogSendCustomKey() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.control_customkey);
@@ -280,13 +276,13 @@ public class BaseMainActivity extends LoggableActivity {
boolean isInEditor;
private void openCustomControls() {
- if(ingameControlsEditorListener != null) {
- ((MainActivity)this).mControlLayout.setModifiable(true);
- navDrawer.getMenu().clear();
- navDrawer.inflateMenu(R.menu.menu_customctrl);
- navDrawer.setNavigationItemSelectedListener(ingameControlsEditorListener);
- isInEditor = true;
- }
+ if(ingameControlsEditorListener == null) return;
+
+ ((MainActivity)this).mControlLayout.setModifiable(true);
+ navDrawer.getMenu().clear();
+ navDrawer.inflateMenu(R.menu.menu_customctrl);
+ navDrawer.setNavigationItemSelectedListener(ingameControlsEditorListener);
+ isInEditor = true;
}
public void leaveCustomControls() {
@@ -364,27 +360,6 @@ public class BaseMainActivity extends LoggableActivity {
if(touchCharInput != null) touchCharInput.switchKeyboardState();
}
-
- public static void sendKeyPress(int keyCode, int modifiers, boolean status) {
- sendKeyPress(keyCode, 0, modifiers, status);
- }
-
- public static void sendKeyPress(int keyCode, int scancode, int modifiers, boolean status) {
- sendKeyPress(keyCode, '\u0000', scancode, modifiers, status);
- }
-
- public static void sendKeyPress(int keyCode, char keyChar, int scancode, int modifiers, boolean status) {
- CallbackBridge.sendKeycode(keyCode, keyChar, scancode, modifiers, status);
- }
-
- public static void sendKeyPress(int keyCode) {
- sendKeyPress(keyCode, CallbackBridge.getCurrentMods(), true);
- sendKeyPress(keyCode, CallbackBridge.getCurrentMods(), false);
- }
-
- public static void sendMouseButton(int button, boolean status) {
- CallbackBridge.sendMouseKeycode(button, CallbackBridge.getCurrentMods(), status);
- }
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java
index ffb6b0e3f..a7677b4c0 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/EfficientAndroidLWJGLKeycode.java
@@ -1,5 +1,7 @@
package net.kdt.pojavlaunch;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
+
import android.view.KeyEvent;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
@@ -197,7 +199,7 @@ public class EfficientAndroidLWJGLKeycode {
try {
System.out.println(keyEvent.getKeyCode() + " " +keyEvent.getDisplayLabel());
char key = (char)(keyEvent.getUnicodeChar() != 0 ? keyEvent.getUnicodeChar() : '\u0000');
- BaseMainActivity.sendKeyPress(
+ sendKeyPress(
getValueByIndex(valueIndex),
key,
0,
@@ -211,7 +213,7 @@ public class EfficientAndroidLWJGLKeycode {
public static void execKeyIndex(int index){
//Send a quick key press.
- BaseMainActivity.sendKeyPress(getValueByIndex(index));
+ sendKeyPress(getValueByIndex(index));
}
public static int getValueByIndex(int index) {
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLView.java
index 44eb842ec..45649ffcf 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLView.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLView.java
@@ -1,10 +1,10 @@
package net.kdt.pojavlaunch;
-import static net.kdt.pojavlaunch.BaseMainActivity.sendKeyPress;
-import static net.kdt.pojavlaunch.BaseMainActivity.sendMouseButton;
import static net.kdt.pojavlaunch.BaseMainActivity.touchCharInput;
import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
+import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
import static org.lwjgl.glfw.CallbackBridge.windowHeight;
import static org.lwjgl.glfw.CallbackBridge.windowWidth;
@@ -17,6 +17,7 @@ import android.os.Looper;
import android.os.Message;
import android.util.*;
import android.view.*;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
@@ -37,6 +38,8 @@ import org.lwjgl.glfw.CallbackBridge;
public class MinecraftGLView extends TextureView {
/* Gamepad object for gamepad inputs, instantiated on need */
private Gamepad gamepad = null;
+ /* Pointer Debug textview, used to show info about the pointer state */
+ private TextView pointerDebugText;
/* Resolution scaler option, allow downsizing a window */
private final float scaleFactor = LauncherPreferences.DEFAULT_PREF.getInt("resolutionRatio",100)/100f;
@@ -88,7 +91,7 @@ public class MinecraftGLView extends TextureView {
float x = CallbackBridge.mouseX;
float y = CallbackBridge.mouseY;
if (CallbackBridge.isGrabbing() &&
- MathUtils.dist(x, y, mouse_x, mouse_y) < FINGER_STILL_THRESHOLD) {
+ MathUtils.dist(x, y, initialX, initialY) < FINGER_STILL_THRESHOLD) {
triggeredLeftMouseButton = true;
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, true);
}
@@ -122,6 +125,13 @@ public class MinecraftGLView extends TextureView {
/** Initialize the view and all its settings */
public void start(){
+ // Add the pointer debug textview
+ pointerDebugText = new TextView(getContext());
+ pointerDebugText.setX(0);
+ pointerDebugText.setY(0);
+ pointerDebugText.setVisibility(GONE);
+ ((ViewGroup)getParent()).addView(pointerDebugText);
+
setSurfaceTextureListener(new SurfaceTextureListener() {
private boolean isCalled = false;
@Override
@@ -418,8 +428,8 @@ public class MinecraftGLView extends TextureView {
releasePointerCapture();
clearFocus();
}
- /*
- if (debugText.getVisibility() == View.VISIBLE && !debugErrored) {
+
+ if (pointerDebugText.getVisibility() == View.VISIBLE && !debugErrored) {
StringBuilder builder = new StringBuilder();
try {
builder.append("PointerCapture debug\n");
@@ -439,12 +449,12 @@ public class MinecraftGLView extends TextureView {
debugErrored = true;
builder.append("Error getting debug. The debug will be stopped!\n").append(Log.getStackTraceString(th));
} finally {
- debugText.setText(builder.toString());
+ pointerDebugText.setText(builder.toString());
builder.setLength(0);
}
- }*/
+ }
- //debugText.setText(CallbackBridge.DEBUG_STRING.toString());
+ pointerDebugText.setText(CallbackBridge.DEBUG_STRING.toString());
CallbackBridge.DEBUG_STRING.setLength(0);
switch (e.getActionMasked()) {
case MotionEvent.ACTION_MOVE:
@@ -523,6 +533,21 @@ public class MinecraftGLView extends TextureView {
return false;
}
+ @Override
+ public boolean dispatchKeyEventPreIme(KeyEvent event) {
+ return super.dispatchKeyEventPreIme(event);
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public boolean dispatchKeyShortcutEvent(KeyEvent event) {
+ return super.dispatchKeyShortcutEvent(event);
+ }
+
/** Get the mouse direction as a string */
private String getMoving(float pos, boolean xOrY) {
if (pos == 0) return "STOPPED";
@@ -571,12 +596,11 @@ public class MinecraftGLView extends TextureView {
return (int)((GUIScale * input)/scaleFactor);
}
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- return super.dispatchKeyEvent(event);
+ /** Toggle the pointerDebugText visibility state */
+ public void togglepointerDebugging() {
+ pointerDebugText.setVisibility(pointerDebugText.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
}
-
/** A small interface called when the listener is ready for the first time */
public interface SurfaceReadyListener {
void isReady();
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java
index fd4ba4762..b62597965 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java
@@ -15,6 +15,7 @@ import net.objecthunter.exp4j.function.Function;
import org.lwjgl.glfw.*;
import static net.kdt.pojavlaunch.LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
public class ControlData {
@@ -174,7 +175,7 @@ public class ControlData {
public void execute(boolean isDown) {
for(int keycode : keycodes){
- BaseMainActivity.sendKeyPress(keycode, 0, isDown);
+ sendKeyPress(keycode, 0, isDown);
}
}
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java
index 5cb26354a..3d7c037df 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/TouchCharInput.java
@@ -3,6 +3,8 @@ package net.kdt.pojavlaunch.customcontrols;
import static android.content.Context.INPUT_METHOD_SERVICE;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
+
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
@@ -125,7 +127,7 @@ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText
* Send the enter key.
*/
private void sendEnter(){
- BaseMainActivity.sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ENTER);
+ sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ENTER);
clear();
}
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java
index d951cab73..a599ad80d 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java
@@ -20,13 +20,14 @@ import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import org.lwjgl.glfw.*;
-import static net.kdt.pojavlaunch.BaseMainActivity.sendMouseButton;
import static net.kdt.pojavlaunch.LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_BUTTONSIZE;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_CONTROL_BOTTOM_OFFSET;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_CONTROL_LEFT_OFFSET;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_CONTROL_RIGHT_OFFSET;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_CONTROL_TOP_OFFSET;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
+import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
@SuppressLint("ViewConstructor")
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener
@@ -512,7 +513,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
setActivated(isDown);
for(int keycode : mProperties.keycodes){
if(keycode >= GLFW_KEY_UNKNOWN){
- MainActivity.sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
+ sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
CallbackBridge.setModifiers(keycode, isDown);
}else{
sendSpecialKey(keycode, isDown);
diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java
index 90aca7f83..dff08a608 100644
--- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java
+++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java
@@ -38,6 +38,8 @@ import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTI
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_WEST;
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.isJoystickEvent;
import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale;
+import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
+import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
public class Gamepad {
@@ -354,7 +356,7 @@ public class Gamepad {
default:
- MainActivity.sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_SPACE, CallbackBridge.getCurrentMods(), event.getAction() == KeyEvent.ACTION_DOWN);
+ sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_SPACE, CallbackBridge.getCurrentMods(), event.getAction() == KeyEvent.ACTION_DOWN);
break;
}
}
@@ -370,15 +372,15 @@ public class Gamepad {
break;
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT:
- MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
+ sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
break;
case LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT:
- MainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
+ sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
break;
default:
- MainActivity.sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
+ sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
break;
}
CallbackBridge.setModifiers(keycode, isDown);
diff --git a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java
index b83fddbca..4964a1e2e 100644
--- a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java
+++ b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java
@@ -84,6 +84,27 @@ public class CallbackBridge {
nativeSendChar(keychar);
}
+ public static void sendKeyPress(int keyCode, int modifiers, boolean status) {
+ sendKeyPress(keyCode, 0, modifiers, status);
+ }
+
+ public static void sendKeyPress(int keyCode, int scancode, int modifiers, boolean status) {
+ sendKeyPress(keyCode, '\u0000', scancode, modifiers, status);
+ }
+
+ public static void sendKeyPress(int keyCode, char keyChar, int scancode, int modifiers, boolean status) {
+ CallbackBridge.sendKeycode(keyCode, keyChar, scancode, modifiers, status);
+ }
+
+ public static void sendKeyPress(int keyCode) {
+ sendKeyPress(keyCode, CallbackBridge.getCurrentMods(), true);
+ sendKeyPress(keyCode, CallbackBridge.getCurrentMods(), false);
+ }
+
+ public static void sendMouseButton(int button, boolean status) {
+ CallbackBridge.sendMouseKeycode(button, CallbackBridge.getCurrentMods(), status);
+ }
+
public static void sendMouseKeycode(int button, int modifiers, boolean isDown) {
DEBUG_STRING.append("MouseKey=").append(button).append(", down=").append(isDown).append("\n");
// if (isGrabbing()) DEBUG_STRING.append("MouseGrabStrace: " + android.util.Log.getStackTraceString(new Throwable()) + "\n");
diff --git a/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml b/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml
index 39caf0138..231728044 100644
--- a/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml
+++ b/app_pojavlauncher/src/main/res/layout/main_with_customctrl.xml
@@ -98,13 +98,6 @@
-
-