Esempio n. 1
0
  @Override
  public void add(Node parent) {
    super.add(parent);
    String mappingName = TextField.this.id + "MOUSE";
    if (!inputManager.hasMapping(mappingName)) {
      inputManager.addMapping(mappingName, new MouseButtonTrigger(0));
    }

    inputManager.addListener(actionListener, TextField.this.id + "MOUSE");
  }
Esempio n. 2
0
  @Override
  public void setVisible(boolean visible) {
    super.setVisible(visible);

    if (visible) {
      inputManager.addListener(actionListener, TextField.this.id + "MOUSE");
      bitmapText.setCullHint(Spatial.CullHint.Never);
    } else {
      inputManager.removeListener(actionListener);
      bitmapText.setCullHint(Spatial.CullHint.Always);
    }
  }
Esempio n. 3
0
 public PlayerInput(Game game) {
   this.game = game;
   this.gameApp = game.getGameApplication();
   inputManager = gameApp.getInputManager();
   inputManager.addRawInputListener(this);
   mouseStatus = new MouseStatus(null, 0, 0);
 }
 public void registerWithInput(InputManager inputManager) {
   String[] inputs = {
     "PathingRenderToggle",
     "TerrainRenderToggle",
     "SunnyRenderToggle",
     "ReduceDetailLevel",
     "IncreeseDetailLevel"
   };
   inputManager.addListener(this, inputs);
 }
Esempio n. 5
0
  public static void setupInputManager(
      final InputManager inputManager, final ActionListener actionListener) {
    if (inputManager != null) {
      //            inputManager.addMapping("SIMPLEAPP_CameraPos", new KeyTrigger(KeyInput.KEY_C));
      //            inputManager.addMapping("SIMPLEAPP_Memory", new KeyTrigger(KeyInput.KEY_M));
      //            inputManager.addListener(actionListener, "SIMPLEAPP_Exit",
      //                    "SIMPLEAPP_CameraPos", "SIMPLEAPP_Memory");

      inputManager.deleteMapping("SIMPLEAPP_Exit");
      inputManager.addMapping(INPUT_MAPPING_SHOW_MAIN_MENU, new KeyTrigger(KeyInput.KEY_ESCAPE));
      inputManager.addListener(actionListener, INPUT_MAPPING_SHOW_MAIN_MENU);

      //            //testing
      //            inputManager.addMapping("BUTTON_LEFT", new
      // MouseButtonTrigger(MouseInput.BUTTON_LEFT));
      //            inputManager.addMapping("BUTTON_MIDDLE", new
      // MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
      //            inputManager.addMapping("BUTTON_RIGHT", new
      // MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
      //            inputManager.addMapping("AXIS_WHEEL", new
      // MouseButtonTrigger(MouseInput.AXIS_WHEEL));
      //            inputManager.addMapping("AXIS_X", new MouseButtonTrigger(MouseInput.AXIS_X));
      //            inputManager.addMapping("AXIS_Y", new MouseButtonTrigger(MouseInput.AXIS_Y));
      //            inputManager.addMapping("AXIS_WHEEL, false", new
      // MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
      //            inputManager.addMapping("AXIS_WHEEL, true", new
      // MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
      //            inputManager.addMapping("AXIS_X, false", new MouseAxisTrigger(MouseInput.AXIS_X,
      // false));
      //            inputManager.addMapping("AXIS_X, true", new MouseAxisTrigger(MouseInput.AXIS_X,
      // true));
      //            inputManager.addMapping("AXIS_Y, false", new MouseAxisTrigger(MouseInput.AXIS_Y,
      // false));
      //            inputManager.addMapping("AXIS_Y, true", new MouseAxisTrigger(MouseInput.AXIS_Y,
      // true));
      //
      //            inputManager.addListener(actionListener,
      //                    "BUTTON_LEFT", "BUTTON_MIDDLE", "BUTTON_RIGHT",
      //                    "AXIS_WHEEL", "AXIS_X", "AXIS_Y",
      //                    "AXIS_WHEEL, false", "AXIS_WHEEL, true", "AXIS_X, false", "AXIS_X,
      // true", "AXIS_Y, false", "AXIS_Y, true");
    }
  }
Esempio n. 6
0
  private void initInput() throws IllegalAccessException {
    inputManager.clearMappings();

    if (inputHandler != null) {
      inputHandler.cleanup();
    }

    inputHandler = new InputHandler(inputManager, clientState, cam);
    respawnLocalPlayerHandler.setInputHandler(inputHandler);

    new BaseInputHandler(inputManager);
  }
  private void setupKeys() {
    InputManager inputManager = app.getInputManager();

    inputManager.addMapping(
        "Rotate Left", new KeyTrigger(KeyInput.KEY_A), new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping(
        "Rotate Right", new KeyTrigger(KeyInput.KEY_D), new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping(
        "Walk Forward", new KeyTrigger(KeyInput.KEY_W), new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping(
        "Walk Backward", new KeyTrigger(KeyInput.KEY_S), new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));

    //        inputManager.addListener(this, "Strafe Left", "Strafe Right");
    inputManager.addListener(this, "Rotate Left", "Rotate Right");
    inputManager.addListener(this, "Walk Forward", "Walk Backward");
    inputManager.addListener(this, "Jump");

    inputManager = null;
  }
Esempio n. 8
0
  public static void HighlightModel(Camera cam, InputManager inputManager) {
    CollisionResults results = new CollisionResults();
    Vector2f mouseCoords = new Vector2f(inputManager.getCursorPosition());

    Ray mouseRay =
        new Ray(
            cam.getWorldCoordinates(mouseCoords, 0),
            cam.getWorldCoordinates(mouseCoords, 1)
                .subtractLocal(cam.getWorldCoordinates(mouseCoords, 0))
                .normalizeLocal());
    Main.s_TreeNode.collideWith(mouseRay, results);

    if (results.size() > 0) {
      Spatial target = results.getClosestCollision().getGeometry();
      AmbientLight light = new AmbientLight();
      light.setColor(ColorRGBA.Blue);
      Main.s_TreeNode.addLight(light);
      target.addLight(light);
    }
  }
Esempio n. 9
0
  public SurfaceMover(Spatial movedNode, Spatial child, Spatial scene, InputManager inputManager) {
    if (scene == null) throw new NullPointerException();

    this.scene = scene;
    // TODO: Clean SphereMotionAllowedListener code
    smal = new SphereMotionAllowedListener(scene, 0.2f);

    inputManager.registerKeyBinding("Left", KeyInput.KEY_J);
    inputManager.registerKeyBinding("Right", KeyInput.KEY_L);
    inputManager.registerKeyBinding("Up", KeyInput.KEY_I);
    inputManager.registerKeyBinding("Down", KeyInput.KEY_K);
    inputManager.registerKeyBinding("PgDn", KeyInput.KEY_PGDN);
    inputManager.registerKeyBinding("PgUp", KeyInput.KEY_PGUP);
    inputManager.registerKeyBinding("Space", KeyInput.KEY_SPACE);
    // used with method onBinding in BindingListener interface
    // in order to add function to keys
    inputManager.addBindingListener(this);

    this.movedNode = movedNode;
    this.normalAligned = child;
  }
Esempio n. 10
0
  public static void MoveModel(Camera cam, InputManager inputManager, Spatial scene) {
    if (Statics.s_PlayerSettingModel == true) {
      CollisionResults results = new CollisionResults();
      Ray ray = new Ray();
      Vector2f click2d = inputManager.getCursorPosition();
      Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 0f);
      Vector3f dir =
          cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 1f)
              .subtractLocal(click3d)
              .normalizeLocal();
      ray.setOrigin(click3d);
      ray.setDirection(dir);
      ray = new Ray(click3d, dir);
      scene.collideWith(ray, results);

      if (results.size() > 0) {
        CollisionResult point = results.getClosestCollision();
        Vector3f destination = point.getContactPoint();
        ObjectHelper.s_Model.setMaterial(ObjectHelper.greenTrans);
        SetModel(destination);
      }
    }
  }
Esempio n. 11
0
  /** Suppression des contrôles par défaut, puis nouveau mapping de contrôle plus adapter. */
  public void setupControls() {
    // Removing some shortcut
    inputManager.deleteMapping("FLYCAM_Left");
    inputManager.deleteMapping("FLYCAM_Right");
    inputManager.deleteMapping("FLYCAM_Up");
    inputManager.deleteMapping("FLYCAM_Down");
    inputManager.deleteMapping("FLYCAM_StrafeLeft");
    inputManager.deleteMapping("FLYCAM_StrafeRight");
    inputManager.deleteMapping("FLYCAM_Forward");
    inputManager.deleteMapping("FLYCAM_Backward");
    inputManager.deleteMapping("FLYCAM_Rise");
    inputManager.deleteMapping("FLYCAM_Lower");
    inputManager.deleteMapping("FLYCAM_ZoomIn");
    inputManager.deleteMapping("FLYCAM_ZoomOut");

    // Keyboard
    // -- empty

    // Mouse
    inputManager.addMapping("RotateEnable", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("MoveEnable", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("MoveX-L", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("MoveX-R", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping("MoveY-U", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("MoveY-D", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("ZoomIn", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    inputManager.addMapping("ZoomOut", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));

    moveEnable = false;
    rotateEnable = false;
    inputManager.setCursorVisible(true);

    inputManager.addListener(actionListener, new String[] {"MoveEnable", "RotateEnable", "TEST"});
    inputManager.addListener(
        analogListener,
        new String[] {"MoveX-L", "MoveX-R", "MoveY-U", "MoveY-D", "ZoomIn", "ZoomOut"});
  }
Esempio n. 12
0
 public UserCommandControl(InputManager inputManager) {
   this.inputManager = inputManager;
   inputManager.addMapping(
       "Client_Key_SHIFT",
       new KeyTrigger(KeyInput.KEY_RSHIFT),
       new KeyTrigger(KeyInput.KEY_LSHIFT));
   inputManager.addMapping("Client_Key_0", new KeyTrigger(KeyInput.KEY_0));
   inputManager.addMapping("Client_Key_1", new KeyTrigger(KeyInput.KEY_1));
   inputManager.addMapping("Client_Key_2", new KeyTrigger(KeyInput.KEY_2));
   inputManager.addMapping("Client_Key_3", new KeyTrigger(KeyInput.KEY_3));
   inputManager.addMapping("Client_Key_4", new KeyTrigger(KeyInput.KEY_4));
   inputManager.addMapping("Client_Key_5", new KeyTrigger(KeyInput.KEY_5));
   inputManager.addMapping("Client_Key_6", new KeyTrigger(KeyInput.KEY_6));
   inputManager.addMapping("Client_Key_7", new KeyTrigger(KeyInput.KEY_7));
   inputManager.addMapping("Client_Key_8", new KeyTrigger(KeyInput.KEY_8));
   inputManager.addMapping("Client_Key_9", new KeyTrigger(KeyInput.KEY_9));
   inputManager.addMapping("Client_Key_F10", new KeyTrigger(KeyInput.KEY_F10));
   inputManager.addMapping("Client_Key_F1", new KeyTrigger(KeyInput.KEY_F1));
   inputManager.addMapping("Client_Key_F2", new KeyTrigger(KeyInput.KEY_F2));
   inputManager.addMapping("Client_Key_F3", new KeyTrigger(KeyInput.KEY_F3));
   inputManager.addMapping("Client_Key_F4", new KeyTrigger(KeyInput.KEY_F4));
   inputManager.addMapping("Client_Key_F5", new KeyTrigger(KeyInput.KEY_F5));
   inputManager.addMapping("Client_Key_F6", new KeyTrigger(KeyInput.KEY_F6));
   inputManager.addMapping("Client_Key_F7", new KeyTrigger(KeyInput.KEY_F7));
   inputManager.addMapping("Client_Key_F8", new KeyTrigger(KeyInput.KEY_F8));
   inputManager.addMapping("Client_Key_F9", new KeyTrigger(KeyInput.KEY_F9));
   inputManager.addListener(
       this,
       "Client_Key_SHIFT",
       "Client_Key_0",
       "Client_Key_1",
       "Client_Key_2",
       "Client_Key_3",
       "Client_Key_4",
       "Client_Key_5",
       "Client_Key_6",
       "Client_Key_7",
       "Client_Key_8",
       "Client_Key_9",
       "Client_Key_F10",
       "Client_Key_F1",
       "Client_Key_F2",
       "Client_Key_F3",
       "Client_Key_F4",
       "Client_Key_F5",
       "Client_Key_F6",
       "Client_Key_F7",
       "Client_Key_F8",
       "Client_Key_F9");
 }
Esempio n. 13
0
  /**
   * @param panel
   * @param id
   * @param pictureFile
   * @param width
   * @param height
   */
  public TextField(
      Panel panel, String id, String pictureFile, float width, float height, boolean lockScale) {
    super(panel.getWindow(), panel, pictureFile, width, height, lockScale);
    this.id = id;
    setName(id);

    // Init the text
    float xP = -getWidth() * 0.5f;
    float yP = getHeight() * 0.5f;
    float recWidth = getWidth();
    float factor = 1f;
    float recHeight = (getHeight() * 0.5f) * factor;
    float padding = 0f;

    bitmapText = window.getBitmapFont().createLabel(id);
    bitmapText.setText(" ");
    bitmapText.setBox(new Rectangle(xP + padding, yP, recWidth + padding, recHeight));
    bitmapText.setSize(fontSize * window.getScaleFactorHeight()); // font size
    bitmapText.setColor(ColorRGBA.DarkGray); // font color
    bitmapText.setAlignment(BitmapFont.Align.Left);
    bitmapText.setVerticalAlignment(BitmapFont.VAlign.Center);
    bitmapText.setLineWrapMode(LineWrapMode.NoWrap);
    widgetNode.attachChild(bitmapText);

    this.inputManager = window.getInputManager();
    this.cam = window.getApplication().getCamera();
    this.results = new CollisionResults();
    this.ray = new Ray(cam.getLocation(), cam.getDirection());

    actionListener =
        new ActionListener() {
          public void onAction(String name, boolean isPressed, float tpf) {
            results.clear();

            if (isVisible() && isEnabled()) {

              if ((TextField.this.id + "MOUSE").equals(name)) {

                // 1. calc direction
                Vector3f origin =
                    new Vector3f(
                        inputManager.getCursorPosition().x, inputManager.getCursorPosition().y, 1f);
                Vector3f direction = new Vector3f(0, 0, -1);

                // 2. Aim the ray from cam loc to cam direction.
                ray.setOrigin(origin);
                ray.setDirection(direction);

                // 3. Collect intersections between Ray and Shootables in results list.
                window.getWindowNode().collideWith(ray, results);

                // 5. Use the results (we mark the hit object)
                if (results.size() > 0) {

                  for (int i = 0; i < results.size(); i++) {
                    CollisionResult cr = results.getCollision(i);
                    //                                System.out.println("\t-> Hit: " +
                    // cr.getGeometry().getParent().getName());

                    if (widgetNode.hasChild(cr.getGeometry())) {
                      //                                    System.out.println("\t\t\tCollision -> "
                      // + TouchButton.this.id);
                      if (isPressed) {
                        wasDown = true;
                        getWindow().removeFocusFromFields();
                        focus = true;
                        fireFocusListener(TextField.this.id);
                      }
                    }
                  }
                }
              }
            }
          }
        };

    inputManager.addRawInputListener(
        new RawInputListener() {

          public void beginInput() {}

          public void endInput() {}

          public void onJoyAxisEvent(JoyAxisEvent evt) {}

          public void onJoyButtonEvent(JoyButtonEvent evt) {}

          public void onMouseMotionEvent(MouseMotionEvent evt) {}

          public void onMouseButtonEvent(MouseButtonEvent evt) {}

          public void onKeyEvent(KeyInputEvent evt) {
            //                System.out.println("Keyinput ***************** Key = " +
            // evt.getKeyCode());

            if (enabled && focus && evt.isReleased()) {
              String keyChar = keyNames.getName(evt.getKeyCode());
              //                    System.out.println("Keyinput ***************** Char = " +
              // keyChar);

              if (evt.getKeyCode() == 14) {
                if (getText().length() > 0) {
                  setText(getText().substring(0, getText().length() - 1));
                }
              } else if (evt.getKeyCode() == 15) {
                focus = false;

              } else if (keyChar != null && evt.getKeyCode() == 57) {
                setText(getText() + " ");

              } else if (keyChar != null && evt.getKeyCode() == 58) {
                caps = !caps;

              } else if (keyChar != null && keyChar.length() == 1) {
                if (!caps) {
                  keyChar = keyChar.toLowerCase();
                }
                setText(getText() + keyChar);
              }

              if (getText().length() > maxLength) {
                setText(getText().substring(0, maxLength));
              }

              fireKeyboardListener(evt);
            }
          }

          public void onTouchEvent(TouchEvent evt) {
            //                System.out.println("Touchinput ***************** Keycode = " +
            // evt.getKeyCode());

            if (enabled && focus && evt.getType().equals(TouchEvent.Type.KEY_DOWN)) {
              String keyChar = touchKeyNames.getName(evt.getKeyCode());
              System.out.println(
                  "\n\n\nTouchinput ***************** KeyCode = " + evt.getKeyCode());

              if (evt.getKeyCode() == 67) { // backspace
                if (getText().length() > 0) {
                  setText(getText().substring(0, getText().length() - 1));
                }

              } else if (keyChar != null && evt.getKeyCode() == 62) { // space
                setText(getText() + " ");

              } else if (keyChar != null && evt.getKeyCode() == 59) { // shift
                caps = !caps;

              } else if (keyChar != null && keyChar.length() == 1) {
                // TODO:
                //                        if (!caps) {
                keyChar = keyChar.toLowerCase();
                //                        }
                setText(getText() + keyChar);
              }

              if (getText().length() > maxLength) {
                setText(getText().substring(0, maxLength));
              }

              //                    if (evt.getKeyCode() == 67) {
              //                        if (getText().length() > 0) {
              //                            setText(getText().substring(0, getText().length()-1));
              //                        }
              //
              //                    } else if (evt.getKeyCode() == 59) {
              //                        if (getText().length() > 0) {
              //                            setText(getText().substring(0, getText().length()-1));
              //                        }
              //
              //                    } else if (keyChar != null && keyChar.length() == 1) {
              //                        setText(getText() + keyChar);
              //                    }
              //
              //                    if (getText().length() > maxLength) {
              //                        setText(getText().substring(0, maxLength));
              //                    }

            }
          }
        });

    // NICKI
    panel.add(this);

    //        bitmapText.setLocalTranslation(bitmapText.getLocalTranslation().x,
    // bitmapText.getLocalTranslation().y, 0.001f);
  }
Esempio n. 14
0
 @Override
 public void remove() {
   super.remove();
   inputManager.removeListener(actionListener);
 }
Esempio n. 15
0
 public boolean cursor() {
   return inputManager.isCursorVisible();
 }
Esempio n. 16
0
 public void cursor(boolean cursor) {
   inputManager.setCursorVisible(cursor);
   cameraManager.flyCamActive(cursor);
 }