src/menu/internet_menu.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Network connection menu: this menu allows the user to choose between
00020  * hosting a game or connecting to a server.
00021  *****************************************************************************/
00022 
00023 
00024 #include "internet_menu.h"
00025 
00026 #include "menu.h"
00027 #include "include/app.h"
00028 #include "gui/button_text.h"
00029 #include "network/network.h"
00030 #include "network/index_server.h"
00031 #include "tool/i18n.h"
00032 
00033 InternetMenu::InternetMenu() :
00034   Menu("menu/bg_network", vCancel)
00035 {
00036   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml",false);
00037   Rectanglei rectZero(0, 0, 0, 0);
00038   
00039   normal_font = Font::GetInstance(Font::FONT_NORMAL);
00040   big_font = Font::GetInstance(Font::FONT_BIG);
00041 
00042   Rectanglei stdRect(0, 0, 300, 64);
00043 
00044   uint x_button = AppWormux::GetInstance()->video.window.GetWidth()/2 - stdRect.GetSizeX()/2;
00045   uint y_box = AppWormux::GetInstance()->video.window.GetHeight()/2 - 200;
00046 
00047   connection_box = new VBox(Rectanglei( x_button, y_box, stdRect.GetSizeX(), 1), false);
00048   connection_box->SetBorder(Point2i(0,0));
00049 
00050   connect_lst = new ListBox( Rectanglei(0, 0, stdRect.GetSizeX(), 300), false);
00051   connection_box->AddWidget(connect_lst);
00052 
00053   refresh = new ButtonText( Point2i(0,0),
00054                                  res, "main_menu/button",
00055                                  _("Refresh"), // Refresh the list of available hosts
00056                                  big_font);
00057   refresh->SetSizePosition( stdRect );
00058   connection_box->AddWidget(refresh);
00059 
00060   connect = new ButtonText( Point2i(0,0),
00061                                  res, "main_menu/button",
00062                                  _("Connect !"),
00063                                  big_font);
00064   connect->SetSizePosition( stdRect );
00065   connection_box->AddWidget(connect);
00066 
00067   widgets.AddWidget(connection_box);
00068 
00069   resource_manager.UnLoadXMLProfile(res);
00070   RefreshList();
00071 }
00072 
00073 InternetMenu::~InternetMenu()
00074 {
00075 }
00076 
00077 void InternetMenu::OnClic(const Point2i &mousePosition, int button)
00078 {     
00079   Widget* w = widgets.Clic(mousePosition, button);  
00080 
00081   if (w == refresh)
00082     RefreshList();
00083   else
00084   if (w == connect && connect_lst->GetSelectedItem() != -1)
00085   {
00086     network.Init();
00087     network.ClientConnect(connect_lst->ReadLabel(), connect_lst->ReadValue());
00088     if( network.IsConnected() )
00089     {
00090       close_menu = true;
00091       sig_ok();
00092     }
00093     else
00094     {
00095       Question question;
00096       question.Set(_("Unable to join the game..."),1,0);
00097       question.Draw();
00098     }
00099   }
00100 }
00101 
00102 void InternetMenu::RefreshList()
00103 {
00104   // Save the currently selected address
00105   int current = connect_lst->GetSelectedItem();
00106 
00107   // Empty the list:
00108   while( connect_lst->Size() != 0 )
00109   {
00110     connect_lst->Select(0);
00111     connect_lst->RemoveSelected();
00112   }
00113 
00114   std::list<address_pair> lst = index_server.GetHostList();
00115 
00116   for(std::list<address_pair>::iterator pair_it = lst.begin();
00117       pair_it != lst.end();
00118       ++pair_it)
00119     connect_lst->AddItem( false, pair_it->first, pair_it->second );
00120 
00121   if(current != -1)
00122     connect_lst->Select( current );
00123 }
00124 
00125 void InternetMenu::Draw(const Point2i &mousePosition){}
00126 
00127 void InternetMenu::__sig_ok()
00128 {
00129 }
00130 
00131 void InternetMenu::__sig_cancel()
00132 {
00133 }

Generated on Mon Jan 1 13:10:58 2007 for Wormux by  doxygen 1.4.7