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