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; }