diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index f02c76d6b4..078739e6a9 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -28,6 +28,7 @@ THE SOFTWARE. #include #include "base/CCDirector.h" +#include "base/CCAsyncTaskPool.h" #include "renderer/CCCustomCommand.h" #include "renderer/CCRenderer.h" #include "platform/CCImage.h" @@ -49,22 +50,39 @@ int ccNextPOT(int x) namespace utils { /** - * Capture screen implementation, don't use it directly. - */ +* Capture screen implementation, don't use it directly. +*/ void onCaptureScreen(const std::function& afterCaptured, const std::string& filename) { + static bool startedCapture = false; + + if (startedCapture) + { + CCLOG("Screen capture is already working"); + if (afterCaptured) + { + afterCaptured(false, filename); + } + return; + } + else + { + startedCapture = true; + } + + auto glView = Director::getInstance()->getOpenGLView(); auto frameSize = glView->getFrameSize(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) frameSize = frameSize * glView->getFrameZoomFactor() * glView->getRetinaFactor(); #endif - + int width = static_cast(frameSize.width); int height = static_cast(frameSize.height); - + bool succeed = false; std::string outputFile = ""; - + do { std::shared_ptr buffer(new GLubyte[width * height * 4], [](GLubyte* p){ CC_SAFE_DELETE_ARRAY(p); }); @@ -72,10 +90,10 @@ void onCaptureScreen(const std::function& afterC { break; } - + glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get()); - + std::shared_ptr flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); }); if (!flippedBuffer) { @@ -87,7 +105,7 @@ void onCaptureScreen(const std::function& afterC memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4); } - std::shared_ptr image(new Image); + Image* image = new (std::nothrow) Image; if (image) { image->initWithRawData(flippedBuffer.get(), width * height * 4, width, height, 8); @@ -100,15 +118,36 @@ void onCaptureScreen(const std::function& afterC CCASSERT(filename.find("/") == std::string::npos, "The existence of a relative path is not guaranteed!"); outputFile = FileUtils::getInstance()->getWritablePath() + filename; } - succeed = image->saveToFile(outputFile); + + // Save image in AsyncTaskPool::TaskType::TASK_IO thread, and call afterCaptured in mainThread + static bool succeedSaveToFile = false; + std::function mainThread = [afterCaptured, outputFile](void* param) + { + if (afterCaptured) + { + afterCaptured(succeedSaveToFile, outputFile); + } + startedCapture = false; + }; + + AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_IO, mainThread, (void*)NULL, [image, outputFile]() + { + succeedSaveToFile = image->saveToFile(outputFile); + delete image; + }); } - }while(0); - - if (afterCaptured) - { - afterCaptured(succeed, outputFile); - } + else + { + CCLOG("Malloc Image memory failed!"); + if (afterCaptured) + { + afterCaptured(succeed, outputFile); + } + startedCapture = false; + } + } while (0); } + /* * Capture screen interface */ diff --git a/cocos/platform/android/ControllerManualAdapter/libs/nibiru_lib.jar b/cocos/platform/android/ControllerManualAdapter/libs/nibiru_lib.jar new file mode 100644 index 0000000000..5b4dc2f919 Binary files /dev/null and b/cocos/platform/android/ControllerManualAdapter/libs/nibiru_lib.jar differ diff --git a/cocos/platform/android/ControllerManualAdapter/libs/nibiru_lib_2_1_8.jar b/cocos/platform/android/ControllerManualAdapter/libs/nibiru_lib_2_1_8.jar deleted file mode 100644 index 5aa738c296..0000000000 Binary files a/cocos/platform/android/ControllerManualAdapter/libs/nibiru_lib_2_1_8.jar and /dev/null differ diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java index b527751778..ba58296795 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java @@ -36,271 +36,271 @@ import android.view.MotionEvent; import android.util.Log; public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener { - // =========================================================== - // Constants - // =========================================================== + // =========================================================== + // Constants + // =========================================================== - private final static String TAG = GameControllerActivity.class.getSimpleName(); + private final static String TAG = GameControllerActivity.class.getSimpleName(); - public static final int DRIVERTYPE_NIBIRU = 0; - public static final int DRIVERTYPE_MOGA = 1; - public static final int DRIVERTYPE_OUYA = 2; - public static final int DRIVERTYPE_STANDARD = 3; - public static final int DRIVERTYPE_UNKNOWN = 4; - - // =========================================================== - // Fields - // =========================================================== - private static GameControllerActivity sGameControllerActivity; - private InputManagerCompat mInputManager = null; - - protected GameControllerHelper mControllerHelper = null; - - protected GameControllerDelegate mControllerNibiru = null; - protected GameControllerDelegate mControllerMoga = null; - protected GameControllerDelegate mControllerOuya = null; - - public void connectController(int driveType){ - try { - - ClassLoader loader = sGameControllerActivity.getClassLoader(); - Class controllerDelegate = null; - if (driveType == DRIVERTYPE_MOGA) { - if (mControllerMoga != null) { - return; - } - controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga"); - } else if (driveType == DRIVERTYPE_NIBIRU) { - if (mControllerNibiru != null) { - mControllerNibiru.onCreate(sGameControllerActivity); - mControllerNibiru.onResume(); - return; - } - controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru"); - } else if (driveType == DRIVERTYPE_OUYA) { - if (mControllerOuya != null) { - return; - } - controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya"); - } - - GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance(); - sGameControllerActivity.setGameControllerInstance(instance, driveType); - - if (driveType == DRIVERTYPE_NIBIRU) { - Method method = controllerDelegate.getDeclaredMethod("onResume"); - method.invoke(instance); - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) { - if (driveType == DRIVERTYPE_NIBIRU) { - mControllerNibiru = controllerDelegate; - }else if (driveType == DRIVERTYPE_MOGA) { - mControllerMoga = controllerDelegate; - } - else if (driveType == DRIVERTYPE_OUYA) { - mControllerOuya = controllerDelegate; - } - controllerDelegate.setControllerEventListener(mControllerEventListener); - controllerDelegate.onCreate(sGameControllerActivity); - } - - public GameControllerDelegate getGameControllerDelegate(int driveType){ - if (driveType == DRIVERTYPE_NIBIRU) { - return mControllerNibiru; - }else if (driveType == DRIVERTYPE_MOGA) { - return mControllerMoga; - } - else if (driveType == DRIVERTYPE_OUYA) { - return mControllerOuya; - } - - return null; - } - - ControllerEventListener mControllerEventListener = new ControllerEventListener() { - - @Override - public void onButtonEvent(String vendorName, int controller, int button, - boolean isPressed, float value, boolean isAnalog) { - GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog); - } - - @Override - public void onAxisEvent(String vendorName, int controller, int axisID, - float value, boolean isAnalog) { - GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog); - } + public static final int DRIVERTYPE_NIBIRU = 0; + public static final int DRIVERTYPE_MOGA = 1; + public static final int DRIVERTYPE_OUYA = 2; + public static final int DRIVERTYPE_STANDARD = 3; + public static final int DRIVERTYPE_UNKNOWN = 4; + + // =========================================================== + // Fields + // =========================================================== + private static GameControllerActivity sGameControllerActivity; + private InputManagerCompat mInputManager = null; + + protected GameControllerHelper mControllerHelper = null; + + protected GameControllerDelegate mControllerNibiru = null; + protected GameControllerDelegate mControllerMoga = null; + protected GameControllerDelegate mControllerOuya = null; + + public void connectController(int driveType){ + try { + + ClassLoader loader = sGameControllerActivity.getClassLoader(); + Class controllerDelegate = null; + if (driveType == DRIVERTYPE_MOGA) { + if (mControllerMoga != null) { + return; + } + controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga"); + } else if (driveType == DRIVERTYPE_NIBIRU) { + if (mControllerNibiru != null) { + mControllerNibiru.onCreate(sGameControllerActivity); + mControllerNibiru.onResume(); + return; + } + controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru"); + } else if (driveType == DRIVERTYPE_OUYA) { + if (mControllerOuya != null) { + return; + } + controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya"); + } + + GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance(); + sGameControllerActivity.setGameControllerInstance(instance, driveType); + + if (driveType == DRIVERTYPE_NIBIRU) { + Method method = controllerDelegate.getDeclaredMethod("onResume"); + method.invoke(instance); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) { + if (driveType == DRIVERTYPE_NIBIRU) { + mControllerNibiru = controllerDelegate; + }else if (driveType == DRIVERTYPE_MOGA) { + mControllerMoga = controllerDelegate; + } + else if (driveType == DRIVERTYPE_OUYA) { + mControllerOuya = controllerDelegate; + } + controllerDelegate.setControllerEventListener(mControllerEventListener); + controllerDelegate.onCreate(sGameControllerActivity); + } + + public GameControllerDelegate getGameControllerDelegate(int driveType){ + if (driveType == DRIVERTYPE_NIBIRU) { + return mControllerNibiru; + }else if (driveType == DRIVERTYPE_MOGA) { + return mControllerMoga; + } + else if (driveType == DRIVERTYPE_OUYA) { + return mControllerOuya; + } + + return null; + } + + ControllerEventListener mControllerEventListener = new ControllerEventListener() { + + @Override + public void onButtonEvent(String vendorName, int controller, int button, + boolean isPressed, float value, boolean isAnalog) { + GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog); + } + + @Override + public void onAxisEvent(String vendorName, int controller, int axisID, + float value, boolean isAnalog) { + GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog); + } - @Override - public void onConnected(String vendorName, int controller) { - GameControllerAdapter.onConnected(vendorName, controller); - } + @Override + public void onConnected(String vendorName, int controller) { + GameControllerAdapter.onConnected(vendorName, controller); + } - @Override - public void onDisconnected(String vendorName, int controller) { - GameControllerAdapter.onDisconnected(vendorName, controller); - } - }; - - // =========================================================== - // Constructors - // =========================================================== - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - sGameControllerActivity = this; - mInputManager = InputManagerCompat.Factory.getInputManager(this); - mInputManager.registerInputDeviceListener(this, null); - - if (mControllerNibiru != null) { - mControllerNibiru.onCreate(this); - } - if (mControllerMoga != null) { - mControllerMoga.onCreate(this); - } - if (mControllerOuya != null) { - mControllerOuya.onCreate(this); - } - if (mControllerHelper == null) { - mControllerHelper = new GameControllerHelper(this); - } - } - - // =========================================================== - // Getter & Setter - // =========================================================== + @Override + public void onDisconnected(String vendorName, int controller) { + GameControllerAdapter.onDisconnected(vendorName, controller); + } + }; + + // =========================================================== + // Constructors + // =========================================================== + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + sGameControllerActivity = this; + mInputManager = InputManagerCompat.Factory.getInputManager(this); + mInputManager.registerInputDeviceListener(this, null); + + if (mControllerNibiru != null) { + mControllerNibiru.onCreate(this); + } + if (mControllerMoga != null) { + mControllerMoga.onCreate(this); + } + if (mControllerOuya != null) { + mControllerOuya.onCreate(this); + } + if (mControllerHelper == null) { + mControllerHelper = new GameControllerHelper(this); + } + } + + // =========================================================== + // Getter & Setter + // =========================================================== - // =========================================================== - // Methods for/from SuperClass/Interfaces - // =========================================================== + // =========================================================== + // Methods for/from SuperClass/Interfaces + // =========================================================== - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - boolean handled = false; - if (mControllerNibiru != null) { - handled |= mControllerNibiru.dispatchKeyEvent(event); - } - if (handled == false && mControllerMoga != null) { - handled |= mControllerMoga.dispatchKeyEvent(event); - } - if (handled == false && mControllerOuya != null) { - handled |= mControllerOuya.dispatchKeyEvent(event); - } - - if (handled == false) { - handled |= mControllerHelper.dispatchKeyEvent(event); - } - - return handled || super.dispatchKeyEvent(event); - } - - @Override - public boolean dispatchGenericMotionEvent(MotionEvent event) { - boolean handled = false; - if (mControllerNibiru != null) { - handled |= mControllerNibiru.dispatchGenericMotionEvent(event); - } - if (handled == false && mControllerMoga != null) { - handled |= mControllerMoga.dispatchGenericMotionEvent(event); - } - if (handled == false && mControllerOuya != null) { - handled |= mControllerOuya.dispatchGenericMotionEvent(event); - } - - if (handled == false) { - handled |= mControllerHelper.dispatchGenericMotionEvent(event); - } - - return handled || super.dispatchGenericMotionEvent(event); - } - - @Override - public void onInputDeviceAdded(int deviceId) { - Log.d(TAG,"onInputDeviceAdded:" + deviceId); - - mControllerHelper.onInputDeviceAdded(deviceId); - } - /* - * This is an unusual case. Input devices don't typically change, but they - * certainly can --- for example a device may have different modes. We use - * this to make sure that the ship has an up-to-date InputDevice. - * - * @see - * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener - * #onInputDeviceChanged(int) - */ - @Override - public void onInputDeviceChanged(int deviceId) { - Log.w(TAG,"onInputDeviceChanged:" + deviceId); - } - - /* - * Remove any ship associated with the ID. - * - * @see - * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener - * #onInputDeviceRemoved(int) - */ - @Override - public void onInputDeviceRemoved(int deviceId) { - Log.d(TAG,"onInputDeviceRemoved:" + deviceId); - - mControllerHelper.onInputDeviceRemoved(deviceId); - } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + boolean handled = false; + if (mControllerNibiru != null) { + handled |= mControllerNibiru.dispatchKeyEvent(event); + } + if (handled == false && mControllerMoga != null) { + handled |= mControllerMoga.dispatchKeyEvent(event); + } + if (handled == false && mControllerOuya != null) { + handled |= mControllerOuya.dispatchKeyEvent(event); + } + + if (handled == false) { + handled |= mControllerHelper.dispatchKeyEvent(event); + } + + return handled || super.dispatchKeyEvent(event); + } + + @Override + public boolean dispatchGenericMotionEvent(MotionEvent event) { + boolean handled = false; + if (mControllerNibiru != null) { + handled |= mControllerNibiru.dispatchGenericMotionEvent(event); + } + if (handled == false && mControllerMoga != null) { + handled |= mControllerMoga.dispatchGenericMotionEvent(event); + } + if (handled == false && mControllerOuya != null) { + handled |= mControllerOuya.dispatchGenericMotionEvent(event); + } + + if (handled == false) { + handled |= mControllerHelper.dispatchGenericMotionEvent(event); + } + + return handled || super.dispatchGenericMotionEvent(event); + } + + @Override + public void onInputDeviceAdded(int deviceId) { + Log.d(TAG,"onInputDeviceAdded:" + deviceId); + + mControllerHelper.onInputDeviceAdded(deviceId); + } + /* + * This is an unusual case. Input devices don't typically change, but they + * certainly can --- for example a device may have different modes. We use + * this to make sure that the ship has an up-to-date InputDevice. + * + * @see + * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener + * #onInputDeviceChanged(int) + */ + @Override + public void onInputDeviceChanged(int deviceId) { + Log.w(TAG,"onInputDeviceChanged:" + deviceId); + } + + /* + * Remove any ship associated with the ID. + * + * @see + * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener + * #onInputDeviceRemoved(int) + */ + @Override + public void onInputDeviceRemoved(int deviceId) { + Log.d(TAG,"onInputDeviceRemoved:" + deviceId); + + mControllerHelper.onInputDeviceRemoved(deviceId); + } - @Override - protected void onResume() { - super.onResume(); - - if (mControllerNibiru != null) { - mControllerNibiru.onResume(); - } - if (mControllerMoga != null) { - mControllerMoga.onResume(); - } - if (mControllerOuya != null) { - mControllerOuya.onResume(); - } - - GameControllerHelper.gatherControllers(mControllerHelper.mGameController); - } - - @Override - protected void onPause() { - if (mControllerNibiru != null) { - mControllerNibiru.onPause(); - } - if (mControllerMoga != null) { - mControllerMoga.onPause(); - } - if (mControllerOuya != null) { - mControllerOuya.onPause(); - } - - super.onPause(); - } - - @Override - protected void onDestroy() { - if (mControllerNibiru != null) { - mControllerNibiru.onDestroy(); - } - if (mControllerMoga != null) { - mControllerMoga.onDestroy(); - } - if (mControllerOuya != null) { - mControllerOuya.onDestroy(); - } - - super.onDestroy(); - } + @Override + protected void onResume() { + super.onResume(); + + if (mControllerNibiru != null) { + mControllerNibiru.onResume(); + } + if (mControllerMoga != null) { + mControllerMoga.onResume(); + } + if (mControllerOuya != null) { + mControllerOuya.onResume(); + } + + GameControllerHelper.gatherControllers(mControllerHelper.mGameController); + } + + @Override + protected void onPause() { + if (mControllerNibiru != null) { + mControllerNibiru.onPause(); + } + if (mControllerMoga != null) { + mControllerMoga.onPause(); + } + if (mControllerOuya != null) { + mControllerOuya.onPause(); + } + + super.onPause(); + } + + @Override + protected void onDestroy() { + if (mControllerNibiru != null) { + mControllerNibiru.onDestroy(); + } + if (mControllerMoga != null) { + mControllerMoga.onDestroy(); + } + if (mControllerOuya != null) { + mControllerOuya.onDestroy(); + } + + super.onDestroy(); + } } \ No newline at end of file diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java index f1cec07d11..0a4ce8b822 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java @@ -10,248 +10,248 @@ import android.view.MotionEvent; public class GameControllerHelper { - public static final String StandardControllerName = "Standard"; - - SparseIntArray ControllerKeyMap; - - private static final int AXIS_X = 0; - private static final int AXIS_Y = 1; - private static final int AXIS_Z = 11; - private static final int AXIS_RZ = 14; - private static final int AXIS_LTRIGGER = 17; - 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_THROTTLE = 19; - - public GameControllerHelper(GameControllerActivity activity){ - - ControllerKeyMap = new SparseIntArray(25); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z); - - ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP); - ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN); - ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT); - ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT); - ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER); - - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK); - - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER); - - ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X); - ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y); - ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X); - ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y); - - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START); - ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT); - } - - private float mOldLeftThumbstickX = 0.0f; - private float mOldLeftThumbstickY = 0.0f; - private float mOldRightThumbstickX = 0.0f; - private float mOldRightThumbstickY = 0.0f; - - private float mOldLeftTrigger = 0.0f; - private float mOldRightTrigger = 0.0f; - private float mOldThrottle = 0.0f; - private float mOldBrake = 0.0f; - private float mOldGas = 0.0f; - - public boolean dispatchGenericMotionEvent(MotionEvent event) { - boolean handled = false; - - int eventSource = event.getSource(); - + public static final String StandardControllerName = "Standard"; + + SparseIntArray ControllerKeyMap; + + private static final int AXIS_X = 0; + private static final int AXIS_Y = 1; + private static final int AXIS_Z = 11; + private static final int AXIS_RZ = 14; + private static final int AXIS_LTRIGGER = 17; + 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_THROTTLE = 19; + + public GameControllerHelper(GameControllerActivity activity){ + + ControllerKeyMap = new SparseIntArray(25); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z); + + ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP); + ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN); + ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT); + ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT); + ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER); + + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK); + + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER); + + ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X); + ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y); + ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X); + ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y); + + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START); + ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT); + } + + private float mOldLeftThumbstickX = 0.0f; + private float mOldLeftThumbstickY = 0.0f; + private float mOldRightThumbstickX = 0.0f; + private float mOldRightThumbstickY = 0.0f; + + private float mOldLeftTrigger = 0.0f; + private float mOldRightTrigger = 0.0f; + private float mOldThrottle = 0.0f; + private float mOldBrake = 0.0f; + private float mOldGas = 0.0f; + + public boolean dispatchGenericMotionEvent(MotionEvent event) { + boolean handled = false; + + int eventSource = event.getSource(); + if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - if (event.getAction() == MotionEvent.ACTION_MOVE) { - int deviceId = event.getDeviceId(); - String deviceName = event.getDevice().getName(); - if(mGameController.get(deviceId) == null){ - gatherControllers(mGameController); - mGameController.append(deviceId, deviceName); - } - - float newAXIS_LX = event.getAxisValue(AXIS_X); - if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true); - mOldLeftThumbstickX = newAXIS_LX; - handled = true; - } - - float newAXIS_LY = event.getAxisValue(AXIS_Y); - if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true); - mOldLeftThumbstickY = newAXIS_LY; - handled = true; - } - - float newAXIS_RX = event.getAxisValue(AXIS_Z); - if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true); - mOldRightThumbstickX = newAXIS_RX; - handled = true; - } - - float newAXIS_RY = event.getAxisValue(AXIS_RZ); - if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true); - mOldRightThumbstickY = newAXIS_RY; - handled = true; - } - - float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER); - if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true); - mOldLeftTrigger = newAXIS_LTRIGGER; - handled = true; - } - - float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER); - if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true); - mOldRightTrigger = newAXIS_RTRIGGER; - handled = true; - } - - float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE); - if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true); - mOldBrake = newAXIS_BRAKE; - handled = true; - } - - float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE); - if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true); - mOldThrottle = newAXIS_THROTTLE; - handled = true; - } - - float newAXIS_GAS = event.getAxisValue(AXIS_GAS); - if (Float.compare(newAXIS_GAS , mOldGas) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true); - mOldGas = newAXIS_GAS; - handled = true; - } - } + || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) + { + if (event.getAction() == MotionEvent.ACTION_MOVE) { + int deviceId = event.getDeviceId(); + String deviceName = event.getDevice().getName(); + if(mGameController.get(deviceId) == null){ + gatherControllers(mGameController); + mGameController.append(deviceId, deviceName); + } + + float newAXIS_LX = event.getAxisValue(AXIS_X); + if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true); + mOldLeftThumbstickX = newAXIS_LX; + handled = true; + } + + float newAXIS_LY = event.getAxisValue(AXIS_Y); + if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true); + mOldLeftThumbstickY = newAXIS_LY; + handled = true; + } + + float newAXIS_RX = event.getAxisValue(AXIS_Z); + if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true); + mOldRightThumbstickX = newAXIS_RX; + handled = true; + } + + float newAXIS_RY = event.getAxisValue(AXIS_RZ); + if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true); + mOldRightThumbstickY = newAXIS_RY; + handled = true; + } + + float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER); + if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true); + mOldLeftTrigger = newAXIS_LTRIGGER; + handled = true; + } + + float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER); + if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true); + mOldRightTrigger = newAXIS_RTRIGGER; + handled = true; + } + + float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE); + if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true); + mOldBrake = newAXIS_BRAKE; + handled = true; + } + + float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE); + if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true); + mOldThrottle = newAXIS_THROTTLE; + handled = true; + } + + float newAXIS_GAS = event.getAxisValue(AXIS_GAS); + if (Float.compare(newAXIS_GAS , mOldGas) != 0) { + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true); + mOldGas = newAXIS_GAS; + handled = true; + } + } } - return handled; - } - - private static SparseArray> mControllerExtendKey = new SparseArray>(); - - public boolean dispatchKeyEvent(KeyEvent event) { - boolean handled = false; - - int eventSource = event.getSource(); - int keyCode = event.getKeyCode(); - int controllerKey = ControllerKeyMap.get(keyCode); - - if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - int deviceId = event.getDeviceId(); - String deviceName = event.getDevice().getName(); - - if(mGameController.get(deviceId) == null){ - gatherControllers(mGameController); - mGameController.append(deviceId, deviceName); - } - - if (controllerKey == 0) { - if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) { - controllerKey = keyCode; - }else { - return false; - } - } - - int action = event.getAction(); - if (action == KeyEvent.ACTION_DOWN) { - handled = true; - GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false); - }else if (action == KeyEvent.ACTION_UP) { - handled = true; - GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false); - } - } - - return handled; + return handled; + } + + private static SparseArray> mControllerExtendKey = new SparseArray>(); + + public boolean dispatchKeyEvent(KeyEvent event) { + boolean handled = false; + + int eventSource = event.getSource(); + int keyCode = event.getKeyCode(); + int controllerKey = ControllerKeyMap.get(keyCode); + + if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) + || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) + { + int deviceId = event.getDeviceId(); + String deviceName = event.getDevice().getName(); + + if(mGameController.get(deviceId) == null){ + gatherControllers(mGameController); + mGameController.append(deviceId, deviceName); + } + + if (controllerKey == 0) { + if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) { + controllerKey = keyCode; + }else { + return false; + } + } + + int action = event.getAction(); + if (action == KeyEvent.ACTION_DOWN) { + handled = true; + GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false); + }else if (action == KeyEvent.ACTION_UP) { + handled = true; + GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false); + } + } + + return handled; + } + + public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) { + if (receive) { + if (mControllerExtendKey.get(deviceId) == null) { + mControllerExtendKey.put(deviceId, new ArrayList()); + } + mControllerExtendKey.get(deviceId).add(externalKeyCode); + } else { + if (mControllerExtendKey.get(deviceId) != null) { + mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode)); + } + } + } + + SparseArray mGameController = new SparseArray(); + + void onInputDeviceAdded(int deviceId){ + try { + InputDevice device = InputDevice.getDevice(deviceId); + int deviceSource = device.getSources(); + + if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) + || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) + { + String deviceName = device.getName(); + mGameController.append(deviceId, deviceName); + GameControllerAdapter.onConnected(deviceName, deviceId); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + void onInputDeviceChanged(int deviceId){ + gatherControllers(mGameController); + } + + void onInputDeviceRemoved(int deviceId) { + if (mGameController.get(deviceId) != null) { + GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId); + mGameController.delete(deviceId); + } + } + + static void gatherControllers(SparseArray controllers){ + int controllerCount = controllers.size(); + for (int i = 0; i < controllerCount; i++) { + try { + int controllerDeveceId = controllers.keyAt(i); + InputDevice device = InputDevice.getDevice(controllerDeveceId); + if (device == null) { + GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId); + controllers.delete(controllerDeveceId); + } + } catch (Exception e) { + int controllerDeveceId = controllers.keyAt(i); + GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId); + controllers.delete(controllerDeveceId); + e.printStackTrace(); + } + } } - - public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) { - if (receive) { - if (mControllerExtendKey.get(deviceId) == null) { - mControllerExtendKey.put(deviceId, new ArrayList()); - } - mControllerExtendKey.get(deviceId).add(externalKeyCode); - } else { - if (mControllerExtendKey.get(deviceId) != null) { - mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode)); - } - } - } - - SparseArray mGameController = new SparseArray(); - - void onInputDeviceAdded(int deviceId){ - try { - InputDevice device = InputDevice.getDevice(deviceId); - int deviceSource = device.getSources(); - - if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - String deviceName = device.getName(); - mGameController.append(deviceId, deviceName); - GameControllerAdapter.onConnected(deviceName, deviceId); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - void onInputDeviceChanged(int deviceId){ - gatherControllers(mGameController); - } - - void onInputDeviceRemoved(int deviceId) { - if (mGameController.get(deviceId) != null) { - GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId); - mGameController.delete(deviceId); - } - } - - static void gatherControllers(SparseArray controllers){ - int controllerCount = controllers.size(); - for (int i = 0; i < controllerCount; i++) { - try { - int controllerDeveceId = controllers.keyAt(i); - InputDevice device = InputDevice.getDevice(controllerDeveceId); - if (device == null) { - GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId); - controllers.delete(controllerDeveceId); - } - } catch (Exception e) { - int controllerDeveceId = controllers.keyAt(i); - GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId); - controllers.delete(controllerDeveceId); - e.printStackTrace(); - } - } - } } diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java index 2fe73a642b..fc11024bbc 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java @@ -14,205 +14,205 @@ import com.bda.controller.StateEvent; public class GameControllerMoga implements ControllerListener, GameControllerDelegate { - private static final String mVendorName = "Moga"; - - private float mOldLeftThumbstickX = 0.0f; - private float mOldLeftThumbstickY = 0.0f; - private float mOldRightThumbstickX = 0.0f; - private float mOldRightThumbstickY = 0.0f; - - private float mOldLeftTrigger = 0.0f; - private float mOldRightTrigger = 0.0f; + private static final String mVendorName = "Moga"; + + private float mOldLeftThumbstickX = 0.0f; + private float mOldLeftThumbstickY = 0.0f; + private float mOldRightThumbstickX = 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() { - mKeyMap = new SparseIntArray(20); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y); - - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, - GameControllerDelegate.BUTTON_LEFT_SHOULDER); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, - GameControllerDelegate.BUTTON_RIGHT_SHOULDER); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, - GameControllerDelegate.BUTTON_LEFT_TRIGGER); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, - GameControllerDelegate.BUTTON_RIGHT_TRIGGER); - - mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, - GameControllerDelegate.BUTTON_DPAD_UP); - mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, - GameControllerDelegate.BUTTON_DPAD_DOWN); - mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, - GameControllerDelegate.BUTTON_DPAD_LEFT); - mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, - GameControllerDelegate.BUTTON_DPAD_RIGHT); - - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, - GameControllerDelegate.BUTTON_START); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, - GameControllerDelegate.BUTTON_SELECT); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, - GameControllerDelegate.BUTTON_START); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, - GameControllerDelegate.BUTTON_LEFT_THUMBSTICK); - mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, - GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK); - } - - public void onKeyEvent(KeyEvent event) { - 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; + public GameControllerMoga() { + mKeyMap = new SparseIntArray(20); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y); + + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, + GameControllerDelegate.BUTTON_LEFT_SHOULDER); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, + GameControllerDelegate.BUTTON_RIGHT_SHOULDER); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, + GameControllerDelegate.BUTTON_LEFT_TRIGGER); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, + GameControllerDelegate.BUTTON_RIGHT_TRIGGER); + + mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, + GameControllerDelegate.BUTTON_DPAD_UP); + mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, + GameControllerDelegate.BUTTON_DPAD_DOWN); + mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, + GameControllerDelegate.BUTTON_DPAD_LEFT); + mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, + GameControllerDelegate.BUTTON_DPAD_RIGHT); + + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, + GameControllerDelegate.BUTTON_START); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, + GameControllerDelegate.BUTTON_SELECT); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, + GameControllerDelegate.BUTTON_START); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, + GameControllerDelegate.BUTTON_LEFT_THUMBSTICK); + mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, + GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK); + } + + public void onKeyEvent(KeyEvent event) { + 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; - if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL - || keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) { - isAnalog = true; - } + if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL + || keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) { + isAnalog = true; + } - if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) { - mControllerEventListener.onButtonEvent(mVendorName, - event.getControllerId(), mKeyMap.get(keycode), isPressed, - isPressed ? 1.0f : 0.0f, isAnalog); - } - } + if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) { + mControllerEventListener.onButtonEvent(mVendorName, + event.getControllerId(), mKeyMap.get(keycode), isPressed, + isPressed ? 1.0f : 0.0f, isAnalog); + } + } - @Override - public void onMotionEvent(MotionEvent event) { - if (mControllerEventListener == null) { - return; - } - int controllerId = event.getControllerId(); - - float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X); - if (newLeftThumbstickX != mOldLeftThumbstickX) { - mControllerEventListener.onAxisEvent(mVendorName, - controllerId, - GameControllerDelegate.THUMBSTICK_LEFT_X, - newLeftThumbstickX, true); - mOldLeftThumbstickX = newLeftThumbstickX; - } + @Override + public void onMotionEvent(MotionEvent event) { + if (mControllerEventListener == null) { + return; + } + int controllerId = event.getControllerId(); + + float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X); + if (newLeftThumbstickX != mOldLeftThumbstickX) { + mControllerEventListener.onAxisEvent(mVendorName, + controllerId, + GameControllerDelegate.THUMBSTICK_LEFT_X, + newLeftThumbstickX, true); + mOldLeftThumbstickX = newLeftThumbstickX; + } - float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y); - if (newLeftThumbstickY != mOldLeftThumbstickY) { - mControllerEventListener.onAxisEvent(mVendorName, - controllerId, - GameControllerDelegate.THUMBSTICK_LEFT_Y, - newLeftThumbstickY, true); - mOldLeftThumbstickY = newLeftThumbstickY; - } + float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y); + if (newLeftThumbstickY != mOldLeftThumbstickY) { + mControllerEventListener.onAxisEvent(mVendorName, + controllerId, + GameControllerDelegate.THUMBSTICK_LEFT_Y, + newLeftThumbstickY, true); + mOldLeftThumbstickY = newLeftThumbstickY; + } - float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z); - if (newRightThumbstickX != mOldRightThumbstickX) { - mControllerEventListener.onAxisEvent(mVendorName, - controllerId, - GameControllerDelegate.THUMBSTICK_RIGHT_X, - newRightThumbstickX, true); - mOldRightThumbstickX = newRightThumbstickX; - } + float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z); + if (newRightThumbstickX != mOldRightThumbstickX) { + mControllerEventListener.onAxisEvent(mVendorName, + controllerId, + GameControllerDelegate.THUMBSTICK_RIGHT_X, + newRightThumbstickX, true); + mOldRightThumbstickX = newRightThumbstickX; + } - float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ); - if (newRightThumbstickY != mOldRightThumbstickY) { - mControllerEventListener.onAxisEvent(mVendorName, - controllerId, - GameControllerDelegate.THUMBSTICK_RIGHT_Y, - newRightThumbstickY, true); - mOldRightThumbstickY = newRightThumbstickY; - } - - float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER); - if (newLeftTrigger != mOldLeftTrigger) { - mControllerEventListener.onAxisEvent(mVendorName, - controllerId, - GameControllerDelegate.BUTTON_LEFT_TRIGGER, - newLeftTrigger, true); - mOldLeftTrigger = newLeftTrigger; - } - - float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER); - if (newRightTrigger != mOldRightTrigger) { - mControllerEventListener.onAxisEvent(mVendorName, - controllerId, - GameControllerDelegate.BUTTON_RIGHT_TRIGGER, - newRightTrigger, true); - mOldRightTrigger = newRightTrigger; - } - } + float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ); + if (newRightThumbstickY != mOldRightThumbstickY) { + mControllerEventListener.onAxisEvent(mVendorName, + controllerId, + GameControllerDelegate.THUMBSTICK_RIGHT_Y, + newRightThumbstickY, true); + mOldRightThumbstickY = newRightThumbstickY; + } + + float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER); + if (newLeftTrigger != mOldLeftTrigger) { + mControllerEventListener.onAxisEvent(mVendorName, + controllerId, + GameControllerDelegate.BUTTON_LEFT_TRIGGER, + newLeftTrigger, true); + mOldLeftTrigger = newLeftTrigger; + } + + float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER); + if (newRightTrigger != mOldRightTrigger) { + mControllerEventListener.onAxisEvent(mVendorName, + controllerId, + GameControllerDelegate.BUTTON_RIGHT_TRIGGER, + newRightTrigger, true); + mOldRightTrigger = newRightTrigger; + } + } - @Override - public void onStateEvent(StateEvent event) { - if (mControllerEventListener != null) { - switch (event.getState()) { - case StateEvent.STATE_CONNECTION: - switch (event.getAction()) { - case StateEvent.ACTION_DISCONNECTED: - // disconnected from controller - mControllerEventListener.onDisconnected(mVendorName, - event.getControllerId()); - break; - case StateEvent.ACTION_CONNECTED: - // connected to controller - mControllerEventListener.onConnected(mVendorName, - event.getControllerId()); - break; - case StateEvent.ACTION_CONNECTING: - // attempting to connect to controller - break; - } - break; - case StateEvent.STATE_POWER_LOW: - if (event.getAction() == StateEvent.ACTION_TRUE) { - // controller has entered low power state - } else { - // controller has entered normal power state - } - break; - } - } - } + @Override + public void onStateEvent(StateEvent event) { + if (mControllerEventListener != null) { + switch (event.getState()) { + case StateEvent.STATE_CONNECTION: + switch (event.getAction()) { + case StateEvent.ACTION_DISCONNECTED: + // disconnected from controller + mControllerEventListener.onDisconnected(mVendorName, + event.getControllerId()); + break; + case StateEvent.ACTION_CONNECTED: + // connected to controller + mControllerEventListener.onConnected(mVendorName, + event.getControllerId()); + break; + case StateEvent.ACTION_CONNECTING: + // attempting to connect to controller + break; + } + break; + case StateEvent.STATE_POWER_LOW: + if (event.getAction() == StateEvent.ACTION_TRUE) { + // controller has entered low power state + } else { + // controller has entered normal power state + } + break; + } + } + } - private Controller mController = null; + private Controller mController = null; - public void onCreate(Context context) { - mController = Controller.getInstance(context); - - mController.init(); - mController.setListener(this, new Handler()); - } + public void onCreate(Context context) { + mController = Controller.getInstance(context); + + mController.init(); + mController.setListener(this, new Handler()); + } - public void onPause() { - mController.onPause(); - } + public void onPause() { + mController.onPause(); + } - public void onResume() { - mController.onResume(); - } + public void onResume() { + mController.onResume(); + } - public void onDestroy() { - mController.exit(); - } - - private ControllerEventListener mControllerEventListener; - @Override - public void setControllerEventListener(ControllerEventListener listener) { - mControllerEventListener = listener; - } + public void onDestroy() { + mController.exit(); + } + + private ControllerEventListener mControllerEventListener; + @Override + public void setControllerEventListener(ControllerEventListener listener) { + mControllerEventListener = listener; + } - @Override - public boolean dispatchKeyEvent(android.view.KeyEvent event) { - return false; - } + @Override + public boolean dispatchKeyEvent(android.view.KeyEvent event) { + return false; + } - @Override - public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) { - return false; - } + @Override + public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) { + return false; + } } diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java index ec3aeb9723..a1e60a5d21 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java @@ -26,16 +26,16 @@ import android.view.MotionEvent; public class GameControllerNibiru implements OnControllerSeviceListener, OnKeyListener, OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameControllerDelegate { - private static final String TAG = "NibiruTag"; - - private Context mContext; - private SparseIntArray mKeyMap; - private ControllerEventListener mControllerEventListener = null; - private ControllerService mControllerService = null; - - public GameControllerNibiru() { - mKeyMap = new SparseIntArray(20); - + private static final String TAG = "NibiruTag"; + + private Context mContext; + private SparseIntArray mKeyMap; + private ControllerEventListener mControllerEventListener = null; + private ControllerService mControllerService = null; + + public GameControllerNibiru() { + mKeyMap = new SparseIntArray(20); + mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_A , GameControllerDelegate.BUTTON_A); mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_B , GameControllerDelegate.BUTTON_B); mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_X , GameControllerDelegate.BUTTON_X); @@ -52,188 +52,188 @@ OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameContr mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_SELECT , GameControllerDelegate.BUTTON_SELECT); mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBL , GameControllerDelegate.BUTTON_LEFT_THUMBSTICK); mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBR , GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK); - } - - @Override - public void setControllerEventListener(ControllerEventListener listener) { - mControllerEventListener = listener; - } - - public void onCreate(Context context) { - mContext = context; - - mControllerService = Controller.getControllerService(); - if (mControllerService != null) { - mControllerService.setControllerServiceListener(this); - mControllerService.setStateListener(this); - mControllerService.setKeyListener(this); - mControllerService.setSimpleStickListener(this); - //mControllerService.setAccListener(this); - //mControllerService.setGyroListener(this); - mControllerService.setEnableLR2(true); - mControllerService.setAutoKeyUpMode(false); - - mControllerService.checkNibiruInstall(mContext, false); - } - } - - public void onPause() { - if (mControllerService != null) { - mControllerService.setEnable(false); - } - } - - public void onResume() { - if (mControllerService != null) { - if (mControllerService.isServiceEnable()) { - //onControllerServiceReady(true); - } else { - if (mControllerService.checkNibiruInstall(mContext, false)) { - try { - mControllerService.register(mContext); - } catch (ControllerServiceException e) { - e.printStackTrace(); - } - } - } - - mControllerService.setEnable(true); - } - } - - public void onDestroy() { - if( mControllerService != null ){ - mControllerService.unregister(); - } - } + } + + @Override + public void setControllerEventListener(ControllerEventListener listener) { + mControllerEventListener = listener; + } + + public void onCreate(Context context) { + mContext = context; + + mControllerService = Controller.getControllerService(context); + if (mControllerService != null) { + mControllerService.setControllerServiceListener(this); + mControllerService.setStateListener(this); + mControllerService.setKeyListener(this); + mControllerService.setSimpleStickListener(this); + //mControllerService.setAccListener(this); + //mControllerService.setGyroListener(this); + mControllerService.setEnableL2R2(true); + mControllerService.setAutoKeyUpMode(false); + + mControllerService.checkNibiruInstall(mContext, false); + } + } + + public void onPause() { + if (mControllerService != null) { + mControllerService.setEnable(false); + } + } + + public void onResume() { + if (mControllerService != null) { + if (mControllerService.isServiceEnable()) { + //onControllerServiceReady(true); + } else { + if (mControllerService.checkNibiruInstall(mContext, false)) { + try { + mControllerService.register(mContext); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } + } + } + + mControllerService.setEnable(true); + } + } + + public void onDestroy() { + if( mControllerService != null ){ + mControllerService.unregister(); + } + } - @Override - public void onControllerServiceReady(boolean isSucc) { - if( isSucc ) - { - if( !mControllerService.hasDeviceConnected() ){ - Bundle bun = new Bundle(); - bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false); - try { - mControllerService.showDeviceManagerUI(mContext, bun); - } catch (ControllerServiceException e) { - e.printStackTrace(); - } - } - } - } + @Override + public void onControllerServiceReady(boolean isSucc) { + if( isSucc ) + { + if( !mControllerService.hasDeviceConnected() ){ + Bundle bun = new Bundle(); + bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false); + /*try { + mControllerService.showDeviceManagerUI(mContext, bun); + } catch (ControllerServiceException e) { + e.printStackTrace(); + }*/ + } + } + } - @Override - public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) { - if (mKeyMap.get(keyCode) == 0) { - Log.e(TAG, "Didn't map the key: " + keyCode); - return; - } - - if (mControllerEventListener != null) { - try { - ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); - - mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(), - mKeyMap.get(keyCode), true, 1.0f, false); - } catch (ControllerServiceException e) { - e.printStackTrace(); - } - } - } + @Override + public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) { + if (mKeyMap.get(keyCode) == 0) { + Log.e(TAG, "Didn't map the key: " + keyCode); + return; + } + + if (mControllerEventListener != null) { + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(), + mKeyMap.get(keyCode), true, 1.0f, false); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } + } + } - @Override - public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) { - if (mKeyMap.get(keyCode) == 0) { - Log.e(TAG, "Didn't map the key: " + keyCode); - return; - } - - if (mControllerEventListener != null) { - try { - ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); - - mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(), - mKeyMap.get(keyCode), false, 0.0f, false); - } catch (ControllerServiceException e) { - e.printStackTrace(); - } - } - } + @Override + public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) { + if (mKeyMap.get(keyCode) == 0) { + Log.e(TAG, "Didn't map the key: " + keyCode); + return; + } + + if (mControllerEventListener != null) { + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(), + mKeyMap.get(keyCode), false, 0.0f, false); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } + } + } - @Override - public void onLeftStickChanged(int playerOrder, float x, float y) { - if (mControllerEventListener != null) { - try { - ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); - - String deviceName = controllerDevice.getDeviceName(); - int deviceId = controllerDevice.getDeviceId(); - - mControllerEventListener.onAxisEvent(deviceName, deviceId, - GameControllerDelegate.THUMBSTICK_LEFT_X, x, true); - mControllerEventListener.onAxisEvent(deviceName, deviceId, - GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true); - } catch (ControllerServiceException e) { - e.printStackTrace(); - } - } - } + @Override + public void onLeftStickChanged(int playerOrder, float x, float y) { + if (mControllerEventListener != null) { + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + String deviceName = controllerDevice.getDeviceName(); + int deviceId = controllerDevice.getDeviceId(); + + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_LEFT_X, x, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } + } + } - @Override - public void onRightStickChanged(int playerOrder, float x, float y) { - if (mControllerEventListener != null) { - try { - ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); - - String deviceName = controllerDevice.getDeviceName(); - int deviceId = controllerDevice.getDeviceId(); - - mControllerEventListener.onAxisEvent(deviceName, deviceId, - GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true); - mControllerEventListener.onAxisEvent(deviceName, deviceId, - GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true); - } catch (ControllerServiceException e) { - e.printStackTrace(); - } - } - } - - @Override - public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) { - if (mControllerEventListener != null) { - if (state == ControllerDevice.STATE_CONN) - { - mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId()); - } - else if (state == ControllerDevice.STATE_DISCONN) - { - mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId()); - } - } - } + @Override + public void onRightStickChanged(int playerOrder, float x, float y) { + if (mControllerEventListener != null) { + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + String deviceName = controllerDevice.getDeviceName(); + int deviceId = controllerDevice.getDeviceId(); + + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } + } + } + + @Override + public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) { + if (mControllerEventListener != null) { + if (state == ControllerDevice.STATE_CONN) + { + mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId()); + } + else if (state == ControllerDevice.STATE_DISCONN) + { + mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId()); + } + } + } - public boolean dispatchGenericMotionEvent(MotionEvent event){ - return mControllerService.handleExternalInput(event); - } - - public boolean dispatchKeyEvent(KeyEvent event){ - return mControllerService.handleExternalInput(event); - } - - @Override - public void onControllerAccEvent(int playerOrder, AccEvent event) { - - } + public boolean dispatchGenericMotionEvent(MotionEvent event){ + return mControllerService.handleExternalInput(event); + } + + public boolean dispatchKeyEvent(KeyEvent event){ + return mControllerService.handleExternalInput(event); + } + + @Override + public void onControllerAccEvent(int playerOrder, AccEvent event) { + + } - @Override - public void onControllerGyroEvent(int playerOrder, GyroEvent event) { - - } + @Override + public void onControllerGyroEvent(int playerOrder, GyroEvent event) { + + } - @Override - public void onBluetoothStateChanged(int state) { - Log.d(TAG, "onBluetoothStateChanged:"+state); - } + @Override + public void onBluetoothStateChanged(int state) { + Log.d(TAG, "onBluetoothStateChanged:"+state); + } } diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java index fab0fdc80a..a750b58351 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java @@ -11,17 +11,17 @@ import android.view.KeyEvent; import android.view.MotionEvent; public class GameControllerOuya implements GameControllerDelegate{ - - private SparseIntArray mKeyMap; - private SparseArray mGameController = new SparseArray(); - - public GameControllerOuya(){ - mKeyMap = new SparseIntArray(20); - mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B); - mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A); - mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X); - mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y); + private SparseIntArray mKeyMap; + + private SparseArray mGameController = new SparseArray(); + + public GameControllerOuya(){ + mKeyMap = new SparseIntArray(20); + mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B); + mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A); + mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X); + mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y); mKeyMap.put(OuyaController.BUTTON_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN); mKeyMap.put(OuyaController.BUTTON_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT); mKeyMap.put(OuyaController.BUTTON_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT); @@ -34,150 +34,142 @@ public class GameControllerOuya implements GameControllerDelegate{ } public void onCreate(Context context) { - OuyaController.init(context); - /*GameControllerAdapter.addRunnableToFrameStartList(new Runnable() { - - @Override - public void run() { - OuyaController.startOfFrame(); - } - - });*/ + OuyaController.init(context); } private float mOldLeftThumbstickX = 0.0f; - private float mOldLeftThumbstickY = 0.0f; - private float mOldRightThumbstickX = 0.0f; - private float mOldRightThumbstickY = 0.0f; - + private float mOldLeftThumbstickY = 0.0f; + private float mOldRightThumbstickX = 0.0f; + private float mOldRightThumbstickY = 0.0f; + private float mOldLeftTrigger = 0.0f; - private float mOldRightTrigger = 0.0f; - + private float mOldRightTrigger = 0.0f; + public boolean dispatchGenericMotionEvent(MotionEvent event) { boolean handled = OuyaController.onGenericMotionEvent(event); if (handled && mControllerEventListener != null) { - int deviceId = event.getDeviceId(); - String deviceName = event.getDevice().getName(); - OuyaController c = OuyaController.getControllerByDeviceId(deviceId); - if (mGameController.get(deviceId) == null) { - GameControllerHelper.gatherControllers(mGameController); - mGameController.append(deviceId, deviceName); - } - - float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2); - if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true); - mOldLeftTrigger = newLeftTrigger; - } - - float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2); - if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true); - mOldRightTrigger = newRightTrigger; - } - - float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X); - if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) { - if (Float.compare(newLeftThumbstickX, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true); - }else { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true); - } - mOldLeftThumbstickX = newLeftThumbstickX; - } - - float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y); - if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) { - if (Float.compare(newLeftThumbstickY, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true); - }else { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true); - } - mOldLeftThumbstickY = newLeftThumbstickY; - } - - float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X); - if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) { - if (Float.compare(newRightThumbstickX, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true); - }else { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true); - } - mOldRightThumbstickX = newRightThumbstickX; - } - - float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y); - if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) { - if (Float.compare(newRightThumbstickY, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true); - }else { - mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true); - } - mOldRightThumbstickY = newRightThumbstickY; - } + int deviceId = event.getDeviceId(); + String deviceName = event.getDevice().getName(); + OuyaController c = OuyaController.getControllerByDeviceId(deviceId); + if (mGameController.get(deviceId) == null) { + GameControllerHelper.gatherControllers(mGameController); + mGameController.append(deviceId, deviceName); + } + + float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2); + if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true); + mOldLeftTrigger = newLeftTrigger; + } + + float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2); + if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true); + mOldRightTrigger = newRightTrigger; + } + + float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X); + if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) { + if (Float.compare(newLeftThumbstickX, 0.0f) == 0) { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true); + }else { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true); + } + mOldLeftThumbstickX = newLeftThumbstickX; + } + + float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y); + if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) { + if (Float.compare(newLeftThumbstickY, 0.0f) == 0) { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true); + }else { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true); + } + mOldLeftThumbstickY = newLeftThumbstickY; + } + + float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X); + if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) { + if (Float.compare(newRightThumbstickX, 0.0f) == 0) { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true); + }else { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true); + } + mOldRightThumbstickX = newRightThumbstickX; + } + + float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y); + if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) { + if (Float.compare(newRightThumbstickY, 0.0f) == 0) { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true); + }else { + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true); + } + mOldRightThumbstickY = newRightThumbstickY; + } } return handled; } public boolean dispatchKeyEvent(KeyEvent event) { - boolean handled = false; - - int action = event.getAction(); - int keyCode = event.getKeyCode(); - - if (action == KeyEvent.ACTION_DOWN) { - handled = OuyaController.onKeyDown(keyCode, event); - } - else if (action == KeyEvent.ACTION_UP) { - handled = OuyaController.onKeyUp(keyCode, event); - } - - if (handled && mControllerEventListener != null) { - boolean isAnalog = false; - - if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){ - isAnalog = true; - } - - int deviceId = event.getDeviceId(); - String deviceName = event.getDevice().getName(); - - if (mGameController.get(deviceId) == null) { - GameControllerHelper.gatherControllers(mGameController); - mGameController.append(deviceId, deviceName); - } - if (action == KeyEvent.ACTION_DOWN) { - mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog); - }else { - mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog); - } - } - - return handled; + boolean handled = false; + + int action = event.getAction(); + int keyCode = event.getKeyCode(); + + if (action == KeyEvent.ACTION_DOWN) { + handled = OuyaController.onKeyDown(keyCode, event); + } + else if (action == KeyEvent.ACTION_UP) { + handled = OuyaController.onKeyUp(keyCode, event); + } + + if (handled && mControllerEventListener != null) { + boolean isAnalog = false; + + if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){ + isAnalog = true; + } + + int deviceId = event.getDeviceId(); + String deviceName = event.getDevice().getName(); + + if (mGameController.get(deviceId) == null) { + GameControllerHelper.gatherControllers(mGameController); + mGameController.append(deviceId, deviceName); + } + if (action == KeyEvent.ACTION_DOWN) { + mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog); + }else { + mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog); + } + } + + return handled; } - public void onPause() { + public void onPause() { // show the mouse cursor OuyaController.showCursor(true); - } - - public void onResume() { + } + + public void onResume() { // hide the mouse cursor OuyaController.showCursor(false); - } - - public void onDestroy() { - - } + } + + public void onDestroy() { + + } - private ControllerEventListener mControllerEventListener; - - @Override - public void setControllerEventListener(ControllerEventListener listener) { - mControllerEventListener = listener; - } - + private ControllerEventListener mControllerEventListener; + + @Override + public void setControllerEventListener(ControllerEventListener listener) { + mControllerEventListener = listener; + } + } diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index 6eefcd775a..867e942063 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -49,7 +49,7 @@ import android.util.DisplayMetrics; import android.util.Log; //Enhance API modification import android.view.Display; import android.view.WindowManager; -import android.content.ServiceConnection; //Enhance API modification +import android.content.ServiceConnection; //Enhance API modification import com.enhance.gameservice.IGameTuningService; //Enhance API modification diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java index 00ddc97845..9c7a2a7a64 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java @@ -144,7 +144,7 @@ public class Cocos2dxHttpURLConnection } } - //Add header + //Add header static void addRequestHeader(HttpURLConnection urlConnection, String key, String value) { urlConnection.setRequestProperty(key, value); } @@ -181,7 +181,7 @@ public class Cocos2dxHttpURLConnection } static String getResponseHeaders(HttpURLConnection http) { - Map> headers = http.getHeaderFields(); + Map> headers = http.getHeaderFields(); if (null == headers) { return null; } diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxJavascriptJavaBridge.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxJavascriptJavaBridge.java index 996bda03c2..9c7cf96359 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxJavascriptJavaBridge.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxJavascriptJavaBridge.java @@ -23,5 +23,5 @@ package org.cocos2dx.lib; public class Cocos2dxJavascriptJavaBridge { - public static native int evalString(String value); + public static native int evalString(String value); } diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java index 70264590df..7a1b0d3204 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxRenderer.java @@ -147,12 +147,12 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer { } public void handleOnPause() { - /** - * onPause may be invoked before onSurfaceCreated, - * and engine will be initialized correctly after - * onSurfaceCreated is invoked. Can not invoke any - * native method before onSurfaceCreated is invoked - */ + /** + * onPause may be invoked before onSurfaceCreated, + * and engine will be initialized correctly after + * onSurfaceCreated is invoked. Can not invoke any + * native method before onSurfaceCreated is invoked + */ if (! mNativeInitCompleted) return; diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java index 5160f680db..ff9105fdbb 100755 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java @@ -126,7 +126,7 @@ public class Cocos2dxWebViewHelper { public void run() { Cocos2dxWebView webView = webViews.get(index); if (webView != null) { - webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null); + webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null); } } }); @@ -138,7 +138,7 @@ public class Cocos2dxWebViewHelper { public void run() { Cocos2dxWebView webView = webViews.get(index); if (webView != null) { - webView.loadDataWithBaseURL(baseUrl, data, null, null, null); + webView.loadDataWithBaseURL(baseUrl, data, null, null, null); } } }); diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index e9cf553a7b..af7782712e 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -6085,6 +6085,18 @@ str return map_object; }, +/** + * @method getFileSize + * @param {String} arg0 + * @return {long} + */ +getFileSize : function ( +str +) +{ + return 0; +}, + /** * @method getValueMapFromData * @param {char} arg0 @@ -6122,15 +6134,17 @@ array }, /** - * @method getFileSize + * @method writeStringToFile * @param {String} arg0 - * @return {long} + * @param {String} arg1 + * @return {bool} */ -getFileSize : function ( +writeStringToFile : function ( +str, str ) { - return 0; + return false; }, /** @@ -6167,6 +6181,20 @@ bool { }, +/** + * @method writeValueVectorToFile + * @param {Array} arg0 + * @param {String} arg1 + * @return {bool} + */ +writeValueVectorToFile : function ( +array, +str +) +{ + return false; +}, + /** * @method isFileExist * @param {String} arg0 @@ -6213,6 +6241,20 @@ str return ; }, +/** + * @method writeValueMapToFile + * @param {map_object} arg0 + * @param {String} arg1 + * @return {bool} + */ +writeValueMapToFile : function ( +map, +str +) +{ + return false; +}, + /** * @method setWritablePath * @param {String} arg0 diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index e257969808..b0a958349e 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -17212,6 +17212,28 @@ bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsv JS_ReportError(cx, "js_cocos2dx_FileUtils_getValueMapFromFile : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getFileSize : Invalid Native Object"); + if (argc == 1) { + std::string arg0; + ok &= jsval_to_std_string(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getFileSize : Error processing arguments"); + long ret = cobj->getFileSize(arg0); + jsval jsret = JSVAL_NULL; + jsret = long_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_FileUtils_getFileSize : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -17278,26 +17300,28 @@ bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *v JS_ReportError(cx, "js_cocos2dx_FileUtils_setSearchPaths : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_FileUtils_writeStringToFile(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getFileSize : Invalid Native Object"); - if (argc == 1) { + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeStringToFile : Invalid Native Object"); + if (argc == 2) { std::string arg0; + std::string arg1; ok &= jsval_to_std_string(cx, args.get(0), &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getFileSize : Error processing arguments"); - long ret = cobj->getFileSize(arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeStringToFile : Error processing arguments"); + bool ret = cobj->writeStringToFile(arg0, arg1); jsval jsret = JSVAL_NULL; - jsret = long_to_jsval(cx, ret); + jsret = BOOLEAN_TO_JSVAL(ret); args.rval().set(jsret); return true; } - JS_ReportError(cx, "js_cocos2dx_FileUtils_getFileSize : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_FileUtils_writeStringToFile : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp) @@ -17380,6 +17404,30 @@ bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp JS_ReportError(cx, "js_cocos2dx_FileUtils_addSearchPath : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_FileUtils_writeValueVectorToFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeValueVectorToFile : Invalid Native Object"); + if (argc == 2) { + cocos2d::ValueVector arg0; + std::string arg1; + ok &= jsval_to_ccvaluevector(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeValueVectorToFile : Error processing arguments"); + bool ret = cobj->writeValueVectorToFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_FileUtils_writeValueVectorToFile : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -17464,6 +17512,30 @@ bool js_cocos2dx_FileUtils_getSuitableFOpen(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_FileUtils_getSuitableFOpen : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_FileUtils_writeValueMapToFile(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeValueMapToFile : Invalid Native Object"); + if (argc == 2) { + cocos2d::ValueMap arg0; + std::string arg1; + ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0); + ok &= jsval_to_std_string(cx, args.get(1), &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeValueMapToFile : Error processing arguments"); + bool ret = cobj->writeValueMapToFile(arg0, arg1); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_FileUtils_writeValueMapToFile : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -17685,17 +17757,20 @@ void js_register_cocos2dx_FileUtils(JSContext *cx, JS::HandleObject global) { JS_FN("getSearchPaths", js_cocos2dx_FileUtils_getSearchPaths, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("writeToFile", js_cocos2dx_FileUtils_writeToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getValueMapFromFile", js_cocos2dx_FileUtils_getValueMapFromFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getFileSize", js_cocos2dx_FileUtils_getFileSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getValueMapFromData", js_cocos2dx_FileUtils_getValueMapFromData, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeDirectory", js_cocos2dx_FileUtils_removeDirectory, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setSearchPaths", js_cocos2dx_FileUtils_setSearchPaths, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("getFileSize", js_cocos2dx_FileUtils_getFileSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("writeStringToFile", js_cocos2dx_FileUtils_writeStringToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setSearchResolutionsOrder", js_cocos2dx_FileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addSearchResolutionsOrder", js_cocos2dx_FileUtils_addSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addSearchPath", js_cocos2dx_FileUtils_addSearchPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("writeValueVectorToFile", js_cocos2dx_FileUtils_writeValueVectorToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isFileExist", js_cocos2dx_FileUtils_isFileExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("purgeCachedEntries", js_cocos2dx_FileUtils_purgeCachedEntries, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("fullPathFromRelativeFile", js_cocos2dx_FileUtils_fullPathFromRelativeFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getSuitableFOpen", js_cocos2dx_FileUtils_getSuitableFOpen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("writeValueMapToFile", js_cocos2dx_FileUtils_writeValueMapToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setWritablePath", js_cocos2dx_FileUtils_setWritablePath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPopupNotify", js_cocos2dx_FileUtils_setPopupNotify, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isDirectoryExist", js_cocos2dx_FileUtils_isDirectoryExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index 0ca3e4563c..bc50f1abfd 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -926,17 +926,20 @@ bool js_cocos2dx_FileUtils_getValueVectorFromFile(JSContext *cx, uint32_t argc, bool js_cocos2dx_FileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_writeToFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_removeDirectory(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_writeStringToFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_addSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_writeValueVectorToFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_purgeCachedEntries(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_fullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_getSuitableFOpen(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_FileUtils_writeValueMapToFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_setPopupNotify(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_FileUtils_isDirectoryExist(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/cocos/scripting/lua-bindings/auto/api/FileUtils.lua b/cocos/scripting/lua-bindings/auto/api/FileUtils.lua index d85eb6101d..9370f24869 100644 --- a/cocos/scripting/lua-bindings/auto/api/FileUtils.lua +++ b/cocos/scripting/lua-bindings/auto/api/FileUtils.lua @@ -127,7 +127,7 @@ -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- --- Checks whether to pop up a message box when failed to load an image.
+-- Checks whether to pop up a message box when failed to load an image.
-- return True if pop up a message box when failed to load an image, false if not. -- @function [parent=#FileUtils] isPopupNotify -- @param self @@ -150,7 +150,10 @@ -- @return array_table#array_table ret (return value: array_table) -------------------------------- --- +-- write a ValueMap into a plist file
+-- param dict the ValueMap want to save
+-- param fullPath The full path to the file you want to save a string
+-- return bool -- @function [parent=#FileUtils] writeToFile -- @param self -- @param #map_table dict @@ -168,7 +171,18 @@ -- @return map_table#map_table ret (return value: map_table) -------------------------------- --- +-- Retrieve the file size.
+-- note If a relative path was passed in, it will be inserted a default root path at the beginning.
+-- param filepath The path of the file, it could be a relative or absolute path.
+-- return The file size. +-- @function [parent=#FileUtils] getFileSize +-- @param self +-- @param #string filepath +-- @return long#long ret (return value: long) + +-------------------------------- +-- Converts the contents of a file to a ValueMap.
+-- This method is used internally. -- @function [parent=#FileUtils] getValueMapFromData -- @param self -- @param #char filedata @@ -205,14 +219,15 @@ -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- --- Retrieve the file size.
--- note If a relative path was passed in, it will be inserted a default root path at the beginning.
--- param filepath The path of the file, it could be a relative or absolute path.
--- return The file size. --- @function [parent=#FileUtils] getFileSize +-- write a string into a file
+-- param dataStr the string want to save
+-- param fullPath The full path to the file you want to save a string
+-- return bool True if write success +-- @function [parent=#FileUtils] writeStringToFile -- @param self --- @param #string filepath --- @return long#long ret (return value: long) +-- @param #string dataStr +-- @param #string fullPath +-- @return bool#bool ret (return value: bool) -------------------------------- -- Sets the array that contains the search order of the resources.
@@ -245,6 +260,17 @@ -- @param #bool front -- @return FileUtils#FileUtils self (return value: cc.FileUtils) +-------------------------------- +-- write ValueVector into a plist file
+-- param vecData the ValueVector want to save
+-- param fullPath The full path to the file you want to save a string
+-- return bool +-- @function [parent=#FileUtils] writeValueVectorToFile +-- @param self +-- @param #array_table vecData +-- @param #string fullPath +-- @return bool#bool ret (return value: bool) + -------------------------------- -- Checks whether a file exists.
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.
@@ -284,6 +310,17 @@ -- @param #string filenameUtf8 -- @return string#string ret (return value: string) +-------------------------------- +-- write ValueMap into a plist file
+-- param dict the ValueMap want to save
+-- param fullPath The full path to the file you want to save a string
+-- return bool +-- @function [parent=#FileUtils] writeValueMapToFile +-- @param self +-- @param #map_table dict +-- @param #string fullPath +-- @return bool#bool ret (return value: bool) + -------------------------------- -- Sets writable path. -- @function [parent=#FileUtils] setWritablePath diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index b26072606f..2425ad5cfb 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -27207,6 +27207,56 @@ int lua_cocos2dx_FileUtils_getValueMapFromFile(lua_State* tolua_S) return 0; } +int lua_cocos2dx_FileUtils_getFileSize(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::FileUtils* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:getFileSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr); + return 0; + } + long ret = cobj->getFileSize(arg0); + tolua_pushnumber(tolua_S,(lua_Number)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:getFileSize",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_getFileSize'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_FileUtils_getValueMapFromData(lua_State* tolua_S) { int argc = 0; @@ -27360,7 +27410,7 @@ int lua_cocos2dx_FileUtils_setSearchPaths(lua_State* tolua_S) return 0; } -int lua_cocos2dx_FileUtils_getFileSize(lua_State* tolua_S) +int lua_cocos2dx_FileUtils_writeStringToFile(lua_State* tolua_S) { int argc = 0; cocos2d::FileUtils* cobj = nullptr; @@ -27380,32 +27430,35 @@ int lua_cocos2dx_FileUtils_getFileSize(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 if (!cobj) { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr); + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_writeStringToFile'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 2) { std::string arg0; + std::string arg1; - ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:getFileSize"); + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:writeStringToFile"); + + ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.FileUtils:writeStringToFile"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_writeStringToFile'", nullptr); return 0; } - long ret = cobj->getFileSize(arg0); - tolua_pushnumber(tolua_S,(lua_Number)ret); + bool ret = cobj->writeStringToFile(arg0, arg1); + tolua_pushboolean(tolua_S,(bool)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:getFileSize",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:writeStringToFile",argc, 2); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_getFileSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_writeStringToFile'.",&tolua_err); #endif return 0; @@ -27594,6 +27647,59 @@ int lua_cocos2dx_FileUtils_addSearchPath(lua_State* tolua_S) return 0; } +int lua_cocos2dx_FileUtils_writeValueVectorToFile(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::FileUtils* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_writeValueVectorToFile'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 2) + { + cocos2d::ValueVector arg0; + std::string arg1; + + ok &= luaval_to_ccvaluevector(tolua_S, 2, &arg0, "cc.FileUtils:writeValueVectorToFile"); + + ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.FileUtils:writeValueVectorToFile"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_writeValueVectorToFile'", nullptr); + return 0; + } + bool ret = cobj->writeValueVectorToFile(arg0, arg1); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:writeValueVectorToFile",argc, 2); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_writeValueVectorToFile'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_FileUtils_isFileExist(lua_State* tolua_S) { int argc = 0; @@ -27794,6 +27900,59 @@ int lua_cocos2dx_FileUtils_getSuitableFOpen(lua_State* tolua_S) return 0; } +int lua_cocos2dx_FileUtils_writeValueMapToFile(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::FileUtils* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_writeValueMapToFile'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 2) + { + cocos2d::ValueMap arg0; + std::string arg1; + + ok &= luaval_to_ccvaluemap(tolua_S, 2, &arg0, "cc.FileUtils:writeValueMapToFile"); + + ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.FileUtils:writeValueMapToFile"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_writeValueMapToFile'", nullptr); + return 0; + } + bool ret = cobj->writeValueMapToFile(arg0, arg1); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:writeValueMapToFile",argc, 2); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_writeValueMapToFile'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_FileUtils_setWritablePath(lua_State* tolua_S) { int argc = 0; @@ -28230,17 +28389,20 @@ int lua_register_cocos2dx_FileUtils(lua_State* tolua_S) tolua_function(tolua_S,"getSearchPaths",lua_cocos2dx_FileUtils_getSearchPaths); tolua_function(tolua_S,"writeToFile",lua_cocos2dx_FileUtils_writeToFile); tolua_function(tolua_S,"getValueMapFromFile",lua_cocos2dx_FileUtils_getValueMapFromFile); + tolua_function(tolua_S,"getFileSize",lua_cocos2dx_FileUtils_getFileSize); tolua_function(tolua_S,"getValueMapFromData",lua_cocos2dx_FileUtils_getValueMapFromData); tolua_function(tolua_S,"removeDirectory",lua_cocos2dx_FileUtils_removeDirectory); tolua_function(tolua_S,"setSearchPaths",lua_cocos2dx_FileUtils_setSearchPaths); - tolua_function(tolua_S,"getFileSize",lua_cocos2dx_FileUtils_getFileSize); + tolua_function(tolua_S,"writeStringToFile",lua_cocos2dx_FileUtils_writeStringToFile); tolua_function(tolua_S,"setSearchResolutionsOrder",lua_cocos2dx_FileUtils_setSearchResolutionsOrder); tolua_function(tolua_S,"addSearchResolutionsOrder",lua_cocos2dx_FileUtils_addSearchResolutionsOrder); tolua_function(tolua_S,"addSearchPath",lua_cocos2dx_FileUtils_addSearchPath); + tolua_function(tolua_S,"writeValueVectorToFile",lua_cocos2dx_FileUtils_writeValueVectorToFile); tolua_function(tolua_S,"isFileExist",lua_cocos2dx_FileUtils_isFileExist); tolua_function(tolua_S,"purgeCachedEntries",lua_cocos2dx_FileUtils_purgeCachedEntries); tolua_function(tolua_S,"fullPathFromRelativeFile",lua_cocos2dx_FileUtils_fullPathFromRelativeFile); tolua_function(tolua_S,"getSuitableFOpen",lua_cocos2dx_FileUtils_getSuitableFOpen); + tolua_function(tolua_S,"writeValueMapToFile",lua_cocos2dx_FileUtils_writeValueMapToFile); tolua_function(tolua_S,"setWritablePath",lua_cocos2dx_FileUtils_setWritablePath); tolua_function(tolua_S,"setPopupNotify",lua_cocos2dx_FileUtils_setPopupNotify); tolua_function(tolua_S,"isDirectoryExist",lua_cocos2dx_FileUtils_isDirectoryExist); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index 48869a081d..ccd7196432 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -2064,6 +2064,9 @@ int register_all_cocos2dx(lua_State* tolua_S); + + + diff --git a/tests/game-controller-test/Resources/nibirusdk.config b/tests/game-controller-test/Resources/nibirusdk.config new file mode 100644 index 0000000000..00e1a4d45c --- /dev/null +++ b/tests/game-controller-test/Resources/nibirusdk.config @@ -0,0 +1,2 @@ +support_lr2=1 +sdk=nibiru \ No newline at end of file diff --git a/tests/game-controller-test/proj.android-studio/app/AndroidManifest.xml b/tests/game-controller-test/proj.android-studio/app/AndroidManifest.xml index 12ce1f878c..2bdd039e17 100644 --- a/tests/game-controller-test/proj.android-studio/app/AndroidManifest.xml +++ b/tests/game-controller-test/proj.android-studio/app/AndroidManifest.xml @@ -9,15 +9,17 @@ + + - - + + + + + + + + + + diff --git a/tests/game-controller-test/proj.android-studio/app/src/org/cocos2dx/game_controller_test/AppActivity.java b/tests/game-controller-test/proj.android-studio/app/src/org/cocos2dx/game_controller_test/AppActivity.java index 97b31b36d4..58936a5293 100644 --- a/tests/game-controller-test/proj.android-studio/app/src/org/cocos2dx/game_controller_test/AppActivity.java +++ b/tests/game-controller-test/proj.android-studio/app/src/org/cocos2dx/game_controller_test/AppActivity.java @@ -29,16 +29,17 @@ import org.cocos2dx.lib.GameControllerActivity; import android.os.Bundle; public class AppActivity extends GameControllerActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - //The standard controller,without doing anything special. e.g: Amazon Fire TV - - //Manually specify an adapter. - this.connectController(DRIVERTYPE_NIBIRU); - this.connectController(DRIVERTYPE_MOGA); - this.connectController(DRIVERTYPE_OUYA); - } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + //The standard controller,without doing anything special. e.g: Amazon Fire TV + + //Manually specify an adapter. + this.connectController(DRIVERTYPE_NIBIRU); + //Nibiru SDK have already integrated with MOGA service. + //this.connectController(DRIVERTYPE_MOGA); + this.connectController(DRIVERTYPE_OUYA); + } } diff --git a/tests/game-controller-test/proj.android/AndroidManifest.xml b/tests/game-controller-test/proj.android/AndroidManifest.xml index ee6c0a0fb3..5385ef9c4b 100644 --- a/tests/game-controller-test/proj.android/AndroidManifest.xml +++ b/tests/game-controller-test/proj.android/AndroidManifest.xml @@ -12,13 +12,15 @@ + + + android:icon="@drawable/icon"> - - + + + + + + + + + +