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