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