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