Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.community.combat.engine;
- import tv.ouya.console.api.OuyaController;
- import android.content.Context;
- import android.hardware.input.InputManager;
- import android.util.Log;
- public class Gameplay3DHelper {
- static
- {
- System.loadLibrary("gameplay");
- }
- private native void registerGamepad(int deviceId, int controllerNumber);
- private native void unregisterGamepad(int deviceId, int controllerNumber);
- public void setupControllerAgent(Context context)
- {
- Log.d("GAMEPLAY3D", "We're Inside the Java Bean!");
- /*
- * Controllers have to be "Connected" to gameplay.
- * This is done through the Gamepad.add() function,
- * to call this function, we must first know what controller's
- * are connected to the console. This is where this next for block comes
- * in handy.
- * We also set up a listener to add any new controllers to are engine too.
- */
- for(int i = 1; i < OuyaController.MAX_CONTROLLERS ; i++)
- {
- OuyaController controller = OuyaController.getControllerByPlayer(i);
- if(controller != null)
- {
- registerGamepad(controller.getDeviceId(), i);
- }
- }
- //Now lets register that handler and it's functionality.
- InputManager inputMan = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
- inputMan.registerInputDeviceListener(new InputManager.InputDeviceListener()
- {
- @Override
- public void onInputDeviceRemoved(int deviceId) {
- int controllerNumber = OuyaController.getPlayerNumByDeviceId(deviceId);
- if(controllerNumber != -1)
- {
- //Is Controller! lets tell ENGINE3D!
- unregisterGamepad(deviceId , controllerNumber);
- }
- else if(controllerNumber == -1)
- {
- Log.v("GAMEPLAY3D", "Old, Non Controller disconnected!");
- }
- }
- @Override
- public void onInputDeviceChanged(int deviceId) {
- // Don't really do anything really...
- }
- @Override
- public void onInputDeviceAdded(int deviceId) {
- int controllerNumber = OuyaController.getPlayerNumByDeviceId(deviceId);
- if(controllerNumber > 0)
- {
- //Controller OK! lets tell ENGINE3D!
- registerGamepad(deviceId , controllerNumber);
- }
- else
- {
- Log.v("GAMEPLAY3D", "New, Non OUYA Controller Connected!");
- }
- }
- },null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement