author | unc0rr |
Tue, 18 Sep 2007 19:52:46 +0000 | |
changeset 600 | f6e5f4e122db |
parent 597 | ec5f057ab268 |
child 601 | 78a68cc4d846 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QStringList> |
|
20 |
#include <QProcess> |
|
21 |
#include <QDir> |
|
22 |
#include <QPixmap> |
|
23 |
#include <QRegExp> |
|
24 |
#include <QIcon> |
|
25 |
#include <QFile> |
|
26 |
#include <QTextStream> |
|
407 | 27 |
#include <QMessageBox> |
502
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
28 |
#include <QPushButton> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
29 |
#include <QListWidget> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
30 |
#include <QStackedLayout> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
31 |
#include <QLineEdit> |
bc178daca088
Fix build with CMake & gcc 4.1.2 on my system (treating #include <QtGui> as including directory)
unc0rr
parents:
496
diff
changeset
|
32 |
#include <QLabel> |
184 | 33 |
|
34 |
#include "hwform.h" |
|
35 |
#include "game.h" |
|
36 |
#include "team.h" |
|
37 |
#include "teamselect.h" |
|
38 |
#include "gameuiconfig.h" |
|
39 |
#include "pages.h" |
|
40 |
#include "hwconsts.h" |
|
314 | 41 |
#include "newnetclient.h" |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
42 |
#include "gamecfgwidget.h" |
412 | 43 |
#include "netudpserver.h" |
416 | 44 |
#include "netudpwidget.h" |
461 | 45 |
#include "chatwidget.h" |
579 | 46 |
#include "playrecordpage.h" |
597
ec5f057ab268
kdevelop project add, initial weapons scheme button
displacer
parents:
587
diff
changeset
|
47 |
#include "selectWeapon.h" |
184 | 48 |
|
49 |
HWForm::HWForm(QWidget *parent) |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
50 |
: QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0) |
184 | 51 |
{ |
52 |
ui.setupUi(this); |
|
53 |
||
301 | 54 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 55 |
|
245 | 56 |
UpdateTeamsLists(); |
184 | 57 |
|
58 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
59 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
60 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
579 | 61 |
connect(ui.pageMain->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
184 | 62 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
63 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
187 | 64 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
530 | 65 |
connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); |
66 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); |
|
184 | 67 |
|
585
7531ae5b146e
Rename PageLocalGame -> PageSimpleGame due to future changes
unc0rr
parents:
581
diff
changeset
|
68 |
connect(ui.pageSimpleGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
7531ae5b146e
Rename PageLocalGame -> PageSimpleGame due to future changes
unc0rr
parents:
581
diff
changeset
|
69 |
connect(ui.pageSimpleGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
184 | 70 |
|
71 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
72 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
73 |
||
289 | 74 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 75 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
493 | 76 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
492 | 77 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
586 | 78 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 79 |
|
289 | 80 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 81 |
connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
82 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 83 |
|
289 | 84 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 85 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
86 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
87 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 88 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
600 | 89 |
connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); |
597
ec5f057ab268
kdevelop project add, initial weapons scheme button
displacer
parents:
587
diff
changeset
|
90 |
// TODO |
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())); |
418 | 95 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
416 | 96 |
connect(ui.pageNet->pUpdateUdpButt, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
97 |
connect(ui.pageNet->pUdpClient->serversList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(NetConnectServer())); |
|
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 |
{ |
|
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 |
{ |
|
336 |
QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem(); |
|
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()); |
412 | 405 |
pUdpServer = new HWNetUdpServer(); |
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) { |
412 | 416 |
pUdpServer->deleteLater(); |
314 | 417 |
pnetserver->StopServer(); |
418 |
delete pnetserver; |
|
419 |
pnetserver=0; |
|
420 |
} |
|
184 | 421 |
} |
422 |
||
383 | 423 |
void HWForm::ForcedDisconnect() |
424 |
{ |
|
425 |
if(pnetserver) return; // we have server - let it care of all things |
|
426 |
if (hwnet) { |
|
427 |
hwnet->deleteLater(); |
|
428 |
hwnet=0; |
|
425 | 429 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 430 |
QMessageBox::tr("Connection to server is lost")); |
383 | 431 |
} |
432 |
GoBack(); |
|
433 |
} |
|
434 |
||
184 | 435 |
void HWForm::NetGameEnter() |
436 |
{ |
|
290 | 437 |
GoToPage(ID_PAGE_NETCFG); |
184 | 438 |
} |
439 |
||
440 |
void HWForm::NetStartGame() |
|
441 |
{ |
|
448 | 442 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
443 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
444 |
hwnet->StartGame(); |
|
184 | 445 |
} |
446 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
447 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 448 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
449 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 450 |
} |
451 |
||
452 |
void HWForm::StartMPGame() |
|
453 |
{ |
|
341 | 454 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 455 |
|
184 | 456 |
game->StartLocal(); |
457 |
} |
|
306 | 458 |
|
448 | 459 |
void HWForm::NetGameStateChanged(GameState __attribute__((unused)) gameState) |
460 |
{ |
|
461 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
462 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
463 |
} |
|
464 |
||
306 | 465 |
void HWForm::GameStateChanged(GameState gameState) |
466 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
467 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
468 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
469 |
ui.pageGameStats->labelGameStats->setText(""); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
470 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
471 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
472 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
473 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
474 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
475 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
476 |
default: ; |
307 | 477 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
478 |
|
307 | 479 |
} |
480 |
||
481 |
void HWForm::AddStatText(const QString & msg) |
|
482 |
{ |
|
483 |
ui.pageGameStats->labelGameStats->setText( |
|
484 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 485 |
} |
486 |
||
487 |
void HWForm::GameStats(char type, const QString & info) |
|
488 |
{ |
|
489 |
switch(type) { |
|
307 | 490 |
case 'r' : { |
491 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
492 |
break; |
|
493 |
} |
|
494 |
case 'D' : { |
|
495 |
int i = info.indexOf(' '); |
|
496 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
497 |
.arg(info.mid(i + 1), info.left(i)); |
|
498 |
AddStatText(message); |
|
499 |
break; |
|
500 |
} |
|
501 |
case 'K' : { |
|
502 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
503 |
AddStatText(message); |
|
504 |
break; |
|
505 |
} |
|
306 | 506 |
} |
507 |
} |
|
508 |
||
341 | 509 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 510 |
{ |
341 | 511 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 512 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
513 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 514 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 515 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 516 |
} |
425 | 517 |
|
518 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
519 |
{ |
|
520 |
QMessageBox::warning(this, |
|
521 |
"Hedgewars", |
|
522 |
msg); |
|
523 |
} |
|
533 | 524 |
|
525 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
526 |
{ |
|
527 |
QString filename; |
|
528 |
QByteArray demo = record; |
|
529 |
if (isDemo) |
|
530 |
{ |
|
531 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
532 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
579 | 533 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer; |
533 | 534 |
} else |
535 |
{ |
|
536 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
537 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
579 | 538 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer; |
533 | 539 |
} |
540 |
||
541 |
||
542 |
QFile demofile(filename); |
|
543 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
544 |
{ |
|
545 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
546 |
return ; |
|
547 |
} |
|
548 |
demofile.write(demo.constData(), demo.size()); |
|
549 |
demofile.close(); |
|
550 |
} |
|
587 | 551 |
|
552 |
void HWForm::StartTraining() |
|
553 |
{ |
|
554 |
CreateGame(0, 0); |
|
555 |
||
556 |
game->StartTraining(); |
|
557 |
} |