NetworkMenu Class Reference

#include <network_menu.h>

Inheritance diagram for NetworkMenu:

Inheritance graph
[legend]
Collaboration diagram for NetworkMenu:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 NetworkMenu ()
 ~NetworkMenu ()
void AddTeamCallback (std::string team_id)
void UpdateTeamCallback (std::string team_id)
void DelTeamCallback (std::string team_id)
void ChangeMapCallback ()
void ReceiveMsgCallback (std::string msg)

Private Member Functions

void SaveOptions ()
void OnClic (const Point2i &mousePosition, int button)
void Draw (const Point2i &mousePosition)
void sig_ok ()
void __sig_ok ()
void __sig_cancel ()

Private Attributes

SpinButtonplayer_number
Boxoptions_box
Labelconnected_players
Labelinited_players
MsgBoxmsg_box
TextBoxline_to_send_tbox
Buttonsend_txt_bt
NetworkTeamsSelectionBoxteam_box
MapSelectionBoxmap_box

Detailed Description

Definition at line 37 of file network_menu.h.


Constructor & Destructor Documentation

NetworkMenu::NetworkMenu (  ) 

Definition at line 46 of file network_menu.cpp.

00046                          :
00047   Menu("menu/bg_network")
00048 {
00049   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml",false);
00050   Rectanglei rectZero(0, 0, 0, 0);
00051   Rectanglei stdRect (0, 0, 130, 30);
00052 
00053   Surface window = AppWormux::GetInstance()->video.window;
00054 
00055   // Calculate main box size
00056   uint mainBoxWidth = window.GetWidth() - 2*MARGIN_SIDE;
00057   uint mapBoxHeight = (window.GetHeight() - MARGIN_TOP - MARGIN_BOTTOM - 2*MARGIN_SIDE) 
00058     - TEAMS_BOX_H - OPTIONS_BOX_H;
00059 
00060   // ################################################
00061   // ##  TEAM SELECTION
00062   // ################################################
00063   team_box = new NetworkTeamsSelectionBox(Rectanglei(MARGIN_SIDE, MARGIN_TOP,
00064                                               mainBoxWidth, TEAMS_BOX_H));
00065   widgets.AddWidget(team_box);
00066 
00067   // ################################################
00068   // ##  MAP SELECTION
00069   // ################################################
00070   if(network.IsServer()) {
00071     map_box = new MapSelectionBox( Rectanglei(MARGIN_SIDE, team_box->GetPositionY()+team_box->GetSizeY()+ MARGIN_SIDE,
00072                                               mainBoxWidth, mapBoxHeight),
00073                                    false);
00074   } else {
00075     map_box = new MapSelectionBox( Rectanglei(MARGIN_SIDE, team_box->GetPositionY()+team_box->GetSizeY()+ MARGIN_SIDE,
00076                                               mainBoxWidth, mapBoxHeight),
00077                                    true);
00078   }
00079   widgets.AddWidget(map_box);
00080 
00081   // ################################################
00082   // ##  GAME OPTIONS
00083   // ################################################
00084 
00085   options_box = new HBox( Rectanglei(MARGIN_SIDE, map_box->GetPositionY()+map_box->GetSizeY()+ MARGIN_SIDE,
00086                                      mainBoxWidth, OPTIONS_BOX_H), true);
00087   options_box->AddWidget(new PictureWidget(Rectanglei(0,0,39,128), "menu/mode_label"));
00088   
00089   Box* tmp_box = new VBox( Rectanglei(0,0, 200,0), false);
00090   player_number = new SpinButton(_("Max number of players:"), rectZero, 
00091                                  GameMode::GetInstance()->max_teams, 1, 2, 
00092                                  GameMode::GetInstance()->max_teams);
00093   
00094   tmp_box->AddWidget(player_number);
00095 
00096   connected_players = new Label(Format(ngettext("%i player connected", "%i players connected", 0), 0), 
00097                                 rectZero, *Font::GetInstance(Font::FONT_SMALL));
00098   tmp_box->AddWidget(connected_players);
00099 
00100   inited_players = new Label(Format(ngettext("%i player ready", "%i players ready", 0), 0), 
00101                              rectZero, *Font::GetInstance(Font::FONT_SMALL));
00102   tmp_box->AddWidget(inited_players);
00103 
00104   options_box->AddWidget(tmp_box);
00105   widgets.AddWidget(options_box);
00106 
00107   // ################################################
00108   // ##  CHAT BOX
00109   // ################################################
00110   VBox* chat_box = new VBox(Rectanglei(options_box->GetPositionX() + options_box->GetSizeX() + MARGIN_SIDE,
00111                                        options_box->GetPositionY(),
00112                                        mainBoxWidth - options_box->GetSizeX() - MARGIN_SIDE,
00113                                        OPTIONS_BOX_H), false);
00114   chat_box->SetBorder(Point2i(0,0));
00115   
00116   msg_box = new MsgBox(Rectanglei( 0, 0, 400, OPTIONS_BOX_H - 20), Font::GetInstance(Font::FONT_SMALL));  
00117   msg_box->NewMessage(_("Join #wormux on irc.freenode.net to find some opponents."));
00118   msg_box->NewMessage(_("WARNING! Disconnections are not yet handled. So you have to restart Wormux after each disconnection!"));
00119 
00120   chat_box->AddWidget(msg_box);
00121 
00122   HBox* tmp2_box = new HBox(Rectanglei(0,0,chat_box->GetSizeX(),16), false);
00123   tmp2_box->SetMargin(4);
00124   tmp2_box->SetBorder(Point2i(0,0));
00125   line_to_send_tbox = new TextBox(" ",
00126                                   Rectanglei(0, 0, chat_box->GetSizeX()-20, 0), 
00127                                   *Font::GetInstance(Font::FONT_SMALL));
00128   tmp2_box->AddWidget(line_to_send_tbox);
00129   
00130   send_txt_bt = new Button(Point2i(0,0), res, "menu/send_txt", true);
00131   tmp2_box->AddWidget(send_txt_bt);
00132 
00133   chat_box->AddWidget(tmp2_box);
00134 
00135   widgets.AddWidget(chat_box);
00136 
00137   resource_manager.UnLoadXMLProfile(res);
00138 }

Here is the call graph for this function:

NetworkMenu::~NetworkMenu (  ) 

Definition at line 140 of file network_menu.cpp.

00141 {
00142 }


Member Function Documentation

void NetworkMenu::__sig_cancel (  )  [private, virtual]

Implements Menu.

Definition at line 206 of file network_menu.cpp.

00207 {
00208   network.Disconnect();
00209 }

Here is the call graph for this function:

void NetworkMenu::__sig_ok (  )  [private, virtual]

Implements Menu.

Definition at line 173 of file network_menu.cpp.

00174 {
00175   if(network.IsClient())
00176   {
00177     // Wait for the server, and stay in the menu map / team can still be changed
00178     Action a(Action::ACTION_CHANGE_STATE);
00179     network.SendAction(&a);
00180     while(network.state != Network::NETWORK_INIT_GAME)
00181     {
00182       Display(Point2i(-1,-1));
00183     }
00184   }
00185 
00186   SaveOptions();
00187   Game::GetInstance()->Start();
00188   network.network_menu = NULL;
00189 }

Here is the call graph for this function:

void NetworkMenu::AddTeamCallback ( std::string  team_id  ) 

Definition at line 242 of file network_menu.cpp.

00243 {
00244   if ( close_menu )
00245     return;
00246 
00247   team_box->AddTeamCallback(team_id);
00248   msg_box->NewMessage(team_id + " selected");
00249 }

Here is the call graph for this function:

Here is the caller graph for this function:

void NetworkMenu::ChangeMapCallback (  ) 

Definition at line 260 of file network_menu.cpp.

00261 {
00262   assert( !close_menu );
00263   // Called from the action handler
00264 
00265   map_box->ChangeMapCallback();
00266 }

Here is the call graph for this function:

Here is the caller graph for this function:

void NetworkMenu::DelTeamCallback ( std::string  team_id  ) 

Definition at line 233 of file network_menu.cpp.

00234 {
00235   if( close_menu )
00236     return;
00237 
00238   // Called from the action handler
00239   team_box->DelTeamCallback(team_id);
00240 }

Here is the call graph for this function:

Here is the caller graph for this function:

void NetworkMenu::Draw ( const Point2i mousePosition  )  [private, virtual]

Implements Menu.

Definition at line 211 of file network_menu.cpp.

00212 {
00213   if(network.IsConnected())
00214   {
00215     //Refresh the number of connected players:
00216     int nbr = network.connected_player;
00217     std::string pl = Format(ngettext("%i player connected", "%i players connected", nbr), nbr);
00218     if(connected_players->GetText() != pl)
00219       connected_players->SetText(pl);
00220     //Refresh the number of players ready:
00221     nbr = network.client_inited;
00222     pl = Format(ngettext("%i player ready", "%i players ready", nbr), nbr);
00223     if(inited_players->GetText() != pl)
00224       inited_players->SetText(pl);
00225   }
00226   else {
00227     close_menu = true;
00228   }
00229   ActionHandler * action_handler = ActionHandler::GetInstance();
00230   action_handler->ExecActions();
00231 }

Here is the call graph for this function:

void NetworkMenu::OnClic ( const Point2i mousePosition,
int  button 
) [private, virtual]

Implements Menu.

Definition at line 144 of file network_menu.cpp.

00145 {
00146   Widget* w = widgets.Clic(mousePosition, button);
00147 
00148   if(w == player_number)
00149   {
00150     network.max_player_number = player_number->GetValue();
00151   }
00152 
00153   if(w == send_txt_bt)
00154   {
00155     std::string empty = "";
00156     network.SendChatMessage(line_to_send_tbox->GetText());
00157     line_to_send_tbox->SetText(empty);
00158   }
00159 }

Here is the call graph for this function:

void NetworkMenu::ReceiveMsgCallback ( std::string  msg  ) 

Definition at line 268 of file network_menu.cpp.

00269 {
00270   msg_box->NewMessage(msg);
00271 }

Here is the call graph for this function:

Here is the caller graph for this function:

void NetworkMenu::SaveOptions (  )  [private]

Definition at line 161 of file network_menu.cpp.

00162 {
00163   // map
00164   map_box->ValidMapSelection();
00165 
00166   // team
00167   team_box->ValidTeamsSelection();
00168 
00169   //Save options in XML
00170 //  Config::GetInstance()->Save();
00171 }

Here is the call graph for this function:

Here is the caller graph for this function:

void NetworkMenu::sig_ok (  )  [private, virtual]

Reimplemented from Menu.

Definition at line 191 of file network_menu.cpp.

00192 {
00193   if(network.IsServer())
00194   {
00195     if(network.connected_player != network.client_inited)
00196     {
00197       int nbr = network.connected_player - network.client_inited;
00198       std::string pl = Format(ngettext("Wait! %i player is not ready yet!", "Wait! %i players are not ready yet!", nbr), nbr);
00199       msg_box->NewMessage(pl);
00200       return;
00201     }
00202   }
00203   Menu::sig_ok();
00204 }

Here is the call graph for this function:

void NetworkMenu::UpdateTeamCallback ( std::string  team_id  ) 

Definition at line 251 of file network_menu.cpp.

00252 {
00253   if ( close_menu )
00254     return;
00255 
00256   team_box->UpdateTeamCallback(team_id);
00257   msg_box->NewMessage(team_id + " updated");
00258 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Label* NetworkMenu::connected_players [private]

Definition at line 42 of file network_menu.h.

Label* NetworkMenu::inited_players [private]

Definition at line 43 of file network_menu.h.

TextBox* NetworkMenu::line_to_send_tbox [private]

Definition at line 47 of file network_menu.h.

MapSelectionBox* NetworkMenu::map_box [private]

Definition at line 54 of file network_menu.h.

MsgBox* NetworkMenu::msg_box [private]

Definition at line 46 of file network_menu.h.

Box* NetworkMenu::options_box [private]

Definition at line 41 of file network_menu.h.

SpinButton* NetworkMenu::player_number [private]

Definition at line 40 of file network_menu.h.

Button* NetworkMenu::send_txt_bt [private]

Definition at line 48 of file network_menu.h.

NetworkTeamsSelectionBox* NetworkMenu::team_box [private]

Definition at line 51 of file network_menu.h.


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