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