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