author | unc0rr |
Sun, 09 Dec 2007 14:12:01 +0000 | |
changeset 637 | 8fa7ed5e13bd |
parent 636 | dc93ac775bb9 |
child 646 | ed610c2cd0a4 |
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> |
636 | 33 |
#include <QRadioButton> |
184 | 34 |
|
35 |
#include "hwform.h" |
|
36 |
#include "game.h" |
|
37 |
#include "team.h" |
|
38 |
#include "teamselect.h" |
|
39 |
#include "gameuiconfig.h" |
|
40 |
#include "pages.h" |
|
41 |
#include "hwconsts.h" |
|
314 | 42 |
#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
|
43 |
#include "gamecfgwidget.h" |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
44 |
#include "netserverslist.h" |
634 | 45 |
#include "netudpserver.h" |
46 |
#include "netwwwserver.h" |
|
461 | 47 |
#include "chatwidget.h" |
579 | 48 |
#include "playrecordpage.h" |
184 | 49 |
|
50 |
HWForm::HWForm(QWidget *parent) |
|
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
51 |
: QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) |
184 | 52 |
{ |
53 |
ui.setupUi(this); |
|
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())); |
184 | 94 |
|
289 | 95 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 96 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
493 | 97 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
492 | 98 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
99 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 100 |
|
289 | 101 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 102 |
|
306 | 103 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
104 |
||
586 | 105 |
connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(GoToSimpleGame())); |
587 | 106 |
connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining())); |
586 | 107 |
connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
311 | 108 |
|
587 | 109 |
connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); |
110 |
connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
111 |
||
600 | 112 |
connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
113 |
||
290 | 114 |
GoToPage(ID_PAGE_MAIN); |
184 | 115 |
} |
116 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
117 |
void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
245 | 118 |
{ |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
119 |
QStringList teamslist; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
120 |
if(editable_teams) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
121 |
teamslist=*editable_teams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
122 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
123 |
teamslist = config->GetTeamsList(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
124 |
} |
245 | 125 |
|
126 |
if(teamslist.empty()) { |
|
127 |
HWTeam defaultTeam("DefaultTeam"); |
|
128 |
defaultTeam.SaveToFile(); |
|
129 |
teamslist.push_back("DefaultTeam"); |
|
130 |
} |
|
131 |
||
132 |
ui.pageOptions->CBTeamName->clear(); |
|
133 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
134 |
} |
|
135 |
||
184 | 136 |
void HWForm::GoToMain() |
137 |
{ |
|
289 | 138 |
GoToPage(ID_PAGE_MAIN); |
184 | 139 |
} |
140 |
||
141 |
void HWForm::GoToSinglePlayer() |
|
142 |
{ |
|
289 | 143 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 144 |
} |
145 |
||
586 | 146 |
void HWForm::GoToSimpleGame() |
147 |
{ |
|
148 |
GoToPage(ID_PAGE_SIMPLEGAME); |
|
149 |
} |
|
150 |
||
587 | 151 |
void HWForm::GoToTraining() |
152 |
{ |
|
153 |
GoToPage(ID_PAGE_TRAINING); |
|
154 |
} |
|
155 |
||
184 | 156 |
void HWForm::GoToSetup() |
157 |
{ |
|
289 | 158 |
GoToPage(ID_PAGE_SETUP); |
184 | 159 |
} |
160 |
||
600 | 161 |
void HWForm::GoToSelectWeapon() |
162 |
{ |
|
163 |
GoToPage(ID_PAGE_SELECTWEAPON); |
|
164 |
} |
|
165 |
||
187 | 166 |
void HWForm::GoToInfo() |
167 |
{ |
|
289 | 168 |
GoToPage(ID_PAGE_INFO); |
187 | 169 |
} |
170 |
||
184 | 171 |
void HWForm::GoToMultiplayer() |
172 |
{ |
|
290 | 173 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 174 |
} |
175 |
||
579 | 176 |
void HWForm::GoToSaves() |
177 |
{ |
|
581 | 178 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Save); |
579 | 179 |
|
180 |
GoToPage(ID_PAGE_DEMOS); |
|
181 |
} |
|
182 |
||
184 | 183 |
void HWForm::GoToDemos() |
184 |
{ |
|
581 | 185 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Demo); |
579 | 186 |
|
290 | 187 |
GoToPage(ID_PAGE_DEMOS); |
184 | 188 |
} |
189 |
||
190 |
void HWForm::GoToNet() |
|
191 |
{ |
|
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
192 |
ui.pageNet->changeServersList(); |
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
193 |
connect(ui.pageNet->netServersWidget->serversList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(NetConnectServer())); |
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
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 |
{ |
|
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
335 |
QListWidgetItem * curritem = ui.pageNet->netServersWidget->serversList->currentItem(); |
416 | 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 |
{ |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
348 |
if(hwnet) { |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
349 |
hwnet->Disconnect(); |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
350 |
delete hwnet; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
351 |
hwnet=0; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
352 |
} |
465 | 353 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
354 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
355 |
|
448 | 356 |
connect(hwnet, SIGNAL(GameStateChanged(GameState)), this, SLOT(NetGameStateChanged(GameState))); |
184 | 357 |
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
|
358 |
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
|
359 |
|
471 | 360 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 361 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
362 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
363 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 364 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 365 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 366 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 367 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 368 |
|
352 | 369 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
370 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 371 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
372 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 373 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 374 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 375 |
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
|
376 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
377 |
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
|
378 |
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
|
379 |
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
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
|
383 | 384 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 385 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
386 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
387 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
388 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
389 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
390 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 391 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 392 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 393 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 394 |
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
|
395 |
|
314 | 396 |
hwnet->Connect(hostName, port, nick); |
184 | 397 |
config->SaveOptions(); |
398 |
} |
|
399 |
||
314 | 400 |
void HWForm::NetConnect() |
401 |
{ |
|
402 |
_NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text()); |
|
403 |
} |
|
404 |
||
405 |
void HWForm::NetStartServer() |
|
406 |
{ |
|
407 |
pnetserver = new HWNetServer; |
|
408 |
pnetserver->StartServer(); |
|
449 | 409 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text()); |
636 | 410 |
|
411 |
if (ui.pageNet->rbLocalGame->isChecked()) |
|
412 |
pRegisterServer = new HWNetUdpServer(0, "hedgewars server", 46631); |
|
413 |
else |
|
414 |
pRegisterServer = new HWNetWwwServer(0, "hedgewars server", 46631); |
|
314 | 415 |
} |
416 |
||
184 | 417 |
void HWForm::NetDisconnect() |
418 |
{ |
|
383 | 419 |
if(hwnet) { |
420 |
hwnet->Disconnect(); |
|
421 |
delete hwnet; |
|
422 |
hwnet=0; |
|
423 |
} |
|
314 | 424 |
if(pnetserver) { |
635 | 425 |
pRegisterServer->unregister(); |
634 | 426 |
pRegisterServer->deleteLater(); |
314 | 427 |
pnetserver->StopServer(); |
428 |
delete pnetserver; |
|
429 |
pnetserver=0; |
|
430 |
} |
|
184 | 431 |
} |
432 |
||
383 | 433 |
void HWForm::ForcedDisconnect() |
434 |
{ |
|
435 |
if(pnetserver) return; // we have server - let it care of all things |
|
436 |
if (hwnet) { |
|
437 |
hwnet->deleteLater(); |
|
438 |
hwnet=0; |
|
425 | 439 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 440 |
QMessageBox::tr("Connection to server is lost")); |
383 | 441 |
} |
442 |
GoBack(); |
|
443 |
} |
|
444 |
||
184 | 445 |
void HWForm::NetGameEnter() |
446 |
{ |
|
290 | 447 |
GoToPage(ID_PAGE_NETCFG); |
184 | 448 |
} |
449 |
||
450 |
void HWForm::NetStartGame() |
|
451 |
{ |
|
448 | 452 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
453 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
454 |
hwnet->StartGame(); |
|
184 | 455 |
} |
456 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
457 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 458 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
459 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 460 |
} |
461 |
||
462 |
void HWForm::StartMPGame() |
|
463 |
{ |
|
341 | 464 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 465 |
|
184 | 466 |
game->StartLocal(); |
467 |
} |
|
306 | 468 |
|
448 | 469 |
void HWForm::NetGameStateChanged(GameState __attribute__((unused)) gameState) |
470 |
{ |
|
471 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
472 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
473 |
} |
|
474 |
||
306 | 475 |
void HWForm::GameStateChanged(GameState gameState) |
476 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
477 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
478 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
479 |
ui.pageGameStats->labelGameStats->setText(""); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
480 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
481 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
482 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
483 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
484 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
485 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
486 |
default: ; |
307 | 487 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
488 |
|
307 | 489 |
} |
490 |
||
491 |
void HWForm::AddStatText(const QString & msg) |
|
492 |
{ |
|
493 |
ui.pageGameStats->labelGameStats->setText( |
|
494 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 495 |
} |
496 |
||
497 |
void HWForm::GameStats(char type, const QString & info) |
|
498 |
{ |
|
499 |
switch(type) { |
|
307 | 500 |
case 'r' : { |
501 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
502 |
break; |
|
503 |
} |
|
504 |
case 'D' : { |
|
505 |
int i = info.indexOf(' '); |
|
506 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
507 |
.arg(info.mid(i + 1), info.left(i)); |
|
508 |
AddStatText(message); |
|
509 |
break; |
|
510 |
} |
|
511 |
case 'K' : { |
|
512 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
513 |
AddStatText(message); |
|
514 |
break; |
|
515 |
} |
|
306 | 516 |
} |
517 |
} |
|
518 |
||
341 | 519 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 520 |
{ |
341 | 521 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 522 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
523 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 524 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 525 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 526 |
} |
425 | 527 |
|
528 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
529 |
{ |
|
530 |
QMessageBox::warning(this, |
|
531 |
"Hedgewars", |
|
532 |
msg); |
|
533 |
} |
|
533 | 534 |
|
535 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
536 |
{ |
|
537 |
QString filename; |
|
538 |
QByteArray demo = record; |
|
539 |
if (isDemo) |
|
540 |
{ |
|
541 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
542 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
579 | 543 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer; |
533 | 544 |
} else |
545 |
{ |
|
546 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
547 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
579 | 548 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer; |
533 | 549 |
} |
550 |
||
551 |
||
552 |
QFile demofile(filename); |
|
553 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
554 |
{ |
|
555 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
556 |
return ; |
|
557 |
} |
|
558 |
demofile.write(demo.constData(), demo.size()); |
|
559 |
demofile.close(); |
|
560 |
} |
|
587 | 561 |
|
562 |
void HWForm::StartTraining() |
|
563 |
{ |
|
564 |
CreateGame(0, 0); |
|
565 |
||
566 |
game->StartTraining(); |
|
567 |
} |