Example usage for com.badlogic.gdx.controllers Controller getName

List of usage examples for com.badlogic.gdx.controllers Controller getName

Introduction

In this page you can find the example usage for com.badlogic.gdx.controllers Controller getName.

Prototype

public String getName();

Source Link

Usage

From source file:ch.hevs.gdx2d.desktop.Xbox.java

License:Apache License

/**
 * @return whether the {@link Controller} is an Xbox controller
 *//*  w  w w .  j av  a2  s .  c om*/
public static boolean isXboxController(Controller controller) {
    System.out.println(controller.getName());
    return controller.getName().toLowerCase().contains("xbox")
            || controller.getName().toLowerCase().contains("x-box");
}

From source file:com.intrepid.nicge.controller.ControllerManager.java

private JoystickPad checkControllersType(Controller controller) {
    String controllerName = controller.getName().toLowerCase();
    if (checkXBox360(controllerName)) {
        return new JoystickPad(controller, MAP_XBOX360);
    } else if (checkPS4(controllerName)) {
        return new JoystickPad(controller, MAP_PS4);
    }//from w w  w.  j a  va2 s.  com

    return null;
}

From source file:com.tnf.ptm.screens.game.ShipControllerControl.java

License:Apache License

ShipControllerControl(PtmApplication ptmApplication) {
    final GameOptions gameOptions = ptmApplication.getOptions();

    Controllers.clearListeners();//from w  ww . j a va 2s. c om

    // print the currently connected controllers to the console
    logger.printDebug(String.format("Controllers Size: {}", Controllers.getControllers().size));
    int i = 0;
    for (Controller controller : Controllers.getControllers()) {
        logger.printDebug(String.format("#{}:{}", i++, controller.getName()));
    }

    // setup the listener that prints events to the console
    Controllers.addListener(new ControllerListener() {
        int indexOf(Controller controller) {
            return Controllers.getControllers().indexOf(controller, true);
        }

        @Override
        public void connected(Controller controller) {
        }

        @Override
        public void disconnected(Controller controller) {
        }

        @Override
        public boolean buttonDown(Controller controller, int buttonIndex) {
            if (buttonIndex == gameOptions.getControllerButtonShoot()) {
                controllerShoot = true;
            } else if (buttonIndex == gameOptions.getControllerButtonShoot2()) {
                controllerShoot2 = true;
            } else if (buttonIndex == gameOptions.getControllerButtonAbility()) {
                controllerAbility = true;
            } else if (buttonIndex == gameOptions.getControllerButtonLeft()) {
                controllerLeft = true;
            } else if (buttonIndex == gameOptions.getControllerButtonRight()) {
                controllerRight = true;
            } else if (buttonIndex == gameOptions.getControllerButtonUp()) {
                controllerUp = true;
            }

            return true;
        }

        @Override
        public boolean buttonUp(Controller controller, int buttonIndex) {
            if (buttonIndex == gameOptions.getControllerButtonShoot()) {
                controllerShoot = false;
            } else if (buttonIndex == gameOptions.getControllerButtonShoot2()) {
                controllerShoot2 = false;
            } else if (buttonIndex == gameOptions.getControllerButtonAbility()) {
                controllerAbility = false;
            } else if (buttonIndex == gameOptions.getControllerButtonLeft()) {
                controllerLeft = false;
            } else if (buttonIndex == gameOptions.getControllerButtonRight()) {
                controllerRight = false;
            } else if (buttonIndex == gameOptions.getControllerButtonUp()) {
                controllerUp = false;
            }

            return true;
        }

        @Override
        public boolean axisMoved(Controller controller, int axisIndex, float value) {
            if (axisIndex == gameOptions.getControllerAxisShoot()) {
                controllerShoot = (value > 0.5f);
            } else if (axisIndex == gameOptions.getControllerAxisShoot2()) {
                controllerShoot2 = (value > 0.5f);
            } else if (axisIndex == gameOptions.getControllerAxisAbility()) {
                controllerAbility = (value > 0.5f);
            } else if (axisIndex == gameOptions.getControllerAxisLeftRight()) {
                boolean invert = gameOptions.isControllerAxisLeftRightInverted();
                if (value < -0.5f) {
                    controllerLeft = !invert;
                    controllerRight = invert;
                } else if (value > 0.5f) {
                    controllerLeft = invert;
                    controllerRight = !invert;
                } else {
                    controllerLeft = false;
                    controllerRight = false;
                }
            } else if (axisIndex == gameOptions.getControllerAxisUpDown()) {
                boolean invert = gameOptions.isControllerAxisUpDownInverted();
                if (value < -0.5f) {
                    controllerUp = !invert;
                    controllerDown = invert;
                } else if (value > 0.5f) {
                    controllerUp = invert;
                    controllerDown = !invert;
                } else {
                    controllerUp = false;
                    controllerDown = false;
                }
            }

            return true;
        }

        @Override
        public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
            logger.printDebug(String.format("#{}, pov {}: {}", indexOf(controller), povIndex, value));
            return false;
        }

        @Override
        public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
            logger.printDebug(String.format("#{},  x slider  {}: {}", indexOf(controller), sliderIndex, value));
            return false;
        }

        @Override
        public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
            logger.printDebug(String.format("#{},  y slider  {}: {}", indexOf(controller), sliderIndex, value));
            return false;
        }

        @Override
        public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
            // not printing this as we get too many values
            return false;
        }
    });

}

From source file:org.destinationsol.game.screens.ShipControllerControl.java

License:Apache License

public ShipControllerControl(SolApplication cmp) {
    final GameOptions gameOptions = cmp.getOptions();

    Controllers.clearListeners();/*from   ww  w .j a  va2  s.com*/

    // print the currently connected controllers to the console
    System.out.println("Controllers: " + Controllers.getControllers().size);
    int i = 0;
    for (Controller controller : Controllers.getControllers()) {
        System.out.println("#" + i++ + ": " + controller.getName());
    }

    // setup the listener that prints events to the console
    Controllers.addListener(new ControllerListener() {
        public int indexOf(Controller controller) {
            return Controllers.getControllers().indexOf(controller, true);
        }

        @Override
        public void connected(Controller controller) {
        }

        @Override
        public void disconnected(Controller controller) {
        }

        @Override
        public boolean buttonDown(Controller controller, int buttonIndex) {
            if (buttonIndex == gameOptions.getControllerButtonShoot()) {
                controllerShoot = true;
            } else if (buttonIndex == gameOptions.getControllerButtonShoot2()) {
                controllerShoot2 = true;
            } else if (buttonIndex == gameOptions.getControllerButtonAbility()) {
                controllerAbility = true;
            } else if (buttonIndex == gameOptions.getControllerButtonLeft()) {
                controllerLeft = true;
            } else if (buttonIndex == gameOptions.getControllerButtonRight()) {
                controllerRight = true;
            } else if (buttonIndex == gameOptions.getControllerButtonUp()) {
                controllerUp = true;
            }

            return true;
        }

        @Override
        public boolean buttonUp(Controller controller, int buttonIndex) {
            if (buttonIndex == gameOptions.getControllerButtonShoot()) {
                controllerShoot = false;
            } else if (buttonIndex == gameOptions.getControllerButtonShoot2()) {
                controllerShoot2 = false;
            } else if (buttonIndex == gameOptions.getControllerButtonAbility()) {
                controllerAbility = false;
            } else if (buttonIndex == gameOptions.getControllerButtonLeft()) {
                controllerLeft = false;
            } else if (buttonIndex == gameOptions.getControllerButtonRight()) {
                controllerRight = false;
            } else if (buttonIndex == gameOptions.getControllerButtonUp()) {
                controllerUp = false;
            }

            return true;
        }

        @Override
        public boolean axisMoved(Controller controller, int axisIndex, float value) {
            if (axisIndex == gameOptions.getControllerAxisShoot()) {
                if (value > 0.5f) {
                    controllerShoot = true;
                } else {
                    controllerShoot = false;
                }
            }

            else if (axisIndex == gameOptions.getControllerAxisShoot2()) {
                if (value > 0.5f) {
                    controllerShoot2 = true;
                } else {
                    controllerShoot2 = false;
                }
            }

            else if (axisIndex == gameOptions.getControllerAxisAbility()) {
                if (value > 0.5f) {
                    controllerAbility = true;
                } else {
                    controllerAbility = false;
                }
            }

            else if (axisIndex == gameOptions.getControllerAxisLeftRight()) {
                boolean invert = gameOptions.isControllerAxisLeftRightInverted();
                if (value < -0.5f) {
                    controllerLeft = invert ? false : true;
                    controllerRight = invert ? true : false;
                } else if (value > 0.5f) {
                    controllerLeft = invert ? true : false;
                    controllerRight = invert ? false : true;
                } else {
                    controllerLeft = false;
                    controllerRight = false;
                }
            }

            else if (axisIndex == gameOptions.getControllerAxisUpDown()) {
                boolean invert = gameOptions.isControllerAxisUpDownInverted();
                if (value < -0.5f) {
                    controllerUp = invert ? false : true;
                    controllerDown = invert ? true : false;
                } else if (value > 0.5f) {
                    controllerUp = invert ? true : false;
                    controllerDown = invert ? false : true;
                } else {
                    controllerUp = false;
                    controllerDown = false;
                }
            }

            return true;
        }

        @Override
        public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
            System.out.println("#" + indexOf(controller) + ", pov " + povIndex + ": " + value);
            return false;
        }

        @Override
        public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
            System.out.println("#" + indexOf(controller) + ", x slider " + sliderIndex + ": " + value);
            return false;
        }

        @Override
        public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
            System.out.println("#" + indexOf(controller) + ", y slider " + sliderIndex + ": " + value);
            return false;
        }

        @Override
        public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
            // not printing this as we get to many values
            return false;
        }
    });

}

From source file:org.matheusdev.ror.client.ClientMaster.java

License:Open Source License

private Controller getController(String name) {
    for (Controller cont : Controllers.getControllers()) {
        if (cont.getName().equals(name)) {
            return cont;
        }//from w ww.  j  a v  a2s  .  c o m
    }
    System.err.println("Couldn't find controller for name \"" + name + "\"");
    return null;
}

From source file:org.matheusdev.ror.screens.ScreenSettings.java

License:Open Source License

private Controller getController(String name) {
    for (Controller controller : Controllers.getControllers()) {
        if (controller.getName().equalsIgnoreCase(name)) {
            return controller;
        }//from   ww  w  .  j ava 2  s . co  m
    }
    return null;
}

From source file:org.matheusdev.ror.screens.ScreenSettings.java

License:Open Source License

@Override
public void tick(float delta) {
    stage.act(delta);//  w w w .j  a  v a  2  s .  c o  m
    if (gamepadRead) {
        search: for (Controller pad : Controllers.getControllers()) {
            for (int i = 0; i < 4; i++) {
                if (!FloatUtils.equalsEpsilon(pad.getAxis(i), 0, 0.1f)) {
                    Config.get().gamepad = pad.getName();
                    gamepadButton.setText(Config.get().gamepad);
                    gamepadButton.setChecked(false);
                    gamepadRead = false;
                    break search;
                }
            }
        }
    }
    if (gamepadButton != null) {
        if (gamepadXAxisRead) {
            for (int i = 0; i < 4; i++) {
                if (!FloatUtils.equalsEpsilon(gamepad.getAxis(i), 0f, 0.5f)) {
                    Config.get().gamepadX = i;
                    gamepadXAxisRead = false;
                    gamepadX.setChecked(false);
                    gamepadX.setText("Record");
                    break;
                }
            }
        }
        if (gamepadYAxisRead) {
            for (int i = 0; i < 4; i++) {
                if (!FloatUtils.equalsEpsilon(gamepad.getAxis(i), 0f, 0.5f)) {
                    Config.get().gamepadY = i;
                    gamepadYAxisRead = false;
                    gamepadY.setChecked(false);
                    gamepadY.setText("Record");
                    break;
                }
            }
        }
    }
}

From source file:seventh.client.SeventhGame.java

License:Open Source License

private void initControllers() {
    Cons.println("Detecting controllers...");
    for (Controller control : Controllers.getControllers()) {
        Cons.println("Found: " + control.getName());
    }//from  www  .  j  a  va2  s  .co m
    Cons.println("Completed checking for controllers");
}

From source file:ve.ucv.ciens.ccg.nxtar.states.InGameState.java

License:Apache License

@Override
public boolean buttonDown(Controller controller, int buttonCode) {
    MotorEvent event;/* w  w w. j a va  2s . com*/
    GamepadUserInput userInput;

    if (stateActive) {
        Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: "
                + Integer.toString(buttonCode));

        if (buttonCode == Ouya.BUTTON_L1) {
            gamepadButtonPressed[0] = true;

            if (!gamepadButtonPressed[4]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_A);
                event.setPower((byte) -100);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_R1) {
            gamepadButtonPressed[1] = true;

            if (!gamepadButtonPressed[5]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_C);
                event.setPower((byte) -100);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_DPAD_LEFT) {
            gamepadButtonPressed[2] = false;

            if (!gamepadButtonPressed[3]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_B);
                event.setPower((byte) -25);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_DPAD_RIGHT) {
            gamepadButtonPressed[3] = false;

            if (!gamepadButtonPressed[2]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_B);
                event.setPower((byte) 25);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_L2) {
            gamepadButtonPressed[4] = false;

            if (!gamepadButtonPressed[0]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_A);
                event.setPower((byte) 100);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_R2) {
            gamepadButtonPressed[5] = false;

            if (!gamepadButtonPressed[1]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_C);
                event.setPower((byte) 100);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_Y) {
            gamepadButtonPressed[6] = true;

            event = new MotorEvent();
            event.setMotor(motor_t.RECENTER);
            event.setPower((byte) 0x00);
            queue.addEvent(event);

        } else if (buttonCode == Ouya.BUTTON_O) {
            userInput = new GamepadUserInput();
            userInput.oButton = true;
            robotArmPositioningSystem.setUserInput(userInput);
            robotArmPositioningSystem.process();

        } else if (buttonCode == Ouya.BUTTON_U) {
            core.nextState = game_states_t.HINTS;
        } else if (buttonCode == Ouya.BUTTON_A || buttonCode == Ouya.BUTTON_MENU) {
            core.nextState = game_states_t.MAIN_MENU;
        }

        return true;
    } else {
        return false;
    }
}

From source file:ve.ucv.ciens.ccg.nxtar.states.InGameState.java

License:Apache License

@Override
public boolean buttonUp(Controller controller, int buttonCode) {
    MotorEvent event;//  ww  w . ja va 2 s . c  o  m

    if (stateActive) {
        Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: "
                + Integer.toString(buttonCode));

        if (buttonCode == Ouya.BUTTON_L1) {
            gamepadButtonPressed[0] = false;

            if (!gamepadButtonPressed[4]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_A);
                event.setPower((byte) 0);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_R1) {
            gamepadButtonPressed[1] = false;

            if (!gamepadButtonPressed[5]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_C);
                event.setPower((byte) 0);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_DPAD_LEFT) {
            gamepadButtonPressed[2] = false;

            if (!gamepadButtonPressed[3]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_B);
                event.setPower((byte) 0);
                queue.addEvent(event);
            }
        } else if (buttonCode == Ouya.BUTTON_DPAD_RIGHT) {
            gamepadButtonPressed[3] = false;

            if (!gamepadButtonPressed[2]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_B);
                event.setPower((byte) 0);
                queue.addEvent(event);
            }
        } else if (buttonCode == Ouya.BUTTON_L2) {
            gamepadButtonPressed[4] = false;

            if (!gamepadButtonPressed[0]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_A);
                event.setPower((byte) 0);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_R2) {
            gamepadButtonPressed[5] = false;

            if (!gamepadButtonPressed[1]) {
                event = new MotorEvent();
                event.setMotor(motor_t.MOTOR_C);
                event.setPower((byte) 0);
                queue.addEvent(event);
            }

        } else if (buttonCode == Ouya.BUTTON_Y) {
            gamepadButtonPressed[6] = false;
        }

        return true;
    } else {
        return false;
    }
}