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