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