32 #include "netclient.h" |
32 #include "netclient.h" |
33 #include "teamselect.h" |
33 #include "teamselect.h" |
34 #include "gameuiconfig.h" |
34 #include "gameuiconfig.h" |
35 #include "pages.h" |
35 #include "pages.h" |
36 #include "hwconsts.h" |
36 #include "hwconsts.h" |
|
37 #include "newnetclient.h" |
37 |
38 |
38 HWForm::HWForm(QWidget *parent) |
39 HWForm::HWForm(QWidget *parent) |
39 : QMainWindow(parent) |
40 : QMainWindow(parent), pnetserver(0) |
40 { |
41 { |
41 ui.setupUi(this); |
42 ui.setupUi(this); |
42 |
43 |
43 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
44 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
44 |
45 |
71 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
72 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
72 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
73 connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
73 |
74 |
74 connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
75 connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
75 connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
76 connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
|
77 connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
76 |
78 |
77 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
79 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
78 connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
80 connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
79 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
81 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
80 |
82 |
229 } |
231 } |
230 CreateGame(0); |
232 CreateGame(0); |
231 game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
233 game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
232 } |
234 } |
233 |
235 |
234 void HWForm::NetConnect() |
236 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
235 { |
237 { |
236 hwnet = new HWNet(config); |
238 hwnet = new HWNewNet(config); |
237 connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
239 connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
238 connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
240 connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
239 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
241 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
240 connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
242 connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
241 hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text()); |
243 hwnet->Connect(hostName, port, nick); |
242 config->SaveOptions(); |
244 config->SaveOptions(); |
243 } |
245 } |
244 |
246 |
|
247 void HWForm::NetConnect() |
|
248 { |
|
249 _NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text()); |
|
250 } |
|
251 |
|
252 void HWForm::NetStartServer() |
|
253 { |
|
254 pnetserver = new HWNetServer; |
|
255 pnetserver->StartServer(); |
|
256 _NetConnect(pnetserver->getRunningHostName(), pnetserver->getRunningPort(), ui.pageNet->editNetNick->text()); |
|
257 } |
|
258 |
245 void HWForm::NetDisconnect() |
259 void HWForm::NetDisconnect() |
246 { |
260 { |
247 hwnet->Disconnect(); |
261 hwnet->Disconnect(); |
248 GoBack(); |
262 GoBack(); |
|
263 delete hwnet; |
|
264 hwnet=0; |
|
265 if(pnetserver) { |
|
266 pnetserver->StopServer(); |
|
267 delete pnetserver; |
|
268 pnetserver=0; |
|
269 } |
249 } |
270 } |
250 |
271 |
251 void HWForm::AddGame(const QString & chan) |
272 void HWForm::AddGame(const QString & chan) |
252 { |
273 { |
253 ui.pageNetChat->ChannelsList->addItem(chan); |
274 ui.pageNetChat->ChannelsList->addItem(chan); |