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