mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3_hot_fix
This commit is contained in:
commit
d6778225e1
|
@ -32,6 +32,7 @@ cocos2d-x-3.2 ???
|
|||
[FIX] UIListView: element position is changed a little when you click and up a list view without move
|
||||
[FIX] UIListView: element will respond to item_end event when end of scrolling a list view
|
||||
[FIX] UIVideo: crash when try to remove videoView(STATE_PLAYBACK_COMPLETED) on android
|
||||
[FIX] WP8: crash of utils::captureScreen()
|
||||
|
||||
cocos2d-x-3.2-alpha0 Jun.17 2014
|
||||
[NEW] Console: add a command to show engine version
|
||||
|
|
|
@ -861,24 +861,25 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: support ends with '/..'
|
||||
// End with '/..'?
|
||||
bool searchFromParent = false;
|
||||
if (length > 3 &&
|
||||
name[length-3] == '/' &&
|
||||
name[length-2] == '.' &&
|
||||
name[length-1] == '.')
|
||||
{
|
||||
searchFromParent = true;
|
||||
subStrlength -= 3;
|
||||
}
|
||||
// bool searchFromParent = false;
|
||||
// if (length > 3 &&
|
||||
// name[length-3] == '/' &&
|
||||
// name[length-2] == '.' &&
|
||||
// name[length-1] == '.')
|
||||
// {
|
||||
// searchFromParent = true;
|
||||
// subStrlength -= 3;
|
||||
// }
|
||||
|
||||
// Remove '/', '//' and '/..' if exist
|
||||
// Remove '/', '//' if exist
|
||||
std::string newName = name.substr(subStrStartPos, subStrlength);
|
||||
// If search from parent, then add * at first to make it match its children, which will do make
|
||||
if (searchFromParent)
|
||||
{
|
||||
newName.insert(0, "[[:alnum:]]+/");
|
||||
}
|
||||
// if (searchFromParent)
|
||||
// {
|
||||
// newName.insert(0, "[[:alnum:]]+/");
|
||||
// }
|
||||
|
||||
if (searchFromRoot)
|
||||
{
|
||||
|
@ -943,10 +944,14 @@ bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback)
|
|||
needRecursive = true;
|
||||
}
|
||||
|
||||
std::hash<std::string> h;
|
||||
size_t hashOfName = h(searchName);
|
||||
bool ret = false;
|
||||
for (const auto& child : _children)
|
||||
{
|
||||
if(std::regex_match(child->_name, std::regex(searchName)))
|
||||
// TODO: regular expression support
|
||||
// Android doesn't support c++ 11 regular expression well, may use external lib
|
||||
if (hashOfName == child->_hashOfName && searchName.compare(child->_name) == 0)
|
||||
{
|
||||
if (!needRecursive)
|
||||
{
|
||||
|
|
|
@ -714,20 +714,17 @@ public:
|
|||
virtual Node* getChildByName(const std::string& name) const;
|
||||
/** Search the children of the receiving node to perform processing for nodes which share a name.
|
||||
*
|
||||
* @param name The name to search for, support c++11 regular expression
|
||||
* @param name The name to search for
|
||||
* Search syntax options:
|
||||
* `/` : When placed at the start of the search string, this indicates that the search should be performed on the tree's node.
|
||||
* `//`: Can only be placed at the begin of the search string. This indicates that the search should be performed on the tree's node
|
||||
* and be performed recursively across the entire node tree.
|
||||
* `..`: The search should move up to the node's parent. Can only be placed at the end of string
|
||||
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children
|
||||
*
|
||||
* @code
|
||||
* enumerateChildren("/MyName", ...): This searches the root's children and matches any node with the name `MyName`.
|
||||
* enumerateChildren("//MyName", ...): This searches the root's children recursively and matches any node with the name `MyName`.
|
||||
* enumerateChildren("[[:alnum:]]+", ...): This search string matches every node of its children.
|
||||
* enumerateChildren("/MyName", ...): This searches the node tree and matches the parent node of every node named `MyName`.
|
||||
* enumerateChildren("A[[:digit:]]", ...): This searches the node's children and returns any child named `A0`, `A1`, ..., `A9`
|
||||
* enumerateChildren("Abby/Normal", ...): This searches the node's grandchildren and returns any node whose name is `Normal`
|
||||
* and whose parent is named `Abby`.
|
||||
* enumerateChildren("//Abby/Normal", ...): This searches the node tree and returns any node whose name is `Normal` and whose
|
||||
|
|
|
@ -72,19 +72,50 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
|||
}
|
||||
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||
// The frame buffer is always created with portrait orientation on WP8.
|
||||
// So if the current device orientation is landscape, we need to rotate the frame buffer.
|
||||
auto renderTargetSize = glView->getRenerTargetSize();
|
||||
CCASSERT(width * height == static_cast<int>(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched");
|
||||
glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
||||
#else
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
||||
#endif
|
||||
|
||||
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
|
||||
if (!flippedBuffer)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||
if (width == static_cast<int>(renderTargetSize.width))
|
||||
{
|
||||
// The current device orientation is portrait.
|
||||
for (int row = 0; row < height; ++row)
|
||||
{
|
||||
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The current device orientation is landscape.
|
||||
for (int row = 0; row < width; ++row)
|
||||
{
|
||||
for (int col = 0; col < height; ++col)
|
||||
{
|
||||
*(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (int row = 0; row < height; ++row)
|
||||
{
|
||||
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Image> image(new Image);
|
||||
if (image)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>libcontrollerdelegate</name>
|
||||
<name>libControllerAutoAdapter</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="androidcontrollernibiru" default="help">
|
||||
<project name="androidControllerAutoAdapter" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lint>
|
||||
<issue id="NewApi">
|
||||
<ignore path="src/org/cocos2dx/lib/GameControllerHelper.java" />
|
||||
</issue>
|
||||
</lint>
|
|
@ -0,0 +1,16 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
android.library=true
|
||||
# Project target.
|
||||
target=android-16
|
||||
android.library.reference.1=../java
|
|
@ -0,0 +1,284 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener;
|
||||
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat;
|
||||
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener;
|
||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
|
||||
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(){
|
||||
mControllerHelper.connectController();
|
||||
}
|
||||
|
||||
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 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
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchKeyEvent(event);
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchKeyEvent(event);
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
handled |= mControllerHelper.dispatchKeyEvent(event);
|
||||
Log.d(TAG, "dispatchKeyEvent:" + handled);
|
||||
|
||||
return handled || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
|
||||
|
||||
return handled || super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
|
||||
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
||||
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
GameControllerAdapter.onConnected("Standard", 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.d(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);
|
||||
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
GameControllerAdapter.onDisconnected("Standard", deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onResume();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onResume();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
mControllerHelper.destrory();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
}
|
|
@ -42,12 +42,6 @@ public class GameControllerHelper {
|
|||
public static final String StandardControllerName = "Standard";
|
||||
public static final String[] DRIVERS_NAME = {"nibiru","moga","ouya",StandardControllerName};
|
||||
|
||||
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;
|
||||
|
||||
public static final String SPP_UUID = "00001101-0000-1000-8000-00805F9B34FB";
|
||||
|
||||
SparseIntArray ControllerKeyMap;
|
||||
|
@ -58,24 +52,21 @@ public class GameControllerHelper {
|
|||
private static final String NIBIRU_DEP_PACKAGE = "com.nibiru";
|
||||
private static final String MOGA__DEP_PACKAGE = "com.bda.pivot.mogapgp";
|
||||
|
||||
private static Cocos2dxActivity sCocos2dxActivity;
|
||||
private static GameControllerActivity sGameControllerActivity;
|
||||
private static GameControllerHelper sControllerHelper;
|
||||
|
||||
private String mLibAdapterFileName;
|
||||
private int mLibAdapterFileSize;
|
||||
|
||||
private List<String> mNibiruSupportedDrives;
|
||||
private String mNibiruDepFileName;
|
||||
private String mNibiruLibFileName;
|
||||
private int mNibiruLibFileSize;
|
||||
private int mNibiruDepFileSize;
|
||||
|
||||
private List<String> mMogaSupportedDrives;
|
||||
private String mMogaDepFileName;
|
||||
private String mMogaLibFileName;
|
||||
private int mMogaLibFileSize;
|
||||
private int mMogaDepFileSize;
|
||||
|
||||
private List<String> mOuyaSupportedDrives;
|
||||
private String mOuyaLibFileName;
|
||||
private int mOuyaLibFileSize;
|
||||
|
||||
private AsyncHttpClient mDownDepsHttpClient = null;
|
||||
|
||||
|
@ -111,8 +102,17 @@ public class GameControllerHelper {
|
|||
mControllerListener = listener;
|
||||
}
|
||||
|
||||
public GameControllerHelper(Cocos2dxActivity activity){
|
||||
sCocos2dxActivity = activity;
|
||||
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;
|
||||
public static final int AXIS_LTRIGGER = 17;
|
||||
public static final int AXIS_RTRIGGER = 18;
|
||||
public static final int AXIS_BRAKE = 23;
|
||||
public static final int AXIS_THROTTLE = 19;
|
||||
|
||||
public GameControllerHelper(GameControllerActivity activity){
|
||||
sGameControllerActivity = activity;
|
||||
sControllerHelper = this;
|
||||
|
||||
ControllerKeyMap = new SparseIntArray(25);
|
||||
|
@ -137,14 +137,16 @@ public class GameControllerHelper {
|
|||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||
|
||||
ControllerKeyMap.put(MotionEvent.AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
|
||||
ControllerKeyMap.put(MotionEvent.AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
|
||||
ControllerKeyMap.put(MotionEvent.AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
|
||||
ControllerKeyMap.put(MotionEvent.AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
|
||||
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);
|
||||
//KEYCODE_BUTTON_MODE
|
||||
mDownDepsHttpClient = new AsyncHttpClient();
|
||||
mDownDepsHttpClient.setTimeout(360 * 1000);
|
||||
}
|
||||
|
||||
public void connectController(){
|
||||
|
@ -155,18 +157,19 @@ public class GameControllerHelper {
|
|||
mOuyaSupportedDrives = new ArrayList<String>(5);
|
||||
|
||||
mLocalSavePath = Environment.getExternalStorageDirectory() + File.separator + "CocosGameController" + File.separator;
|
||||
mConfigFilePath = sCocos2dxActivity.getFilesDir().getAbsolutePath() + File.separator + COCOS_CONTROLLER_CONFIG;
|
||||
mDownDepsHttpClient = new AsyncHttpClient();
|
||||
mDownDepsHttpClient.setTimeout(360 * 1000);
|
||||
Log.i(TAG, "mLocalSavePath:" + mLocalSavePath);
|
||||
mConfigFilePath = sGameControllerActivity.getFilesDir().getAbsolutePath() + File.separator + COCOS_CONTROLLER_CONFIG;
|
||||
Log.i(TAG, "mConfigFilePath:" + mConfigFilePath);
|
||||
|
||||
}
|
||||
|
||||
if (mControllerListener != null) {
|
||||
mControllerListener.onDownloadConfigStarted();
|
||||
}
|
||||
if (mLazyConfigInit) {
|
||||
if (mDownDepsHttpClient != null) {
|
||||
mDownDepsHttpClient.cancelRequests(sCocos2dxActivity, true);
|
||||
}
|
||||
//if (mDownDepsHttpClient != null) {
|
||||
// mDownDepsHttpClient.cancelRequests(sGameControllerActivity, true);
|
||||
//}
|
||||
requestControllerConfig();
|
||||
}
|
||||
else {
|
||||
|
@ -187,7 +190,7 @@ public class GameControllerHelper {
|
|||
|
||||
public void destrory(){
|
||||
if (mDownDepsHttpClient != null) {
|
||||
mDownDepsHttpClient.cancelRequests(sCocos2dxActivity, true);
|
||||
mDownDepsHttpClient.cancelRequests(sGameControllerActivity, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,12 +216,12 @@ public class GameControllerHelper {
|
|||
//filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
|
||||
sCocos2dxActivity.registerReceiver(mBluetoothReceiver, filter);
|
||||
sGameControllerActivity.registerReceiver(mBluetoothReceiver, filter);
|
||||
|
||||
IntentFilter appFilter = new IntentFilter();
|
||||
appFilter.addAction("android.intent.action.PACKAGE_ADDED");
|
||||
appFilter.addDataScheme("package");
|
||||
sCocos2dxActivity.registerReceiver(mAppReceiver, appFilter);
|
||||
sGameControllerActivity.registerReceiver(mAppReceiver, appFilter);
|
||||
}
|
||||
|
||||
if (!mBluetoothAdapter.isEnabled()) {
|
||||
|
@ -238,34 +241,34 @@ public class GameControllerHelper {
|
|||
String deviceName = device.getName();
|
||||
|
||||
if (mNibiruSupportedDrives.contains(deviceName)) {
|
||||
return DRIVERTYPE_NIBIRU;
|
||||
return GameControllerActivity.DRIVERTYPE_NIBIRU;
|
||||
}
|
||||
else if (mMogaSupportedDrives.contains(deviceName)) {
|
||||
return DRIVERTYPE_MOGA;
|
||||
return GameControllerActivity.DRIVERTYPE_MOGA;
|
||||
}
|
||||
else if (mOuyaSupportedDrives.contains(deviceName)) {
|
||||
return DRIVERTYPE_OUYA;
|
||||
return GameControllerActivity.DRIVERTYPE_OUYA;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return DRIVERTYPE_UNKNOWN;
|
||||
return GameControllerActivity.DRIVERTYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
public static void installApplication(String filePath){
|
||||
if (sCocos2dxActivity != null) {
|
||||
if (sGameControllerActivity != null) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
sCocos2dxActivity.startActivity(intent);
|
||||
sGameControllerActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkApplication(String packName){
|
||||
try {
|
||||
ApplicationInfo applicationInfo = sCocos2dxActivity.getPackageManager().getApplicationInfo(packName, PackageManager.GET_UNINSTALLED_PACKAGES);
|
||||
ApplicationInfo applicationInfo = sGameControllerActivity.getPackageManager().getApplicationInfo(packName, PackageManager.GET_UNINSTALLED_PACKAGES);
|
||||
Log.d(TAG, applicationInfo.toString());
|
||||
return true;
|
||||
} catch (NameNotFoundException e) {
|
||||
|
@ -297,7 +300,7 @@ public class GameControllerHelper {
|
|||
|
||||
mBluetoothDevices.add(device);
|
||||
int type = checkDriverType(device);
|
||||
if (type != DRIVERTYPE_UNKNOWN) {
|
||||
if (type != GameControllerActivity.DRIVERTYPE_UNKNOWN) {
|
||||
mTargetDriverType = type;
|
||||
mClearDevices += 1;
|
||||
}
|
||||
|
@ -312,7 +315,7 @@ public class GameControllerHelper {
|
|||
else {
|
||||
if (mBluetoothDevices.size() == 0) {
|
||||
if (checkApplication(NIBIRU_DEP_PACKAGE)) {
|
||||
downControllerDeps(DRIVERTYPE_NIBIRU);
|
||||
downControllerDeps(GameControllerActivity.DRIVERTYPE_NIBIRU);
|
||||
}
|
||||
Log.w(TAG, "Not found any supported bluetooth game controller!");
|
||||
}else {
|
||||
|
@ -320,7 +323,10 @@ public class GameControllerHelper {
|
|||
downControllerDeps(mTargetDriverType);
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, "More than one device");
|
||||
Log.i(TAG, "Not clear target!");
|
||||
if (checkApplication(NIBIRU_DEP_PACKAGE)) {
|
||||
downControllerDeps(GameControllerActivity.DRIVERTYPE_NIBIRU);
|
||||
}
|
||||
//todo:show sel
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +341,7 @@ public class GameControllerHelper {
|
|||
mBluetoothDevices.clear();
|
||||
mDevicesDriver.clear();
|
||||
mClearDevices = 0;
|
||||
mTargetDriverType = DRIVERTYPE_UNKNOWN;
|
||||
mTargetDriverType = GameControllerActivity.DRIVERTYPE_UNKNOWN;
|
||||
|
||||
//check moga controller
|
||||
Iterator<BluetoothDevice> it = mBluetoothAdapter.getBondedDevices().iterator();
|
||||
|
@ -348,7 +354,7 @@ public class GameControllerHelper {
|
|||
mBluetoothDevices.add(device);
|
||||
int type = checkDriverType(device);
|
||||
Log.d(TAG, "BluetoothDevice objects that are bonded (paired) to the local adapter :" + device.getName());
|
||||
if (type != DRIVERTYPE_UNKNOWN) {
|
||||
if (type != GameControllerActivity.DRIVERTYPE_UNKNOWN) {
|
||||
mClearDevices += 1;
|
||||
mTargetDriverType = type;
|
||||
}
|
||||
|
@ -361,7 +367,7 @@ public class GameControllerHelper {
|
|||
};
|
||||
|
||||
private static int depsCount = 0;
|
||||
private static int mTargetDriverType = DRIVERTYPE_UNKNOWN;
|
||||
private static int mTargetDriverType = GameControllerActivity.DRIVERTYPE_UNKNOWN;
|
||||
|
||||
private static int mDownloadTotalSize;
|
||||
private static int mDownloadLibSize;
|
||||
|
@ -369,7 +375,9 @@ public class GameControllerHelper {
|
|||
private static int mDepDownloadCompletedSize;
|
||||
|
||||
public void downControllerDeps(int driverType){
|
||||
if (driverType == DRIVERTYPE_STANDARD || driverType == DRIVERTYPE_UNKNOWN) {
|
||||
if (driverType != GameControllerActivity.DRIVERTYPE_NIBIRU
|
||||
&& driverType != GameControllerActivity.DRIVERTYPE_MOGA
|
||||
&& driverType != GameControllerActivity.DRIVERTYPE_OUYA) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -388,64 +396,37 @@ public class GameControllerHelper {
|
|||
|
||||
String remoteDir = COCOS_CONTROLLER_URL + DRIVERS_NAME[driverType] + File.separator;
|
||||
|
||||
if (driverType == DRIVERTYPE_NIBIRU) {
|
||||
mDownloadLibSize = mNibiruLibFileSize;
|
||||
mDownloadTotalSize += mNibiruLibFileSize;
|
||||
if (driverType == GameControllerActivity.DRIVERTYPE_NIBIRU) {
|
||||
if (!checkApplication(NIBIRU_DEP_PACKAGE)) {
|
||||
depsCount += 1;
|
||||
mDownloadTotalSize += mNibiruDepFileSize;
|
||||
mDownDepsHttpClient.get(remoteDir + mNibiruDepFileName, new MyDepsAsyncHandler(
|
||||
new File(mLocalSavePath + mNibiruDepFileName), MyDepsAsyncHandler.FILETYPE_DEP_APK));
|
||||
}
|
||||
|
||||
File libFile = new File(mLocalSavePath + mNibiruLibFileName);
|
||||
if (libFile.exists() && libFile.length() == mNibiruLibFileSize) {
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
onDepsReady();
|
||||
}
|
||||
}
|
||||
else {
|
||||
mDownDepsHttpClient.get(remoteDir + mNibiruLibFileName, new MyDepsAsyncHandler(
|
||||
libFile, MyDepsAsyncHandler.FILETYPE_JAR));
|
||||
}
|
||||
|
||||
}
|
||||
else if (driverType == DRIVERTYPE_MOGA) {
|
||||
mDownloadLibSize = mMogaLibFileSize;
|
||||
mDownloadTotalSize += mMogaLibFileSize;
|
||||
else if (driverType == GameControllerActivity.DRIVERTYPE_MOGA) {
|
||||
if (!checkApplication(MOGA__DEP_PACKAGE)) {
|
||||
mDownloadTotalSize += mMogaDepFileSize;
|
||||
depsCount += 1;
|
||||
mDownDepsHttpClient.get(remoteDir + mMogaDepFileName, new MyDepsAsyncHandler(
|
||||
new File(mLocalSavePath + mMogaDepFileName), MyDepsAsyncHandler.FILETYPE_DEP_APK));
|
||||
}
|
||||
|
||||
File libFile = new File(mLocalSavePath + mMogaLibFileName);
|
||||
if (libFile.exists() && libFile.length() == mMogaLibFileSize) {
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
onDepsReady();
|
||||
}
|
||||
}else {
|
||||
mDownDepsHttpClient.get(remoteDir + mMogaLibFileName, new MyDepsAsyncHandler(
|
||||
libFile, MyDepsAsyncHandler.FILETYPE_JAR));
|
||||
}
|
||||
}
|
||||
else if(driverType == DRIVERTYPE_OUYA){
|
||||
mDownloadLibSize = mOuyaLibFileSize;
|
||||
mDownloadTotalSize += mOuyaLibFileSize;
|
||||
else if(driverType == GameControllerActivity.DRIVERTYPE_OUYA){
|
||||
|
||||
File libFile = new File(mLocalSavePath + mOuyaLibFileName);
|
||||
if (libFile.exists() && libFile.length() == mOuyaLibFileSize) {
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
onDepsReady();
|
||||
}
|
||||
}else {
|
||||
mDownDepsHttpClient.get(remoteDir + mOuyaLibFileName, new MyDepsAsyncHandler(
|
||||
new File(mLocalSavePath + mOuyaLibFileName), MyDepsAsyncHandler.FILETYPE_JAR));
|
||||
}
|
||||
|
||||
File libFile = new File(mLocalSavePath + mLibAdapterFileName);
|
||||
if (libFile.exists() && libFile.length() == mLibAdapterFileSize) {
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
onDepsReady();
|
||||
}
|
||||
}else {
|
||||
mDownloadLibSize = mLibAdapterFileSize;
|
||||
mDownloadTotalSize += mDownloadLibSize;
|
||||
mDownDepsHttpClient.get(COCOS_CONTROLLER_URL + mLibAdapterFileName, new MyDepsAsyncHandler(
|
||||
new File(mLocalSavePath + mLibAdapterFileName), MyDepsAsyncHandler.FILETYPE_JAR));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,19 +465,6 @@ public class GameControllerHelper {
|
|||
Log.e(TAG,"Failed to download:" + file.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
Log.d(TAG, "Down file success:" + file.getName());
|
||||
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
if (mControllerListener != null) {
|
||||
mControllerListener.onDownloadDepsFinished(true);
|
||||
}
|
||||
sControllerHelper.onDepsReady();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int bytesWritten, int totalSize) {
|
||||
if (mFileType == FILETYPE_JAR) {
|
||||
|
@ -510,14 +478,41 @@ public class GameControllerHelper {
|
|||
}
|
||||
Log.d(TAG, "totalSize:" + totalSize + ", bytesWritten:" + bytesWritten);
|
||||
}
|
||||
|
||||
|
||||
public void onSuccess(File file) {
|
||||
Log.d(TAG, "11Down file success:" + file.getName());
|
||||
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
if (mControllerListener != null) {
|
||||
mControllerListener.onDownloadDepsFinished(true);
|
||||
}
|
||||
sControllerHelper.onDepsReady();
|
||||
}
|
||||
super.onSuccess(file);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void onSuccess(int arg0, Header[] arg1, File file) {
|
||||
Log.d(TAG, "22Down file success:" + file.getName());
|
||||
|
||||
depsCount -= 1;
|
||||
if (depsCount == 0) {
|
||||
if (mControllerListener != null) {
|
||||
mControllerListener.onDownloadDepsFinished(true);
|
||||
}
|
||||
sControllerHelper.onDepsReady();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private void onDepsReady(){
|
||||
Log.d(TAG, "onDepsReady:" + mTargetDriverType);
|
||||
|
||||
if (mTargetDriverType == DRIVERTYPE_NIBIRU) {
|
||||
if (mTargetDriverType == GameControllerActivity.DRIVERTYPE_NIBIRU) {
|
||||
if (checkApplication(NIBIRU_DEP_PACKAGE)) {
|
||||
createControllerInstance(mLocalSavePath + mNibiruLibFileName, mTargetDriverType);
|
||||
createControllerInstance(mLocalSavePath + mLibAdapterFileName, mTargetDriverType);
|
||||
}
|
||||
else {
|
||||
if (mControllerListener != null) {
|
||||
|
@ -526,9 +521,9 @@ public class GameControllerHelper {
|
|||
installApplication(mLocalSavePath + mNibiruDepFileName);
|
||||
}
|
||||
}
|
||||
else if (mTargetDriverType == DRIVERTYPE_MOGA) {
|
||||
else if (mTargetDriverType == GameControllerActivity.DRIVERTYPE_MOGA) {
|
||||
if (checkApplication(MOGA__DEP_PACKAGE)) {
|
||||
createControllerInstance(mLocalSavePath + mMogaLibFileName, mTargetDriverType);
|
||||
createControllerInstance(mLocalSavePath + mLibAdapterFileName, mTargetDriverType);
|
||||
}
|
||||
else {
|
||||
if (mControllerListener != null) {
|
||||
|
@ -537,25 +532,14 @@ public class GameControllerHelper {
|
|||
installApplication(mLocalSavePath + mMogaDepFileName);
|
||||
}
|
||||
}
|
||||
else if (mTargetDriverType == DRIVERTYPE_OUYA) {
|
||||
/*if (checkApplication(OUYA_FRAMEWORK_PACKAGE)) {
|
||||
if (checkApplication(OUYA_LAUNCHER_PACKAGE)) {
|
||||
createControllerInstance(mLocalSavePath + mOuyaLibFileName, mTargetSDK);
|
||||
}
|
||||
else {
|
||||
installApplication(mLocalSavePath + mOuyaLauncherFileName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
installApplication(mLocalSavePath + mOuyaFrameworkFileName);
|
||||
}*/
|
||||
createControllerInstance(mLocalSavePath + mOuyaLibFileName, mTargetDriverType);
|
||||
else if (mTargetDriverType == GameControllerActivity.DRIVERTYPE_OUYA) {
|
||||
createControllerInstance(mLocalSavePath + mLibAdapterFileName, mTargetDriverType);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String CONFIGKEY_DRIVES = "drives";
|
||||
private static final String CONFIGKEY_LIB_FILENAME = "lib";
|
||||
private static final String CONFIGKEY_LIB_FILESIZE = "lib-size";
|
||||
private static final String CONFIGKEY_LIBADAPTER_FILENAME = "adapter-file";
|
||||
private static final String CONFIGKEY_LIBADAPTER_FILESIZE = "adapter-filesize";
|
||||
private static final String CONFIGKEY_DEP_FILENAME = "dep-apk";
|
||||
private static final String CONFIGKEY_DEP_FILESIZE = "dep-size";
|
||||
|
||||
|
@ -565,7 +549,14 @@ public class GameControllerHelper {
|
|||
mOuyaSupportedDrives.clear();
|
||||
|
||||
try {
|
||||
int tint = 9879;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("intvalue",tint);
|
||||
Log.w(TAG, "intJson:" + jsonObject);
|
||||
|
||||
JSONObject configObject = new JSONObject(jsonString);
|
||||
mLibAdapterFileName = configObject.getString(CONFIGKEY_LIBADAPTER_FILENAME);
|
||||
mLibAdapterFileSize = configObject.getInt(CONFIGKEY_LIBADAPTER_FILESIZE);
|
||||
|
||||
JSONObject nibiruObject = configObject.getJSONObject("nibiru");
|
||||
JSONArray drives = nibiruObject.getJSONArray(CONFIGKEY_DRIVES);
|
||||
|
@ -575,8 +566,6 @@ public class GameControllerHelper {
|
|||
}
|
||||
mNibiruDepFileName = nibiruObject.getString(CONFIGKEY_DEP_FILENAME);
|
||||
mNibiruDepFileSize = nibiruObject.getInt(CONFIGKEY_DEP_FILESIZE);
|
||||
mNibiruLibFileName = nibiruObject.getString(CONFIGKEY_LIB_FILENAME);
|
||||
mNibiruLibFileSize = nibiruObject.getInt(CONFIGKEY_LIB_FILESIZE);
|
||||
|
||||
JSONObject mogaObject = configObject.getJSONObject("moga");
|
||||
drives = mogaObject.getJSONArray(CONFIGKEY_DRIVES);
|
||||
|
@ -586,8 +575,6 @@ public class GameControllerHelper {
|
|||
}
|
||||
mMogaDepFileName = mogaObject.getString(CONFIGKEY_DEP_FILENAME);
|
||||
mMogaDepFileSize = mogaObject.getInt(CONFIGKEY_DEP_FILESIZE);
|
||||
mMogaLibFileName = mogaObject.getString(CONFIGKEY_LIB_FILENAME);
|
||||
mMogaLibFileSize = mogaObject.getInt(CONFIGKEY_LIB_FILESIZE);
|
||||
|
||||
JSONObject ouyaObject = configObject.getJSONObject("ouya");
|
||||
drives = ouyaObject.getJSONArray(CONFIGKEY_DRIVES);
|
||||
|
@ -595,10 +582,7 @@ public class GameControllerHelper {
|
|||
for (int i = 0; i < count; i++) {
|
||||
mOuyaSupportedDrives.add(drives.getString(i));
|
||||
}
|
||||
mOuyaLibFileName = ouyaObject.getString(CONFIGKEY_LIB_FILENAME);
|
||||
mOuyaLibFileSize = ouyaObject.getInt(CONFIGKEY_LIB_FILESIZE);
|
||||
//mOuyaFrameworkFileName = ouyaObject.getString("dep-framework");
|
||||
//mOuyaLauncherFileName = ouyaObject.getString("dep-launcher");
|
||||
|
||||
mLazyConfigInit = false;
|
||||
return true;
|
||||
} catch (Exception e1) {
|
||||
|
@ -677,7 +661,6 @@ public class GameControllerHelper {
|
|||
if (mControllerListener != null) {
|
||||
mControllerListener.onDownloadConfigFinished(false);
|
||||
}
|
||||
Log.e(TAG, "Failed to download controller config!");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -685,10 +668,14 @@ public class GameControllerHelper {
|
|||
}
|
||||
|
||||
private static void showToast(String message){
|
||||
Toast.makeText(sCocos2dxActivity, message, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(sGameControllerActivity, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private static void createControllerInstance(String libFilePath,int sdkType) {
|
||||
private static void createControllerInstance(String libFilePath,int driveType) {
|
||||
//if (sGameControllerActivity.getGameControllerDelegate(driveType) != null) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
File libFile = new File(libFilePath);
|
||||
if (! libFile.exists()) {
|
||||
Log.w(TAG, libFile.toString() + "not exist!");
|
||||
|
@ -698,21 +685,20 @@ public class GameControllerHelper {
|
|||
DexClassLoader classLoader = null;
|
||||
|
||||
try {
|
||||
File dexOutputDir = sCocos2dxActivity.getDir("dex", Context.MODE_PRIVATE);
|
||||
|
||||
File dexOutputDir = sGameControllerActivity.getDir("dex", Context.MODE_PRIVATE);
|
||||
classLoader = new DexClassLoader(libFile.getCanonicalPath(), dexOutputDir.getCanonicalPath(),
|
||||
null, sCocos2dxActivity.getClassLoader());
|
||||
null, sGameControllerActivity.getClassLoader());
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> controllerDelegate = null;
|
||||
if (sdkType == DRIVERTYPE_MOGA) {
|
||||
if (driveType == GameControllerActivity.DRIVERTYPE_MOGA) {
|
||||
controllerDelegate = classLoader.loadClass("org.cocos2dx.lib.GameControllerMoga");
|
||||
} else if (sdkType == DRIVERTYPE_NIBIRU) {
|
||||
} else if (driveType == GameControllerActivity.DRIVERTYPE_NIBIRU) {
|
||||
controllerDelegate = classLoader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
|
||||
} else if (sdkType == DRIVERTYPE_OUYA) {
|
||||
} else if (driveType == GameControllerActivity.DRIVERTYPE_OUYA) {
|
||||
controllerDelegate = classLoader.loadClass("org.cocos2dx.lib.GameControllerOuya");
|
||||
}
|
||||
|
||||
|
@ -721,8 +707,8 @@ public class GameControllerHelper {
|
|||
if (mControllerListener != null) {
|
||||
mControllerListener.onConnectController();
|
||||
}
|
||||
sCocos2dxActivity.setGameControllerInstance(instance);
|
||||
if (sdkType == DRIVERTYPE_NIBIRU) {
|
||||
sGameControllerActivity.setGameControllerInstance(instance, driveType);
|
||||
if (driveType == GameControllerActivity.DRIVERTYPE_NIBIRU) {
|
||||
Method method = controllerDelegate.getDeclaredMethod("onResume");
|
||||
method.invoke(instance);
|
||||
}
|
||||
|
@ -739,10 +725,10 @@ public class GameControllerHelper {
|
|||
String packageName = intent.getDataString();
|
||||
Log.d(TAG, "mAppReceiver:" + intent);
|
||||
if (packageName.contains(NIBIRU_DEP_PACKAGE)) {
|
||||
createControllerInstance(mLocalSavePath + mNibiruLibFileName, DRIVERTYPE_NIBIRU);
|
||||
createControllerInstance(mLocalSavePath + mLibAdapterFileName, GameControllerActivity.DRIVERTYPE_NIBIRU);
|
||||
}
|
||||
else if (packageName.contains(MOGA__DEP_PACKAGE)) {
|
||||
createControllerInstance(mLocalSavePath + mMogaLibFileName, DRIVERTYPE_MOGA);
|
||||
createControllerInstance(mLocalSavePath + mLibAdapterFileName, GameControllerActivity.DRIVERTYPE_MOGA);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -768,35 +754,35 @@ public class GameControllerHelper {
|
|||
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
int devicedId = event.getDeviceId();
|
||||
|
||||
float newAXIS_LX = event.getAxisValue(MotionEvent.AXIS_X);
|
||||
float newAXIS_LX = event.getAxisValue(AXIS_X);
|
||||
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
|
||||
mOldLeftThumbstickX = newAXIS_LX;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_LY = event.getAxisValue(MotionEvent.AXIS_Y);
|
||||
float newAXIS_LY = event.getAxisValue(AXIS_Y);
|
||||
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
|
||||
mOldLeftThumbstickY = newAXIS_LY;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RX = event.getAxisValue(MotionEvent.AXIS_Z);
|
||||
float newAXIS_RX = event.getAxisValue(AXIS_Z);
|
||||
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
|
||||
mOldRightThumbstickX = newAXIS_RX;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RY = event.getAxisValue(MotionEvent.AXIS_RZ);
|
||||
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
|
||||
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
|
||||
mOldRightThumbstickY = newAXIS_RY;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_LTRIGGER = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
||||
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
|
||||
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
|
||||
if (Float.compare(newAXIS_LTRIGGER, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
|
||||
|
@ -807,7 +793,7 @@ public class GameControllerHelper {
|
|||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RTRIGGER = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
||||
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
|
||||
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
|
||||
if (Float.compare(newAXIS_RTRIGGER, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
|
||||
|
@ -818,7 +804,7 @@ public class GameControllerHelper {
|
|||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_BRAKE = event.getAxisValue(MotionEvent.AXIS_BRAKE);
|
||||
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
|
||||
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
|
||||
if (Float.compare(newAXIS_BRAKE, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
|
||||
|
@ -829,7 +815,7 @@ public class GameControllerHelper {
|
|||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_THROTTLE = event.getAxisValue(MotionEvent.AXIS_THROTTLE);
|
||||
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
|
||||
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
|
||||
if (Float.compare(newAXIS_THROTTLE, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>libcontrollerouya</name>
|
||||
<name>libControllerManualAdapter</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="androidcontrollerdelegate" default="help">
|
||||
<project name="androidControllerManualAdapter" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lint>
|
||||
<issue id="NewApi">
|
||||
<ignore path="src/org/cocos2dx/lib/GameControllerHelper.java" />
|
||||
</issue>
|
||||
</lint>
|
|
@ -0,0 +1,316 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener;
|
||||
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat;
|
||||
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener;
|
||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@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
|
||||
// ===========================================================
|
||||
|
||||
// ===========================================================
|
||||
// Methods for/from SuperClass/Interfaces
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchKeyEvent(event);
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchKeyEvent(event);
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
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 (mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
|
||||
|
||||
return handled || super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
|
||||
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
||||
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
GameControllerAdapter.onConnected("Standard", 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.d(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);
|
||||
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
GameControllerAdapter.onDisconnected("Standard", deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onResume();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onResume();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
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;
|
||||
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);
|
||||
//KEYCODE_BUTTON_MODE
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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 devicedId = event.getDeviceId();
|
||||
|
||||
float newAXIS_LX = event.getAxisValue(AXIS_X);
|
||||
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, 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(StandardControllerName, devicedId, 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(StandardControllerName, devicedId, 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(StandardControllerName, devicedId, 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) {
|
||||
if (Float.compare(newAXIS_LTRIGGER, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
|
||||
}else {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, true, newAXIS_LTRIGGER, true);
|
||||
}
|
||||
mOldLeftTrigger = newAXIS_LTRIGGER;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
|
||||
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
|
||||
if (Float.compare(newAXIS_RTRIGGER, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
|
||||
}else {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_RTRIGGER, true);
|
||||
}
|
||||
mOldRightTrigger = newAXIS_RTRIGGER;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
|
||||
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
|
||||
if (Float.compare(newAXIS_BRAKE, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
|
||||
}else {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, true, newAXIS_BRAKE, true);
|
||||
}
|
||||
mOldBrake = newAXIS_BRAKE;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
|
||||
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
|
||||
if (Float.compare(newAXIS_THROTTLE, 0.0f) == 0) {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
|
||||
}else {
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_THROTTLE, true);
|
||||
}
|
||||
mOldThrottle = newAXIS_THROTTLE;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
|
||||
int eventSource = event.getSource();
|
||||
int controllerKey = ControllerKeyMap.get(event.getKeyCode());
|
||||
|
||||
if (controllerKey != 0 && (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)
|
||||
|| ((eventSource & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD)))
|
||||
{
|
||||
int action = event.getAction();
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
handled = true;
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName,event.getDeviceId(), controllerKey,true, 1.0f, false);
|
||||
}else if (action == KeyEvent.ACTION_UP) {
|
||||
handled = true;
|
||||
GameControllerAdapter.onButtonEvent(StandardControllerName,event.getDeviceId(), controllerKey,false, 0.0f, false);
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.cocos2dx.lib.inputmanagercompat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public interface InputManagerCompat {
|
||||
/**
|
||||
* Gets information about the input device with the specified id.
|
||||
*
|
||||
* @param id The device id
|
||||
* @return The input device or null if not found
|
||||
*/
|
||||
public InputDevice getInputDevice(int id);
|
||||
|
||||
/**
|
||||
* Gets the ids of all input devices in the system.
|
||||
*
|
||||
* @return The input device ids.
|
||||
*/
|
||||
public int[] getInputDeviceIds();
|
||||
|
||||
/**
|
||||
* Registers an input device listener to receive notifications about when
|
||||
* input devices are added, removed or changed.
|
||||
*
|
||||
* @param listener The listener to register.
|
||||
* @param handler The handler on which the listener should be invoked, or
|
||||
* null if the listener should be invoked on the calling thread's
|
||||
* looper.
|
||||
*/
|
||||
public void registerInputDeviceListener(InputManagerCompat.InputDeviceListener listener,
|
||||
Handler handler);
|
||||
|
||||
/**
|
||||
* Unregisters an input device listener.
|
||||
*
|
||||
* @param listener The listener to unregister.
|
||||
*/
|
||||
public void unregisterInputDeviceListener(InputManagerCompat.InputDeviceListener listener);
|
||||
|
||||
/*
|
||||
* The following three calls are to simulate V16 behavior on pre-Jellybean
|
||||
* devices. If you don't call them, your callback will never be called
|
||||
* pre-API 16.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pass the motion events to the InputManagerCompat. This is used to
|
||||
* optimize for polling for controllers. If you do not pass these events in,
|
||||
* polling will cause regular object creation.
|
||||
*
|
||||
* @param event the motion event from the app
|
||||
*/
|
||||
public void onGenericMotionEvent(MotionEvent event);
|
||||
|
||||
/**
|
||||
* Tell the V9 input manager that it should stop polling for disconnected
|
||||
* devices. You can call this during onPause in your activity, although you
|
||||
* might want to call it whenever your game is not active (or whenever you
|
||||
* don't care about being notified of new input devices)
|
||||
*/
|
||||
public void onPause();
|
||||
|
||||
/**
|
||||
* Tell the V9 input manager that it should start polling for disconnected
|
||||
* devices. You can call this during onResume in your activity, although you
|
||||
* might want to call it less often (only when the gameplay is actually
|
||||
* active)
|
||||
*/
|
||||
public void onResume();
|
||||
|
||||
public interface InputDeviceListener {
|
||||
/**
|
||||
* Called whenever the input manager detects that a device has been
|
||||
* added. This will only be called in the V9 version when a motion event
|
||||
* is detected.
|
||||
*
|
||||
* @param deviceId The id of the input device that was added.
|
||||
*/
|
||||
void onInputDeviceAdded(int deviceId);
|
||||
|
||||
/**
|
||||
* Called whenever the properties of an input device have changed since
|
||||
* they were last queried. This will not be called for the V9 version of
|
||||
* the API.
|
||||
*
|
||||
* @param deviceId The id of the input device that changed.
|
||||
*/
|
||||
void onInputDeviceChanged(int deviceId);
|
||||
|
||||
/**
|
||||
* Called whenever the input manager detects that a device has been
|
||||
* removed. For the V9 version, this can take some time depending on the
|
||||
* poll rate.
|
||||
*
|
||||
* @param deviceId The id of the input device that was removed.
|
||||
*/
|
||||
void onInputDeviceRemoved(int deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to construct a compatible InputManager.
|
||||
*/
|
||||
public static class Factory {
|
||||
|
||||
/**
|
||||
* Constructs and returns a compatible InputManger
|
||||
*
|
||||
* @param context the Context that will be used to get the system
|
||||
* service from
|
||||
* @return a compatible implementation of InputManager
|
||||
*/
|
||||
public static InputManagerCompat getInputManager(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
return new InputManagerV16(context);
|
||||
} else {
|
||||
return new InputManagerV9();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.cocos2dx.lib.inputmanagercompat;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public class InputManagerV16 implements InputManagerCompat {
|
||||
|
||||
private final InputManager mInputManager;
|
||||
private final Map<InputManagerCompat.InputDeviceListener, V16InputDeviceListener> mListeners;
|
||||
|
||||
public InputManagerV16(Context context) {
|
||||
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
||||
mListeners = new HashMap<InputManagerCompat.InputDeviceListener, V16InputDeviceListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputDevice getInputDevice(int id) {
|
||||
return mInputManager.getInputDevice(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getInputDeviceIds() {
|
||||
return mInputManager.getInputDeviceIds();
|
||||
}
|
||||
|
||||
static class V16InputDeviceListener implements InputManager.InputDeviceListener {
|
||||
final InputManagerCompat.InputDeviceListener mIDL;
|
||||
|
||||
public V16InputDeviceListener(InputDeviceListener idl) {
|
||||
mIDL = idl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
mIDL.onInputDeviceAdded(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
mIDL.onInputDeviceChanged(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
mIDL.onInputDeviceRemoved(deviceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
|
||||
V16InputDeviceListener v16Listener = new V16InputDeviceListener(listener);
|
||||
mInputManager.registerInputDeviceListener(v16Listener, handler);
|
||||
mListeners.put(listener, v16Listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterInputDeviceListener(InputDeviceListener listener) {
|
||||
V16InputDeviceListener curListener = mListeners.remove(listener);
|
||||
if (null != curListener)
|
||||
{
|
||||
mInputManager.unregisterInputDeviceListener(curListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenericMotionEvent(MotionEvent event) {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
// unused in V16
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.cocos2dx.lib.inputmanagercompat;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
public class InputManagerV9 implements InputManagerCompat {
|
||||
private static final String LOG_TAG = "InputManagerV9";
|
||||
private static final int MESSAGE_TEST_FOR_DISCONNECT = 101;
|
||||
private static final long CHECK_ELAPSED_TIME = 3000L;
|
||||
|
||||
private static final int ON_DEVICE_ADDED = 0;
|
||||
private static final int ON_DEVICE_CHANGED = 1;
|
||||
private static final int ON_DEVICE_REMOVED = 2;
|
||||
|
||||
private final SparseArray<long[]> mDevices;
|
||||
private final Map<InputDeviceListener, Handler> mListeners;
|
||||
private final Handler mDefaultHandler;
|
||||
|
||||
private static class PollingMessageHandler extends Handler {
|
||||
private final WeakReference<InputManagerV9> mInputManager;
|
||||
|
||||
PollingMessageHandler(InputManagerV9 im) {
|
||||
mInputManager = new WeakReference<InputManagerV9>(im);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case MESSAGE_TEST_FOR_DISCONNECT:
|
||||
InputManagerV9 imv = mInputManager.get();
|
||||
if (null != imv) {
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
int size = imv.mDevices.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
long[] lastContact = imv.mDevices.valueAt(i);
|
||||
if (null != lastContact) {
|
||||
if (time - lastContact[0] > CHECK_ELAPSED_TIME) {
|
||||
// check to see if the device has been
|
||||
// disconnected
|
||||
int id = imv.mDevices.keyAt(i);
|
||||
if (null == InputDevice.getDevice(id)) {
|
||||
// disconnected!
|
||||
imv.notifyListeners(ON_DEVICE_REMOVED, id);
|
||||
imv.mDevices.remove(id);
|
||||
} else {
|
||||
lastContact[0] = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sendEmptyMessageDelayed(MESSAGE_TEST_FOR_DISCONNECT,
|
||||
CHECK_ELAPSED_TIME);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public InputManagerV9() {
|
||||
mDevices = new SparseArray<long[]>();
|
||||
mListeners = new HashMap<InputDeviceListener, Handler>();
|
||||
mDefaultHandler = new PollingMessageHandler(this);
|
||||
// as a side-effect, populates our collection of watched
|
||||
// input devices
|
||||
getInputDeviceIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputDevice getInputDevice(int id) {
|
||||
return InputDevice.getDevice(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getInputDeviceIds() {
|
||||
// add any hitherto unknown devices to our
|
||||
// collection of watched input devices
|
||||
int[] activeDevices = InputDevice.getDeviceIds();
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
for ( int id : activeDevices ) {
|
||||
long[] lastContact = mDevices.get(id);
|
||||
if ( null == lastContact ) {
|
||||
// we have a new device
|
||||
mDevices.put(id, new long[] { time });
|
||||
}
|
||||
}
|
||||
return activeDevices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
|
||||
mListeners.remove(listener);
|
||||
if (handler == null) {
|
||||
handler = mDefaultHandler;
|
||||
}
|
||||
mListeners.put(listener, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterInputDeviceListener(InputDeviceListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyListeners(int why, int deviceId) {
|
||||
// the state of some device has changed
|
||||
if (!mListeners.isEmpty()) {
|
||||
// yes... this will cause an object to get created... hopefully
|
||||
// it won't happen very often
|
||||
for (InputDeviceListener listener : mListeners.keySet()) {
|
||||
Handler handler = mListeners.get(listener);
|
||||
DeviceEvent odc = DeviceEvent.getDeviceEvent(why, deviceId, listener);
|
||||
handler.post(odc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeviceEvent implements Runnable {
|
||||
private int mMessageType;
|
||||
private int mId;
|
||||
private InputDeviceListener mListener;
|
||||
private static Queue<DeviceEvent> sEventQueue = new ArrayDeque<DeviceEvent>();
|
||||
|
||||
private DeviceEvent() {
|
||||
}
|
||||
|
||||
static DeviceEvent getDeviceEvent(int messageType, int id,
|
||||
InputDeviceListener listener) {
|
||||
DeviceEvent curChanged = sEventQueue.poll();
|
||||
if (null == curChanged) {
|
||||
curChanged = new DeviceEvent();
|
||||
}
|
||||
curChanged.mMessageType = messageType;
|
||||
curChanged.mId = id;
|
||||
curChanged.mListener = listener;
|
||||
return curChanged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
switch (mMessageType) {
|
||||
case ON_DEVICE_ADDED:
|
||||
mListener.onInputDeviceAdded(mId);
|
||||
break;
|
||||
case ON_DEVICE_CHANGED:
|
||||
mListener.onInputDeviceChanged(mId);
|
||||
break;
|
||||
case ON_DEVICE_REMOVED:
|
||||
mListener.onInputDeviceRemoved(mId);
|
||||
break;
|
||||
default:
|
||||
Log.e(LOG_TAG, "Unknown Message Type");
|
||||
break;
|
||||
}
|
||||
// dump this runnable back in the queue
|
||||
sEventQueue.offer(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenericMotionEvent(MotionEvent event) {
|
||||
// detect new devices
|
||||
int id = event.getDeviceId();
|
||||
long[] timeArray = mDevices.get(id);
|
||||
if (null == timeArray) {
|
||||
notifyListeners(ON_DEVICE_ADDED, id);
|
||||
timeArray = new long[1];
|
||||
mDevices.put(id, timeArray);
|
||||
}
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
timeArray[0] = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mDefaultHandler.removeMessages(MESSAGE_TEST_FOR_DISCONNECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mDefaultHandler.sendEmptyMessage(MESSAGE_TEST_FOR_DISCONNECT);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>libcontrollermoga</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,83 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="androidcontrollermoga" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>libcontrollernibiru</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,4 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.cocos2dx.lib"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="10"/>
|
||||
|
||||
</manifest>
|
|
@ -1,17 +0,0 @@
|
|||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
|
@ -1,4 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.cocos2dx.lib"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="10"/>
|
||||
|
||||
</manifest>
|
|
@ -1,17 +0,0 @@
|
|||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="androidcontrollerouya" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
|
@ -1,20 +0,0 @@
|
|||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
|
@ -12,5 +12,4 @@
|
|||
|
||||
android.library=true
|
||||
# Project target.
|
||||
target=android-16
|
||||
android.library.reference.1=../ControllerDelegate
|
||||
target=android-10
|
||||
|
|
|
@ -24,9 +24,6 @@ THE SOFTWARE.
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
|
||||
import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener;
|
||||
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat;
|
||||
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
@ -36,15 +33,12 @@ import android.content.pm.PackageManager;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewGroup;
|
||||
import android.util.Log;
|
||||
import android.widget.FrameLayout;
|
||||
import android.preference.PreferenceManager.OnActivityResultListener;
|
||||
|
||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener, InputDeviceListener {
|
||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
|
@ -59,10 +53,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
private Cocos2dxHandler mHandler;
|
||||
private static Cocos2dxActivity sContext = null;
|
||||
private Cocos2dxVideoHelper mVideoHelper = null;
|
||||
private InputManagerCompat mInputManager = null;
|
||||
|
||||
protected GameControllerHelper mControllerHelper = null;
|
||||
protected GameControllerDelegate mControllerDelegate = null;
|
||||
|
||||
public static Context getContext() {
|
||||
return sContext;
|
||||
|
@ -79,45 +69,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
}
|
||||
}
|
||||
|
||||
public void setGameControllerInstance(GameControllerDelegate controllerDelegate) {
|
||||
if (mControllerDelegate != null) {
|
||||
mControllerDelegate.onDestroy();
|
||||
mControllerDelegate = null;
|
||||
}
|
||||
mControllerDelegate = controllerDelegate;
|
||||
mControllerDelegate.setControllerEventListener(mControllerEventListener);
|
||||
mControllerDelegate.onCreate(this);
|
||||
}
|
||||
|
||||
public GameControllerDelegate getGameControllerInstance(){
|
||||
return mControllerDelegate;
|
||||
}
|
||||
|
||||
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 onDisconnected(String vendorName, int controller) {
|
||||
GameControllerAdapter.onDisconnected(vendorName, controller);
|
||||
}
|
||||
};
|
||||
|
||||
// ===========================================================
|
||||
// Constructors
|
||||
// ===========================================================
|
||||
|
@ -137,16 +88,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
if (mVideoHelper == null) {
|
||||
mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
|
||||
}
|
||||
|
||||
mInputManager = InputManagerCompat.Factory.getInputManager(this);
|
||||
mInputManager.registerInputDeviceListener(this, null);
|
||||
|
||||
if (mControllerDelegate != null) {
|
||||
mControllerDelegate.onCreate(this);
|
||||
}
|
||||
if (mControllerHelper == null) {
|
||||
mControllerHelper = new GameControllerHelper(this);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
|
@ -157,96 +98,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
// Methods for/from SuperClass/Interfaces
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerDelegate != null) {
|
||||
handled = mControllerDelegate.dispatchKeyEvent(event);
|
||||
}
|
||||
else {
|
||||
handled = mControllerHelper.dispatchKeyEvent(event);
|
||||
}
|
||||
return handled || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerDelegate != null) {
|
||||
handled = mControllerDelegate.dispatchGenericMotionEvent(event);
|
||||
}else {
|
||||
handled = mControllerHelper.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
return handled || super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
|
||||
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
||||
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
GameControllerAdapter.onConnected("Standard", 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.d(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);
|
||||
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
GameControllerAdapter.onDisconnected("Standard", deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Cocos2dxHelper.onResume();
|
||||
this.mGLSurfaceView.onResume();
|
||||
|
||||
if (mControllerDelegate != null) {
|
||||
mControllerDelegate.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (mControllerDelegate != null) {
|
||||
mControllerDelegate.onPause();
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
|
||||
Cocos2dxHelper.onPause();
|
||||
|
@ -255,11 +116,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mControllerDelegate != null) {
|
||||
mControllerDelegate.onDestroy();
|
||||
}
|
||||
mControllerHelper.destrory();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ public:
|
|||
const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;};
|
||||
|
||||
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;};
|
||||
Size getRenerTargetSize() const { return Size(m_width, m_height); }
|
||||
|
||||
virtual void setIMEKeyboardState(bool bOpen);
|
||||
void ShowKeyboard(Windows::Foundation::Rect r);
|
||||
|
|
|
@ -1104,7 +1104,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)const
|
|||
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
|
||||
}
|
||||
|
||||
float Layout::caculateNearestDistance(Widget* baseWidget)
|
||||
float Layout::calculateNearestDistance(Widget* baseWidget)
|
||||
{
|
||||
float distance = FLT_MAX;
|
||||
|
||||
|
@ -1114,7 +1114,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget)
|
|||
Layout *layout = dynamic_cast<Layout*>(node);
|
||||
int length;
|
||||
if (layout) {
|
||||
length = layout->caculateNearestDistance(baseWidget);
|
||||
length = layout->calculateNearestDistance(baseWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1137,7 +1137,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget)
|
|||
return distance;
|
||||
}
|
||||
|
||||
float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget)
|
||||
float Layout::calculateFarestDistance(cocos2d::ui::Widget *baseWidget)
|
||||
{
|
||||
float distance = -FLT_MAX;
|
||||
|
||||
|
@ -1147,7 +1147,7 @@ float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget)
|
|||
Layout *layout = dynamic_cast<Layout*>(node);
|
||||
int length;
|
||||
if (layout) {
|
||||
length = layout->caculateFarestDistance(baseWidget);
|
||||
length = layout->calculateFarestDistance(baseWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1194,7 +1194,8 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
|
|||
|
||||
float distance = FLT_MAX;
|
||||
int found = 0;
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT ||
|
||||
direction == FocusDirection::DOWN || direction == FocusDirection::UP)
|
||||
{
|
||||
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
|
@ -1207,7 +1208,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
|
|||
Layout *layout = dynamic_cast<Layout*>(w);
|
||||
if (layout)
|
||||
{
|
||||
length = layout->caculateNearestDistance(baseWidget);
|
||||
length = layout->calculateNearestDistance(baseWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1225,39 +1226,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
|
|||
return found;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
found = 0;
|
||||
distance = FLT_MAX;
|
||||
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
|
||||
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
{
|
||||
Widget *w = dynamic_cast<Widget*>(this->getChildren().at(index));
|
||||
if (w && w->isFocusEnabled())
|
||||
{
|
||||
Vec2 wPosition = this->getWorldCenterPoint(w);
|
||||
float length;
|
||||
Layout *layout = dynamic_cast<Layout*>(w);
|
||||
if (layout)
|
||||
{
|
||||
length = layout->caculateNearestDistance(baseWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
length = (wPosition - widgetPosition).getLength();
|
||||
}
|
||||
|
||||
if (length < distance)
|
||||
{
|
||||
found = index;
|
||||
distance = length;
|
||||
}
|
||||
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
CCASSERT(0, "invalid focus direction!!!");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1273,7 +1242,8 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
|
|||
|
||||
float distance = -FLT_MAX;
|
||||
int found = 0;
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT
|
||||
|| direction == FocusDirection::DOWN || direction == FocusDirection::UP)
|
||||
{
|
||||
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
|
@ -1286,7 +1256,7 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
|
|||
Layout *layout = dynamic_cast<Layout*>(w);
|
||||
if (layout)
|
||||
{
|
||||
length = layout->caculateFarestDistance(baseWidget);
|
||||
length = layout->calculateFarestDistance(baseWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1304,39 +1274,6 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
|
|||
return found;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
found = 0;
|
||||
distance = -FLT_MAX;
|
||||
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
|
||||
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
{
|
||||
Widget *w = dynamic_cast<Widget*>(this->getChildren().at(index));
|
||||
if (w && w->isFocusEnabled())
|
||||
{
|
||||
Vec2 wPosition = this->getWorldCenterPoint(w);
|
||||
float length;
|
||||
Layout *layout = dynamic_cast<Layout*>(w);
|
||||
if (layout)
|
||||
{
|
||||
length = layout->caculateFarestDistance(baseWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
length = (wPosition - widgetPosition).getLength();
|
||||
}
|
||||
|
||||
if (length > distance)
|
||||
{
|
||||
found = index;
|
||||
distance = length;
|
||||
}
|
||||
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
CCASSERT(0, "invalid focus direction!!!");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1368,6 +1305,9 @@ Widget *Layout::findFirstNonLayoutWidget()
|
|||
Layout* layout = dynamic_cast<Layout*>(node);
|
||||
if (layout) {
|
||||
widget = layout->findFirstNonLayoutWidget();
|
||||
if (widget != nullptr) {
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
else{
|
||||
Widget *w = dynamic_cast<Widget*>(node);
|
||||
|
|
|
@ -376,7 +376,7 @@ protected:
|
|||
*@param the base widget which will be used to caculate the distance between the layout's children and itself
|
||||
*@return return the nearest distance between the baseWidget and the layout's children
|
||||
*/
|
||||
float caculateNearestDistance(Widget* baseWidget);
|
||||
float calculateNearestDistance(Widget* baseWidget);
|
||||
|
||||
/**
|
||||
* caculate the farest distance between the baseWidget and the children of the layout
|
||||
|
@ -384,7 +384,7 @@ protected:
|
|||
*@return return the farest distance between the baseWidget and the layout's children
|
||||
*/
|
||||
|
||||
float caculateFarestDistance(Widget* baseWidget);
|
||||
float calculateFarestDistance(Widget* baseWidget);
|
||||
|
||||
/**
|
||||
* when a layout pass the focus to it's child, use this method to determine which algorithm to use, nearest or farest distance algorithm or not
|
||||
|
|
|
@ -747,38 +747,36 @@
|
|||
"cocos/platform/android/CCGLView.h",
|
||||
"cocos/platform/android/CCPlatformDefine.h",
|
||||
"cocos/platform/android/CCStdC.h",
|
||||
"cocos/platform/android/ControllerDelegate/.classpath",
|
||||
"cocos/platform/android/ControllerDelegate/.project",
|
||||
"cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs",
|
||||
"cocos/platform/android/ControllerDelegate/AndroidManifest.xml",
|
||||
"cocos/platform/android/ControllerDelegate/ant.properties",
|
||||
"cocos/platform/android/ControllerDelegate/build.xml",
|
||||
"cocos/platform/android/ControllerDelegate/proguard-project.txt",
|
||||
"cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java",
|
||||
"cocos/platform/android/ControllerMoga/.classpath",
|
||||
"cocos/platform/android/ControllerMoga/.project",
|
||||
"cocos/platform/android/ControllerMoga/.settings/org.eclipse.jdt.core.prefs",
|
||||
"cocos/platform/android/ControllerMoga/AndroidManifest.xml",
|
||||
"cocos/platform/android/ControllerMoga/ant.properties",
|
||||
"cocos/platform/android/ControllerMoga/build.xml",
|
||||
"cocos/platform/android/ControllerMoga/proguard-project.txt",
|
||||
"cocos/platform/android/ControllerMoga/src/org/cocos2dx/lib/GameControllerMoga.java",
|
||||
"cocos/platform/android/ControllerNibiru/.classpath",
|
||||
"cocos/platform/android/ControllerNibiru/.project",
|
||||
"cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs",
|
||||
"cocos/platform/android/ControllerNibiru/AndroidManifest.xml",
|
||||
"cocos/platform/android/ControllerNibiru/ant.properties",
|
||||
"cocos/platform/android/ControllerNibiru/build.xml",
|
||||
"cocos/platform/android/ControllerNibiru/proguard-project.txt",
|
||||
"cocos/platform/android/ControllerNibiru/src/org/cocos2dx/lib/GameControllerNibiru.java",
|
||||
"cocos/platform/android/ControllerOuya/.classpath",
|
||||
"cocos/platform/android/ControllerOuya/.project",
|
||||
"cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs",
|
||||
"cocos/platform/android/ControllerOuya/AndroidManifest.xml",
|
||||
"cocos/platform/android/ControllerOuya/ant.properties",
|
||||
"cocos/platform/android/ControllerOuya/build.xml",
|
||||
"cocos/platform/android/ControllerOuya/proguard-project.txt",
|
||||
"cocos/platform/android/ControllerOuya/src/org/cocos2dx/lib/GameControllerOuya.java",
|
||||
"cocos/platform/android/ControllerAutoAdapter/.classpath",
|
||||
"cocos/platform/android/ControllerAutoAdapter/.project",
|
||||
"cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs",
|
||||
"cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml",
|
||||
"cocos/platform/android/ControllerAutoAdapter/ant.properties",
|
||||
"cocos/platform/android/ControllerAutoAdapter/build.xml",
|
||||
"cocos/platform/android/ControllerAutoAdapter/lint.xml",
|
||||
"cocos/platform/android/ControllerAutoAdapter/proguard-project.txt",
|
||||
"cocos/platform/android/ControllerAutoAdapter/project.properties",
|
||||
"cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerActivity.java",
|
||||
"cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerHelper.java",
|
||||
"cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
|
||||
"cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
|
||||
"cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/.classpath",
|
||||
"cocos/platform/android/ControllerManualAdapter/.project",
|
||||
"cocos/platform/android/ControllerManualAdapter/.settings/org.eclipse.jdt.core.prefs",
|
||||
"cocos/platform/android/ControllerManualAdapter/AndroidManifest.xml",
|
||||
"cocos/platform/android/ControllerManualAdapter/ant.properties",
|
||||
"cocos/platform/android/ControllerManualAdapter/build.xml",
|
||||
"cocos/platform/android/ControllerManualAdapter/lint.xml",
|
||||
"cocos/platform/android/ControllerManualAdapter/proguard-project.txt",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
|
||||
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
|
||||
"cocos/platform/android/java/.classpath",
|
||||
"cocos/platform/android/java/.project",
|
||||
"cocos/platform/android/java/.settings/org.eclipse.jdt.core.prefs",
|
||||
|
@ -807,11 +805,8 @@
|
|||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerHelper.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
|
||||
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
|
||||
"cocos/platform/android/javaactivity.cpp",
|
||||
"cocos/platform/android/jni/DPIJni.cpp",
|
||||
"cocos/platform/android/jni/DPIJni.h",
|
||||
|
|
|
@ -1269,28 +1269,28 @@ void NodeNameTest::onEnter()
|
|||
// enumerateChildren()
|
||||
// name = regular expression
|
||||
int i = 0;
|
||||
parent = Node::create();
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
auto node = Node::create();
|
||||
sprintf(name, "node%d", i);
|
||||
node->setName(name);
|
||||
parent->addChild(node);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return false;
|
||||
});
|
||||
CCAssert(i == 100, "");
|
||||
|
||||
i = 0;
|
||||
parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return true;
|
||||
});
|
||||
CCAssert(i == 1, "");
|
||||
// parent = Node::create();
|
||||
// for (int i = 0; i < 100; ++i)
|
||||
// {
|
||||
// auto node = Node::create();
|
||||
// sprintf(name, "node%d", i);
|
||||
// node->setName(name);
|
||||
// parent->addChild(node);
|
||||
// }
|
||||
//
|
||||
// i = 0;
|
||||
// parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return false;
|
||||
// });
|
||||
// CCAssert(i == 100, "");
|
||||
//
|
||||
// i = 0;
|
||||
// parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return true;
|
||||
// });
|
||||
// CCAssert(i == 1, "");
|
||||
|
||||
|
||||
// enumerateChildren
|
||||
|
@ -1326,89 +1326,119 @@ void NodeNameTest::onEnter()
|
|||
});
|
||||
CCAssert(i == 1, "");
|
||||
|
||||
i = 0;
|
||||
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return false;
|
||||
});
|
||||
CCAssert(i == 10000, "");
|
||||
|
||||
i = 0;
|
||||
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return true;
|
||||
});
|
||||
CCAssert(i == 1, "");
|
||||
|
||||
// search from parent
|
||||
// name is xxx/..
|
||||
i = 0;
|
||||
parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return true;
|
||||
});
|
||||
CCAssert(i == 1, "");
|
||||
|
||||
i = 0;
|
||||
parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return false;
|
||||
});
|
||||
CCAssert(i == 10000, "");
|
||||
|
||||
// name = /xxx : search from root
|
||||
// search from root
|
||||
parent = getScene();
|
||||
for (int j = 0; j < 100; j++)
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
auto node = Node::create();
|
||||
sprintf(name, "node%d", j);
|
||||
node->setName(name);
|
||||
node->setName("node");
|
||||
parent->addChild(node);
|
||||
|
||||
for (int k = 0; k < 100; ++k)
|
||||
for (int j = 0; j < 100; ++j)
|
||||
{
|
||||
auto child = Node::create();
|
||||
sprintf(name, "node%d", k);
|
||||
child->setName(name);
|
||||
child->setName("child");
|
||||
node->addChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
parent->enumerateChildren("/node", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return false;
|
||||
});
|
||||
CCAssert(i == 100, "");
|
||||
|
||||
i = 0;
|
||||
enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return true;
|
||||
});
|
||||
CCAssert(i == 1, "");
|
||||
|
||||
i = 0;
|
||||
enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return false;
|
||||
});
|
||||
CCAssert(i == 10100, ""); // 10000(children) + 100(parent)
|
||||
|
||||
i = 0;
|
||||
enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return true;
|
||||
});
|
||||
CCAssert(i == 1, "");
|
||||
|
||||
i = 0;
|
||||
enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
|
||||
parent->enumerateChildren("//child", [&i](Node* node) -> bool {
|
||||
++i;
|
||||
return false;
|
||||
});
|
||||
CCAssert(i == 10000, "");
|
||||
|
||||
// i = 0;
|
||||
// parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return false;
|
||||
// });
|
||||
// CCAssert(i == 10000, "");
|
||||
//
|
||||
// i = 0;
|
||||
// parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return true;
|
||||
// });
|
||||
// CCAssert(i == 1, "");
|
||||
|
||||
// search from parent
|
||||
// name is xxx/..
|
||||
// i = 0;
|
||||
// parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return true;
|
||||
// });
|
||||
// CCAssert(i == 1, "");
|
||||
//
|
||||
// i = 0;
|
||||
// parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return false;
|
||||
// });
|
||||
// CCAssert(i == 10000, "");
|
||||
|
||||
// name = /xxx : search from root
|
||||
// parent = getScene();
|
||||
// for (int j = 0; j < 100; j++)
|
||||
// {
|
||||
// auto node = Node::create();
|
||||
// sprintf(name, "node%d", j);
|
||||
// node->setName(name);
|
||||
// parent->addChild(node);
|
||||
//
|
||||
// for (int k = 0; k < 100; ++k)
|
||||
// {
|
||||
// auto child = Node::create();
|
||||
// sprintf(name, "node%d", k);
|
||||
// child->setName(name);
|
||||
// node->addChild(child);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// i = 0;
|
||||
// enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return false;
|
||||
// });
|
||||
// CCAssert(i == 100, "");
|
||||
|
||||
// i = 0;
|
||||
// enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return true;
|
||||
// });
|
||||
// CCAssert(i == 1, "");
|
||||
//
|
||||
// i = 0;
|
||||
// enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return false;
|
||||
// });
|
||||
// CCAssert(i == 10100, ""); // 10000(children) + 100(parent)
|
||||
//
|
||||
// i = 0;
|
||||
// enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return true;
|
||||
// });
|
||||
// CCAssert(i == 1, "");
|
||||
//
|
||||
// i = 0;
|
||||
// enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
|
||||
// ++i;
|
||||
// return false;
|
||||
// });
|
||||
// CCAssert(i == 10000, "");
|
||||
|
||||
// utils::findChildren()
|
||||
|
||||
parent = Node::create();
|
||||
|
|
|
@ -341,7 +341,6 @@ Effect3DOutline::Effect3DOutline()
|
|||
|
||||
Effect3DOutline::~Effect3DOutline()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_sprite);
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);
|
||||
#endif
|
||||
|
@ -371,8 +370,6 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite)
|
|||
|
||||
if(sprite != _sprite)
|
||||
{
|
||||
CC_SAFE_RETAIN(sprite);
|
||||
CC_SAFE_RELEASE_NULL(_sprite);
|
||||
_sprite = sprite;
|
||||
|
||||
auto mesh = sprite->getMesh();
|
||||
|
|
|
@ -103,6 +103,7 @@ protected:
|
|||
|
||||
Vec3 _outlineColor;
|
||||
float _outlineWidth;
|
||||
//weak reference
|
||||
EffectSprite3D* _sprite;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
EventListenerCustom* _backToForegroundListener;
|
||||
|
|
|
@ -10,4 +10,4 @@
|
|||
# Project target.
|
||||
target=android-10
|
||||
|
||||
android.library.reference.1=../../../cocos/platform/android/java
|
||||
android.library.reference.1=../../../cocos/platform/android/ControllerDelegate
|
||||
|
|
|
@ -25,14 +25,14 @@ package org.cocos2dx.game_controller_test;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||
import org.cocos2dx.lib.GameControllerActivity;
|
||||
import org.cocos2dx.lib.GameControllerHelper.ControllerListener;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
public class AppActivity extends Cocos2dxActivity {
|
||||
public class AppActivity extends GameControllerActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
Loading…
Reference in New Issue