00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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"),
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
00105 int current = connect_lst->GetSelectedItem();
00106
00107
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 }