Example #1
0
  private final GUIObject createPlayerPulldown(
      GUIRoot gui_root,
      Group group,
      GUIObject previous,
      PulldownButton[] slot_buttons,
      PulldownButton[] race_buttons,
      PulldownButton[] team_buttons,
      Diode[] ready_marks,
      Label[] ratings,
      int index,
      int num_players) {
    PulldownMenu pulldown_menu = new PulldownMenu();
    PulldownItem open_item = new PulldownItem(Utils.getBundleString(bundle, "open"));
    PulldownItem closed_item = new PulldownItem(Utils.getBundleString(bundle, "closed"));
    PulldownItem computer_easy_item = new PulldownItem(Utils.getBundleString(bundle, "easy_ai"));
    PulldownItem computer_normal_item =
        new PulldownItem(Utils.getBundleString(bundle, "normal_ai"));
    PulldownItem computer_hard_item = new PulldownItem(Utils.getBundleString(bundle, "hard_ai"));
    pulldown_menu.addItem(open_item);
    pulldown_menu.addItem(closed_item);
    if (!rated) {
      pulldown_menu.addItem(computer_easy_item);
      pulldown_menu.addItem(computer_normal_item);
      pulldown_menu.addItem(computer_hard_item);
    }
    PulldownButton pulldown_button = new PulldownButton(gui_root, pulldown_menu, CLOSED_INDEX, 150);
    slot_buttons[index] = pulldown_button;
    group.addChild(pulldown_button);
    if (previous != null) pulldown_button.place(previous, BOTTOM_MID);
    else pulldown_button.place();
    pulldown_menu.addItemChosenListener(new PlayerSlotListener(index));
    pulldown_button.setDisabled(local_player_slot != 0 || index == local_player_slot);

    PulldownMenu race_pulldown_menu = new PulldownMenu();
    for (int i = 0; i < RacesResources.getNumRaces(); i++) {
      PulldownItem race_item = new PulldownItem(RacesResources.getRaceName(i));
      race_pulldown_menu.addItem(race_item);
    }
    PulldownMenu team_pulldown_menu = new PulldownMenu();
    int num_teams = num_players;
    if (rated) num_teams = 2;
    for (int i = 0; i < num_teams; i++) {
      String team_str =
          Utils.getBundleString(bundle, "team", new Object[] {Integer.toString(i + 1)});
      PulldownItem race_item = new PulldownItem(team_str);
      team_pulldown_menu.addItem(race_item);
    }
    PulldownButton race_pulldown_button = new PulldownButton(gui_root, race_pulldown_menu, 0, 115);
    PulldownButton team_pulldown_button =
        new PulldownButton(gui_root, team_pulldown_menu, index % num_teams, 115);
    race_buttons[index] = race_pulldown_button;
    team_buttons[index] = team_pulldown_button;
    group.addChild(race_pulldown_button);
    group.addChild(team_pulldown_button);
    race_pulldown_button.place(pulldown_button, RIGHT_MID);
    team_pulldown_button.place(race_pulldown_button, RIGHT_MID);
    race_pulldown_menu.addItemChosenListener(new PlayerSlotListener(index));
    team_pulldown_menu.addItemChosenListener(new PlayerSlotListener(index));
    race_pulldown_button.setDisabled(!canControlSlot(index));
    team_pulldown_button.setDisabled(!canControlSlot(index));

    Diode ready_mark = new Diode();
    ready_marks[index] = ready_mark;
    group.addChild(ready_mark);
    ready_mark.place(team_pulldown_button, RIGHT_MID);
    Font font = Skin.getSkin().getEditFont();
    ratings[index] = new Label("", font, RATING_WIDTH, Label.ALIGN_RIGHT);
    if (rated) {
      group.addChild(ratings[index]);
      ratings[index].place(ready_mark, RIGHT_MID);
    }
    String player_str =
        Utils.getBundleString(bundle, "player", new Object[] {Integer.toString(index + 1)});
    Label label = new Label(player_str, Skin.getSkin().getEditFont());
    label.setColor(Player.COLORS[index]);
    group.addChild(label);
    label.place(pulldown_button, LEFT_MID);

    return pulldown_button;
  }
Example #2
0
 public final void setPlayers(PlayerSlot[] players) {
   int num_humans = countHumans(players);
   int[] player_slots = new int[num_humans];
   int[] player_ratings = new int[num_humans];
   int[] player_teams = new int[num_humans];
   int human_index = 0;
   updating = true;
   SortedSet new_human_names = new TreeSet();
   for (int i = 0; i < players.length; i++) {
     PlayerSlot player = players[i];
     PulldownButton slot_button = slot_buttons[i];
     PulldownButton race_button = race_buttons[i];
     PulldownButton team_button = team_buttons[i];
     Diode ready_mark = ready_marks[i];
     ready_mark.setLit(player.isReady());
     race_button.getMenu().chooseItem(player.getInfo() != null ? player.getInfo().getRace() : 0);
     team_button.getMenu().chooseItem(player.getInfo() != null ? player.getInfo().getTeam() : 0);
     if (player.getType() != PlayerSlot.CLOSED) {
       slot_button
           .getMenu()
           .getItem(OPEN_INDEX)
           .setLabelString(Utils.getBundleString(bundle, "open"));
       slot_button.getMenu().chooseItem(OPEN_INDEX);
     } else {
       slot_button.getMenu().chooseItem(CLOSED_INDEX);
     }
     race_button.setDisabled(true);
     team_button.setDisabled(true);
     if (player.getInfo() != null) {
       PlayerInfo player_info = player.getInfo();
       switch (player.getType()) {
         case PlayerSlot.AI:
           assert !rated;
           slot_button.getMenu().chooseItem(player.getAIDifficulty() + 1);
           race_button.setDisabled(!canControlSlot(i));
           team_button.setDisabled(!canControlSlot(i));
           break;
         case PlayerSlot.HUMAN:
           String player_name = player_info.getName();
           new_human_names.add(player_name);
           slot_button.getMenu().getItem(OPEN_INDEX).setLabelString(player_name);
           slot_button.getMenu().chooseItem(OPEN_INDEX);
           race_button.setDisabled(i != local_player_slot);
           team_button.setDisabled(i != local_player_slot);
           player_slots[human_index] = i;
           player_ratings[human_index] = player.getRating();
           player_teams[human_index] = player_info.getTeam();
           human_index++;
           break;
         default:
           throw new RuntimeException("Unknown Player type: " + player.getType());
       }
     }
   }
   if (rated)
     updateRatedLabels(
         player_slots,
         player_ratings,
         GameSession.calculateMatchPoints(player_ratings, player_teams));
   Iterator it = new_human_names.iterator();
   while (it.hasNext()) {
     String name = (String) it.next();
     if (human_names.contains(name)) human_names.remove(name);
     else playerJoined(name);
   }
   it = human_names.iterator();
   while (it.hasNext()) {
     String name = (String) it.next();
     playerLeft(name);
   }
   human_names = new_human_names;
   setReady(players[local_player_slot].isReady());
   setStartEnable(players);
   updating = false;
 }