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