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