@Override public boolean buttonDown(Controller controller, int buttonCode) { if (currentMenuOption != null && KeyboardInputProcessor.isXbox360Controller(controller.getName())) { switch(buttonCode) { case KeyboardInputProcessor.XBOX_360_A: menuAction(); return true; case KeyboardInputProcessor.XBOX_360_BACK: dismissMenu(); return true; } } if (currentMenuOption == returnToTitleOption && KeyboardInputProcessor.isXbox360Controller(controller.getName())) { if (buttonCode != KeyboardInputProcessor.XBOX_360_A) { returnToTitleOption.resetVisited(); } } return false; }
@Override public boolean axisMoved(Controller controller, int axisCode, float value) { Gdx.app.log(getClass().getSimpleName(), "axisMoved(" + controller + ", " + axisCode + ", " + value + ")"); if (Math.abs(value) > .5f) { if (currentMenuOption.buttonIndex == com.gradualgames.ggvm.Controller.Buttons.LEFT || currentMenuOption.buttonIndex == com.gradualgames.ggvm.Controller.Buttons.RIGHT) { inputProcessor.getActualAxisToAxisCode().inverse().forcePut(axisCode, KeyboardInputProcessor.Axis.X); } else if (currentMenuOption.buttonIndex == com.gradualgames.ggvm.Controller.Buttons.UP || currentMenuOption.buttonIndex == com.gradualgames.ggvm.Controller.Buttons.DOWN) { inputProcessor.getActualAxisToAxisCode().inverse().forcePut(axisCode, KeyboardInputProcessor.Axis.Y); } menu = topLevelMenu; menu.activate(); } return false; }
@Override public boolean buttonUp(Controller controller, int buttonCode) { if(controller == pads[0]) { if(buttonCode == 0){ InputManager.jump[0] = false; }else if(buttonCode == 2) { InputManager.attack[0] = false; } }else if(controller == pads[1]) { if(buttonCode == 0){ InputManager.jump[1] = false; }else if(buttonCode == 2) { InputManager.attack[1] = false ; } } return true; }
/** * Hilfsfunktion, die prüft, ob eine Axe losgelassen wurde. * * @see InputManager#axisMoved(Controller, int, float) * * @param controller der Controller, von dem das Ereignis aus geht * @param axisCode der Code der Axe * @return true, wenn die Axe wirklich losgelassen wurde */ private boolean axisReleased(Controller controller, int axisCode) { AxisKey lowAxis = new AxisKey(axisCode, false, controller); if (controllerGameAxisStateInverse.containsKey(lowAxis) && controllerGameAxisStateInverse.get(lowAxis)) { controllerGameAxisStateInverse.put(lowAxis, false); return controllerUp(controllerGameAxisBindingInverse.get(lowAxis)); } AxisKey highAxis = new AxisKey(axisCode, true, controller); if (controllerGameAxisStateInverse.containsKey(highAxis) && controllerGameAxisStateInverse.get(highAxis)) { controllerGameAxisStateInverse.put(highAxis, false); return controllerUp(controllerGameAxisBindingInverse.get(highAxis)); } return false; }
public static int findHighAxisValue(Controller controller, float analogToDigitalTreshold, float maxAcceptedAnalogValue) { // Cycle through axis indexes to check if there is a high value float highestValue = 0; int axisWithHighestValue = -1; for (int i = 0; i <= 500; i++) { float abs = Math.abs(controller.getAxis(i)); if (abs > highestValue && abs >= analogToDigitalTreshold && abs <= maxAcceptedAnalogValue) { highestValue = abs; axisWithHighestValue = i; } } return axisWithHighestValue; }
protected MappedInputs getControllerMapping(Controller controller) { if (!initialized) throw new IllegalStateException("Call commitConfig() before creating Controller Listeners"); MappedInputs retVal = null; // initialize mapping map and controller information if not already present if (mappedInputs == null) mappedInputs = new HashMap<>(); retVal = mappedInputs.get(controller.getName()); // in case the controller is not recorded or loaded already, initialize it if (retVal == null) { MappedInputs defaultMapping = new MappedInputs(controller); if (getDefaultMapping(defaultMapping)) { retVal = defaultMapping; mappedInputs.put(retVal.controllerName, retVal); } } return retVal; }
@Override public boolean buttonDown(Controller controller, int buttonCode) { if(controller == pads[0]) { if(buttonCode == 0) { InputManager.jump[0] = true; }else if(buttonCode == 2) { InputManager.attack[0] = true; } }else if(controller == pads[1]) { if(buttonCode == 0){ InputManager.jump[1] = true; }else if(buttonCode == 2) { InputManager.attack[1] = true; } } return true; }
@Override public boolean povMoved(Controller controller, int povCode, PovDirection value) { switch(value) { case north: cursorUp(); break; case south: cursorDown(); break; } return false; }
@Override public boolean buttonDown(Controller controller, int buttonCode) { Gdx.app.log(getClass().getSimpleName(), "buttonDown(" + controller + ", " + buttonCode + ")"); inputProcessor.getButtonIndexToButton().inverse().forcePut(buttonCode, currentMenuOption.buttonIndex); menu = topLevelMenu; menu.activate(); return false; }
@Override public boolean povMoved(Controller controller, int povCode, PovDirection value) { Gdx.app.log(getClass().getSimpleName(), "povMoved(" + controller + ", " + povCode + ", " + value + ")"); //User decided to use a d-pad---clear out any axis configurations since these can conflict. inputProcessor.getActualAxisToAxisCode().clear(); menu = topLevelMenu; menu.activate(); return false; }
public KeyboardInputProcessor() { super(); buttonToButtonUpIndex.put(com.gradualgames.ggvm.Controller.Buttons.LEFT.ordinal(), com.gradualgames.ggvm.Controller.Buttons.RIGHT.ordinal()); buttonToButtonUpIndex.put(com.gradualgames.ggvm.Controller.Buttons.RIGHT.ordinal(), com.gradualgames.ggvm.Controller.Buttons.LEFT.ordinal()); buttonToButtonUpIndex.put(com.gradualgames.ggvm.Controller.Buttons.UP.ordinal(), com.gradualgames.ggvm.Controller.Buttons.DOWN.ordinal()); buttonToButtonUpIndex.put(com.gradualgames.ggvm.Controller.Buttons.DOWN.ordinal(), com.gradualgames.ggvm.Controller.Buttons.UP.ordinal()); logControllers(); }
private void logControllers() { Array<Controller> controllers = Controllers.getControllers(); Gdx.app.log(getClass().getSimpleName(), "****** Controller Names *********"); for(Controller controller: controllers) { Gdx.app.log(getClass().getSimpleName(), controller.getName()); } Gdx.app.log(getClass().getSimpleName(), "********************************"); }
public void autoConfigure() { Array<Controller> controllers = Controllers.getControllers(); if (controllers.size > 0) { Controller controller = controllers.get(0); if (isXbox360Controller(controller.getName())) { buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.A, XBOX_360_A); buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.B, XBOX_360_X); buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.SELECT, XBOX_360_LEFT_SHOULDER); buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.START, XBOX_360_START); } else if (controller.getName().equals(RETRO_USB_NAME)) { buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.A, RETRO_USB_A); buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.B, RETRO_USB_B); buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.SELECT, RETRO_USB_SELECT); buttonIndexToButton.put(com.gradualgames.ggvm.Controller.Buttons.START, RETRO_USB_START); actualAxisToAxisCode.put(Axis.X, 1); actualAxisToAxisCode.put(Axis.Y, 0); } } buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.A, Input.Keys.F); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.B, Input.Keys.D); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.SELECT, Input.Keys.A); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.START, Input.Keys.S); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.UP, Input.Keys.UP); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.RIGHT, Input.Keys.RIGHT); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.DOWN, Input.Keys.DOWN); buttonIndexToKeyCode.put(com.gradualgames.ggvm.Controller.Buttons.LEFT, Input.Keys.LEFT); }
public String getNameForButton(int button) { Array<Controller> controllers = Controllers.getControllers(); if (controllers.size > 0) { Controller controller = controllers.get(0); if (KeyboardInputProcessor.isXbox360Controller(controller.getName())) { switch(button) { case XBOX_360_A: return "A"; case XBOX_360_B: return "B"; case XBOX_360_X: return "X"; case XBOX_360_Y: return "Y"; case XBOX_360_LEFT_SHOULDER: return "LSHLDR"; case XBOX_360_RIGHT_SHOULDER: return "RSHLDR"; case XBOX_360_BACK: return "BACK"; case XBOX_360_START: return "START"; } } else if (controller.getName().equals(RETRO_USB_NAME)) { switch(button) { case RETRO_USB_A: return "A"; case RETRO_USB_B: return "B"; case RETRO_USB_SELECT: return "SELECT"; case RETRO_USB_START: return "START"; } } } return Integer.toString(button); }
@Override public boolean axisMoved(Controller controller, int axisCode, float value) { //Controller 1 if(controller == pads[0]) { if(axisCode == 1) { if(Math.abs(value) < 0.3) InputManager.horizontal[0] = 0; else InputManager.horizontal[0] = value; } // Trigger if(axisCode ==4){ if(Math.abs(value) < 0.1) InputManager.trigger[0] = 0; else InputManager.trigger[0] = value; } } //Controller 2 else if(controller == pads[1]) { if(axisCode == 1) { if(Math.abs(value) < 0.3) InputManager.horizontal[1] = 0; else InputManager.horizontal[1] = value; } // Trigger if(axisCode ==4){ if(Math.abs(value) < 0.1) InputManager.trigger[1] = 0; else InputManager.trigger[1] = value; } } return true; }
@Override public boolean buttonDown(Controller controller, int buttonCode) { if (buttonIndexToButton.containsValue(buttonCode)) { ggvm.setButtonState(buttonIndexToButton.inverse().get(buttonCode).ordinal(), true); } if (KeyboardInputProcessor.isXbox360Controller(controller.getName()) && buttonCode == XBOX_360_BACK) { stopGGVmAndActivateMenu(); } return false; }
@Override public boolean buttonUp(Controller controller, int buttonCode) { if (buttonIndexToButton.containsValue(buttonCode)) { ggvm.setButtonState(buttonIndexToButton.inverse().get(buttonCode).ordinal(), false); } return false; }
@Override public boolean axisMoved(Controller controller, int axisCode, float value) { if (actualAxisToAxisCode.containsValue(axisCode)) { Axis actualAxis = actualAxisToAxisCode.inverse().get(axisCode); switch(actualAxis) { case X: if (value >= .5) { ggvm.setLeftButtonState(false); ggvm.setRightButtonState(true); } else if (value <= -.5 ) { ggvm.setLeftButtonState(true); ggvm.setRightButtonState(false); } else { ggvm.setLeftButtonState(false); ggvm.setRightButtonState(false); } break; case Y: if (value > .5) { ggvm.setDownButtonState(true); ggvm.setUpButtonState(false); } else if (value < -.5) { ggvm.setDownButtonState(false); ggvm.setUpButtonState(true); } else { ggvm.setDownButtonState(false); ggvm.setUpButtonState(false); } break; } } return false; }
@Override public void init(StageControl stage) { for (Controller controller : Controllers.getControllers()) { ConfigController config = new ConfigController(controller.getName()); config.load(); configs.put(controller, config); } }
private boolean isPressed(Controller controller, ConfigKeymap.Input input) { switch (input.getType()) { case ConfigKeymap.Input.TYPE_AXIS: return input.getExtra() == 0 ? controller.getAxis(input.getInput()) < -.2 : controller.getAxis(input.getInput()) > .2; case ConfigKeymap.Input.TYPE_POV: return controller.getPov(input.getInput()).ordinal() == input.getExtra(); case ConfigKeymap.Input.TYPE_BUTTON: return controller.getButton(input.getInput()); } return false; }
@Override public void connected(Controller controller) { if(paused) { if (controllers.get(0) == null) controllers.set(0, new TDController(controller, 0)); else controllers.set(1, new TDController(controller, 1)); paused = false; for(ControlListener listener: listeners) if(listener.onResume()) break; } }
@Override public void disconnected(Controller controller) { for(TDController c: controllers) if(c != null && c.getController().equals(controller)) { if(neededControllers == 2 || neededControllers == 1 && c.getPlayer() == 0) { paused = true; for(ControlListener listener: listeners) if(listener.onPause(true, neededControllers - getControllerCount())) break; } controllers.set(c.getPlayer(), null); } }
@Override public boolean buttonDown(Controller controller, int buttonCode) { if(paused) { //Set controller to p1 or p2 if isn't connected already paused = false; for(ControlListener listener: listeners) if(listener.onResume()) break; } return true; }
/** * Initialisierung. * * Lädt alle angeschlossenen Controller und legt den InputProcessor fest. * * @param inputProcessor der InputProcessor an den Controllereingaben gesendet werden sollen */ public void init(InputProcessor inputProcessor) { this.feedForwardProcessor = inputProcessor; for (Controller controller : Controllers.getControllers()) { loadController(controller); } buildInverse(); }
/** * Lädt einen einzelnen Controller, sofern für diesen ein Mapping bekannt ist. * * @param controller der Controller, der geladen werden soll */ private void loadController(Controller controller) { if (controller.getName().toLowerCase().contains("sony computer entertainment")) { loadDefaultControllerMapping(controller, "ps4"); } else if (controller.getName().toLowerCase().contains("xbox") && controller.getName().contains("360")) { loadDefaultControllerMapping(controller, "xbox360"); } }
/** * Wird derzeit auf der Desktop Platform nicht unterstützt. * @param controller unbenutzt */ @Override public void connected(Controller controller) { //loadController(controller); //buildInverse(); }
/** * Wird aufgerufen, wenn ein Button auf dem Controller gedrückt wird. * Das Ereignis wird an den InputProcessor weitergeleitet, wenn mit diesem eine Aktion verknüpft ist. * * @see InputManager#buttonUp(Controller, int) * * @param controller der Controller, auf dem der Button gedrückt wurde * @param buttonCode der Code des Buttons * @return true, wenn das Ereignis beachtet wurde */ @Override public boolean buttonDown(Controller controller, int buttonCode) { if (feedForwardProcessor == null) return false; ButtonKey button = new ButtonKey(buttonCode, controller); if (!controllerGameButtonBindingInverse.containsKey(button)) return false; Action action = controllerGameButtonBindingInverse.get(button); return controllerDown(action); }
/** * Wird aufgerufen, wenn ein Button auf dem Controller losgelassen wird. * Das Ereignis wird an den InputProcessor weitergeleitet, wenn mit diesem eine Aktion verknüpft ist. * * @see InputManager#buttonDown(Controller, int) * * @param controller der Controller, auf dem der Button losgelassen wurde * @param buttonCode der Code des Buttons * @return true, wenn das Ereignis beachtet wurde */ @Override public boolean buttonUp(Controller controller, int buttonCode) { if (feedForwardProcessor == null) return false; ButtonKey button = new ButtonKey(buttonCode, controller); if (!controllerGameButtonBindingInverse.containsKey(button)) return false; Action action = controllerGameButtonBindingInverse.get(button); return controllerUp(action); }
/** * Wird aufgerufen, wenn sich eine Axe am Controller (Stick, Trigger) ändert. * Das analoge Ereignis wird durch einen Threshold in ein digitales Ereignis umgewandelt, * und dann genau wie bei den Button-Funktionen verarbeitet. * * @see InputManager#buttonDown(Controller, int) * @see InputManager#buttonUp(Controller, int) * @see InputManager#axisReleased(Controller, int) * * @param controller der Controller, dessen Axe bewegt wurde * @param axisCode der Code der Axe * @param value die neue Position dieser Axe * @return true, wenn das Ereignis beachtet wurde */ @Override public boolean axisMoved(Controller controller, int axisCode, float value) { if (feedForwardProcessor == null) return false; boolean high; if (value > 0.7f) high = true; else if (value < -0.7f) high = false; else return axisReleased(controller, axisCode); AxisKey axis = new AxisKey(axisCode, high, controller); if (!controllerGameAxisBindingInverse.containsKey(axis)) return false; if (!controllerGameAxisStateInverse.containsKey(axis)) { controllerGameAxisStateInverse.put(axis, true); } else { if (controllerGameAxisStateInverse.get(axis)) return false; else controllerGameAxisStateInverse.put(axis, true); } controllerDown(controllerGameAxisBindingInverse.get(axis)); return false; }
public MappedController(Controller controller, ControllerMappings mappings) { this.controller = controller; this.mappings = mappings; this.analogToDigitalTreshold = mappings.analogToDigitalTreshold; refreshMappingCache(); }
public static int findPressedButton(Controller controller) { // Cycle through button indexes to check if a button is pressed // Some gamepads report buttons from 90 to 107, so we check up to index 500 // this should be moved into controller implementation which knows it better for (int i = 0; i <= 500; i++) if (controller.getButton(i)) return i; return -1; }
/** * resets mapping for the given controller. Warning: already instantiated {@link MappedController} will still hold * a reference to the old mapping, so be sure to refresh such references with its * {@link MappedController#refreshMappingCache()}. * {@link MappedControllerAdapter} is not concerned. * * @param controller */ public void resetMappings(Controller controller) { if (mappedInputs == null) return; mappedInputs.remove(controller.getName()); waitingForReverseButtonFirstIdx = -1; waitingForReverseButtonAxisId = -1; }
@Override public boolean povMoved(Controller controller, int povCode, PovDirection value) { if(controller == pads[0]) { }else if(controller == pads[1]) { } return true; }
@Override public boolean configuredButtonDown(Controller controller, int buttonId) { if (targetInput == null || !buttonMappings.containsKey(buttonId)) return false; return targetInput.keyDown(buttonMappings.get(buttonId)); }
@Override public boolean configuredButtonUp(Controller controller, int buttonId) { if (targetInput == null || !buttonMappings.containsKey(buttonId)) return false; return targetInput.keyUp(buttonMappings.get(buttonId)); }
protected boolean buttonChange(Controller controller, int buttonIndex, boolean isDown) { boolean isReverse = false; ControllerMappings.MappedInputs mapping = mappings.getControllerMapping(controller); if (mapping == null) return false; ConfiguredInput configuredInput = mapping.getConfiguredFromButton(buttonIndex); if (configuredInput == null) { configuredInput = mapping.getConfiguredFromReverseButton(buttonIndex); isReverse = true; } if (configuredInput == null) return false; switch (configuredInput.inputType) { case button: if (isDown) return configuredButtonDown(controller, configuredInput.inputId); else return configuredButtonUp(controller, configuredInput.inputId); case axis: case axisDigital: return configuredAxisMoved(controller, configuredInput.inputId, !isDown ? 0 : isReverse ? -1f : 1f); default: // axis analog may not happen Gdx.app.log(ControllerMappings.LOG_TAG, "Button mapped to analog axis not allowed!"); return false; } }
@Override public boolean axisMoved(Controller controller, int axisIndex, float value) { //TODO axis fires very often, so cache last controller and last two axis ControllerMappings.MappedInputs mapping = mappings.getControllerMapping(controller); if (mapping == null) return false; ConfiguredInput configuredInput = mapping.getConfiguredFromAxis(axisIndex); if (configuredInput == null) return false; switch (configuredInput.inputType) { case axis: case axisAnalog: return configuredAxisMoved(controller, configuredInput.inputId, value); case axisDigital: return configuredAxisMoved(controller, configuredInput.inputId, Math.abs(value) < analogToDigitalTreshold ? 0 : 1 * Math.signum(value)); default: // button may not happen Gdx.app.log(ControllerMappings.LOG_TAG, "Axis mapped to button not allowed!"); return false; } }
public GamePadManager() { Controllers.addListener(this); count = Controllers.getControllers().size; pads = new Controller[2]; for(int i = 0; i < count; i++) { if(i > 1) break; pads[i] = Controllers.getControllers().get(i); } }
@Override public boolean buttonDown(Controller controller, int buttonCode) { return false; }
@Override public boolean buttonUp(Controller controller, int buttonCode) { return false; }