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