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