QTfrontend/hwform.cpp
changeset 632 5e09ae25729f
parent 625 373353eaa742
child 634 b9db5ff5cfdb
equal deleted inserted replaced
631:f7df3889f2ff 632:5e09ae25729f
    38 #include "gameuiconfig.h"
    38 #include "gameuiconfig.h"
    39 #include "pages.h"
    39 #include "pages.h"
    40 #include "hwconsts.h"
    40 #include "hwconsts.h"
    41 #include "newnetclient.h"
    41 #include "newnetclient.h"
    42 #include "gamecfgwidget.h"
    42 #include "gamecfgwidget.h"
    43 #include "netudpserver.h"
    43 #include "netserverslist.h"
    44 #include "netudpwidget.h"
    44 #include "netudpwidget.h"
    45 #include "netwwwwidget.h"
    45 #include "netwwwwidget.h"
    46 #include "chatwidget.h"
    46 #include "chatwidget.h"
    47 #include "playrecordpage.h"
    47 #include "playrecordpage.h"
    48 
    48 
    49 HWForm::HWForm(QWidget *parent)
    49 HWForm::HWForm(QWidget *parent)
    50   : QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0)
    50   : QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0)
    51 {
    51 {
    52 	ui.setupUi(this);
    52 	ui.setupUi(this);
    53 
       
    54 	config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
    53 	config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
    55 
    54 
    56 	UpdateTeamsLists();
    55 	UpdateTeamsLists();
    57 
    56 
    58 	connect(ui.pageMain->BtnSinglePlayer,	SIGNAL(clicked()),	this, SLOT(GoToSinglePlayer()));
    57 	connect(ui.pageMain->BtnSinglePlayer,	SIGNAL(clicked()),	this, SLOT(GoToSinglePlayer()));
    89 	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
    88 	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
    90 
    89 
    91 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    90 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    92 	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
    91 	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
    93 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
    92 	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
    94 	connect(ui.pageMain->BtnNet,	SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList()));
       
    95 	connect(ui.pageNet->pUpdateUdpButt, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList()));
       
    96 	connect(ui.pageNet->pUdpClient->serversList,	SIGNAL(doubleClicked (const QModelIndex &)),	this, SLOT(NetConnectServer()));
       
    97 
    93 
    98 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    94 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
    99 	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
    95 	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
   100 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)),
    96 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)),
   101 		ui.pageNetGame->BtnGo, SLOT(setEnabled(bool)));
    97 		ui.pageNetGame->BtnGo, SLOT(setEnabled(bool)));
   190 	GoToPage(ID_PAGE_DEMOS);
   186 	GoToPage(ID_PAGE_DEMOS);
   191 }
   187 }
   192 
   188 
   193 void HWForm::GoToNet()
   189 void HWForm::GoToNet()
   194 {
   190 {
       
   191 	ui.pageNet->changeServersList();
       
   192 	connect(ui.pageNet->netServersWidget->serversList,	SIGNAL(doubleClicked (const QModelIndex &)),	this, SLOT(NetConnectServer()));
       
   193 
   195 	GoToPage(ID_PAGE_NET);
   194 	GoToPage(ID_PAGE_NET);
   196 }
   195 }
   197 
   196 
   198 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   197 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   199 {
   198 {
   330 	game->PlayDemo(curritem->data(Qt::UserRole).toString());
   329 	game->PlayDemo(curritem->data(Qt::UserRole).toString());
   331 }
   330 }
   332 
   331 
   333 void HWForm::NetConnectServer()
   332 void HWForm::NetConnectServer()
   334 {
   333 {
   335   QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem();
   334   QListWidgetItem * curritem = ui.pageNet->netServersWidget->serversList->currentItem();
   336   if (!curritem) {
   335   if (!curritem) {
   337     QMessageBox::critical(this,
   336     QMessageBox::critical(this,
   338 			  tr("Error"),
   337 			  tr("Error"),
   339 			  tr("Please, select server from the list above"),
   338 			  tr("Please, select server from the list above"),
   340 			  tr("OK"));
   339 			  tr("OK"));
   399 void HWForm::NetStartServer()
   398 void HWForm::NetStartServer()
   400 {
   399 {
   401   pnetserver = new HWNetServer;
   400   pnetserver = new HWNetServer;
   402   pnetserver->StartServer();
   401   pnetserver->StartServer();
   403   _NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text());
   402   _NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text());
   404   pUdpServer = new HWNetUdpServer();
   403 //  pUdpServer = new HWNetUdpServer();
   405 }
   404 }
   406 
   405 
   407 void HWForm::NetDisconnect()
   406 void HWForm::NetDisconnect()
   408 {
   407 {
   409   if(hwnet) {
   408   if(hwnet) {
   410     hwnet->Disconnect();
   409     hwnet->Disconnect();
   411     delete hwnet;
   410     delete hwnet;
   412     hwnet=0;
   411     hwnet=0;
   413   }
   412   }
   414   if(pnetserver) {
   413   if(pnetserver) {
   415     pUdpServer->deleteLater();
   414 //    pUdpServer->deleteLater();
   416     pnetserver->StopServer();
   415     pnetserver->StopServer();
   417     delete pnetserver;
   416     delete pnetserver;
   418     pnetserver=0;
   417     pnetserver=0;
   419   }
   418   }
   420 }
   419 }