Exemple #1
0
  public GameMenu(
      GameNetwork game_network,
      GUIRoot gui_root,
      SelectGameMenu owner,
      Game game,
      WorldGenerator generator,
      int player_slot,
      int compare_width,
      int compare_height,
      int button_width) {
    super(Utils.getBundleString(getBundle(), "game_caption"));
    this.game_network = game_network;
    this.owner = owner;
    this.gui_root = gui_root;
    this.local_player_slot = player_slot;
    this.rated = game.isRated();
    this.game = game;

    String tag = "";
    if (rated) tag = Utils.getBundleString(bundle, "rated") + " ";
    Label game_name_label =
        new Label(
            Utils.getBundleString(bundle, "game") + " " + tag + game.getName(),
            Skin.getSkin().getHeadlineFont());
    slot_buttons = new PulldownButton[MatchmakingServerInterface.MAX_PLAYERS];
    race_buttons = new PulldownButton[MatchmakingServerInterface.MAX_PLAYERS];
    team_buttons = new PulldownButton[MatchmakingServerInterface.MAX_PLAYERS];
    ready_marks = new Diode[MatchmakingServerInterface.MAX_PLAYERS];
    ratings = new Label[MatchmakingServerInterface.MAX_PLAYERS];
    Group player_group = new Group();
    GUIObject previous = null;
    for (int i = 0; i < MatchmakingServerInterface.MAX_PLAYERS; i++)
      previous =
          createPlayerPulldown(
              gui_root,
              player_group,
              previous,
              slot_buttons,
              race_buttons,
              team_buttons,
              ready_marks,
              ratings,
              i,
              MatchmakingServerInterface.MAX_PLAYERS);
    player_group.compileCanvas();
    addChild(player_group);

    Box pdata = Skin.getSkin().getPanelData().getBox();
    FormData fdata = Skin.getSkin().getFormData();

    int width = compare_width - pdata.getLeftOffset() - pdata.getRightOffset();
    chat_info =
        new Label(Utils.getBundleString(bundle, "chat"), Skin.getSkin().getEditFont(), width);
    Group chat_line_group = new Group();
    chat_line = new EditLine(width - SEND_BUTTON_WIDTH - fdata.getObjectSpacing(), 100);
    send_button = new HorizButton(Utils.getBundleString(bundle, "send"), SEND_BUTTON_WIDTH);
    send_button.addMouseClickListener(new SendListener());
    chat_line_group.addChild(chat_line);
    chat_line.place();
    chat_line_group.addChild(send_button);
    send_button.place(chat_line, RIGHT_MID);
    chat_line_group.compileCanvas();
    addChild(chat_line_group);

    chat_line.addEnterListener(new ChatListener());
    addChild(game_name_label);
    addChild(chat_info);

    start_button = new HorizButton(Utils.getBundleString(bundle, "start"), button_width);
    if (local_player_slot == 0) {
      addChild(start_button);
      start_button.addMouseClickListener(new StartListener());
    }
    int height =
        compare_height
            - pdata.getTopOffset()
            - pdata.getBottomOffset()
            - chat_info.getHeight()
            - chat_line.getHeight()
            - game_name_label.getHeight()
            - player_group.getHeight()
            - start_button.getHeight()
            - 5 * fdata.getObjectSpacing();
    chat_box = new TextBox(width, height, Skin.getSkin().getEditFont(), -1);
    addChild(chat_box);
    ready_button = new HorizButton(Utils.getBundleString(bundle, "ready"), button_width);
    addChild(ready_button);
    ready_button.addMouseClickListener(new ReadyListener());
    HorizButton cancel_button =
        new HorizButton(Utils.getBundleString(bundle, "cancel"), button_width);
    addChild(cancel_button);
    cancel_button.addMouseClickListener(new CancelButtonListener());
    HorizButton info_button = new HorizButton(Utils.getBundleString(bundle, "info"), button_width);
    addChild(info_button);
    info_button.addMouseClickListener(new InfoButtonListener());

    game_name_label.place();
    player_group.place(game_name_label, BOTTOM_LEFT);
    chat_info.place(player_group, BOTTOM_LEFT);
    chat_box.place(chat_info, BOTTOM_LEFT);
    chat_line_group.place(chat_box, BOTTOM_LEFT);
    cancel_button.place(chat_line_group, BOTTOM_RIGHT);
    info_button.place(chat_line_group, BOTTOM_LEFT);
    ready_button.place(cancel_button, LEFT_MID);
    if (local_player_slot == 0) start_button.place(ready_button, LEFT_MID);
    Font font = Skin.getSkin().getEditFont();
    if (rated) {
      Label rating =
          new Label(Utils.getBundleString(bundle, "rating"), font, RATING_WIDTH, Label.ALIGN_RIGHT);
      addChild(rating);
      rating.place(player_group, TOP_RIGHT);
    }
    compileCanvas();
  }
Exemple #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;
  }