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