示例#1
0
  private void handleInput() {
    while (Keyboard.next()) {
      if (Keyboard.isRepeatEvent()) {
        continue;
      }

      if (!Keyboard.getEventKeyState()) {
        continue;
      }

      if (Keyboard.getEventKey() == Keyboard.KEY_A) {
        broadcastController.requestAuthToken(username, password);
      } else if (Keyboard.getEventKey() == Keyboard.KEY_S) {
        broadcastController.setStreamInfo(username, "Java Game", "Fun times");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_P) {
        if (broadcastController.getIsPaused()) {
          broadcastController.resumeBroadcasting();
        } else {
          broadcastController.pauseBroadcasting();
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
        if (broadcastController.getIsBroadcasting()) {
          broadcastController.stopBroadcasting();
        } else {
          VideoParams videoParams =
              broadcastController.getRecommendedVideoParams(
                  Display.getDisplayMode().getWidth(),
                  Display.getDisplayMode().getHeight(),
                  broadcastFramesPerSecond);
          videoParams.verticalFlip = true;

          broadcastController.startBroadcasting(videoParams);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_R) {
        broadcastController.runCommercial();
      } else if (Keyboard.getEventKey() == Keyboard.KEY_I) {
        if (ingestTester != null) {
          broadcastController.cancelIngestTest();
          ingestTester = null;
        } else {
          ingestTester = broadcastController.startIngestTest();
          ingestTester.setListener(this);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_G) {
        broadcastController.requestGameNameList("final");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_1) {
        broadcastController.sendActionMetaData(
            "TestAction",
            broadcastController.getCurrentBroadcastTime(),
            "Something cool happened",
            "{ \"MyValue\" : \"42\" }");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_2) {
        if (metaDataSpanSequenceId == -1) {
          metaDataSpanSequenceId =
              broadcastController.startSpanMetaData(
                  "TestSpan",
                  broadcastController.getCurrentBroadcastTime(),
                  "Something cool just started happening",
                  "{ \"MyValue\" : \"42\" }");
        } else {
          broadcastController.endSpanMetaData(
              "TestSpan",
              broadcastController.getCurrentBroadcastTime(),
              metaDataSpanSequenceId,
              "Something cool just stopped happening",
              "{ \"MyValue\" : \"42\" }");
          metaDataSpanSequenceId = -1;
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_C) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connect(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_V) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connectAnonymous(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_M) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.sendChatMessage("Test chat message: " + System.currentTimeMillis());
          }
        }
      }
    }
  }
  /**
   * Process keyboard input - first look for "system" like events, then otherwise pass to the Player
   * object
   */
  public void processKeyboardInput() {
    boolean debugEnabled = Config.getInstance().isDebug();

    boolean screenHasFocus = screenHasFocus();

    while (Keyboard.next()) {
      int key = Keyboard.getEventKey();

      if (!Keyboard.isRepeatEvent() && Keyboard.getEventKeyState()) {
        if (key == Keyboard.KEY_ESCAPE) {
          if (_openDisplay != null) {
            closeScreen();
          } else {
            togglePauseMenu();
          }
        }

        // Should this be here?
        if (key == Keyboard.KEY_I) {
          toggleInventory();
        }

        if (key == Keyboard.KEY_F3) {
          Config.getInstance().setDebug(!Config.getInstance().isDebug());
        }

        if (key == Keyboard.KEY_F && !screenHasFocus) {
          toggleViewingDistance();
        }

        if (key == Keyboard.KEY_F12) {
          Terasology.getInstance().getActiveWorldRenderer().printScreen();
        }

        // Pass input to focused GUI element
        if (_openDisplay != null && !_openDisplay.isOverlay()) {
          _openDisplay.processKeyboardInput(key);
        } else {
          for (UIDisplayElement screen : _guiScreens) {
            if (screenCanFocus(screen)) {
              screen.processKeyboardInput(key);
            }
          }
        }
      }

      // Features for debug mode only
      if (debugEnabled && !screenHasFocus && Keyboard.getEventKeyState()) {
        if (key == Keyboard.KEY_UP) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() + 0.005);
        }

        if (key == Keyboard.KEY_DOWN) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() - 0.005);
        }

        if (key == Keyboard.KEY_RIGHT) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() + 0.02);
        }

        if (key == Keyboard.KEY_LEFT) {
          getActiveWorldProvider().setTime(getActiveWorldProvider().getTime() - 0.02);
        }

        if (key == Keyboard.KEY_R && !Keyboard.isRepeatEvent()) {
          getWorldRenderer().setWireframe(!getWorldRenderer().isWireframe());
        }

        if (key == Keyboard.KEY_P && !Keyboard.isRepeatEvent()) {
          getWorldRenderer().setCameraMode(WorldRenderer.CAMERA_MODE.PLAYER);
        }

        if (key == Keyboard.KEY_O && !Keyboard.isRepeatEvent()) {
          getWorldRenderer().setCameraMode(WorldRenderer.CAMERA_MODE.SPAWN);
        }
      }

      // Pass input to the current player
      if (!screenHasFocus)
        _localPlayerSys.processKeyboardInput(
            key, Keyboard.getEventKeyState(), Keyboard.isRepeatEvent());
    }
  }