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