// ################################################ // ## GAME MENU CLASS // ################################################ GameMenu::GameMenu() : Menu("menu/bg_play") { Surface& window = GetMainWindow(); // Calculate main box size int team_box_height = 240; uint mainBoxWidth = window.GetWidth() - 2*MARGIN_SIDE; uint mainBoxHeight = window.GetHeight() - MARGIN_TOP - MARGIN_BOTTOM - 2*MARGIN_SIDE; uint mapsHeight = mainBoxHeight - team_box_height - 60; uint multitabsWidth = mainBoxWidth; bool multitabs = false; if (window.GetWidth() > 640 && mapsHeight > 200) { multitabs = true; multitabsWidth = mainBoxWidth - 20; mapsHeight = 200; team_box_height = mainBoxHeight - 200 - 60; } else { mapsHeight = mainBoxHeight - 60; team_box_height = mainBoxHeight - 60; } MultiTabs * tabs = new MultiTabs(Point2i(mainBoxWidth, mainBoxHeight)); // ################################################ // ## TEAM AND MAP SELECTION // ################################################ team_box = new LocalTeamsSelectionBox(Point2i(multitabsWidth, team_box_height), multitabs); map_box = new MapSelectionBox(Point2i(multitabsWidth-4, mapsHeight), multitabs); if (!multitabs) { tabs->AddNewTab("TAB_Team", _("Teams"), team_box); tabs->AddNewTab("TAB_Map", _("Map"), map_box); } else { VBox *box = new VBox(mainBoxWidth, false, false, true); std::string tabs_title = _("Teams") + std::string(" - "); tabs_title += _("Map"); box->AddWidget(team_box); box->AddWidget(map_box); tabs->AddNewTab("TAB_Team_Map", tabs_title, box); } // ################################################ // ## GAME OPTIONS // ################################################ Point2i option_size(114, 114); game_options = new GameModeEditor(mainBoxWidth, option_size, false); tabs->AddNewTab("TAB_Game", _("Game"), game_options); tabs->SetPosition(MARGIN_SIDE, MARGIN_TOP); widgets.AddWidget(tabs); widgets.Pack(); }
ReplayMenu::ReplayMenu() : Menu("menu/bg_play") , selected(NULL) { // Center the boxes! uint h = GetMainWindow().GetHeight(); uint size_y = h-50; float z = size_y/430.0; uint border = 5*z; uint size_x = GetMainWindow().GetWidth()/19; uint w = 8*size_x - 2*border; Font::font_size_t fsize1 = Font::GetFixedSize(z * 18); Font::font_size_t fsize2 = Font::GetFixedSize(z * 16); #define ARG_LIST fsize1, Font::FONT_BOLD, primary_red_color, Text::ALIGN_LEFT_TOP, true #define ARG_LIST2 fsize2, Font::FONT_BOLD, dark_gray_color, Text::ALIGN_LEFT_TOP, false //Replay files VBox *vbox = new VBox(8*size_x, true); vbox->SetPosition(size_x, size_y/20); widgets.AddWidget(vbox); file_box = new VBox(w, false); file_box->SetBorder(border); file_box->SetSelfBackgroundColor(transparent_color); vbox->AddWidget(file_box); file_box->AddWidget(new Label(_("Select a replay:"), w, ARG_LIST)); replay_lbox = new FileListBox(Point2i(w-20, (9*size_y)/10 - fsize1 - 3*5)); replay_lbox->SetBorder(defaultOptionColorRect, 2); // Windows may SFN => uppercase extensions replay_lbox->AddExtensionFilter("WRF"); replay_lbox->AddExtensionFilter("wrf"); replay_lbox->StartListing(); file_box->AddWidget(replay_lbox); //Info vbox = new VBox(8*size_x); vbox->SetPosition(10*size_x, size_y/20); widgets.AddWidget(vbox); info_box = new VBox(w, false); info_box->SetBorder(border); info_box->SetSelfBackgroundColor(transparent_color); vbox->AddWidget(info_box); info_box->AddWidget(new Label(_("Replay info"), w, ARG_LIST)); vbox = new VBox(w-10, true); info_box->AddWidget(vbox); Box *panel = new VBox(w-10-2*border, false); panel->SetBorder(border); panel->SetSelfBackgroundColor(transparent_color); panel->SetMargin(0); vbox->AddWidget(panel); // Version panel->AddWidget(new Label(_("Version"), w-10, ARG_LIST)); version_lbl = new Label(" ", w-10, ARG_LIST2); panel->AddWidget(version_lbl); // Date panel->AddWidget(new Label(_("Date"), w-10, ARG_LIST)); date_lbl = new Label(" ", w-10, ARG_LIST2); panel->AddWidget(date_lbl); // Duration panel->AddWidget(new Label(_("Duration"), w-10, ARG_LIST)); duration_lbl = new Label(" ", w-20, ARG_LIST2); panel->AddWidget(duration_lbl); // Comment panel->AddWidget(new Label(_("Comment"), w-10, ARG_LIST)); comment_lbl = new Label(" ", w-10, ARG_LIST2); panel->AddWidget(comment_lbl); // Teams panel->AddWidget(new Label(_("Teams"), w-10, ARG_LIST)); teams_lbox = new ScrollBox(Point2i(w-10, (9*size_y)/10 - 6*(fsize1+fsize2)- 4*border -2*5)); panel->AddWidget(teams_lbox); widgets.Pack(); }
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(); }
TeamsSelectionBox::TeamsSelectionBox(const Point2i &_size, bool network, bool w_border) : HBox(_size.y, w_border, false) { if (!w_border) SetNoBorder(); SetMargin(0); // How many teams ? VBox *tmp = new VBox(120, false, false, true); if (network) { local_teams_nb = new SpinButtonWithPicture(_("Local teams:"), "menu/team_number", Point2i(100, 130), 0, 1, 0, MAX_NB_TEAMS); } else { local_teams_nb = new SpinButtonWithPicture(_("Number of teams:"), "menu/team_number", Point2i(100, 130), 2, 1, 2, MAX_NB_TEAMS); } tmp->AddWidget(local_teams_nb); //tmp->AddWidget(new NullWidget(Point2i(120, 120))); AddWidget(tmp); uint box_w = _size.x - local_teams_nb->GetSizeX() - 10; Point2i grid_size = Point2i(box_w, _size.y); Point2i grid_dim = grid_size / Point2i(300 + 10, 130 + 10); Point2i box_size; bool use_list; if (grid_dim.x*grid_dim.y < (int)MAX_NB_TEAMS) { use_list = true; box_size.SetValues(box_w - 40, 120); } else { use_list = false; box_size.SetValues((grid_size / grid_dim) - 10); } for (uint i=0; i < MAX_NB_TEAMS; i++) { std::string player_name = _("Player") ; char num_player[4]; sprintf(num_player, " %d", i+1); player_name += num_player; teams_selections.push_back(new TeamBox(player_name, box_size)); } // If the intended gridbox would be too big for the intended size, // instead create a listbox if (use_list) { // Warning: this box takes the ownership of the widgets in teams_selections: // while any other Box will delete the ones it contains, TeamScrollBox // doesn't really contain them as widgets. They therefore aren't released // through this mechanism, but with a manual one. This manual mechanism // requires we have a *real* copy of the vector for when it is destroyed. list_box = new TeamScrollBox(teams_selections, Point2i(box_w-20, _size.y-10)); list_box->SetNbTeams(0); AddWidget(list_box); } else { list_box = NULL; Box * teams_grid_box = new GridBox(grid_dim.y, grid_dim.x, 10, false); teams_grid_box->SetNoBorder(); for (uint i=0; i<MAX_NB_TEAMS; i++) teams_grid_box->AddWidget(teams_selections[i]); AddWidget(teams_grid_box); } // Load Teams' list GetTeamsList().full_list.sort(compareTeams); }