mirror of https://github.com/axmolengine/axmol.git
Merge pull request #7286 from Dhilan007/v3-gc0702
fixed can't get valid value from trigger button.
This commit is contained in:
commit
1a089f4a18
|
@ -121,8 +121,7 @@ public:
|
||||||
void sendEventButton(ControllerButtonInput* button, bool isPressed, float value, bool isAnalog)
|
void sendEventButton(ControllerButtonInput* button, bool isPressed, float value, bool isAnalog)
|
||||||
{
|
{
|
||||||
button->setPressed(isPressed);
|
button->setPressed(isPressed);
|
||||||
if (!isAnalog)
|
button->setValue(value);
|
||||||
button->setValue(value);
|
|
||||||
button->setAnalog(isAnalog);
|
button->setAnalog(isAnalog);
|
||||||
EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, _controller, button);
|
EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, _controller, button);
|
||||||
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.cocos2dx.lib;
|
package org.cocos2dx.lib;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
@ -17,6 +18,7 @@ public class GameControllerHelper {
|
||||||
private static final int AXIS_RZ = 14;
|
private static final int AXIS_RZ = 14;
|
||||||
private static final int AXIS_LTRIGGER = 17;
|
private static final int AXIS_LTRIGGER = 17;
|
||||||
private static final int AXIS_RTRIGGER = 18;
|
private static final int AXIS_RTRIGGER = 18;
|
||||||
|
public static final int AXIS_GAS = 22;
|
||||||
private static final int AXIS_BRAKE = 23;
|
private static final int AXIS_BRAKE = 23;
|
||||||
private static final int AXIS_THROTTLE = 19;
|
private static final int AXIS_THROTTLE = 19;
|
||||||
|
|
||||||
|
@ -63,6 +65,7 @@ public class GameControllerHelper {
|
||||||
private float mOldRightTrigger = 0.0f;
|
private float mOldRightTrigger = 0.0f;
|
||||||
private float mOldThrottle = 0.0f;
|
private float mOldThrottle = 0.0f;
|
||||||
private float mOldBrake = 0.0f;
|
private float mOldBrake = 0.0f;
|
||||||
|
private float mOldGas = 0.0f;
|
||||||
|
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
|
@ -146,6 +149,17 @@ public class GameControllerHelper {
|
||||||
mOldThrottle = newAXIS_THROTTLE;
|
mOldThrottle = newAXIS_THROTTLE;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
|
||||||
|
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
|
||||||
|
if (Float.compare(newAXIS_GAS, 0.0f) == 0) {
|
||||||
|
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
|
||||||
|
}else {
|
||||||
|
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_GAS, true);
|
||||||
|
}
|
||||||
|
mOldGas = newAXIS_GAS;
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -10,4 +10,4 @@
|
||||||
# Project target.
|
# Project target.
|
||||||
target=android-10
|
target=android-10
|
||||||
|
|
||||||
android.library.reference.1=../../../cocos/platform/android/ControllerAutoAdapter
|
android.library.reference.1=../../../cocos/platform/android/ControllerManualAdapter
|
||||||
|
|
|
@ -36,12 +36,7 @@ public class AppActivity extends GameControllerActivity {
|
||||||
|
|
||||||
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
||||||
|
|
||||||
//Automatic adaptation for connect controller.
|
|
||||||
//Supported Platform: Nibiru / Moga / Ouya TV
|
|
||||||
this.connectController();
|
|
||||||
|
|
||||||
//Manually specify an adapter.
|
//Manually specify an adapter.
|
||||||
//Requirements: using libControllerDriveAdapter project
|
|
||||||
//this.connectController(DRIVERTYPE_NIBIRU);
|
//this.connectController(DRIVERTYPE_NIBIRU);
|
||||||
//this.connectController(DRIVERTYPE_MOGA);
|
//this.connectController(DRIVERTYPE_MOGA);
|
||||||
//this.connectController(DRIVERTYPE_OUYA);
|
//this.connectController(DRIVERTYPE_OUYA);
|
||||||
|
|
Loading…
Reference in New Issue