TeamsSelectionBox Class Reference

#include <teams_selection_box.h>

Inheritance diagram for TeamsSelectionBox:

Inheritance graph
[legend]
Collaboration diagram for TeamsSelectionBox:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TeamsSelectionBox (const Rectanglei &rect)
void ValidTeamsSelection ()
WidgetClic (const Point2i &mousePosition, uint button)

Private Member Functions

void SetNbTeams (uint nb_teams)
void PrevTeam (int i)
void NextTeam (int i)

Private Attributes

SpinButtonBigteams_nb
std::vector< TeamBox * > teams_selections

Detailed Description

Definition at line 40 of file teams_selection_box.h.


Constructor & Destructor Documentation

TeamsSelectionBox::TeamsSelectionBox ( const Rectanglei rect  ) 

Definition at line 26 of file teams_selection_box.cpp.

00026                                                            : HBox(rect, true)
00027 {
00028   AddWidget(new PictureWidget(Rectanglei(0,0,38,150), "menu/teams_label"));
00029 
00030   // How many teams ?
00031   teams_nb = new SpinButtonBig(_("Number of teams:"), Rectanglei(0, 0, 130, 30),
00032                                2, 1,
00033                                2, MAX_NB_TEAMS);
00034   AddWidget(teams_nb);
00035 
00036   Box * top_n_bottom_team_options = new VBox( Rectanglei(0, 0,
00037                                                          rect.GetSizeX() - teams_nb->GetSizeX() - 60, 0)
00038                                               ,false);
00039   top_n_bottom_team_options->SetBorder(Point2i(5,0));
00040   top_n_bottom_team_options->SetMargin(10);
00041   Box * top_team_options = new HBox ( Rectanglei(0, 0, 0, rect.GetSizeY()/2 - 20), false);
00042   Box * bottom_team_options = new HBox ( Rectanglei(0, 0, 0, rect.GetSizeY()/2 - 20), false);
00043   top_team_options->SetBorder(Point2i(0,0));
00044   bottom_team_options->SetBorder(Point2i(0,0));
00045 
00046   // Initialize teams
00047   uint team_w_size= top_n_bottom_team_options->GetSizeX() * 2 / MAX_NB_TEAMS;
00048 
00049   for (uint i=0; i < MAX_NB_TEAMS; i++) {
00050     std::string player_name = _("Player") ;
00051     char num_player[4];
00052     sprintf(num_player, " %d", i+1);
00053     player_name += num_player;
00054     teams_selections.push_back(new TeamBox(player_name, Rectanglei(0,0,team_w_size,rect.GetSizeY()/2)));
00055     if ( i%2 == 0)
00056       top_team_options->AddWidget(teams_selections.at(i));
00057     else
00058       bottom_team_options->AddWidget(teams_selections.at(i));
00059   }
00060 
00061   top_n_bottom_team_options->AddWidget(top_team_options);
00062   top_n_bottom_team_options->AddWidget(bottom_team_options);
00063 
00064   AddWidget(top_n_bottom_team_options); 
00065 
00066   // Load Teams' list
00067   teams_list.full_list.sort(compareTeams);
00068 
00069   TeamsList::iterator
00070     it=teams_list.playing_list.begin(),
00071     end=teams_list.playing_list.end();
00072 
00073   uint j=0;
00074   for (; it != end && j<teams_selections.size(); ++it, j++)
00075     {
00076       teams_selections.at(j)->SetTeam((**it), true);
00077     }
00078   
00079   if (j < 2) {
00080     SetNbTeams(2);
00081     teams_nb->SetValue(2);
00082   } else {
00083     teams_nb->SetValue(j);
00084   }
00085 }

Here is the call graph for this function:


Member Function Documentation

Widget * TeamsSelectionBox::Clic ( const Point2i mousePosition,
uint  button 
) [virtual]

Reimplemented from Box.

Definition at line 87 of file teams_selection_box.cpp.

00088 {
00089   if (!Contains(mousePosition)) return NULL;
00090 
00091   if (teams_nb->Clic(mousePosition, button)){
00092     SetNbTeams(teams_nb->GetValue());
00093 
00094   } else {
00095     for (uint i=0; i<teams_selections.size() ; i++) {
00096 
00097       if ( teams_selections.at(i)->Contains(mousePosition) ) {
00098         
00099         Widget * w = teams_selections.at(i)->Clic(mousePosition, button);
00100 
00101         if ( w == NULL ) {
00102           if ( button == SDL_BUTTON_LEFT || button == SDL_BUTTON_WHEELDOWN ) {
00103             NextTeam(i);
00104           } else if ( button == SDL_BUTTON_RIGHT || button == SDL_BUTTON_WHEELUP ) {
00105             PrevTeam(i);
00106           }
00107         } else {
00108           return w;
00109         }
00110         break;
00111       }
00112     }
00113   }
00114 
00115   return NULL;
00116 }

Here is the call graph for this function:

void TeamsSelectionBox::NextTeam ( int  i  )  [private]

Definition at line 156 of file teams_selection_box.cpp.

00157 {
00158   if (teams_selections.at(i)->GetTeam() == NULL) return;
00159 
00160   bool to_continue;
00161   Team* tmp;
00162   int previous_index = -1, index;
00163 
00164   teams_list.FindById(teams_selections.at(i)->GetTeam()->GetId(), previous_index);
00165 
00166   index = previous_index+1;
00167 
00168   do 
00169     {
00170       to_continue = false;
00171 
00172       // select the first team if we are outside list
00173       if ( index >= int(teams_list.full_list.size()) )
00174         index = 0;
00175 
00176       // Get the team at current index
00177       tmp = teams_list.FindByIndex(index);
00178       
00179       // Check if that team is already selected
00180       for (int j = 0; j < teams_nb->GetValue(); j++) {
00181         if (j!= i && tmp == teams_selections.at(j)->GetTeam()) {
00182           index++;
00183           to_continue = true;
00184           break;
00185         }
00186       }
00187       
00188       // We have found a team which is not selected
00189       if (tmp != NULL && !to_continue)
00190         teams_selections.at(i)->SetTeam(*tmp);
00191     } while ( index != previous_index && to_continue);
00192 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamsSelectionBox::PrevTeam ( int  i  )  [private]

Definition at line 118 of file teams_selection_box.cpp.

00119 {
00120   if (teams_selections.at(i)->GetTeam() == NULL) return;
00121 
00122   bool to_continue;
00123   Team* tmp;
00124   int previous_index = -1, index;  
00125 
00126   teams_list.FindById(teams_selections.at(i)->GetTeam()->GetId(), previous_index);
00127 
00128   index = previous_index-1;
00129 
00130   do 
00131     {
00132       to_continue = false;
00133 
00134       // select the last team if we are outside list
00135       if ( index < 0 )
00136         index = int(teams_list.full_list.size())-1;
00137 
00138       // Get the team at current index
00139       tmp = teams_list.FindByIndex(index);
00140       
00141       // Check if that team is already selected
00142       for (int j = 0; j < teams_nb->GetValue(); j++) {
00143         if (j!= i && tmp == teams_selections.at(j)->GetTeam()) {
00144           index--;
00145           to_continue = true;
00146           break;
00147         }
00148       }
00149       
00150       // We have found a team which is not selected
00151       if (tmp != NULL && !to_continue)
00152         teams_selections.at(i)->SetTeam(*tmp);
00153     } while ( index != previous_index && to_continue);
00154 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamsSelectionBox::SetNbTeams ( uint  nb_teams  )  [private]

Definition at line 194 of file teams_selection_box.cpp.

00195 {
00196   // we hide the useless teams selector
00197   for (uint i=nb_teams; i<teams_selections.size(); i++) {
00198     teams_selections.at(i)->ClearTeam();
00199   }
00200 
00201   for (uint i=0; i<nb_teams;i++) {
00202     if (teams_selections.at(i)->GetTeam() == NULL) {
00203       // we should find an available team
00204       teams_selections.at(i)->SetTeam(*(teams_list.FindByIndex(i)));
00205       NextTeam(i);
00206     }
00207   }
00208 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamsSelectionBox::ValidTeamsSelection (  ) 

Definition at line 210 of file teams_selection_box.cpp.

00211 {
00212   uint nb_teams=0;
00213   for (uint i=0; i < teams_selections.size(); i++) {
00214     if (teams_selections.at(i)->GetTeam() != NULL)
00215       nb_teams++;
00216   }
00217 
00218   if (nb_teams >= 2) {
00219     std::list<uint> selection;
00220 
00221     for (uint i=0; i < teams_selections.size(); i++) {
00222       if (teams_selections.at(i)->GetTeam() != NULL) {
00223         int index = -1;
00224         teams_selections.at(i)->ValidOptions();
00225         teams_list.FindById(teams_selections.at(i)->GetTeam()->GetId(), index);
00226         if (index > -1)
00227           selection.push_back(uint(index));
00228       }
00229     }
00230     teams_list.ChangeSelection (selection);
00231   }
00232 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

SpinButtonBig* TeamsSelectionBox::teams_nb [private]

Definition at line 43 of file teams_selection_box.h.

std::vector<TeamBox*> TeamsSelectionBox::teams_selections [private]

Definition at line 44 of file teams_selection_box.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:24:37 2007 for Wormux by  doxygen 1.4.7