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