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