Beispiel #1
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;
 }
Beispiel #2
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;
  }
Beispiel #3
0
 private final void adjustPlayerSlot(int player_slot) {
   if (updating || game_network.getClient() == null) return;
   PlayerSlot player = game_network.getClient().getPlayers()[player_slot];
   int index = slot_buttons[player_slot].getMenu().getChosenItemIndex();
   if (index == COMPUTER_HARD_INDEX && !Renderer.isRegistered()) {
     slot_buttons[player_slot].getMenu().chooseItem(COMPUTER_NORMAL_INDEX);
     index = COMPUTER_NORMAL_INDEX;
     ResourceBundle db = ResourceBundle.getBundle(DemoForm.class.getName());
     Form demo_form =
         new DemoForm(
             gui_root,
             Utils.getBundleString(db, "hard_ai_unavailable_header"),
             new GUIImage(512, 256, 0f, 0f, 1f, 1f, "/textures/gui/demo_hardai"),
             Utils.getBundleString(db, "hard_ai_unavailable"));
     gui_root.addModalForm(demo_form);
   }
   int race_index = race_buttons[player_slot].getMenu().getChosenItemIndex();
   int team_index = team_buttons[player_slot].getMenu().getChosenItemIndex();
   int difficulty_index = slot_buttons[player_slot].getMenu().getChosenItemIndex() - 1;
   boolean race_changed = player.getInfo() == null || race_index != player.getInfo().getRace();
   boolean team_changed = player.getInfo() == null || team_index != player.getInfo().getTeam();
   boolean ready_changed = ready != player.isReady();
   boolean difficulty_changed =
       player.getInfo() == null || player.getAIDifficulty() != difficulty_index;
   PulldownButton slot_button = slot_buttons[player_slot];
   switch (index) {
     case OPEN_INDEX:
       if ((player.getType() != PlayerSlot.OPEN && player.getType() != PlayerSlot.HUMAN)
           || race_changed
           || team_changed
           || ready_changed) {
         if (player_slot == local_player_slot) {
           int new_type = PlayerSlot.HUMAN;
           game_network
               .getClient()
               .getServerInterface()
               .setPlayerSlot(
                   player_slot, new_type, race_index, team_index, ready, PlayerSlot.AI_NONE);
         } else {
           game_network.getClient().getServerInterface().resetSlotState(player_slot, true);
         }
       }
       break;
     case CLOSED_INDEX:
       if (player.getType() != PlayerSlot.CLOSED || race_changed || team_changed) {
         slot_button
             .getMenu()
             .getItem(OPEN_INDEX)
             .setLabelString(Utils.getBundleString(bundle, "open"));
         game_network.getClient().getServerInterface().resetSlotState(player_slot, false);
       }
       break;
     case COMPUTER_EASY_INDEX:
     case COMPUTER_NORMAL_INDEX:
     case COMPUTER_HARD_INDEX:
       assert !rated;
       boolean new_ai = player.getType() != PlayerSlot.AI;
       if (new_ai || race_changed || team_changed || difficulty_changed) {
         slot_button
             .getMenu()
             .getItem(OPEN_INDEX)
             .setLabelString(Utils.getBundleString(bundle, "open"));
         if (new_ai) {
           team_index = player_slot;
           race_index =
               new Random(LocalEventQueue.getQueue().getHighPrecisionManager().getTick())
                   .nextInt(RacesResources.getNumRaces());
         }
         game_network
             .getClient()
             .getServerInterface()
             .setPlayerSlot(
                 player_slot, PlayerSlot.AI, race_index, team_index, true, difficulty_index);
       }
       break;
     default:
       throw new RuntimeException("Invalid item index");
   }
 }