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