mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into issue_9586
This commit is contained in:
commit
8bc68395de
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
#include <stdlib.h>
|
||||
|
||||
#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<void(bool, const std::string&)>& 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<int>(frameSize.width);
|
||||
int height = static_cast<int>(frameSize.height);
|
||||
|
||||
|
||||
bool succeed = false;
|
||||
std::string outputFile = "";
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
std::shared_ptr<GLubyte> buffer(new GLubyte[width * height * 4], [](GLubyte* p){ CC_SAFE_DELETE_ARRAY(p); });
|
||||
|
@ -72,10 +90,10 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
|||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
||||
|
||||
|
||||
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
|
||||
if (!flippedBuffer)
|
||||
{
|
||||
|
@ -87,7 +105,7 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
|||
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
||||
}
|
||||
|
||||
std::shared_ptr<Image> 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<void(bool, const std::string&)>& 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<void(void*)> 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
|
||||
*/
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
|
||||
|
||||
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<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
|
||||
|
||||
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<Integer>());
|
||||
}
|
||||
mControllerExtendKey.get(deviceId).add(externalKeyCode);
|
||||
} else {
|
||||
if (mControllerExtendKey.get(deviceId) != null) {
|
||||
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
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<String> 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<Integer>());
|
||||
}
|
||||
mControllerExtendKey.get(deviceId).add(externalKeyCode);
|
||||
} else {
|
||||
if (mControllerExtendKey.get(deviceId) != null) {
|
||||
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
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<String> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,17 +11,17 @@ import android.view.KeyEvent;
|
|||
import android.view.MotionEvent;
|
||||
|
||||
public class GameControllerOuya implements GameControllerDelegate{
|
||||
|
||||
private SparseIntArray mKeyMap;
|
||||
|
||||
private SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
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<String> mGameController = new SparseArray<String>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<String, List<String>> headers = http.getHeaderFields();
|
||||
Map<String, List<String>> headers = http.getHeaderFields();
|
||||
if (null == headers) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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. <br>
|
||||
-- Checks whether to pop up a message box when failed to load an image.<br>
|
||||
-- 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<br>
|
||||
-- param dict the ValueMap want to save<br>
|
||||
-- param fullPath The full path to the file you want to save a string<br>
|
||||
-- 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.<br>
|
||||
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
||||
-- param filepath The path of the file, it could be a relative or absolute path.<br>
|
||||
-- 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.<br>
|
||||
-- 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.<br>
|
||||
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
||||
-- param filepath The path of the file, it could be a relative or absolute path.<br>
|
||||
-- return The file size.
|
||||
-- @function [parent=#FileUtils] getFileSize
|
||||
-- write a string into a file<br>
|
||||
-- param dataStr the string want to save<br>
|
||||
-- param fullPath The full path to the file you want to save a string<br>
|
||||
-- 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.<br>
|
||||
|
@ -245,6 +260,17 @@
|
|||
-- @param #bool front
|
||||
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
||||
|
||||
--------------------------------
|
||||
-- write ValueVector into a plist file<br>
|
||||
-- param vecData the ValueVector want to save<br>
|
||||
-- param fullPath The full path to the file you want to save a string<br>
|
||||
-- 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.<br>
|
||||
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
||||
|
@ -284,6 +310,17 @@
|
|||
-- @param #string filenameUtf8
|
||||
-- @return string#string ret (return value: string)
|
||||
|
||||
--------------------------------
|
||||
-- write ValueMap into a plist file<br>
|
||||
-- param dict the ValueMap want to save<br>
|
||||
-- param fullPath The full path to the file you want to save a string<br>
|
||||
-- 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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2064,6 +2064,9 @@ int register_all_cocos2dx(lua_State* tolua_S);
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
support_lr2=1
|
||||
sdk=nibiru
|
|
@ -9,15 +9,17 @@
|
|||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<activity
|
||||
android:name=".AppActivity"
|
||||
android:screenOrientation="landscape"
|
||||
|
@ -30,6 +32,16 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.nibiru.lib.controller.InfoActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
|
||||
<service android:name="com.nibiru.lib.utils.NibiruControllerService" android:process=":controller" >
|
||||
<intent-filter>
|
||||
<action android:name="com.nibiru.controller.service" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,15 @@
|
|||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/icon">
|
||||
android:icon="@drawable/icon">
|
||||
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<activity android:name=".AppActivity"
|
||||
android:label="@string/app_name"
|
||||
|
@ -31,6 +33,16 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.nibiru.lib.controller.InfoActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
|
||||
<service android:name="com.nibiru.lib.utils.NibiruControllerService" android:process=":controller" >
|
||||
<intent-filter>
|
||||
<action android:name="com.nibiru.controller.service" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
<supports-screens android:anyDensity="true"
|
||||
android:smallScreens="true"
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
append_str=' \'
|
||||
|
||||
list_alldir()
|
||||
{
|
||||
for file in $1/*
|
||||
do
|
||||
if [ -f $file ]; then
|
||||
echo $file$append_str | grep .cpp
|
||||
fi
|
||||
|
||||
if [ -d $file ]; then
|
||||
list_alldir $file
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
list_alldir "$1"
|
||||
else
|
||||
list_alldir "."
|
||||
fi
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue