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