author | displacer |
Thu, 07 Aug 2008 13:38:24 +0000 | |
changeset 1163 | 5186cf914549 |
parent 1162 | 91bf5e3e558d |
child 1165 | 40eeae82e70b |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2005-2008 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 <QFile> |
|
20 |
#include <QTextStream> |
|
407 | 21 |
#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
|
22 |
#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
|
23 |
#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
|
24 |
#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
|
25 |
#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
|
26 |
#include <QLabel> |
636 | 27 |
#include <QRadioButton> |
654 | 28 |
#include <QSpinBox> |
674 | 29 |
#include <QCloseEvent> |
184 | 30 |
|
31 |
#include "hwform.h" |
|
32 |
#include "game.h" |
|
33 |
#include "team.h" |
|
34 |
#include "teamselect.h" |
|
681 | 35 |
#include "selectWeapon.h" |
184 | 36 |
#include "gameuiconfig.h" |
37 |
#include "pages.h" |
|
38 |
#include "hwconsts.h" |
|
314 | 39 |
#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
|
40 |
#include "gamecfgwidget.h" |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
41 |
#include "netserverslist.h" |
634 | 42 |
#include "netudpserver.h" |
43 |
#include "netwwwserver.h" |
|
461 | 44 |
#include "chatwidget.h" |
579 | 45 |
#include "playrecordpage.h" |
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
46 |
#include "input_ip.h" |
184 | 47 |
|
48 |
HWForm::HWForm(QWidget *parent) |
|
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
49 |
: QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) |
184 | 50 |
{ |
51 |
ui.setupUi(this); |
|
301 | 52 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 53 |
|
245 | 54 |
UpdateTeamsLists(); |
695 | 55 |
UpdateWeapons(); |
184 | 56 |
|
1162 | 57 |
connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool))); |
58 |
onFrontendFullscreen(config->isFrontendFullscreen()); |
|
59 |
||
184 | 60 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
61 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
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 |
|
67 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
68 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
69 |
||
289 | 70 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 71 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
493 | 72 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
492 | 73 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
586 | 74 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 75 |
|
289 | 76 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 77 |
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
|
78 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 79 |
|
289 | 80 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 81 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
82 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
83 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 84 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
695 | 85 |
|
694 | 86 |
connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); |
87 |
connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon())); |
|
695 | 88 |
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons())); |
697 | 89 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&))); |
184 | 90 |
|
289 | 91 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
92 |
connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
646 | 93 |
connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
666 | 94 |
connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
646 | 95 |
|
96 |
connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
97 |
connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
|
184 | 98 |
|
289 | 99 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 100 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
493 | 101 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
492 | 102 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
103 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 104 |
|
289 | 105 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 106 |
|
306 | 107 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
108 |
||
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
724
diff
changeset
|
109 |
connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
587 | 110 |
connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining())); |
1150 | 111 |
connect(ui.pageSinglePlayer->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
112 |
connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
|
113 |
connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
586 | 114 |
connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
311 | 115 |
|
587 | 116 |
connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); |
117 |
connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
118 |
||
600 | 119 |
connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
683 | 120 |
connect(ui.pageSelectWeapon->BtnDefault, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(setDefault())); |
121 |
connect(ui.pageSelectWeapon->BtnSave, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(save())); |
|
600 | 122 |
|
718 | 123 |
connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()), |
124 |
ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first |
|
724 | 125 |
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
718 | 126 |
this, SLOT(UpdateWeapons())); // executed second |
724 | 127 |
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
718 | 128 |
this, SLOT(GoBack())); // executed third |
129 |
||
290 | 130 |
GoToPage(ID_PAGE_MAIN); |
184 | 131 |
} |
132 |
||
1162 | 133 |
void HWForm::onFrontendFullscreen(bool value) |
134 |
{ |
|
135 |
qDebug() << "fullscreen = " << value; |
|
1163 | 136 |
if (value) |
137 |
setWindowState(windowState() | Qt::WindowFullScreen); |
|
138 |
else { |
|
139 |
setWindowState(windowState() & !Qt::WindowFullScreen); |
|
140 |
} |
|
1162 | 141 |
} |
142 |
||
695 | 143 |
void HWForm::UpdateWeapons() |
144 |
{ |
|
702 | 145 |
// FIXME: rewrite this with boost (or TR1/0x) |
146 |
QVector<QComboBox*> combos; |
|
147 |
combos.push_back(ui.pageOptions->WeaponsName); |
|
148 |
combos.push_back(ui.pageMultiplayer->gameCFG->WeaponsName); |
|
149 |
combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName); |
|
696 | 150 |
|
702 | 151 |
for(QVector<QComboBox*>::iterator it=combos.begin(); it!=combos.end(); ++it) { |
152 |
(*it)->clear(); |
|
153 |
(*it)->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames()); |
|
154 |
int pos=(*it)->findText("Default"); |
|
155 |
if (pos!=-1) { |
|
156 |
(*it)->setCurrentIndex(pos); |
|
157 |
} |
|
158 |
} |
|
695 | 159 |
} |
160 |
||
697 | 161 |
void HWForm::NetWeaponNameChanged(const QString& name) |
162 |
{ |
|
163 |
QString ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText()); |
|
703 | 164 |
hwnet->onWeaponsNameChanged(name, ammo); |
697 | 165 |
} |
166 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
167 |
void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
245 | 168 |
{ |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
169 |
QStringList teamslist; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
170 |
if(editable_teams) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
171 |
teamslist=*editable_teams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
172 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
173 |
teamslist = config->GetTeamsList(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
174 |
} |
245 | 175 |
|
176 |
if(teamslist.empty()) { |
|
177 |
HWTeam defaultTeam("DefaultTeam"); |
|
178 |
defaultTeam.SaveToFile(); |
|
179 |
teamslist.push_back("DefaultTeam"); |
|
180 |
} |
|
181 |
||
182 |
ui.pageOptions->CBTeamName->clear(); |
|
183 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
184 |
} |
|
185 |
||
184 | 186 |
void HWForm::GoToMain() |
187 |
{ |
|
289 | 188 |
GoToPage(ID_PAGE_MAIN); |
184 | 189 |
} |
190 |
||
191 |
void HWForm::GoToSinglePlayer() |
|
192 |
{ |
|
289 | 193 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 194 |
} |
195 |
||
587 | 196 |
void HWForm::GoToTraining() |
197 |
{ |
|
198 |
GoToPage(ID_PAGE_TRAINING); |
|
199 |
} |
|
200 |
||
184 | 201 |
void HWForm::GoToSetup() |
202 |
{ |
|
289 | 203 |
GoToPage(ID_PAGE_SETUP); |
184 | 204 |
} |
205 |
||
694 | 206 |
void HWForm::GoToSelectNewWeapon() |
207 |
{ |
|
717 | 208 |
ui.pageSelectWeapon->pWeapons->setWeaponsName("", false); |
694 | 209 |
GoToPage(ID_PAGE_SELECTWEAPON); |
210 |
} |
|
211 |
||
600 | 212 |
void HWForm::GoToSelectWeapon() |
213 |
{ |
|
717 | 214 |
ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText(), true); |
600 | 215 |
GoToPage(ID_PAGE_SELECTWEAPON); |
216 |
} |
|
217 |
||
187 | 218 |
void HWForm::GoToInfo() |
219 |
{ |
|
289 | 220 |
GoToPage(ID_PAGE_INFO); |
187 | 221 |
} |
222 |
||
184 | 223 |
void HWForm::GoToMultiplayer() |
224 |
{ |
|
290 | 225 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 226 |
} |
227 |
||
579 | 228 |
void HWForm::GoToSaves() |
229 |
{ |
|
581 | 230 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Save); |
579 | 231 |
|
232 |
GoToPage(ID_PAGE_DEMOS); |
|
233 |
} |
|
234 |
||
184 | 235 |
void HWForm::GoToDemos() |
236 |
{ |
|
581 | 237 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Demo); |
579 | 238 |
|
290 | 239 |
GoToPage(ID_PAGE_DEMOS); |
184 | 240 |
} |
241 |
||
242 |
void HWForm::GoToNet() |
|
243 |
{ |
|
646 | 244 |
ui.pageNet->updateServersList(); |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
245 |
|
289 | 246 |
GoToPage(ID_PAGE_NET); |
184 | 247 |
} |
248 |
||
646 | 249 |
void HWForm::GoToNetServer() |
250 |
{ |
|
251 |
GoToPage(ID_PAGE_NETSERVER); |
|
252 |
} |
|
253 |
||
496 | 254 |
void HWForm::OnPageShown(quint8 id, quint8 lastid) |
311 | 255 |
{ |
322 | 256 |
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) { |
311 | 257 |
QStringList tmNames=config->GetTeamsList(); |
322 | 258 |
TeamSelWidget* curTeamSelWidget; |
496 | 259 |
if(id == ID_PAGE_MULTIPLAYER) { |
260 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
|
261 |
} else { |
|
322 | 262 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
496 | 263 |
} |
311 | 264 |
QList<HWTeam> teamsList; |
265 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
266 |
HWTeam team(*it); |
|
267 |
team.LoadFromFile(); |
|
268 |
teamsList.push_back(team); |
|
269 |
} |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
270 |
if(lastid==ID_PAGE_SETUP) { // _TEAM |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
271 |
if (editedTeam) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
272 |
curTeamSelWidget->addTeam(*editedTeam); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
273 |
} |
496 | 274 |
} else { |
275 |
curTeamSelWidget->resetPlayingTeams(teamsList); |
|
276 |
} |
|
311 | 277 |
} |
278 |
} |
|
279 |
||
289 | 280 |
void HWForm::GoToPage(quint8 id) |
281 |
{ |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
282 |
quint8 lastid=ui.Pages->currentIndex(); |
289 | 283 |
PagesStack.push(ui.Pages->currentIndex()); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
284 |
OnPageShown(id, lastid); |
289 | 285 |
ui.Pages->setCurrentIndex(id); |
286 |
} |
|
287 |
||
288 |
void HWForm::GoBack() |
|
289 |
{ |
|
350 | 290 |
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) { |
383 | 291 |
if(hwnet || pnetserver) NetDisconnect(); |
350 | 292 |
} |
289 | 293 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
496 | 294 |
OnPageShown(id, ui.Pages->currentIndex()); |
289 | 295 |
ui.Pages->setCurrentIndex(id); |
184 | 296 |
} |
297 |
||
530 | 298 |
void HWForm::btnExitPressed() |
299 |
{ |
|
300 |
eggTimer.start(); |
|
301 |
} |
|
302 |
||
303 |
void HWForm::btnExitClicked() |
|
304 |
{ |
|
305 |
if (eggTimer.elapsed() < 3000) |
|
306 |
close(); |
|
307 |
else |
|
308 |
{ |
|
309 |
QPushButton * btn = findChild<QPushButton *>("imageButt"); |
|
310 |
if (btn) |
|
311 |
{ |
|
312 |
btn->setIcon(QIcon(":/res/bonus.png")); |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
317 |
void HWForm::IntermediateSetup() |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
318 |
{ |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
319 |
quint8 id=ui.Pages->currentIndex(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
320 |
TeamSelWidget* curTeamSelWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
321 |
if(id == ID_PAGE_MULTIPLAYER) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
322 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
323 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
324 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
325 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
326 |
QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
327 |
QStringList tmnames; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
328 |
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
|
329 |
tmnames+=it->TeamName; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
330 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
331 |
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
|
332 |
|
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
333 |
GoToPage(ID_PAGE_SETUP); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
334 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
335 |
|
184 | 336 |
void HWForm::NewTeam() |
337 |
{ |
|
245 | 338 |
editedTeam = new HWTeam("unnamed"); |
339 |
editedTeam->SetToPage(this); |
|
290 | 340 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 341 |
} |
342 |
||
343 |
void HWForm::EditTeam() |
|
344 |
{ |
|
245 | 345 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
346 |
editedTeam->LoadFromFile(); |
|
347 |
editedTeam->SetToPage(this); |
|
290 | 348 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 349 |
} |
350 |
||
351 |
void HWForm::TeamSave() |
|
352 |
{ |
|
245 | 353 |
editedTeam->GetFromPage(this); |
354 |
editedTeam->SaveToFile(); |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
355 |
delete editedTeam; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
356 |
editedTeam=0; |
245 | 357 |
UpdateTeamsLists(); |
290 | 358 |
GoBack(); |
184 | 359 |
} |
360 |
||
361 |
void HWForm::TeamDiscard() |
|
362 |
{ |
|
245 | 363 |
delete editedTeam; |
496 | 364 |
editedTeam=0; |
290 | 365 |
GoBack(); |
184 | 366 |
} |
367 |
||
368 |
void HWForm::SimpleGame() |
|
369 |
{ |
|
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
724
diff
changeset
|
370 |
CreateGame(0, 0, cDefaultAmmoStore->mid(10)); |
184 | 371 |
game->StartQuick(); |
372 |
} |
|
373 |
||
374 |
void HWForm::PlayDemo() |
|
375 |
{ |
|
376 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
377 |
if (!curritem) |
|
378 |
{ |
|
379 |
QMessageBox::critical(this, |
|
380 |
tr("Error"), |
|
581 | 381 |
tr("Please, select record from the list above"), |
184 | 382 |
tr("OK")); |
383 |
return ; |
|
384 |
} |
|
696 | 385 |
CreateGame(0, 0, 0); |
580 | 386 |
game->PlayDemo(curritem->data(Qt::UserRole).toString()); |
184 | 387 |
} |
388 |
||
666 | 389 |
void HWForm::NetConnectServer(const QString & host, quint16 port) |
416 | 390 |
{ |
666 | 391 |
_NetConnect(host, port, ui.pageOptions->editNetNick->text()); |
416 | 392 |
} |
393 |
||
314 | 394 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 395 |
{ |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
396 |
if(hwnet) { |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
397 |
hwnet->Disconnect(); |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
398 |
delete hwnet; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
399 |
hwnet=0; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
400 |
} |
465 | 401 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
402 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
403 |
|
660 | 404 |
connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
184 | 405 |
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
|
406 |
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
|
407 |
|
471 | 408 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 409 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
410 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
411 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 412 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 413 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 414 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 415 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 416 |
|
352 | 417 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
418 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 419 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
420 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 421 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 422 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 423 |
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
|
424 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
|
383 | 432 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 433 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
434 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
435 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
436 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
437 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
438 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 439 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 440 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 441 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 442 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
703 | 443 |
connect(hwnet, SIGNAL(ammoChanged(const QString&, const QString&)), ui.pageNetGame->pGameCFG, SLOT(setNetAmmo(const QString&, const QString&))); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
444 |
|
314 | 445 |
hwnet->Connect(hostName, port, nick); |
184 | 446 |
} |
447 |
||
314 | 448 |
void HWForm::NetConnect() |
449 |
{ |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
450 |
HWHostPortDialog * hpd = new HWHostPortDialog(this); |
654 | 451 |
hpd->leHost->setText(*netHost); |
452 |
hpd->sbPort->setValue(netPort); |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
453 |
|
654 | 454 |
if (hpd->exec() == QDialog::Accepted) |
455 |
{ |
|
456 |
config->SaveOptions(); |
|
457 |
delete netHost; |
|
458 |
netHost = new QString(hpd->leHost->text()); |
|
459 |
netPort = hpd->sbPort->value(); |
|
460 |
_NetConnect(*netHost, netPort, ui.pageOptions->editNetNick->text()); |
|
461 |
} |
|
314 | 462 |
} |
463 |
||
464 |
void HWForm::NetStartServer() |
|
465 |
{ |
|
672
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
466 |
config->SaveOptions(); |
636 | 467 |
|
672
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
468 |
pnetserver = new HWNetServer; |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
469 |
if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value())) |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
470 |
{ |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
471 |
QMessageBox::critical(0, tr("Error"), |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
472 |
tr("Unable to start the server")); |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
473 |
delete pnetserver; |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
474 |
pnetserver = 0; |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
475 |
return; |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
476 |
} |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
477 |
|
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
478 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageOptions->editNetNick->text()); |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
479 |
|
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
480 |
if (ui.pageNet->rbLocalGame->isChecked()) |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
481 |
pRegisterServer = new HWNetUdpServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value()); |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
482 |
else |
08ed55ea1e2a
- Fix a bug when server fails to start, and then connecting to another server on the same host (strange, the fix won't work on my machine)
unc0rr
parents:
668
diff
changeset
|
483 |
pRegisterServer = new HWNetWwwServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value()); |
314 | 484 |
} |
485 |
||
184 | 486 |
void HWForm::NetDisconnect() |
487 |
{ |
|
383 | 488 |
if(hwnet) { |
489 |
hwnet->Disconnect(); |
|
490 |
delete hwnet; |
|
491 |
hwnet=0; |
|
492 |
} |
|
314 | 493 |
if(pnetserver) { |
660 | 494 |
if (pRegisterServer) |
495 |
{ |
|
496 |
pRegisterServer->unregister(); |
|
497 |
pRegisterServer = 0; |
|
498 |
} |
|
659 | 499 |
|
314 | 500 |
pnetserver->StopServer(); |
501 |
delete pnetserver; |
|
502 |
pnetserver=0; |
|
503 |
} |
|
184 | 504 |
} |
505 |
||
383 | 506 |
void HWForm::ForcedDisconnect() |
507 |
{ |
|
508 |
if(pnetserver) return; // we have server - let it care of all things |
|
509 |
if (hwnet) { |
|
510 |
hwnet->deleteLater(); |
|
511 |
hwnet=0; |
|
425 | 512 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 513 |
QMessageBox::tr("Connection to server is lost")); |
383 | 514 |
} |
515 |
GoBack(); |
|
516 |
} |
|
517 |
||
184 | 518 |
void HWForm::NetGameEnter() |
519 |
{ |
|
290 | 520 |
GoToPage(ID_PAGE_NETCFG); |
184 | 521 |
} |
522 |
||
523 |
void HWForm::NetStartGame() |
|
524 |
{ |
|
448 | 525 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
526 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
527 |
hwnet->StartGame(); |
|
184 | 528 |
} |
529 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
530 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 531 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
532 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 533 |
} |
534 |
||
535 |
void HWForm::StartMPGame() |
|
536 |
{ |
|
696 | 537 |
QString ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageMultiplayer->gameCFG->WeaponsName->currentText()); |
538 |
||
539 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo); |
|
306 | 540 |
|
184 | 541 |
game->StartLocal(); |
542 |
} |
|
306 | 543 |
|
544 |
void HWForm::GameStateChanged(GameState gameState) |
|
545 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
546 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
547 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
548 |
ui.pageGameStats->labelGameStats->setText(""); |
661
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
549 |
if (pRegisterServer) |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
550 |
{ |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
551 |
pRegisterServer->unregister(); |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
552 |
pRegisterServer = 0; |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
553 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
554 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
555 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
556 |
case gsFinished: { |
686 | 557 |
GoBack(); |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
558 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
559 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
560 |
} |
686 | 561 |
default: { |
562 |
quint8 id = ui.Pages->currentIndex(); |
|
563 |
if (id == ID_PAGE_INGAME) GoBack(); |
|
564 |
}; |
|
307 | 565 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
566 |
|
660 | 567 |
if (hwnet) |
568 |
{ |
|
569 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
570 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
571 |
} |
|
307 | 572 |
} |
573 |
||
574 |
void HWForm::AddStatText(const QString & msg) |
|
575 |
{ |
|
576 |
ui.pageGameStats->labelGameStats->setText( |
|
577 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 578 |
} |
579 |
||
580 |
void HWForm::GameStats(char type, const QString & info) |
|
581 |
{ |
|
582 |
switch(type) { |
|
307 | 583 |
case 'r' : { |
584 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
585 |
break; |
|
586 |
} |
|
587 |
case 'D' : { |
|
588 |
int i = info.indexOf(' '); |
|
589 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
590 |
.arg(info.mid(i + 1), info.left(i)); |
|
591 |
AddStatText(message); |
|
592 |
break; |
|
593 |
} |
|
869 | 594 |
case 'k' : { |
595 |
int i = info.indexOf(' '); |
|
596 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> kills.</p>") |
|
597 |
.arg(info.mid(i + 1), info.left(i)); |
|
598 |
AddStatText(message); |
|
599 |
break; |
|
600 |
} |
|
307 | 601 |
case 'K' : { |
602 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
603 |
AddStatText(message); |
|
604 |
break; |
|
605 |
} |
|
306 | 606 |
} |
607 |
} |
|
608 |
||
696 | 609 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo) |
306 | 610 |
{ |
696 | 611 |
game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
306 | 612 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
613 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 614 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 615 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
686 | 616 |
|
617 |
GoToPage(ID_PAGE_INGAME); |
|
306 | 618 |
} |
425 | 619 |
|
620 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
621 |
{ |
|
622 |
QMessageBox::warning(this, |
|
623 |
"Hedgewars", |
|
624 |
msg); |
|
625 |
} |
|
533 | 626 |
|
627 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
628 |
{ |
|
629 |
QString filename; |
|
630 |
QByteArray demo = record; |
|
631 |
if (isDemo) |
|
632 |
{ |
|
633 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
634 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
989 | 635 |
demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
579 | 636 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer; |
533 | 637 |
} else |
638 |
{ |
|
639 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
640 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
579 | 641 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer; |
533 | 642 |
} |
643 |
||
644 |
||
645 |
QFile demofile(filename); |
|
646 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
647 |
{ |
|
648 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
649 |
return ; |
|
650 |
} |
|
651 |
demofile.write(demo.constData(), demo.size()); |
|
652 |
demofile.close(); |
|
653 |
} |
|
587 | 654 |
|
655 |
void HWForm::StartTraining() |
|
656 |
{ |
|
696 | 657 |
CreateGame(0, 0, 0); |
587 | 658 |
|
659 |
game->StartTraining(); |
|
660 |
} |
|
660 | 661 |
|
662 |
void HWForm::CreateNetGame() |
|
663 |
{ |
|
697 | 664 |
QString ammo; |
665 |
if (pnetserver) { |
|
666 |
ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText()); |
|
667 |
} else { |
|
668 |
ammo=ui.pageNetGame->pGameCFG->getNetAmmo(); |
|
669 |
} |
|
696 | 670 |
CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo); |
660 | 671 |
|
672 |
connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
|
673 |
connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
|
674 |
||
675 |
game->StartNet(); |
|
676 |
} |
|
674 | 677 |
|
678 |
void HWForm::closeEvent(QCloseEvent *event) |
|
679 |
{ |
|
680 |
config->SaveOptions(); |
|
681 |
event->accept(); |
|
682 |
} |