예제 #1
0
  private void keyConfigSequence() {

    while (loop) {

      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

      try {
        menuTheme
            .getFont()
            .glDrawText(
                "\\c#FFFFFFKey Bindings",
                (Main.SCREEN_WIDTH - menuTheme.getFont().getStringWidth("Key Bindings")) / 2 + 2,
                50);

      } catch (InvalidEscapeSequenceException e) {
        e.printStackTrace();
      }

      Input.poll();
      mouseEvents = Input.getMouseEvents();
      keyEvents = Input.getKeyEvents();

      try {
        drawKeyConfigText(margin, 75, 30);
      } catch (InvalidEscapeSequenceException e) {

      }

      for (GLUIComponent t : keyConfigTextField) {

        t.processKeyEvents(keyEvents);
        t.processMouseEvents(mouseEvents);
        t.update(0);
        t.renderGL();
      }

      Display.update();

      if (Display.isCloseRequested()) {
        Game.GAME_STATE = Game.GAME_STATE_QUIT;
        menu = false;
        loop = false;
      } else if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        loop = false;
      }
    }

    for (GLUIComponent t : keyConfigTextField) {

      if (t instanceof GLTextField) {
        ((GLTextField) t).setText(((GLTextField) t).getText().toUpperCase());
        KeyBindings.valueOf(t.getContext().toString())
            .setUserKey(Keyboard.getKeyIndex(((GLTextField) t).getText()));
      }
    }
  }
예제 #2
0
  private void keyConfigSequenceButtons() {

    /** TODO: Set this up properly along with corresponding text */
    GLTextField up, down, left, right;
    GLTextField inventory, questlog, talk, interact, menu;

    keyConfigTextField = new ArrayList<GLUIComponent>();

    int x = margin + 100;
    int y = 75;
    int w = 75;
    int h = 20;
    int offset = 30;

    up = new GLTextField(menuTheme, x, y + 0 * offset, w, h, 2, 2, 2, 2, 1);
    up.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_UP.getUserKey()));
    up.toggleCursor();
    up.setContext(KeyBindings.KEY_UP);

    down = new GLTextField(menuTheme, x, y + 1 * offset, w, h, 2, 2, 2, 2, 1);
    down.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_DOWN.getUserKey()));
    down.toggleCursor();
    down.setContext(KeyBindings.KEY_DOWN);

    left = new GLTextField(menuTheme, x, y + 2 * offset, w, h, 2, 2, 2, 2, 1);
    left.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_LEFT.getUserKey()));
    left.toggleCursor();
    left.setContext(KeyBindings.KEY_LEFT);

    right = new GLTextField(menuTheme, x, y + 3 * offset, w, h, 2, 2, 2, 2, 1);
    right.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_RIGHT.getUserKey()));
    right.toggleCursor();
    right.setContext(KeyBindings.KEY_RIGHT);

    inventory = new GLTextField(menuTheme, x, y + 4 * offset, w, h, 2, 2, 2, 2, 1);
    inventory.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_INVENTORY.getUserKey()));
    inventory.toggleCursor();
    inventory.setContext(KeyBindings.KEY_INVENTORY);

    questlog = new GLTextField(menuTheme, x, y + 5 * offset, w, h, 2, 2, 2, 2, 1);
    questlog.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_QUESTLOG.getUserKey()));
    questlog.toggleCursor();
    questlog.setContext(KeyBindings.KEY_QUESTLOG);

    talk = new GLTextField(menuTheme, x, y + 6 * offset, w, h, 2, 2, 2, 2, 1);
    talk.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_TALK.getUserKey()));
    talk.toggleCursor();
    talk.setContext(KeyBindings.KEY_TALK);

    interact = new GLTextField(menuTheme, x, y + 7 * offset, w, h, 2, 2, 2, 2, 1);
    interact.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_INTERACT.getUserKey()));
    interact.toggleCursor();
    interact.setContext(KeyBindings.KEY_INTERACT);

    menu = new GLTextField(menuTheme, x, y + 8 * offset, w, h, 2, 2, 2, 2, 1);
    menu.setText(Keyboard.getKeyName(Main.KeyBindings.KEY_MENU.getUserKey()));
    menu.toggleCursor();
    menu.setContext(KeyBindings.KEY_MENU);

    GLButton defaultButton =
        new GLButton(
            "Default",
            menuTheme,
            Main.SCREEN_WIDTH - margin - (menuTheme.getFont().getStringWidth("Default") + 16),
            350,
            menuTheme.getFont().getStringWidth("Default") + 16,
            menuTheme.getFont().getStringHeight("Default") + 6) {

          @Override
          protected void onClick() {

            // TODO: reset keys to default

            /*for (KeyBindings i : Main.KeyBindings.values()) {
            	i.setUserKey(i.getDefaultKey());
            }*/
          }
        };

    keyConfigTextField.add(up);
    keyConfigTextField.add(down);
    keyConfigTextField.add(left);
    keyConfigTextField.add(right);
    keyConfigTextField.add(inventory);
    keyConfigTextField.add(questlog);
    keyConfigTextField.add(talk);
    keyConfigTextField.add(interact);
    keyConfigTextField.add(menu);
    keyConfigTextField.add(returnButton);
    keyConfigTextField.add(defaultButton);
  }