author | displacer |
Sat, 24 Feb 2007 08:56:58 +0000 | |
changeset 492 | 78e80f899b59 |
parent 486 | 7ea71cd3acd5 |
child 493 | 0c0ed17ad675 |
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 <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())); |
492 | 68 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
69 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
|
184 | 70 |
|
289 | 71 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 72 |
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
|
73 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 74 |
|
289 | 75 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 76 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
77 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
78 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 79 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 80 |
|
289 | 81 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 82 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
314 | 83 |
connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
418 | 84 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
416 | 85 |
connect(ui.pageNet->pUpdateUdpButt, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
86 |
connect(ui.pageNet->pUdpClient->serversList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(NetConnectServer())); |
|
184 | 87 |
|
289 | 88 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 89 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
492 | 90 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
91 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
|
184 | 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 |
||
311 | 158 |
void HWForm::OnPageShown(quint8 id) |
159 |
{ |
|
322 | 160 |
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) { |
311 | 161 |
QStringList tmNames=config->GetTeamsList(); |
322 | 162 |
TeamSelWidget* curTeamSelWidget; |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
163 |
id == ID_PAGE_MULTIPLAYER ? curTeamSelWidget=ui.pageMultiplayer->teamsSelect : |
322 | 164 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
311 | 165 |
QList<HWTeam> teamsList; |
166 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
167 |
HWTeam team(*it); |
|
168 |
team.LoadFromFile(); |
|
169 |
teamsList.push_back(team); |
|
170 |
} |
|
322 | 171 |
curTeamSelWidget->resetPlayingTeams(teamsList); |
311 | 172 |
} |
173 |
} |
|
174 |
||
289 | 175 |
void HWForm::GoToPage(quint8 id) |
176 |
{ |
|
177 |
PagesStack.push(ui.Pages->currentIndex()); |
|
311 | 178 |
OnPageShown(id); |
289 | 179 |
ui.Pages->setCurrentIndex(id); |
180 |
} |
|
181 |
||
182 |
void HWForm::GoBack() |
|
183 |
{ |
|
350 | 184 |
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) { |
383 | 185 |
if(hwnet || pnetserver) NetDisconnect(); |
350 | 186 |
} |
289 | 187 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
311 | 188 |
OnPageShown(id); |
289 | 189 |
ui.Pages->setCurrentIndex(id); |
184 | 190 |
} |
191 |
||
192 |
void HWForm::NewTeam() |
|
193 |
{ |
|
245 | 194 |
editedTeam = new HWTeam("unnamed"); |
195 |
editedTeam->SetToPage(this); |
|
290 | 196 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 197 |
} |
198 |
||
199 |
void HWForm::EditTeam() |
|
200 |
{ |
|
245 | 201 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
202 |
editedTeam->LoadFromFile(); |
|
203 |
editedTeam->SetToPage(this); |
|
290 | 204 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 205 |
} |
206 |
||
207 |
void HWForm::TeamSave() |
|
208 |
{ |
|
245 | 209 |
editedTeam->GetFromPage(this); |
210 |
editedTeam->SaveToFile(); |
|
211 |
delete editedTeam; |
|
212 |
UpdateTeamsLists(); |
|
290 | 213 |
GoBack(); |
184 | 214 |
} |
215 |
||
216 |
void HWForm::TeamDiscard() |
|
217 |
{ |
|
245 | 218 |
delete editedTeam; |
290 | 219 |
GoBack(); |
184 | 220 |
} |
221 |
||
222 |
void HWForm::SimpleGame() |
|
223 |
{ |
|
341 | 224 |
CreateGame(ui.pageLocalGame->gameCFG, 0); |
184 | 225 |
game->StartQuick(); |
226 |
} |
|
227 |
||
228 |
void HWForm::PlayDemo() |
|
229 |
{ |
|
230 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
231 |
if (!curritem) |
|
232 |
{ |
|
233 |
QMessageBox::critical(this, |
|
234 |
tr("Error"), |
|
235 |
tr("Please, select demo from the list above"), |
|
236 |
tr("OK")); |
|
237 |
return ; |
|
238 |
} |
|
341 | 239 |
CreateGame(0, 0); |
271 | 240 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
184 | 241 |
} |
242 |
||
416 | 243 |
void HWForm::NetConnectServer() |
244 |
{ |
|
245 |
QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem(); |
|
246 |
if (!curritem) { |
|
247 |
QMessageBox::critical(this, |
|
248 |
tr("Error"), |
|
249 |
tr("Please, select server from the list above"), |
|
250 |
tr("OK")); |
|
251 |
return ; |
|
252 |
} |
|
253 |
_NetConnect(curritem->text(), 46631, ui.pageNet->editNetNick->text()); |
|
254 |
} |
|
255 |
||
314 | 256 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 257 |
{ |
465 | 258 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
259 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
448 | 260 |
connect(hwnet, SIGNAL(GameStateChanged(GameState)), this, SLOT(NetGameStateChanged(GameState))); |
184 | 261 |
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
|
262 |
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
|
263 |
|
471 | 264 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 265 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
266 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
267 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 268 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 269 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 270 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 271 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 272 |
|
352 | 273 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
274 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 275 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
276 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 277 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 278 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 279 |
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
|
280 |
|
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(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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
|
383 | 288 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 289 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
290 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
291 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
292 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
293 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
294 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 295 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 296 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 297 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 298 |
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
|
299 |
|
314 | 300 |
hwnet->Connect(hostName, port, nick); |
184 | 301 |
config->SaveOptions(); |
302 |
} |
|
303 |
||
314 | 304 |
void HWForm::NetConnect() |
305 |
{ |
|
306 |
_NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text()); |
|
307 |
} |
|
308 |
||
309 |
void HWForm::NetStartServer() |
|
310 |
{ |
|
311 |
pnetserver = new HWNetServer; |
|
312 |
pnetserver->StartServer(); |
|
449 | 313 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text()); |
412 | 314 |
pUdpServer = new HWNetUdpServer(); |
314 | 315 |
} |
316 |
||
184 | 317 |
void HWForm::NetDisconnect() |
318 |
{ |
|
383 | 319 |
if(hwnet) { |
320 |
hwnet->Disconnect(); |
|
321 |
delete hwnet; |
|
322 |
hwnet=0; |
|
323 |
} |
|
314 | 324 |
if(pnetserver) { |
412 | 325 |
pUdpServer->deleteLater(); |
314 | 326 |
pnetserver->StopServer(); |
327 |
delete pnetserver; |
|
328 |
pnetserver=0; |
|
329 |
} |
|
184 | 330 |
} |
331 |
||
383 | 332 |
void HWForm::ForcedDisconnect() |
333 |
{ |
|
334 |
if(pnetserver) return; // we have server - let it care of all things |
|
335 |
if (hwnet) { |
|
336 |
hwnet->deleteLater(); |
|
337 |
hwnet=0; |
|
425 | 338 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 339 |
QMessageBox::tr("Connection to server is lost")); |
383 | 340 |
} |
341 |
GoBack(); |
|
342 |
} |
|
343 |
||
184 | 344 |
void HWForm::NetGameEnter() |
345 |
{ |
|
290 | 346 |
GoToPage(ID_PAGE_NETCFG); |
184 | 347 |
} |
348 |
||
349 |
void HWForm::NetStartGame() |
|
350 |
{ |
|
448 | 351 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
352 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
353 |
hwnet->StartGame(); |
|
184 | 354 |
} |
355 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
356 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 357 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
358 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 359 |
} |
360 |
||
361 |
void HWForm::StartMPGame() |
|
362 |
{ |
|
341 | 363 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 364 |
|
184 | 365 |
game->StartLocal(); |
366 |
} |
|
306 | 367 |
|
448 | 368 |
void HWForm::NetGameStateChanged(GameState __attribute__((unused)) gameState) |
369 |
{ |
|
370 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
371 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
372 |
} |
|
373 |
||
306 | 374 |
void HWForm::GameStateChanged(GameState gameState) |
375 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
376 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
377 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
378 |
ui.pageGameStats->labelGameStats->setText(""); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
379 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
380 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
381 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
382 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
383 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
384 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
385 |
default: ; |
307 | 386 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
387 |
|
307 | 388 |
} |
389 |
||
390 |
void HWForm::AddStatText(const QString & msg) |
|
391 |
{ |
|
392 |
ui.pageGameStats->labelGameStats->setText( |
|
393 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 394 |
} |
395 |
||
396 |
void HWForm::GameStats(char type, const QString & info) |
|
397 |
{ |
|
398 |
switch(type) { |
|
307 | 399 |
case 'r' : { |
400 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
401 |
break; |
|
402 |
} |
|
403 |
case 'D' : { |
|
404 |
int i = info.indexOf(' '); |
|
405 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
406 |
.arg(info.mid(i + 1), info.left(i)); |
|
407 |
AddStatText(message); |
|
408 |
break; |
|
409 |
} |
|
410 |
case 'K' : { |
|
411 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
412 |
AddStatText(message); |
|
413 |
break; |
|
414 |
} |
|
306 | 415 |
} |
416 |
} |
|
417 |
||
341 | 418 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 419 |
{ |
341 | 420 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 421 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
422 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 423 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
306 | 424 |
} |
425 | 425 |
|
426 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
427 |
{ |
|
428 |
QMessageBox::warning(this, |
|
429 |
"Hedgewars", |
|
430 |
msg); |
|
431 |
} |