fixed can't get valid value from trigger button[Moga]

This commit is contained in:
Dhilan007 2014-07-02 15:09:24 +08:00
parent c5dc7b9cd0
commit adfc010555
1 changed files with 43 additions and 6 deletions

View File

@ -21,6 +21,9 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
private float mOldRightThumbstickX = 0.0f; private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f; private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
private SparseIntArray mKeyMap = null; private SparseIntArray mKeyMap = null;
public GameControllerMoga() { public GameControllerMoga() {
@ -61,8 +64,12 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
} }
public void onKeyEvent(KeyEvent event) { public void onKeyEvent(KeyEvent event) {
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
int keycode = event.getKeyCode(); int keycode = event.getKeyCode();
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
return;
}
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
boolean isAnalog = false; boolean isAnalog = false;
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
@ -82,10 +89,12 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
if (mControllerEventListener == null) { if (mControllerEventListener == null) {
return; return;
} }
int controllerId = event.getControllerId();
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X); float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
if (newLeftThumbstickX != mOldLeftThumbstickX) { if (newLeftThumbstickX != mOldLeftThumbstickX) {
mControllerEventListener.onAxisEvent(mVendorName, mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(), controllerId,
GameControllerDelegate.THUMBSTICK_LEFT_X, GameControllerDelegate.THUMBSTICK_LEFT_X,
newLeftThumbstickX, true); newLeftThumbstickX, true);
mOldLeftThumbstickX = newLeftThumbstickX; mOldLeftThumbstickX = newLeftThumbstickX;
@ -94,7 +103,7 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y); float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
if (newLeftThumbstickY != mOldLeftThumbstickY) { if (newLeftThumbstickY != mOldLeftThumbstickY) {
mControllerEventListener.onAxisEvent(mVendorName, mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(), controllerId,
GameControllerDelegate.THUMBSTICK_LEFT_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y,
newLeftThumbstickY, true); newLeftThumbstickY, true);
mOldLeftThumbstickY = newLeftThumbstickY; mOldLeftThumbstickY = newLeftThumbstickY;
@ -103,7 +112,7 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z); float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
if (newRightThumbstickX != mOldRightThumbstickX) { if (newRightThumbstickX != mOldRightThumbstickX) {
mControllerEventListener.onAxisEvent(mVendorName, mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(), controllerId,
GameControllerDelegate.THUMBSTICK_RIGHT_X, GameControllerDelegate.THUMBSTICK_RIGHT_X,
newRightThumbstickX, true); newRightThumbstickX, true);
mOldRightThumbstickX = newRightThumbstickX; mOldRightThumbstickX = newRightThumbstickX;
@ -112,11 +121,39 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ); float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
if (newRightThumbstickY != mOldRightThumbstickY) { if (newRightThumbstickY != mOldRightThumbstickY) {
mControllerEventListener.onAxisEvent(mVendorName, mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(), controllerId,
GameControllerDelegate.THUMBSTICK_RIGHT_Y, GameControllerDelegate.THUMBSTICK_RIGHT_Y,
newRightThumbstickY, true); newRightThumbstickY, true);
mOldRightThumbstickY = newRightThumbstickY; mOldRightThumbstickY = newRightThumbstickY;
} }
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
if (newLeftTrigger != mOldLeftTrigger) {
boolean isPressed = true;
if (Float.compare(newLeftTrigger, 0.0f) == 0) {
isPressed = false;
}
mControllerEventListener.onButtonEvent(mVendorName,
controllerId,
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
isPressed,
newLeftTrigger, true);
mOldLeftTrigger = newLeftTrigger;
}
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
if (newRightTrigger != mOldRightTrigger) {
boolean isPressed = true;
if (Float.compare(newRightTrigger, 0.0f) == 0) {
isPressed = false;
}
mControllerEventListener.onButtonEvent(mVendorName,
controllerId,
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
isPressed,
newRightTrigger, true);
mOldRightTrigger = newRightTrigger;
}
} }
@Override @Override