Example #1
0
TeamBox::TeamBox(const std::string& _player_name, const Point2i& _size, uint g)
  : HBox(_size.y, false, false, false)
  , ai_level(0)
  , group(g)
{
  associated_team = NULL;

  SetMargin(2);
  SetBorder(transparent_color, 4);
  Widget::SetBackgroundColor(transparent_color);

  Profile *res = GetResourceManager().LoadXMLProfile("graphism.xml", false);

  player_local[0] = LOAD_RES_IMAGE("menu/player_local_human");
  player_local[1] = LOAD_RES_IMAGE("menu/player_local_ai");
  player_local[2] = LOAD_RES_IMAGE("menu/player_local_ai_dumb");
  player_local[3] = LOAD_RES_IMAGE("menu/player_local_ai_strong");

  player_remote[0] = LOAD_RES_IMAGE("menu/player_remote_human");
  player_remote[1] = LOAD_RES_IMAGE("menu/player_remote_ai");
  player_remote[2] = LOAD_RES_IMAGE("menu/player_remote_ai_dumb");
  player_remote[3] = LOAD_RES_IMAGE("menu/player_remote_ai_strong");

  int width = _size.x - (CHAR_COUNT_WIDGET_SIZE+2*margin+2*border_size);
  Box * tmp_player_box = new VBox(_size.y-2*border_size, false, false, false);
  tmp_player_box->SetMargin(4);
  tmp_player_box->SetNoBorder();
  AddWidget(tmp_player_box);

  tmp_player_box->AddWidget(new NullWidget(Point2i(width, 20)));

  /********   Box for team logo, commander, custom team, ai & group  *******/
  HBox *hbox = new HBox(W_UNDEF, false, false, false);
  hbox->SetMargin(0);
  hbox->SetNoBorder();
  tmp_player_box->AddWidget(hbox);

  /****    AI    ****/
  player_type =  new PictureWidget(Point2i(40, 40));
  player_type->SetSurface(player_local[ai_level]);
  hbox->AddWidget(player_type);

  /****    Team Logo    ****/
  team_logo = new PictureWidget(Point2i(40, 40));
  hbox->AddWidget(team_logo);

  /****     Team name/commander    ****/
  VBox *vbox = new VBox(W_UNDEF, false, false, false);
  vbox->SetMargin(0);
  vbox->SetNoBorder();
  hbox->AddWidget(vbox);

  previous_player_name = "team";
  team_name = new Label(previous_player_name, width - (40*2 + 60),
                        Font::FONT_MEDIUM, Font::FONT_BOLD);
  vbox->AddWidget(team_name);

  /****    Names: "Head commander" + text/custom team    ****/
  vbox->AddWidget(new Label(_("Head commander"), width - (40*2 + 60),
                            Font::FONT_SMALL, Font::FONT_BOLD));

  /****  Group selection box ****/
  nullw = new NullWidget(Point2i(60, 40));
  nullw->SetBackgroundColor(TeamGroup::Colors[g]);
  hbox->AddWidget(nullw);

  custom_team_list = GetCustomTeamsList().GetList();
  custom_team_current_id = 0;

  if (custom_team_list.empty()) {
    player_name = new TextBox(_player_name, width,
                              Font::FONT_SMALL, Font::FONT_BOLD);
    tmp_player_box->AddWidget(player_name);

    next_custom_team = NULL;
    previous_custom_team = NULL;

  } else {
    next_custom_team = new Button(res, "menu/big_plus");
    previous_custom_team = new Button(res, "menu/big_minus");

    player_name = new TextBox(_player_name, width - 2 * (next_custom_team->GetSizeX() + 2),
                              Font::FONT_SMALL, Font::FONT_BOLD);

    Box * tmp_name_box = new HBox(player_name->GetSizeY(), false, false, false);
    tmp_name_box->SetNoBorder();
    tmp_name_box->SetMargin(2);

    tmp_name_box->AddWidget(previous_custom_team);
    tmp_name_box->AddWidget(player_name);
    tmp_name_box->AddWidget(next_custom_team);
    tmp_player_box->AddWidget(tmp_name_box);
  }

  /**********     Number of characters        **********/
  nb_characters = new SpinButtonWithPicture(_("Number of characters"), "menu/ico_play",
                                            Point2i(CHAR_COUNT_WIDGET_SIZE, 110), 6, 1, 1, 10);
  AddWidget(nb_characters);
  Pack();
}