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