NetworkConnectionMenu Class Reference

#include <network_connection_menu.h>

Inheritance diagram for NetworkConnectionMenu:

Inheritance graph
[legend]
Collaboration diagram for NetworkConnectionMenu:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 NetworkConnectionMenu ()
 ~NetworkConnectionMenu ()

Private Types

 NET_HOST
 NET_CONNECT_LOCAL
 NET_BROWSE_INTERNET
enum  network_menu_action_t { NET_HOST, NET_CONNECT_LOCAL, NET_BROWSE_INTERNET }

Private Member Functions

void OnClic (const Point2i &mousePosition, int button)
void Draw (const Point2i &mousePosition)
void SetAction (network_menu_action_t action)
void sig_ok ()
void __sig_ok ()
void __sig_cancel ()

Private Attributes

Buttonprevious_action_bt
Buttonnext_action_bt
Labelaction_label
network_menu_action_t current_action
Labelserver_address_label
TextBoxserver_address
Labelport_number_label
TextBoxport_number
CheckBoxinternet_server
VBoxconnection_box
MsgBoxmsg_box

Detailed Description

Definition at line 34 of file network_connection_menu.h.


Member Enumeration Documentation

enum NetworkConnectionMenu::network_menu_action_t [private]

Enumerator:
NET_HOST 
NET_CONNECT_LOCAL 
NET_BROWSE_INTERNET 

Definition at line 36 of file network_connection_menu.h.


Constructor & Destructor Documentation

NetworkConnectionMenu::NetworkConnectionMenu (  ) 

Definition at line 42 of file network_connection_menu.cpp.

00042                                              :
00043   Menu("menu/bg_network", vOkCancel)
00044 {
00045   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml",false);
00046   Rectanglei rectZero(0, 0, 0, 0);
00047   
00048   Font * normal_font = Font::GetInstance(Font::FONT_NORMAL);
00049   Font * big_font = Font::GetInstance(Font::FONT_BIG);
00050 
00051   Rectanglei stdRect(0, 0, 300, 64);
00052 
00053   uint x_button = AppWormux::GetInstance()->video.window.GetWidth()/2 - stdRect.GetSizeX()/2;
00054   uint y_box = AppWormux::GetInstance()->video.window.GetHeight()/2 - 200;
00055 
00056   // Connection related widgets
00057   connection_box = new VBox(Rectanglei( x_button, y_box, stdRect.GetSizeX(), 1), false);
00058   connection_box->SetBorder(Point2i(0,0));
00059 
00060   // What do we want to do ?
00061   Box* action_box = new HBox(stdRect, false);
00062 
00063   previous_action_bt = new Button(Point2i(0, 0), res, "menu/big_minus", false);
00064   next_action_bt = new Button(Point2i(0, 0), res, "menu/big_plus", false);
00065   action_label = new Label(_("Connect to an internet game"), 
00066                            Rectanglei(0,0,250,0), 
00067                            *big_font, white_color, true);
00068   action_box->AddWidget(previous_action_bt);
00069   action_box->AddWidget(action_label);
00070   action_box->AddWidget(next_action_bt);
00071 
00072   connection_box->AddWidget(action_box);
00073 
00074   // Server address
00075   server_address_label = new Label(_("Server address:"), rectZero, *normal_font);
00076   connection_box->AddWidget(server_address_label);
00077   server_address = new TextBox("localhost", rectZero, *normal_font);
00078   connection_box->AddWidget(server_address);
00079 
00080   // Server port
00081   port_number_label = new Label(_("Port:"), rectZero, *normal_font);
00082   connection_box->AddWidget(port_number_label);
00083   port_number = new TextBox(WORMUX_NETWORK_PORT, rectZero, *normal_font);
00084   connection_box->AddWidget(port_number);
00085 
00086   // Available on internet ?
00087   internet_server = new CheckBox(_("Server available on Internet"),
00088                                  Rectanglei(0,0,0,0),
00089                                  true);
00090   connection_box->AddWidget(internet_server);
00091 
00092   widgets.AddWidget(connection_box);
00093 
00094   SetAction(NET_BROWSE_INTERNET);
00095 
00096   // Warning about experimental networking
00097   msg_box = new MsgBox(Rectanglei( AppWormux::GetInstance()->video.window.GetWidth()/2 - 300,
00098                                    y_box+connection_box->GetSizeY() + 30, 
00099                                    600, 200), 
00100                        Font::GetInstance(Font::FONT_SMALL));
00101   widgets.AddWidget(msg_box);
00102 
00103   msg_box->NewMessage(_("WARNING!! Network is still under developement and therefore a little experimental."));
00104   msg_box->NewMessage(""); // Skip a line
00105   msg_box->NewMessage(_("Some weapons are disabled, because of known bugs (ninjarope, airhammer, blowtorch, submachine gun) and surely many other things don't work either!"));
00106   msg_box->NewMessage(""); // Skip a line
00107   msg_box->NewMessage(_("Join #wormux on irc.freenode.net to find some opponents."));
00108   msg_box->NewMessage(""); // Skip a line
00109   msg_box->NewMessage(_("Have a good game!"));
00110   msg_box->NewMessage(""); // Skip a line
00111 
00112   resource_manager.UnLoadXMLProfile(res);
00113 }

Here is the call graph for this function:

NetworkConnectionMenu::~NetworkConnectionMenu (  ) 

Definition at line 115 of file network_connection_menu.cpp.

00116 {
00117 }


Member Function Documentation

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

Implements Menu.

Definition at line 261 of file network_connection_menu.cpp.

00262 {
00263   network.Disconnect();
00264 }

Here is the call graph for this function:

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

Implements Menu.

Definition at line 256 of file network_connection_menu.cpp.

00257 {
00258   network.Disconnect();
00259 }

Here is the call graph for this function:

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

Implements Menu.

Definition at line 186 of file network_connection_menu.cpp.

00186 {}

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

Implements Menu.

Definition at line 119 of file network_connection_menu.cpp.

00120 {
00121   Widget* w = widgets.Clic(mousePosition, button);
00122 
00123   if (w == next_action_bt) {
00124     switch (current_action) {
00125     case NET_HOST:
00126       SetAction(NET_CONNECT_LOCAL);
00127       break;
00128     case NET_CONNECT_LOCAL:
00129       SetAction(NET_BROWSE_INTERNET);
00130       break;
00131     case NET_BROWSE_INTERNET:
00132       SetAction(NET_HOST);
00133       break;
00134     }
00135     return;
00136   } 
00137 
00138   if (w == previous_action_bt) {
00139     switch (current_action) {
00140     case NET_HOST:
00141       SetAction(NET_BROWSE_INTERNET);
00142       break;
00143     case NET_CONNECT_LOCAL:
00144       SetAction(NET_HOST);
00145       break;
00146     case NET_BROWSE_INTERNET:
00147       SetAction(NET_CONNECT_LOCAL);
00148       break;
00149     }
00150     return;
00151   }
00152 }

Here is the call graph for this function:

void NetworkConnectionMenu::SetAction ( network_menu_action_t  action  )  [private]

Definition at line 154 of file network_connection_menu.cpp.

00155 {
00156   current_action = action;
00157 
00158   switch (current_action) {
00159   case NET_HOST:
00160     action_label->SetText(_("Host a game"));
00161     server_address_label->SetVisible(false);
00162     server_address->SetVisible(false);
00163     port_number_label->SetVisible(true);
00164     port_number->SetVisible(true);
00165     internet_server->SetVisible(true);
00166     break;
00167   case NET_CONNECT_LOCAL:
00168     action_label->SetText(_("Connect to game"));
00169     server_address_label->SetVisible(true);
00170     server_address->SetVisible(true);
00171     port_number_label->SetVisible(true);
00172     port_number->SetVisible(true);
00173     internet_server->SetVisible(false);
00174     break;
00175   case NET_BROWSE_INTERNET:
00176     action_label->SetText(_("Connect to an internet game"));
00177     server_address_label->SetVisible(false);
00178     server_address->SetVisible(false);
00179     port_number_label->SetVisible(false);
00180     port_number->SetVisible(false);
00181     internet_server->SetVisible(false);
00182     break;
00183   } 
00184 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from Menu.

Definition at line 188 of file network_connection_menu.cpp.

00189 {
00190   switch (current_action) {
00191   case NET_HOST: // Hosting your own server
00192     if( !internet_server->GetValue() )
00193       index_server.SetHiddenServer();
00194 
00195     if( !index_server.Connect() ) {
00196       msg_box->NewMessage(_("Error: Unable to contact index server to host a game"));
00197       return;
00198     }
00199 
00200     network.Init();
00201     network.ServerStart(port_number->GetText());
00202 
00203     index_server.SendServerStatus();
00204 
00205     if(network.IsConnected()) {
00206       network.client_inited = 1;
00207     } else {
00208       msg_box->NewMessage(_("Error: Unable to start server"));
00209       return;
00210     }
00211     break;
00212 
00213 
00214   case NET_CONNECT_LOCAL: // Direct connexion to a server
00215     network.Init();
00216     network.ClientConnect(server_address->GetText(), port_number->GetText());
00217     if (!network.IsConnected()) {
00218       msg_box->NewMessage(Format(_("Error: Unable to connect to %s:%s"),
00219                                  (server_address->GetText()).c_str(), (port_number->GetText()).c_str()));
00220       return;
00221     }
00222     break;
00223 
00224   case NET_BROWSE_INTERNET: // Search an internet game!
00225     if( !index_server.Connect() ) {
00226       msg_box->NewMessage(_("Error: Unable to contact index server to search an internet game"));
00227       return;
00228     }
00229 
00230     InternetMenu im;
00231     im.Run();
00232 
00233     index_server.Disconnect();
00234 
00235     // we don't go back into the main menu!
00236     // -> im.Run() may have connected to a host so the 
00237     // if(network.IsConnected()) just below will be catched and close the menu
00238     break;
00239   }
00240 
00241   if (network.IsConnected()) {
00242     // run the network menu ! :-)
00243     NetworkMenu nm;
00244     network.network_menu = &nm;
00245     nm.Run();
00246     network.network_menu = NULL;
00247     index_server.Disconnect();
00248 
00249     // back to main menu after playing
00250     Menu::sig_ok();
00251   } else {
00252     // TODO : add error sound and dialog
00253   }
00254 }

Here is the call graph for this function:


Member Data Documentation

Label* NetworkConnectionMenu::action_label [private]

Definition at line 45 of file network_connection_menu.h.

VBox* NetworkConnectionMenu::connection_box [private]

Definition at line 55 of file network_connection_menu.h.

network_menu_action_t NetworkConnectionMenu::current_action [private]

Definition at line 46 of file network_connection_menu.h.

CheckBox* NetworkConnectionMenu::internet_server [private]

Definition at line 54 of file network_connection_menu.h.

MsgBox* NetworkConnectionMenu::msg_box [private]

Definition at line 57 of file network_connection_menu.h.

Button * NetworkConnectionMenu::next_action_bt [private]

Definition at line 43 of file network_connection_menu.h.

TextBox* NetworkConnectionMenu::port_number [private]

Definition at line 52 of file network_connection_menu.h.

Label* NetworkConnectionMenu::port_number_label [private]

Definition at line 51 of file network_connection_menu.h.

Button* NetworkConnectionMenu::previous_action_bt [private]

Definition at line 43 of file network_connection_menu.h.

TextBox* NetworkConnectionMenu::server_address [private]

Definition at line 49 of file network_connection_menu.h.

Label* NetworkConnectionMenu::server_address_label [private]

Definition at line 48 of file network_connection_menu.h.


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