author | displacer |
Sat, 26 May 2007 20:00:29 +0000 | |
changeset 523 | eddcef907b28 |
parent 502 | bc178daca088 |
child 530 | f0b962214436 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QStringList> |
|
20 |
#include <QProcess> |
|
21 |
#include <QDir> |
|
22 |
#include <QPixmap> |
|
23 |
#include <QRegExp> |
|
24 |
#include <QIcon> |
|
25 |
#include <QFile> |
|
26 |
#include <QTextStream> |
|
407 | 27 |
#include <QMessageBox> |
502
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
28 |
#include <QPushButton> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
29 |
#include <QListWidget> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
30 |
#include <QStackedLayout> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
31 |
#include <QLineEdit> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
32 |
#include <QLabel> |
184 | 33 |
|
34 |
#include "hwform.h" |
|
35 |
#include "game.h" |
|
36 |
#include "team.h" |
|
37 |
#include "teamselect.h" |
|
38 |
#include "gameuiconfig.h" |
|
39 |
#include "pages.h" |
|
40 |
#include "hwconsts.h" |
|
314 | 41 |
#include "newnetclient.h" |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
42 |
#include "gamecfgwidget.h" |
412 | 43 |
#include "netudpserver.h" |
416 | 44 |
#include "netudpwidget.h" |
461 | 45 |
#include "chatwidget.h" |
184 | 46 |
|
47 |
HWForm::HWForm(QWidget *parent) |
|
412 | 48 |
: QMainWindow(parent), pnetserver(0), pUdpServer(0) |
184 | 49 |
{ |
50 |
ui.setupUi(this); |
|
51 |
||
301 | 52 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 53 |
|
245 | 54 |
UpdateTeamsLists(); |
184 | 55 |
|
56 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
57 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
58 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
59 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
60 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
187 | 61 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
184 | 62 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close())); |
63 |
||
289 | 64 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 65 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
66 |
||
67 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
68 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
69 |
||
289 | 70 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 71 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
493 | 72 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
492 | 73 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
184 | 74 |
|
289 | 75 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 76 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
77 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 78 |
|
289 | 79 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 80 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
81 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
82 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 83 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 84 |
|
289 | 85 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 86 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
314 | 87 |
connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
418 | 88 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
416 | 89 |
connect(ui.pageNet->pUpdateUdpButt, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
90 |
connect(ui.pageNet->pUdpClient->serversList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(NetConnectServer())); |
|
184 | 91 |
|
289 | 92 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 93 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
493 | 94 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
492 | 95 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
493 | 96 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(NewTeam()), this, SLOT(NewTeam())); |
184 | 97 |
|
289 | 98 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 99 |
|
306 | 100 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
101 |
||
311 | 102 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(NewTeam()), this, SLOT(NewTeam())); |
103 |
||
290 | 104 |
GoToPage(ID_PAGE_MAIN); |
184 | 105 |
} |
106 |
||
245 | 107 |
void HWForm::UpdateTeamsLists() |
108 |
{ |
|
109 |
QStringList teamslist = config->GetTeamsList(); |
|
110 |
||
111 |
if(teamslist.empty()) { |
|
112 |
HWTeam defaultTeam("DefaultTeam"); |
|
113 |
defaultTeam.SaveToFile(); |
|
114 |
teamslist.push_back("DefaultTeam"); |
|
115 |
} |
|
116 |
||
117 |
ui.pageOptions->CBTeamName->clear(); |
|
118 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
119 |
} |
|
120 |
||
184 | 121 |
void HWForm::GoToMain() |
122 |
{ |
|
289 | 123 |
GoToPage(ID_PAGE_MAIN); |
184 | 124 |
} |
125 |
||
126 |
void HWForm::GoToSinglePlayer() |
|
127 |
{ |
|
289 | 128 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 129 |
} |
130 |
||
131 |
void HWForm::GoToSetup() |
|
132 |
{ |
|
289 | 133 |
GoToPage(ID_PAGE_SETUP); |
184 | 134 |
} |
135 |
||
187 | 136 |
void HWForm::GoToInfo() |
137 |
{ |
|
289 | 138 |
GoToPage(ID_PAGE_INFO); |
187 | 139 |
} |
140 |
||
184 | 141 |
void HWForm::GoToMultiplayer() |
142 |
{ |
|
290 | 143 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 144 |
} |
145 |
||
146 |
void HWForm::GoToDemos() |
|
147 |
{ |
|
148 |
QDir tmpdir; |
|
149 |
tmpdir.cd(cfgdir->absolutePath()); |
|
150 |
tmpdir.cd("Demos"); |
|
151 |
tmpdir.setFilter(QDir::Files); |
|
152 |
ui.pagePlayDemo->DemosList->clear(); |
|
271 | 153 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_" + cProtoVer)) |
154 |
.replaceInStrings(QRegExp("^(.*).hwd_" + cProtoVer), "\\1")); |
|
290 | 155 |
GoToPage(ID_PAGE_DEMOS); |
184 | 156 |
} |
157 |
||
158 |
void HWForm::GoToNet() |
|
159 |
{ |
|
289 | 160 |
GoToPage(ID_PAGE_NET); |
184 | 161 |
} |
162 |
||
496 | 163 |
void HWForm::OnPageShown(quint8 id, quint8 lastid) |
311 | 164 |
{ |
322 | 165 |
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) { |
311 | 166 |
QStringList tmNames=config->GetTeamsList(); |
322 | 167 |
TeamSelWidget* curTeamSelWidget; |
496 | 168 |
if(id == ID_PAGE_MULTIPLAYER) { |
169 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
|
170 |
} else { |
|
322 | 171 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
496 | 172 |
} |
311 | 173 |
QList<HWTeam> teamsList; |
174 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
175 |
HWTeam team(*it); |
|
176 |
team.LoadFromFile(); |
|
177 |
teamsList.push_back(team); |
|
178 |
} |
|
496 | 179 |
if(lastid==ID_PAGE_SETUP_TEAM) { |
180 |
if (editedTeam) curTeamSelWidget->addTeam(*editedTeam); |
|
181 |
} else { |
|
182 |
curTeamSelWidget->resetPlayingTeams(teamsList); |
|
183 |
} |
|
311 | 184 |
} |
185 |
} |
|
186 |
||
289 | 187 |
void HWForm::GoToPage(quint8 id) |
188 |
{ |
|
189 |
PagesStack.push(ui.Pages->currentIndex()); |
|
311 | 190 |
OnPageShown(id); |
289 | 191 |
ui.Pages->setCurrentIndex(id); |
192 |
} |
|
193 |
||
194 |
void HWForm::GoBack() |
|
195 |
{ |
|
350 | 196 |
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) { |
383 | 197 |
if(hwnet || pnetserver) NetDisconnect(); |
350 | 198 |
} |
289 | 199 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
496 | 200 |
OnPageShown(id, ui.Pages->currentIndex()); |
289 | 201 |
ui.Pages->setCurrentIndex(id); |
184 | 202 |
} |
203 |
||
204 |
void HWForm::NewTeam() |
|
205 |
{ |
|
245 | 206 |
editedTeam = new HWTeam("unnamed"); |
207 |
editedTeam->SetToPage(this); |
|
290 | 208 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 209 |
} |
210 |
||
211 |
void HWForm::EditTeam() |
|
212 |
{ |
|
245 | 213 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
214 |
editedTeam->LoadFromFile(); |
|
215 |
editedTeam->SetToPage(this); |
|
290 | 216 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 217 |
} |
218 |
||
219 |
void HWForm::TeamSave() |
|
220 |
{ |
|
245 | 221 |
editedTeam->GetFromPage(this); |
222 |
editedTeam->SaveToFile(); |
|
223 |
UpdateTeamsLists(); |
|
290 | 224 |
GoBack(); |
496 | 225 |
delete editedTeam; |
226 |
editedTeam=0; |
|
184 | 227 |
} |
228 |
||
229 |
void HWForm::TeamDiscard() |
|
230 |
{ |
|
245 | 231 |
delete editedTeam; |
496 | 232 |
editedTeam=0; |
290 | 233 |
GoBack(); |
184 | 234 |
} |
235 |
||
236 |
void HWForm::SimpleGame() |
|
237 |
{ |
|
341 | 238 |
CreateGame(ui.pageLocalGame->gameCFG, 0); |
184 | 239 |
game->StartQuick(); |
240 |
} |
|
241 |
||
242 |
void HWForm::PlayDemo() |
|
243 |
{ |
|
244 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
245 |
if (!curritem) |
|
246 |
{ |
|
247 |
QMessageBox::critical(this, |
|
248 |
tr("Error"), |
|
249 |
tr("Please, select demo from the list above"), |
|
250 |
tr("OK")); |
|
251 |
return ; |
|
252 |
} |
|
341 | 253 |
CreateGame(0, 0); |
271 | 254 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
184 | 255 |
} |
256 |
||
416 | 257 |
void HWForm::NetConnectServer() |
258 |
{ |
|
259 |
QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem(); |
|
260 |
if (!curritem) { |
|
261 |
QMessageBox::critical(this, |
|
262 |
tr("Error"), |
|
263 |
tr("Please, select server from the list above"), |
|
264 |
tr("OK")); |
|
265 |
return ; |
|
266 |
} |
|
267 |
_NetConnect(curritem->text(), 46631, ui.pageNet->editNetNick->text()); |
|
268 |
} |
|
269 |
||
314 | 270 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 271 |
{ |
465 | 272 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
273 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
448 | 274 |
connect(hwnet, SIGNAL(GameStateChanged(GameState)), this, SLOT(NetGameStateChanged(GameState))); |
184 | 275 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
276 |
connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
277 |
|
471 | 278 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 279 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
280 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
281 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 282 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 283 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 284 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 285 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 286 |
|
352 | 287 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
288 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 289 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
290 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 291 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 292 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 293 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&))); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
294 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
295 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(seedChanged(const QString &)), hwnet, SLOT(onSeedChanged(const QString &))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
296 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(mapChanged(const QString &)), hwnet, SLOT(onMapChanged(const QString &))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
297 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(themeChanged(const QString &)), hwnet, SLOT(onThemeChanged(const QString &))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
298 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(initHealthChanged(quint32)), hwnet, SLOT(onInitHealthChanged(quint32))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
299 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(turnTimeChanged(quint32)), hwnet, SLOT(onTurnTimeChanged(quint32))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
300 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(fortsModeChanged(bool)), hwnet, SLOT(onFortsModeChanged(bool))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
301 |
|
383 | 302 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 303 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
304 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
305 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
306 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
307 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
308 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 309 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 310 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 311 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 312 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
313 |
|
314 | 314 |
hwnet->Connect(hostName, port, nick); |
184 | 315 |
config->SaveOptions(); |
316 |
} |
|
317 |
||
314 | 318 |
void HWForm::NetConnect() |
319 |
{ |
|
320 |
_NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text()); |
|
321 |
} |
|
322 |
||
323 |
void HWForm::NetStartServer() |
|
324 |
{ |
|
325 |
pnetserver = new HWNetServer; |
|
326 |
pnetserver->StartServer(); |
|
449 | 327 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text()); |
412 | 328 |
pUdpServer = new HWNetUdpServer(); |
314 | 329 |
} |
330 |
||
184 | 331 |
void HWForm::NetDisconnect() |
332 |
{ |
|
383 | 333 |
if(hwnet) { |
334 |
hwnet->Disconnect(); |
|
335 |
delete hwnet; |
|
336 |
hwnet=0; |
|
337 |
} |
|
314 | 338 |
if(pnetserver) { |
412 | 339 |
pUdpServer->deleteLater(); |
314 | 340 |
pnetserver->StopServer(); |
341 |
delete pnetserver; |
|
342 |
pnetserver=0; |
|
343 |
} |
|
184 | 344 |
} |
345 |
||
383 | 346 |
void HWForm::ForcedDisconnect() |
347 |
{ |
|
348 |
if(pnetserver) return; // we have server - let it care of all things |
|
349 |
if (hwnet) { |
|
350 |
hwnet->deleteLater(); |
|
351 |
hwnet=0; |
|
425 | 352 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 353 |
QMessageBox::tr("Connection to server is lost")); |
383 | 354 |
} |
355 |
GoBack(); |
|
356 |
} |
|
357 |
||
184 | 358 |
void HWForm::NetGameEnter() |
359 |
{ |
|
290 | 360 |
GoToPage(ID_PAGE_NETCFG); |
184 | 361 |
} |
362 |
||
363 |
void HWForm::NetStartGame() |
|
364 |
{ |
|
448 | 365 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
366 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
367 |
hwnet->StartGame(); |
|
184 | 368 |
} |
369 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
370 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 371 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
372 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 373 |
} |
374 |
||
375 |
void HWForm::StartMPGame() |
|
376 |
{ |
|
341 | 377 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 378 |
|
184 | 379 |
game->StartLocal(); |
380 |
} |
|
306 | 381 |
|
448 | 382 |
void HWForm::NetGameStateChanged(GameState __attribute__((unused)) gameState) |
383 |
{ |
|
384 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
385 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
386 |
} |
|
387 |
||
306 | 388 |
void HWForm::GameStateChanged(GameState gameState) |
389 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
390 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
391 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
392 |
ui.pageGameStats->labelGameStats->setText(""); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
393 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
394 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
395 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
396 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
397 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
398 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
399 |
default: ; |
307 | 400 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
401 |
|
307 | 402 |
} |
403 |
||
404 |
void HWForm::AddStatText(const QString & msg) |
|
405 |
{ |
|
406 |
ui.pageGameStats->labelGameStats->setText( |
|
407 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 408 |
} |
409 |
||
410 |
void HWForm::GameStats(char type, const QString & info) |
|
411 |
{ |
|
412 |
switch(type) { |
|
307 | 413 |
case 'r' : { |
414 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
415 |
break; |
|
416 |
} |
|
417 |
case 'D' : { |
|
418 |
int i = info.indexOf(' '); |
|
419 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
420 |
.arg(info.mid(i + 1), info.left(i)); |
|
421 |
AddStatText(message); |
|
422 |
break; |
|
423 |
} |
|
424 |
case 'K' : { |
|
425 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
426 |
AddStatText(message); |
|
427 |
break; |
|
428 |
} |
|
306 | 429 |
} |
430 |
} |
|
431 |
||
341 | 432 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 433 |
{ |
341 | 434 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 435 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
436 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 437 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
306 | 438 |
} |
425 | 439 |
|
440 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
441 |
{ |
|
442 |
QMessageBox::warning(this, |
|
443 |
"Hedgewars", |
|
444 |
msg); |
|
445 |
} |