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