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