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