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