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 e876d17a2..2a1d56cf0 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 @@ -46,9 +46,6 @@ public class Gamepad { private final GamepadMapping menuMap = new GamepadMapping(); private GamepadMapping currentMap = menuMap; - private boolean leftThumbstickToggle = false; - private boolean rightThumbstickToggle = false; - private boolean isGrabbing = false; @@ -122,9 +119,11 @@ public class Gamepad { if(isGrabbing){ //TODO hide the cursor currentMap = gameMap; + menuMap.resetPressedState(); }else{ //TODO place the cursor at the center currentMap = menuMap; + gameMap.resetPressedState(); gameActivity.mouse_x = CallbackBridge.windowWidth/2; gameActivity.mouse_y = CallbackBridge.windowHeight/2; @@ -140,61 +139,61 @@ public class Gamepad { //create mappings to fit our needs //GAMEMAP - gameMap.BUTTON_A = new int[]{LWJGLGLFWKeycode.GLFW_KEY_SPACE}; - gameMap.BUTTON_B = new int[]{LWJGLGLFWKeycode.GLFW_KEY_Q}; - gameMap.BUTTON_X = new int[]{LWJGLGLFWKeycode.GLFW_KEY_F}; - gameMap.BUTTON_Y = new int[]{LWJGLGLFWKeycode.GLFW_KEY_E}; + gameMap.BUTTON_A.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_SPACE}; + gameMap.BUTTON_B.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_Q}; + gameMap.BUTTON_X.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_F}; + gameMap.BUTTON_Y.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_E}; gameMap.DIRECTION_FORWARD = new int[]{LWJGLGLFWKeycode.GLFW_KEY_W}; gameMap.DIRECTION_BACKWARD = new int[]{LWJGLGLFWKeycode.GLFW_KEY_S}; gameMap.DIRECTION_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_D}; gameMap.DIRECTION_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_A}; - gameMap.DPAD_UP = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - gameMap.DPAD_DOWN = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - gameMap.DPAD_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - gameMap.DPAD_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + gameMap.DPAD_UP.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + gameMap.DPAD_DOWN.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + gameMap.DPAD_RIGHT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + gameMap.DPAD_LEFT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - gameMap.SHOULDER_LEFT = new int[]{GamepadMapping.MOUSE_SCROLL_UP}; - gameMap.SHOULDER_RIGHT = new int[]{GamepadMapping.MOUSE_SCROLL_DOWN}; + gameMap.SHOULDER_LEFT.keycodes = new int[]{GamepadMapping.MOUSE_SCROLL_UP}; + gameMap.SHOULDER_RIGHT.keycodes = new int[]{GamepadMapping.MOUSE_SCROLL_DOWN}; - gameMap.TRIGGER_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT}; - gameMap.TRIGGER_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT}; + gameMap.TRIGGER_LEFT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT}; + gameMap.TRIGGER_RIGHT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT}; - gameMap.THUMBSTICK_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT}; - gameMap.THUMBSTICK_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_F5}; + gameMap.THUMBSTICK_LEFT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT}; + gameMap.THUMBSTICK_RIGHT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_F5}; - gameMap.BUTTON_START = new int[]{LWJGLGLFWKeycode.GLFW_KEY_ESCAPE}; - gameMap.BUTTON_SELECT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + gameMap.BUTTON_START.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_ESCAPE}; + gameMap.BUTTON_SELECT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; //MENU MAP - menuMap.BUTTON_A = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT}; - menuMap.BUTTON_B = new int[]{LWJGLGLFWKeycode.GLFW_KEY_ESCAPE}; - menuMap.BUTTON_X = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT}; - menuMap.BUTTON_Y = new int[]{LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT}; //Oops, doesn't work since left shift isn't properly applied. + menuMap.BUTTON_A.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT}; + menuMap.BUTTON_B.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_ESCAPE}; + menuMap.BUTTON_X.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT}; + menuMap.BUTTON_Y.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT}; //Oops, doesn't work since left shift isn't properly applied. menuMap.DIRECTION_FORWARD = new int[]{GamepadMapping.MOUSE_SCROLL_UP, GamepadMapping.MOUSE_SCROLL_UP, GamepadMapping.MOUSE_SCROLL_UP,GamepadMapping.MOUSE_SCROLL_UP,GamepadMapping.MOUSE_SCROLL_UP}; menuMap.DIRECTION_BACKWARD = new int[]{GamepadMapping.MOUSE_SCROLL_DOWN, GamepadMapping.MOUSE_SCROLL_DOWN, GamepadMapping.MOUSE_SCROLL_DOWN,GamepadMapping.MOUSE_SCROLL_DOWN,GamepadMapping.MOUSE_SCROLL_DOWN}; menuMap.DIRECTION_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; menuMap.DIRECTION_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.DPAD_UP = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.DPAD_DOWN = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.DPAD_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.DPAD_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.DPAD_UP.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.DPAD_DOWN.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.DPAD_RIGHT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.DPAD_LEFT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.SHOULDER_LEFT = new int[]{GamepadMapping.MOUSE_SCROLL_UP}; - menuMap.SHOULDER_RIGHT = new int[]{GamepadMapping.MOUSE_SCROLL_DOWN}; + menuMap.SHOULDER_LEFT.keycodes = new int[]{GamepadMapping.MOUSE_SCROLL_UP}; + menuMap.SHOULDER_RIGHT.keycodes = new int[]{GamepadMapping.MOUSE_SCROLL_DOWN}; - menuMap.TRIGGER_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.TRIGGER_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.TRIGGER_LEFT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.TRIGGER_RIGHT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.THUMBSTICK_LEFT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.THUMBSTICK_RIGHT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.THUMBSTICK_LEFT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.THUMBSTICK_RIGHT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; - menuMap.BUTTON_START = new int[]{LWJGLGLFWKeycode.GLFW_KEY_ESCAPE}; - menuMap.BUTTON_SELECT = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; + menuMap.BUTTON_START.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_ESCAPE}; + menuMap.BUTTON_SELECT.keycodes = new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}; } @@ -210,7 +209,7 @@ public class Gamepad { } private void update(KeyEvent event){ - sendButton(event.getKeyCode(), event.getAction() == KeyEvent.ACTION_DOWN, getCurrentMap()); + sendButton(event); } private void update(MotionEvent event){ @@ -241,8 +240,8 @@ public class Gamepad { } private void updateAnalogTriggers(MotionEvent event){ - sendInput(getCurrentMap().TRIGGER_RIGHT, event.getAxisValue(MotionEvent.AXIS_RTRIGGER) > 0.5); - sendInput(getCurrentMap().TRIGGER_LEFT, event.getAxisValue(MotionEvent.AXIS_LTRIGGER) > 0.5); + //sendInput(getCurrentMap().TRIGGER_RIGHT, event.getAxisValue(MotionEvent.AXIS_RTRIGGER) > 0.5); + //sendInput(getCurrentMap().TRIGGER_LEFT, event.getAxisValue(MotionEvent.AXIS_LTRIGGER) > 0.5); } @@ -284,62 +283,61 @@ public class Gamepad { } - private void sendButton(int keycode, boolean isDown, GamepadMapping map){ + private void sendButton(KeyEvent event){ + int keycode = event.getKeyCode(); switch (keycode){ case KeyEvent.KEYCODE_BUTTON_A: - sendInput(map.BUTTON_A, isDown); + getCurrentMap().BUTTON_A.update(event); break; case KeyEvent.KEYCODE_BUTTON_B: - sendInput(map.BUTTON_B, isDown); + getCurrentMap().BUTTON_B.update(event); break; case KeyEvent.KEYCODE_BUTTON_X: - sendInput(map.BUTTON_X, isDown); + getCurrentMap().BUTTON_X.update(event); break; case KeyEvent.KEYCODE_BUTTON_Y: - sendInput(map.BUTTON_Y, isDown); + getCurrentMap().BUTTON_Y.update(event); break; //Shoulders case KeyEvent.KEYCODE_BUTTON_L1: - sendInput(map.SHOULDER_LEFT, isDown); + getCurrentMap().SHOULDER_LEFT.update(event); break; case KeyEvent.KEYCODE_BUTTON_R1: - sendInput(map.SHOULDER_RIGHT, isDown); + getCurrentMap().SHOULDER_RIGHT.update(event); break; //Triggers case KeyEvent.KEYCODE_BUTTON_L2: - sendInput(map.TRIGGER_LEFT, isDown); + getCurrentMap().TRIGGER_LEFT.update(event); break; case KeyEvent.KEYCODE_BUTTON_R2: - sendInput(map.TRIGGER_RIGHT, isDown); + getCurrentMap().TRIGGER_RIGHT.update(event); break; //L3 || R3 case KeyEvent.KEYCODE_BUTTON_THUMBL: - leftThumbstickToggle = !leftThumbstickToggle; - if(leftThumbstickToggle) sendInput(map.THUMBSTICK_LEFT, isDown); + getCurrentMap().THUMBSTICK_LEFT.update(event); break; case KeyEvent.KEYCODE_BUTTON_THUMBR: - rightThumbstickToggle = !rightThumbstickToggle; - if(rightThumbstickToggle) sendInput(map.THUMBSTICK_RIGHT, isDown); + getCurrentMap().THUMBSTICK_RIGHT.update(event); break; case KeyEvent.KEYCODE_BUTTON_START: - sendInput(map.BUTTON_START, isDown); + getCurrentMap().BUTTON_START.update(event); break; case KeyEvent.KEYCODE_BUTTON_SELECT: - sendInput(map.BUTTON_SELECT, isDown); + getCurrentMap().BUTTON_SELECT.update(event); break; default: - BaseMainActivity.sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_SPACE, CallbackBridge.getCurrentMods(), isDown); + BaseMainActivity.sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_SPACE, CallbackBridge.getCurrentMods(), event.getAction() == KeyEvent.ACTION_DOWN); break; } } - private static void sendInput(int[] keycodes, boolean isDown){ + public static void sendInput(int[] keycodes, boolean isDown){ for(int keycode : keycodes){ switch (keycode){ case GamepadMapping.MOUSE_SCROLL_DOWN: diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapping.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapping.java index b47aaea77..61af4a286 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapping.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapping.java @@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.customcontrols.gamepad; import net.kdt.pojavlaunch.LWJGLGLFWKeycode; +import java.security.PublicKey; import java.util.HashMap; public class GamepadMapping { @@ -19,34 +20,58 @@ public class GamepadMapping { */ - public int[] BUTTON_A; - public int[] BUTTON_B; - public int[] BUTTON_X; - public int[] BUTTON_Y; + public GamepadButton BUTTON_A = new GamepadButton(); + public GamepadButton BUTTON_B = new GamepadButton(); + public GamepadButton BUTTON_X = new GamepadButton(); + public GamepadButton BUTTON_Y = new GamepadButton(); - public int[] BUTTON_START; - public int[] BUTTON_SELECT; + public GamepadButton BUTTON_START = new GamepadButton(); + public GamepadButton BUTTON_SELECT = new GamepadButton(); - public int[] TRIGGER_RIGHT; //R2 - public int[] TRIGGER_LEFT; //L2 + public GamepadButton TRIGGER_RIGHT = new GamepadButton(); //R2 + public GamepadButton TRIGGER_LEFT = new GamepadButton(); //L2 - public int[] SHOULDER_RIGHT; //R1 - public int[] SHOULDER_LEFT; //L1 + public GamepadButton SHOULDER_RIGHT = new GamepadButton(); //R1 + public GamepadButton SHOULDER_LEFT = new GamepadButton(); //L1 public int[] DIRECTION_FORWARD; public int[] DIRECTION_BACKWARD; public int[] DIRECTION_RIGHT; public int[] DIRECTION_LEFT; - public int[] THUMBSTICK_RIGHT; //R3 - public int[] THUMBSTICK_LEFT; //L3 + public GamepadButton THUMBSTICK_RIGHT = new GamepadButton(); //R3 + public GamepadButton THUMBSTICK_LEFT = new GamepadButton(); //L3 - public int[] DPAD_UP; - public int[] DPAD_RIGHT; - public int[] DPAD_DOWN; - public int[] DPAD_LEFT; + public GamepadButton DPAD_UP = new GamepadButton(); + public GamepadButton DPAD_RIGHT = new GamepadButton(); + public GamepadButton DPAD_DOWN = new GamepadButton(); + public GamepadButton DPAD_LEFT = new GamepadButton(); + public void resetPressedState(){ + BUTTON_A.resetButtonState(); + BUTTON_B.resetButtonState(); + BUTTON_X.resetButtonState(); + BUTTON_Y.resetButtonState(); + + BUTTON_START.resetButtonState(); + BUTTON_SELECT.resetButtonState(); + + TRIGGER_LEFT.resetButtonState(); + TRIGGER_RIGHT.resetButtonState(); + + SHOULDER_LEFT.resetButtonState(); + SHOULDER_RIGHT.resetButtonState(); + + THUMBSTICK_LEFT.resetButtonState(); + THUMBSTICK_RIGHT.resetButtonState(); + + DPAD_UP.resetButtonState(); + DPAD_RIGHT.resetButtonState(); + DPAD_DOWN.resetButtonState(); + DPAD_LEFT.resetButtonState(); + + } }