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