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