author | unc0rr |
Sun, 31 Aug 2008 16:27:47 +0000 | |
changeset 1241 | 9a2def515c98 |
parent 1235 | 070629f3902d |
child 1268 | 34c3795ecb63 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2005-2008 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> |
1235 | 30 |
#include <QCheckBox> |
184 | 31 |
|
32 |
#include "hwform.h" |
|
33 |
#include "game.h" |
|
34 |
#include "team.h" |
|
35 |
#include "teamselect.h" |
|
681 | 36 |
#include "selectWeapon.h" |
184 | 37 |
#include "gameuiconfig.h" |
38 |
#include "pages.h" |
|
39 |
#include "hwconsts.h" |
|
314 | 40 |
#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
|
41 |
#include "gamecfgwidget.h" |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
42 |
#include "netserverslist.h" |
634 | 43 |
#include "netudpserver.h" |
44 |
#include "netwwwserver.h" |
|
461 | 45 |
#include "chatwidget.h" |
579 | 46 |
#include "playrecordpage.h" |
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
47 |
#include "input_ip.h" |
184 | 48 |
|
49 |
HWForm::HWForm(QWidget *parent) |
|
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
50 |
: QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) |
184 | 51 |
{ |
52 |
ui.setupUi(this); |
|
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
53 |
|
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
54 |
ui.pageOptions->CBResolution->addItems(sdli.getResolutions()); |
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
55 |
|
301 | 56 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 57 |
|
245 | 58 |
UpdateTeamsLists(); |
695 | 59 |
UpdateWeapons(); |
184 | 60 |
|
1162 | 61 |
connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool))); |
62 |
onFrontendFullscreen(config->isFrontendFullscreen()); |
|
63 |
||
184 | 64 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
65 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
66 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
187 | 67 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
530 | 68 |
connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); |
69 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); |
|
184 | 70 |
|
71 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
72 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
73 |
||
289 | 74 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 75 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
493 | 76 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
492 | 77 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
586 | 78 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 79 |
|
289 | 80 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 81 |
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
|
82 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 83 |
|
289 | 84 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 85 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
86 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
87 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 88 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
695 | 89 |
|
694 | 90 |
connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); |
91 |
connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon())); |
|
695 | 92 |
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons())); |
697 | 93 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&))); |
184 | 94 |
|
289 | 95 |
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
|
96 |
connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
646 | 97 |
connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
666 | 98 |
connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
646 | 99 |
|
100 |
connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
101 |
connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
|
184 | 102 |
|
289 | 103 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 104 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
493 | 105 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
492 | 106 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
107 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 108 |
|
289 | 109 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 110 |
|
306 | 111 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
112 |
||
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
724
diff
changeset
|
113 |
connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
587 | 114 |
connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining())); |
1150 | 115 |
connect(ui.pageSinglePlayer->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
116 |
connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
|
117 |
connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
586 | 118 |
connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
311 | 119 |
|
587 | 120 |
connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); |
121 |
connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
122 |
||
600 | 123 |
connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
683 | 124 |
connect(ui.pageSelectWeapon->BtnDefault, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(setDefault())); |
125 |
connect(ui.pageSelectWeapon->BtnSave, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(save())); |
|
600 | 126 |
|
718 | 127 |
connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()), |
128 |
ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first |
|
724 | 129 |
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
718 | 130 |
this, SLOT(UpdateWeapons())); // executed second |
724 | 131 |
connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), |
718 | 132 |
this, SLOT(GoBack())); // executed third |
133 |
||
290 | 134 |
GoToPage(ID_PAGE_MAIN); |
184 | 135 |
} |
136 |
||
1162 | 137 |
void HWForm::onFrontendFullscreen(bool value) |
138 |
{ |
|
1163 | 139 |
if (value) |
140 |
setWindowState(windowState() | Qt::WindowFullScreen); |
|
141 |
else { |
|
142 |
setWindowState(windowState() & !Qt::WindowFullScreen); |
|
143 |
} |
|
1162 | 144 |
} |
145 |
||
695 | 146 |
void HWForm::UpdateWeapons() |
147 |
{ |
|
702 | 148 |
// FIXME: rewrite this with boost (or TR1/0x) |
149 |
QVector<QComboBox*> combos; |
|
150 |
combos.push_back(ui.pageOptions->WeaponsName); |
|
151 |
combos.push_back(ui.pageMultiplayer->gameCFG->WeaponsName); |
|
152 |
combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName); |
|
696 | 153 |
|
702 | 154 |
for(QVector<QComboBox*>::iterator it=combos.begin(); it!=combos.end(); ++it) { |
155 |
(*it)->clear(); |
|
156 |
(*it)->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames()); |
|
157 |
int pos=(*it)->findText("Default"); |
|
158 |
if (pos!=-1) { |
|
159 |
(*it)->setCurrentIndex(pos); |
|
160 |
} |
|
161 |
} |
|
695 | 162 |
} |
163 |
||
697 | 164 |
void HWForm::NetWeaponNameChanged(const QString& name) |
165 |
{ |
|
166 |
QString ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText()); |
|
703 | 167 |
hwnet->onWeaponsNameChanged(name, ammo); |
697 | 168 |
} |
169 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
170 |
void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
245 | 171 |
{ |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
172 |
QStringList teamslist; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
173 |
if(editable_teams) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
174 |
teamslist=*editable_teams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
175 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
176 |
teamslist = config->GetTeamsList(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
177 |
} |
245 | 178 |
|
179 |
if(teamslist.empty()) { |
|
180 |
HWTeam defaultTeam("DefaultTeam"); |
|
181 |
defaultTeam.SaveToFile(); |
|
182 |
teamslist.push_back("DefaultTeam"); |
|
183 |
} |
|
184 |
||
185 |
ui.pageOptions->CBTeamName->clear(); |
|
186 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
187 |
} |
|
188 |
||
184 | 189 |
void HWForm::GoToMain() |
190 |
{ |
|
289 | 191 |
GoToPage(ID_PAGE_MAIN); |
184 | 192 |
} |
193 |
||
194 |
void HWForm::GoToSinglePlayer() |
|
195 |
{ |
|
289 | 196 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 197 |
} |
198 |
||
587 | 199 |
void HWForm::GoToTraining() |
200 |
{ |
|
201 |
GoToPage(ID_PAGE_TRAINING); |
|
202 |
} |
|
203 |
||
184 | 204 |
void HWForm::GoToSetup() |
205 |
{ |
|
289 | 206 |
GoToPage(ID_PAGE_SETUP); |
184 | 207 |
} |
208 |
||
694 | 209 |
void HWForm::GoToSelectNewWeapon() |
210 |
{ |
|
717 | 211 |
ui.pageSelectWeapon->pWeapons->setWeaponsName("", false); |
694 | 212 |
GoToPage(ID_PAGE_SELECTWEAPON); |
213 |
} |
|
214 |
||
600 | 215 |
void HWForm::GoToSelectWeapon() |
216 |
{ |
|
717 | 217 |
ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText(), true); |
600 | 218 |
GoToPage(ID_PAGE_SELECTWEAPON); |
219 |
} |
|
220 |
||
187 | 221 |
void HWForm::GoToInfo() |
222 |
{ |
|
289 | 223 |
GoToPage(ID_PAGE_INFO); |
187 | 224 |
} |
225 |
||
184 | 226 |
void HWForm::GoToMultiplayer() |
227 |
{ |
|
290 | 228 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 229 |
} |
230 |
||
579 | 231 |
void HWForm::GoToSaves() |
232 |
{ |
|
581 | 233 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Save); |
579 | 234 |
|
235 |
GoToPage(ID_PAGE_DEMOS); |
|
236 |
} |
|
237 |
||
184 | 238 |
void HWForm::GoToDemos() |
239 |
{ |
|
581 | 240 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Demo); |
579 | 241 |
|
290 | 242 |
GoToPage(ID_PAGE_DEMOS); |
184 | 243 |
} |
244 |
||
245 |
void HWForm::GoToNet() |
|
246 |
{ |
|
646 | 247 |
ui.pageNet->updateServersList(); |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
248 |
|
289 | 249 |
GoToPage(ID_PAGE_NET); |
184 | 250 |
} |
251 |
||
646 | 252 |
void HWForm::GoToNetServer() |
253 |
{ |
|
254 |
GoToPage(ID_PAGE_NETSERVER); |
|
255 |
} |
|
256 |
||
496 | 257 |
void HWForm::OnPageShown(quint8 id, quint8 lastid) |
311 | 258 |
{ |
322 | 259 |
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) { |
311 | 260 |
QStringList tmNames=config->GetTeamsList(); |
322 | 261 |
TeamSelWidget* curTeamSelWidget; |
496 | 262 |
if(id == ID_PAGE_MULTIPLAYER) { |
263 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
|
264 |
} else { |
|
322 | 265 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
496 | 266 |
} |
311 | 267 |
QList<HWTeam> teamsList; |
268 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
269 |
HWTeam team(*it); |
|
270 |
team.LoadFromFile(); |
|
271 |
teamsList.push_back(team); |
|
272 |
} |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
273 |
if(lastid==ID_PAGE_SETUP) { // _TEAM |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
274 |
if (editedTeam) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
275 |
curTeamSelWidget->addTeam(*editedTeam); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
276 |
} |
496 | 277 |
} else { |
278 |
curTeamSelWidget->resetPlayingTeams(teamsList); |
|
279 |
} |
|
311 | 280 |
} |
281 |
} |
|
282 |
||
289 | 283 |
void HWForm::GoToPage(quint8 id) |
284 |
{ |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
285 |
quint8 lastid=ui.Pages->currentIndex(); |
289 | 286 |
PagesStack.push(ui.Pages->currentIndex()); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
287 |
OnPageShown(id, lastid); |
289 | 288 |
ui.Pages->setCurrentIndex(id); |
289 |
} |
|
290 |
||
291 |
void HWForm::GoBack() |
|
292 |
{ |
|
350 | 293 |
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) { |
383 | 294 |
if(hwnet || pnetserver) NetDisconnect(); |
350 | 295 |
} |
289 | 296 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
496 | 297 |
OnPageShown(id, ui.Pages->currentIndex()); |
289 | 298 |
ui.Pages->setCurrentIndex(id); |
184 | 299 |
} |
300 |
||
530 | 301 |
void HWForm::btnExitPressed() |
302 |
{ |
|
303 |
eggTimer.start(); |
|
304 |
} |
|
305 |
||
306 |
void HWForm::btnExitClicked() |
|
307 |
{ |
|
308 |
if (eggTimer.elapsed() < 3000) |
|
309 |
close(); |
|
310 |
else |
|
311 |
{ |
|
312 |
QPushButton * btn = findChild<QPushButton *>("imageButt"); |
|
313 |
if (btn) |
|
314 |
{ |
|
315 |
btn->setIcon(QIcon(":/res/bonus.png")); |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
320 |
void HWForm::IntermediateSetup() |
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 |
quint8 id=ui.Pages->currentIndex(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
323 |
TeamSelWidget* curTeamSelWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
324 |
if(id == ID_PAGE_MULTIPLAYER) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
325 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
326 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
327 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
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 |
QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
330 |
QStringList tmnames; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
331 |
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
|
332 |
tmnames+=it->TeamName; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
333 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
334 |
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
|
335 |
|
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
336 |
GoToPage(ID_PAGE_SETUP); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
337 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
338 |
|
184 | 339 |
void HWForm::NewTeam() |
340 |
{ |
|
245 | 341 |
editedTeam = new HWTeam("unnamed"); |
342 |
editedTeam->SetToPage(this); |
|
290 | 343 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 344 |
} |
345 |
||
346 |
void HWForm::EditTeam() |
|
347 |
{ |
|
245 | 348 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
349 |
editedTeam->LoadFromFile(); |
|
350 |
editedTeam->SetToPage(this); |
|
290 | 351 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 352 |
} |
353 |
||
354 |
void HWForm::TeamSave() |
|
355 |
{ |
|
245 | 356 |
editedTeam->GetFromPage(this); |
357 |
editedTeam->SaveToFile(); |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
358 |
delete editedTeam; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
359 |
editedTeam=0; |
245 | 360 |
UpdateTeamsLists(); |
290 | 361 |
GoBack(); |
184 | 362 |
} |
363 |
||
364 |
void HWForm::TeamDiscard() |
|
365 |
{ |
|
245 | 366 |
delete editedTeam; |
496 | 367 |
editedTeam=0; |
290 | 368 |
GoBack(); |
184 | 369 |
} |
370 |
||
371 |
void HWForm::SimpleGame() |
|
372 |
{ |
|
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
724
diff
changeset
|
373 |
CreateGame(0, 0, cDefaultAmmoStore->mid(10)); |
184 | 374 |
game->StartQuick(); |
375 |
} |
|
376 |
||
377 |
void HWForm::PlayDemo() |
|
378 |
{ |
|
379 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
380 |
if (!curritem) |
|
381 |
{ |
|
382 |
QMessageBox::critical(this, |
|
383 |
tr("Error"), |
|
581 | 384 |
tr("Please, select record from the list above"), |
184 | 385 |
tr("OK")); |
386 |
return ; |
|
387 |
} |
|
696 | 388 |
CreateGame(0, 0, 0); |
580 | 389 |
game->PlayDemo(curritem->data(Qt::UserRole).toString()); |
184 | 390 |
} |
391 |
||
666 | 392 |
void HWForm::NetConnectServer(const QString & host, quint16 port) |
416 | 393 |
{ |
666 | 394 |
_NetConnect(host, port, ui.pageOptions->editNetNick->text()); |
416 | 395 |
} |
396 |
||
314 | 397 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 398 |
{ |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
399 |
if(hwnet) { |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
400 |
hwnet->Disconnect(); |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
401 |
delete hwnet; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
402 |
hwnet=0; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
403 |
} |
465 | 404 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
405 |
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
|
406 |
|
660 | 407 |
connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
184 | 408 |
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
|
409 |
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
|
410 |
|
471 | 411 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 412 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
413 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
414 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 415 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 416 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 417 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 418 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 419 |
|
352 | 420 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
421 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 422 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
423 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 424 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 425 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 426 |
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
|
427 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
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
|
434 |
|
383 | 435 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 436 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
437 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
438 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
439 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
440 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
441 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 442 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 443 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 444 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 445 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
703 | 446 |
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
|
447 |
|
314 | 448 |
hwnet->Connect(hostName, port, nick); |
184 | 449 |
} |
450 |
||
314 | 451 |
void HWForm::NetConnect() |
452 |
{ |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
453 |
HWHostPortDialog * hpd = new HWHostPortDialog(this); |
654 | 454 |
hpd->leHost->setText(*netHost); |
455 |
hpd->sbPort->setValue(netPort); |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
456 |
|
654 | 457 |
if (hpd->exec() == QDialog::Accepted) |
458 |
{ |
|
459 |
config->SaveOptions(); |
|
460 |
delete netHost; |
|
461 |
netHost = new QString(hpd->leHost->text()); |
|
462 |
netPort = hpd->sbPort->value(); |
|
463 |
_NetConnect(*netHost, netPort, ui.pageOptions->editNetNick->text()); |
|
464 |
} |
|
314 | 465 |
} |
466 |
||
467 |
void HWForm::NetStartServer() |
|
468 |
{ |
|
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
|
469 |
config->SaveOptions(); |
636 | 470 |
|
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
|
471 |
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
|
472 |
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
|
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 |
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
|
475 |
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
|
476 |
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
|
477 |
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
|
478 |
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
|
479 |
} |
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
|
480 |
|
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
|
481 |
_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
|
482 |
|
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
pRegisterServer = new HWNetWwwServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value()); |
314 | 487 |
} |
488 |
||
184 | 489 |
void HWForm::NetDisconnect() |
490 |
{ |
|
383 | 491 |
if(hwnet) { |
492 |
hwnet->Disconnect(); |
|
493 |
delete hwnet; |
|
494 |
hwnet=0; |
|
495 |
} |
|
314 | 496 |
if(pnetserver) { |
660 | 497 |
if (pRegisterServer) |
498 |
{ |
|
499 |
pRegisterServer->unregister(); |
|
500 |
pRegisterServer = 0; |
|
501 |
} |
|
659 | 502 |
|
314 | 503 |
pnetserver->StopServer(); |
504 |
delete pnetserver; |
|
505 |
pnetserver=0; |
|
506 |
} |
|
184 | 507 |
} |
508 |
||
383 | 509 |
void HWForm::ForcedDisconnect() |
510 |
{ |
|
511 |
if(pnetserver) return; // we have server - let it care of all things |
|
512 |
if (hwnet) { |
|
513 |
hwnet->deleteLater(); |
|
514 |
hwnet=0; |
|
425 | 515 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 516 |
QMessageBox::tr("Connection to server is lost")); |
383 | 517 |
} |
518 |
GoBack(); |
|
519 |
} |
|
520 |
||
184 | 521 |
void HWForm::NetGameEnter() |
522 |
{ |
|
290 | 523 |
GoToPage(ID_PAGE_NETCFG); |
184 | 524 |
} |
525 |
||
526 |
void HWForm::NetStartGame() |
|
527 |
{ |
|
448 | 528 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
529 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
530 |
hwnet->StartGame(); |
|
184 | 531 |
} |
532 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
533 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 534 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
535 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 536 |
} |
537 |
||
538 |
void HWForm::StartMPGame() |
|
539 |
{ |
|
696 | 540 |
QString ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageMultiplayer->gameCFG->WeaponsName->currentText()); |
541 |
||
542 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo); |
|
306 | 543 |
|
184 | 544 |
game->StartLocal(); |
545 |
} |
|
306 | 546 |
|
547 |
void HWForm::GameStateChanged(GameState gameState) |
|
548 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
549 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
550 |
case gsStarted: { |
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
551 |
sdli.StopMusic(); |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1165
diff
changeset
|
552 |
GoToPage(ID_PAGE_INGAME); |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
553 |
ui.pageGameStats->labelGameStats->setText(""); |
661
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
554 |
if (pRegisterServer) |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
555 |
{ |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
556 |
pRegisterServer->unregister(); |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
557 |
pRegisterServer = 0; |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
558 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
559 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
560 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
561 |
case gsFinished: { |
686 | 562 |
GoBack(); |
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
563 |
sdli.StartMusic(); |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
564 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
565 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
566 |
} |
686 | 567 |
default: { |
568 |
quint8 id = ui.Pages->currentIndex(); |
|
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
569 |
if (id == ID_PAGE_INGAME) { |
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
570 |
GoBack(); |
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
571 |
sdli.StartMusic(); |
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
572 |
} |
686 | 573 |
}; |
307 | 574 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
575 |
|
660 | 576 |
if (hwnet) |
577 |
{ |
|
578 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
579 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
580 |
} |
|
307 | 581 |
} |
582 |
||
583 |
void HWForm::AddStatText(const QString & msg) |
|
584 |
{ |
|
585 |
ui.pageGameStats->labelGameStats->setText( |
|
586 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 587 |
} |
588 |
||
589 |
void HWForm::GameStats(char type, const QString & info) |
|
590 |
{ |
|
591 |
switch(type) { |
|
307 | 592 |
case 'r' : { |
593 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
594 |
break; |
|
595 |
} |
|
596 |
case 'D' : { |
|
597 |
int i = info.indexOf(' '); |
|
598 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
599 |
.arg(info.mid(i + 1), info.left(i)); |
|
600 |
AddStatText(message); |
|
601 |
break; |
|
602 |
} |
|
869 | 603 |
case 'k' : { |
604 |
int i = info.indexOf(' '); |
|
605 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> kills.</p>") |
|
606 |
.arg(info.mid(i + 1), info.left(i)); |
|
607 |
AddStatText(message); |
|
608 |
break; |
|
609 |
} |
|
307 | 610 |
case 'K' : { |
611 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
612 |
AddStatText(message); |
|
613 |
break; |
|
614 |
} |
|
306 | 615 |
} |
616 |
} |
|
617 |
||
696 | 618 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo) |
306 | 619 |
{ |
696 | 620 |
game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
306 | 621 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
622 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 623 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 624 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 625 |
} |
425 | 626 |
|
627 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
628 |
{ |
|
629 |
QMessageBox::warning(this, |
|
630 |
"Hedgewars", |
|
631 |
msg); |
|
632 |
} |
|
533 | 633 |
|
634 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
635 |
{ |
|
636 |
QString filename; |
|
637 |
QByteArray demo = record; |
|
638 |
if (isDemo) |
|
639 |
{ |
|
640 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
641 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
989 | 642 |
demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
579 | 643 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer; |
533 | 644 |
} else |
645 |
{ |
|
646 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
647 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
579 | 648 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer; |
533 | 649 |
} |
650 |
||
651 |
||
652 |
QFile demofile(filename); |
|
653 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
654 |
{ |
|
655 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
656 |
return ; |
|
657 |
} |
|
658 |
demofile.write(demo.constData(), demo.size()); |
|
659 |
demofile.close(); |
|
660 |
} |
|
587 | 661 |
|
662 |
void HWForm::StartTraining() |
|
663 |
{ |
|
696 | 664 |
CreateGame(0, 0, 0); |
587 | 665 |
|
666 |
game->StartTraining(); |
|
667 |
} |
|
660 | 668 |
|
669 |
void HWForm::CreateNetGame() |
|
670 |
{ |
|
697 | 671 |
QString ammo; |
672 |
if (pnetserver) { |
|
673 |
ammo=ui.pageSelectWeapon->pWeapons->getWeaponsString(ui.pageNetGame->pGameCFG->WeaponsName->currentText()); |
|
674 |
} else { |
|
675 |
ammo=ui.pageNetGame->pGameCFG->getNetAmmo(); |
|
676 |
} |
|
696 | 677 |
CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo); |
660 | 678 |
|
679 |
connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
|
680 |
connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
|
681 |
||
682 |
game->StartNet(); |
|
683 |
} |
|
674 | 684 |
|
685 |
void HWForm::closeEvent(QCloseEvent *event) |
|
686 |
{ |
|
687 |
config->SaveOptions(); |
|
688 |
event->accept(); |
|
689 |
} |
|
1235 | 690 |
|
691 |
void HWForm::Music(bool checked) |
|
692 |
{ |
|
693 |
if (checked) |
|
694 |
sdli.StartMusic(); |
|
695 |
else |
|
696 |
sdli.StopMusic(); |
|
697 |
} |