mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -04:00
Detect swapped axis between triggers and RJoystick
This commit is contained in:
parent
4c71e66f48
commit
cf6737b1ac
@ -56,17 +56,28 @@ public class Gamepad {
|
|||||||
private GamepadMap currentMap = gameMap;
|
private GamepadMap currentMap = gameMap;
|
||||||
|
|
||||||
private boolean lastGrabbingState = true;
|
private boolean lastGrabbingState = true;
|
||||||
private final boolean hasDigitalTriggers;
|
private final boolean mModifierDigitalTriggers;
|
||||||
|
private boolean mModifierSwappedAxis = false; //Triggers and right stick axis are swapped.
|
||||||
|
|
||||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
private final Handler inputHandler = new Handler(Looper.getMainLooper());
|
||||||
private final Runnable switchStateRunnable;
|
private final Runnable switchStateRunnable;
|
||||||
|
|
||||||
public Gamepad(BaseMainActivity gameActivity, InputDevice inputDevice){
|
public Gamepad(BaseMainActivity gameActivity, InputDevice inputDevice){
|
||||||
//Toast.makeText(gameActivity.getApplicationContext(),"GAMEPAD CREATED", Toast.LENGTH_LONG).show();
|
//Toast.makeText(gameActivity.getApplicationContext(),"GAMEPAD CREATED", Toast.LENGTH_LONG).show();
|
||||||
|
for(InputDevice.MotionRange range : inputDevice.getMotionRanges()){
|
||||||
|
if(range.getAxis() == MotionEvent.AXIS_RX || range.getAxis() == MotionEvent.AXIS_RY){
|
||||||
|
mModifierSwappedAxis = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
leftJoystick = new GamepadJoystick(MotionEvent.AXIS_X, MotionEvent.AXIS_Y, inputDevice);
|
leftJoystick = new GamepadJoystick(MotionEvent.AXIS_X, MotionEvent.AXIS_Y, inputDevice);
|
||||||
rightJoystick = new GamepadJoystick(MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, inputDevice);
|
if(!mModifierSwappedAxis)
|
||||||
hasDigitalTriggers = inputDevice.hasKeys(KeyEvent.KEYCODE_BUTTON_R2)[0];
|
rightJoystick = new GamepadJoystick(MotionEvent.AXIS_Z, MotionEvent.AXIS_RZ, inputDevice);
|
||||||
|
else
|
||||||
|
rightJoystick = new GamepadJoystick(MotionEvent.AXIS_RX, MotionEvent.AXIS_RY, inputDevice);
|
||||||
|
|
||||||
|
mModifierDigitalTriggers = inputDevice.hasKeys(KeyEvent.KEYCODE_BUTTON_R2)[0];
|
||||||
|
|
||||||
this.gameActivity = gameActivity;
|
this.gameActivity = gameActivity;
|
||||||
pointerView = this.gameActivity.findViewById(R.id.console_pointer);
|
pointerView = this.gameActivity.findViewById(R.id.console_pointer);
|
||||||
@ -80,11 +91,11 @@ public class Gamepad {
|
|||||||
updateGrabbingState();
|
updateGrabbingState();
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
handler.postDelayed(this, 16);
|
inputHandler.postDelayed(this, 16);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handler.postDelayed(handlerRunnable, 16);
|
inputHandler.postDelayed(handlerRunnable, 16);
|
||||||
|
|
||||||
//Initialize runnables to be used by the input system, avoiding generating one each time is better memory.
|
//Initialize runnables to be used by the input system, avoiding generating one each time is better memory.
|
||||||
switchStateRunnable = () -> {
|
switchStateRunnable = () -> {
|
||||||
@ -118,7 +129,7 @@ public class Gamepad {
|
|||||||
if(lastHorizontalValue != 0 || lastVerticalValue != 0){
|
if(lastHorizontalValue != 0 || lastVerticalValue != 0){
|
||||||
GamepadJoystick currentJoystick = lastGrabbingState ? leftJoystick : rightJoystick;
|
GamepadJoystick currentJoystick = lastGrabbingState ? leftJoystick : rightJoystick;
|
||||||
|
|
||||||
acceleration = (mouseMagnitude - currentJoystick.getDeadzone())/(1 - currentJoystick.getDeadzone());
|
double acceleration = (mouseMagnitude - currentJoystick.getDeadzone()) / (1 - currentJoystick.getDeadzone());
|
||||||
acceleration = Math.pow(acceleration, mouseMaxAcceleration);
|
acceleration = Math.pow(acceleration, mouseMaxAcceleration);
|
||||||
if(acceleration > 1) acceleration = 1;
|
if(acceleration > 1) acceleration = 1;
|
||||||
|
|
||||||
@ -181,9 +192,9 @@ public class Gamepad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAnalogTriggers(MotionEvent event){
|
private void updateAnalogTriggers(MotionEvent event){
|
||||||
if(!hasDigitalTriggers){
|
if(!mModifierDigitalTriggers){
|
||||||
getCurrentMap().TRIGGER_LEFT.update((event.getAxisValue(MotionEvent.AXIS_LTRIGGER) > 0.5) || (event.getAxisValue(MotionEvent.AXIS_BRAKE) > 0.5));
|
getCurrentMap().TRIGGER_LEFT.update((event.getAxisValue(mModifierSwappedAxis ? MotionEvent.AXIS_Z : MotionEvent.AXIS_LTRIGGER) > 0.5) || (event.getAxisValue(MotionEvent.AXIS_BRAKE) > 0.5));
|
||||||
getCurrentMap().TRIGGER_RIGHT.update((event.getAxisValue(MotionEvent.AXIS_RTRIGGER) > 0.5) || (event.getAxisValue(MotionEvent.AXIS_GAS) > 0.5));
|
getCurrentMap().TRIGGER_RIGHT.update((event.getAxisValue(mModifierSwappedAxis ? MotionEvent.AXIS_RZ : MotionEvent.AXIS_RTRIGGER) > 0.5) || (event.getAxisValue(MotionEvent.AXIS_GAS) > 0.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user