Example #1
0
  private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
    if (value < axisDeadZone) {
      invokeAnalogs(hash, value, !applyTpf);
      return;
    }

    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
      return;
    }

    boolean valueChanged = !axisValues.containsKey(hash);
    if (applyTpf) {
      value *= frameTPF;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
      Mapping mapping = maps.get(i);
      ArrayList<InputListener> listeners = mapping.listeners;
      int listenerSize = listeners.size();
      for (int j = listenerSize - 1; j >= 0; j--) {
        InputListener listener = listeners.get(j);

        if (listener instanceof ActionListener && valueChanged) {
          ((ActionListener) listener).onAction(mapping.name, true, frameTPF);
        }

        if (listener instanceof AnalogListener) {
          ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF);
        }
      }
    }
  }
  @Override
  public void onJoyAxisEvent(JoyAxisEvent arg0) {
    JoystickAxis axis = arg0.getAxis();
    float value = arg0.getValue();

    // TODO fix
    if (axis == axis.getJoystick().getXAxis()) { // left/right normal stick
      if (value > 0) {
        a.onAction("Left", false, 0);
        a.onAction(
            "Right", true, Math.abs(value) < stickdeadzone ? 0 : value); // less than deadzone = 0
      } else {
        a.onAction("Left", false, 0);
        a.onAction("Right", true, Math.abs(value) < stickdeadzone ? 0 : value);
      }
    } else if (axis == axis.getJoystick().getYAxis()) { // up/down normal stick
      // not mapped yet

    } else if (axis == axis.getJoystick().getAxis(JoystickAxis.Z_AXIS)) { // triggers?
      if (value > 0) { // brake
        a.onAction("Accel", false, 0);
        a.onAction(
            "Brake", true, Math.abs(value) < stickdeadzone ? 0 : value); // less than deadzone = 0
      } else {
        a.onAction("Brake", false, 0);
        a.onAction("Accel", true, Math.abs(value) < stickdeadzone ? 0 : -value);
      }

    } else if (axis == axis.getJoystick().getAxis(JoystickAxis.Z_ROTATION)) {
      // not mapped yet

    } else if (axis.getName().equals("Y Rotation")) { // The other stick
      // not mapped yet

    } else if (axis.getName().equals("X Rotation")) { // The other stick
      // not mapped yet

    } else if (axis == axis.getJoystick().getPovXAxis()) { // DPAD
      // TODO - fix the pov_x and pov_y buttons

    } else if (axis == axis.getJoystick().getPovYAxis()) {

    }

    arg0.isConsumed();
  }
Example #3
0
  private void invokeActions(int hash, boolean pressed) {
    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
      return;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
      Mapping mapping = maps.get(i);
      ArrayList<InputListener> listeners = mapping.listeners;
      int listenerSize = listeners.size();
      for (int j = listenerSize - 1; j >= 0; j--) {
        InputListener listener = listeners.get(j);
        if (listener instanceof ActionListener) {
          ((ActionListener) listener).onAction(mapping.name, pressed, frameTPF);
        }
      }
    }
  }
  @Override
  public void onJoyButtonEvent(JoyButtonEvent arg0) {
    a.onAction(Integer.toString(arg0.getButtonIndex()), arg0.isPressed(), arg0.isPressed() ? 1 : 0);

    arg0.isConsumed();
  }