/**
   * Get all LWJGL DisplayModes into the DropDown
   *
   * @param screen
   */
  private void fillResolutionDropDown(final Screen screen) {
    try {
      DisplayMode currentMode = Display.getDisplayMode();
      List<DisplayMode> sorted = new ArrayList<DisplayMode>();

      DisplayMode[] modes = Display.getAvailableDisplayModes();
      for (int i = 0; i < modes.length; i++) {
        DisplayMode mode = modes[i];
        if (mode.getBitsPerPixel() == 32 && mode.getFrequency() == currentMode.getFrequency()) {
          // since Nifty does not yet support automatically rescaling of the GUI and since this
          // example/demo was designed for 1024x768 pixel we can't allow resolutions below this
          // size.
          if (mode.getWidth() >= 1024 && mode.getHeight() >= 768) {
            sorted.add(mode);
          }
        }
      }

      Collections.sort(
          sorted,
          new Comparator<DisplayMode>() {
            @Override
            public int compare(DisplayMode o1, DisplayMode o2) {
              int widthCompare =
                  Integer.valueOf(o1.getWidth()).compareTo(Integer.valueOf(o2.getWidth()));
              if (widthCompare != 0) {
                return widthCompare;
              }
              int heightCompare =
                  Integer.valueOf(o1.getHeight()).compareTo(Integer.valueOf(o2.getHeight()));
              if (heightCompare != 0) {
                return heightCompare;
              }
              return o1.toString().compareTo(o2.toString());
            }
          });

      DropDown dropDown = screen.findNiftyControl("resolutions", DropDown.class);
      for (DisplayMode mode : sorted) {
        dropDown.addItem(mode);
      }
    } catch (Exception e) {
    }
  }
Ejemplo n.º 2
0
  public void playerLoader(MenuApp menuApp, Screen screen, String map) {

    AssetManager as = menuApp.getAssetManager();

    PlayerDataManager pdm = PlayerDataManager.load(as);
    PlayerDataMapManager pdmm = PlayerDataMapManager.load(as, map);

    ArrayList<PlayerData> list = pdm.getPlayer();

    int id = 0;

    int countTeams = 0;
    for (int i = 0; i < list.size(); i++) {
      PlayerData playerData = list.get(i);

      PlayerDataMap playerDataMap = pdmm.getPlayer().get(playerData.getId());

      if (playerDataMap != null) {
        if (playerDataMap.getController() != PlayerDataMap.none) {
          countTeams++;
        }
      }
    }

    for (int i = 0; i < list.size(); i++) {
      PlayerData playerData = list.get(i);
      PlayerDataMap playerDataMap = pdmm.getPlayer().get(playerData.getId());

      if (playerDataMap != null) {
        if (playerDataMap.getController() != PlayerDataMap.none) {
          id++;

          CustomControlCreator createMultiplayerPanel =
              new CustomControlCreator("myPlayerPanel", "playerPanel");
          de.lessvoid.nifty.elements.Element e =
              createMultiplayerPanel.create(nifty, screen, screen.findElementByName("slot" + i));

          TextField tf = e.findNiftyControl("id", TextField.class);
          tf.setText(id + "");
          tf.setEnabled(false);

          tf = e.findNiftyControl("playername", TextField.class);
          tf.setText(playerData.getName());
          tf.setEnabled(false);

          DropDown dd = e.findNiftyControl("team", DropDown.class);
          for (int b = 0; b < countTeams; b++) {
            dd.addItem("Team " + (b + 1));
          }
          // dd.setEnabled(false);

          PanelRenderer colorPanel = e.findElementByName("color").getRenderer(PanelRenderer.class);
          Color color =
              new Color(
                  playerData.getColor().r,
                  playerData.getColor().g,
                  playerData.getColor().b,
                  playerData.getColor().a);
          colorPanel.setBackgroundColor(color);
        }
      }
    }
  }