author | unc0rr |
Sun, 08 Mar 2009 20:22:52 +0000 | |
changeset 1874 | 1b145e099b75 |
parent 1873 | 815a3ff1fe4b |
child 1875 | 189370d394db |
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 |
|
1874 | 483 |
// rooms list page stuff |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1312
diff
changeset
|
484 |
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
|
485 |
ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1846
diff
changeset
|
486 |
connect(hwnet, SIGNAL(adminAccess(bool)), |
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1846
diff
changeset
|
487 |
ui.pageRoomsList, SLOT(setAdmin(bool))); |
1860 | 488 |
connect(hwnet, SIGNAL(adminAccess(bool)), |
489 |
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
|
490 |
|
1377 | 491 |
connect(hwnet, SIGNAL(serverMessage(const QString&)), |
1587 | 492 |
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
|
493 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1312
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
hwnet, SLOT(JoinRoom(const QString&))); |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
498 |
connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)), |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
499 |
this, SLOT(NetGameMaster())); |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
500 |
connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)), |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
501 |
this, SLOT(NetGameSlave())); |
1315 | 502 |
connect(ui.pageRoomsList, SIGNAL(askForRoomList()), |
503 |
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
|
504 |
|
1874 | 505 |
// net page stuff |
1357 | 506 |
connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1360 | 507 |
ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&))); |
1405 | 508 |
connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)), |
509 |
ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool))); |
|
1364 | 510 |
connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1360 | 511 |
ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&))); |
1860 | 512 |
connect(hwnet, SIGNAL(roomMaster(bool)), |
513 |
ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool))); |
|
461 | 514 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
515 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
1577 | 516 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
1648 | 517 |
connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
518 |
ui.pageNetGame, SLOT(setReadyStatus(bool))); |
|
1577 | 519 |
|
1874 | 520 |
// chat widget actions |
1391 | 521 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)), |
522 |
hwnet, SLOT(kickPlayer(const QString&))); |
|
1860 | 523 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)), |
524 |
hwnet, SLOT(banPlayer(const QString&))); |
|
1577 | 525 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)), |
526 |
hwnet, SLOT(infoPlayer(const QString&))); |
|
1860 | 527 |
connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
528 |
hwnet, SLOT(kickPlayer(const QString&))); |
|
529 |
connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
|
530 |
hwnet, SLOT(banPlayer(const QString&))); |
|
1577 | 531 |
connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)), |
532 |
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
|
533 |
|
1874 | 534 |
// chatting |
1568 | 535 |
connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)), |
536 |
hwnet, SLOT(chatLineToLobby(const QString&))); |
|
537 |
connect(hwnet, SIGNAL(chatStringLobby(const QString&)), |
|
538 |
ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&))); |
|
539 |
connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
|
540 |
ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&))); |
|
541 |
||
1874 | 542 |
// nick list stuff |
471 | 543 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 544 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 545 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 546 |
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
|
547 |
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
|
548 |
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
|
549 |
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
|
550 |
ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&))); |
461 | 551 |
|
1874 | 552 |
// teams selecting stuff |
352 | 553 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
554 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 555 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
556 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 557 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 558 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 559 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&))); |
425 | 560 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 561 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 562 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 563 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
1874 | 564 |
|
565 |
//connect(ui.pageNetGame->pGameCFG->pMapContainer, SIGNAL(newTemplateFilter(int)), hwnet, SLOT(onTemplateFilterChanged(int))); |
|
566 |
||
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
567 |
//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
|
568 |
|
1874 | 569 |
// config stuff |
570 |
connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
|
571 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
|
572 |
||
573 |
||
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
574 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
1874 | 575 |
|
576 |
hwnet->Connect(hostName, port, nick); |
|
184 | 577 |
} |
578 |
||
314 | 579 |
void HWForm::NetConnect() |
580 |
{ |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
581 |
HWHostPortDialog * hpd = new HWHostPortDialog(this); |
654 | 582 |
hpd->leHost->setText(*netHost); |
583 |
hpd->sbPort->setValue(netPort); |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
584 |
|
654 | 585 |
if (hpd->exec() == QDialog::Accepted) |
586 |
{ |
|
587 |
config->SaveOptions(); |
|
588 |
delete netHost; |
|
589 |
netHost = new QString(hpd->leHost->text()); |
|
590 |
netPort = hpd->sbPort->value(); |
|
1418 | 591 |
NetConnectServer(*netHost, netPort); |
654 | 592 |
} |
314 | 593 |
} |
594 |
||
595 |
void HWForm::NetStartServer() |
|
596 |
{ |
|
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
|
597 |
config->SaveOptions(); |
636 | 598 |
|
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
|
599 |
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
|
600 |
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
|
601 |
{ |
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
|
602 |
QMessageBox::critical(0, tr("Error"), |
1509 | 603 |
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
|
604 |
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
|
605 |
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
|
606 |
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
|
607 |
} |
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
|
608 |
|
1418 | 609 |
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
|
610 |
|
1418 | 611 |
pRegisterServer = new HWNetUdpServer(0, |
612 |
ui.pageNetServer->leServerDescr->text(), |
|
613 |
ui.pageNetServer->sbPort->value()); |
|
614 |
} |
|
615 |
||
616 |
void HWForm::AsyncNetServerStart() |
|
617 |
{ |
|
618 |
NetConnectServer("localhost", pnetserver->getRunningPort()); |
|
314 | 619 |
} |
620 |
||
184 | 621 |
void HWForm::NetDisconnect() |
622 |
{ |
|
1800 | 623 |
qDebug("NetDisconnect"); |
1509 | 624 |
if(hwnet) { |
625 |
hwnet->Disconnect(); |
|
626 |
delete hwnet; |
|
627 |
hwnet = 0; |
|
628 |
} |
|
629 |
if(pnetserver) { |
|
630 |
if (pRegisterServer) |
|
631 |
{ |
|
632 |
pRegisterServer->unregister(); |
|
633 |
pRegisterServer = 0; |
|
634 |
} |
|
659 | 635 |
|
1509 | 636 |
pnetserver->StopServer(); |
637 |
delete pnetserver; |
|
638 |
pnetserver = 0; |
|
639 |
} |
|
184 | 640 |
} |
641 |
||
383 | 642 |
void HWForm::ForcedDisconnect() |
643 |
{ |
|
1418 | 644 |
if(pnetserver) return; // we have server - let it care of all things |
645 |
if (hwnet) { |
|
646 |
hwnet->deleteLater(); |
|
647 |
hwnet = 0; |
|
648 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
|
649 |
QMessageBox::tr("Connection to server is lost")); |
|
1800 | 650 |
|
1418 | 651 |
} |
1800 | 652 |
if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); |
383 | 653 |
} |
654 |
||
1311 | 655 |
void HWForm::NetConnected() |
656 |
{ |
|
657 |
GoToPage(ID_PAGE_ROOMSLIST); |
|
658 |
} |
|
659 |
||
184 | 660 |
void HWForm::NetGameEnter() |
661 |
{ |
|
1593 | 662 |
ui.pageNetGame->pChatWidget->clear(); |
1354
a8dcdeb88a43
Various small insignificant improvements everywhere
unc0rr
parents:
1347
diff
changeset
|
663 |
GoToPage(ID_PAGE_NETGAME); |
184 | 664 |
} |
665 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
666 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 667 |
{ |
1418 | 668 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 669 |
} |
670 |
||
671 |
void HWForm::StartMPGame() |
|
672 |
{ |
|
1531 | 673 |
QString ammo; |
674 |
ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData( |
|
675 |
ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex() |
|
676 |
).toString(); |
|
696 | 677 |
|
678 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo); |
|
306 | 679 |
|
184 | 680 |
game->StartLocal(); |
681 |
} |
|
306 | 682 |
|
683 |
void HWForm::GameStateChanged(GameState gameState) |
|
684 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
685 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
686 |
case gsStarted: { |
1268
34c3795ecb63
Fix music starting to play after the round even if it was turned off
unc0rr
parents:
1235
diff
changeset
|
687 |
Music(false); |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1165
diff
changeset
|
688 |
GoToPage(ID_PAGE_INGAME); |
1622 | 689 |
ui.pageGameStats->clear(); |
661
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
690 |
if (pRegisterServer) |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
691 |
{ |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
692 |
pRegisterServer->unregister(); |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
693 |
pRegisterServer = 0; |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
694 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
695 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
696 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
697 |
case gsFinished: { |
686 | 698 |
GoBack(); |
1268
34c3795ecb63
Fix music starting to play after the round even if it was turned off
unc0rr
parents:
1235
diff
changeset
|
699 |
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
|
700 |
GoToPage(ID_PAGE_GAMESTATS); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1343
diff
changeset
|
701 |
if (hwnet) hwnet->gameFinished(); |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
702 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
703 |
} |
686 | 704 |
default: { |
705 |
quint8 id = ui.Pages->currentIndex(); |
|
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
706 |
if (id == ID_PAGE_INGAME) { |
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
707 |
GoBack(); |
1268
34c3795ecb63
Fix music starting to play after the round even if it was turned off
unc0rr
parents:
1235
diff
changeset
|
708 |
Music(ui.pageOptions->CBEnableMusic->isChecked()); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1343
diff
changeset
|
709 |
if (hwnet) hwnet->gameFinished(); |
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
710 |
} |
686 | 711 |
}; |
307 | 712 |
} |
713 |
} |
|
714 |
||
696 | 715 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo) |
306 | 716 |
{ |
696 | 717 |
game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
306 | 718 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
1622 | 719 |
connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &))); |
425 | 720 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 721 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 722 |
} |
425 | 723 |
|
724 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
725 |
{ |
|
726 |
QMessageBox::warning(this, |
|
727 |
"Hedgewars", |
|
728 |
msg); |
|
729 |
} |
|
533 | 730 |
|
731 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
732 |
{ |
|
733 |
QString filename; |
|
734 |
QByteArray demo = record; |
|
1487
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
735 |
QString recordFileName = |
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
736 |
config->appendDateTimeToRecordName() ? |
1664 | 737 |
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
|
738 |
"LastRound"; |
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
739 |
|
533 | 740 |
if (isDemo) |
741 |
{ |
|
742 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
743 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
989 | 744 |
demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
1487
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
745 |
filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + ".hwd_" + *cProtoVer; |
533 | 746 |
} else |
747 |
{ |
|
748 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
749 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
1487
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
750 |
filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + ".hws_" + *cProtoVer; |
533 | 751 |
} |
752 |
||
753 |
||
754 |
QFile demofile(filename); |
|
755 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
756 |
{ |
|
757 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
758 |
return ; |
|
759 |
} |
|
760 |
demofile.write(demo.constData(), demo.size()); |
|
761 |
demofile.close(); |
|
762 |
} |
|
587 | 763 |
|
764 |
void HWForm::StartTraining() |
|
765 |
{ |
|
696 | 766 |
CreateGame(0, 0, 0); |
587 | 767 |
|
768 |
game->StartTraining(); |
|
769 |
} |
|
660 | 770 |
|
771 |
void HWForm::CreateNetGame() |
|
772 |
{ |
|
697 | 773 |
QString ammo; |
1517 | 774 |
ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData( |
775 |
ui.pageNetGame->pGameCFG->WeaponsName->currentIndex() |
|
776 |
).toString(); |
|
777 |
||
696 | 778 |
CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo); |
660 | 779 |
|
780 |
connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
|
1356 | 781 |
connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &))); |
660 | 782 |
connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
1356 | 783 |
connect(hwnet, SIGNAL(chatStringFromNet(const QString &)), game, SLOT(FromNetChat(const QString &))); |
660 | 784 |
|
785 |
game->StartNet(); |
|
786 |
} |
|
674 | 787 |
|
788 |
void HWForm::closeEvent(QCloseEvent *event) |
|
789 |
{ |
|
790 |
config->SaveOptions(); |
|
791 |
event->accept(); |
|
792 |
} |
|
1235 | 793 |
|
794 |
void HWForm::Music(bool checked) |
|
795 |
{ |
|
796 |
if (checked) |
|
797 |
sdli.StartMusic(); |
|
798 |
else |
|
799 |
sdli.StopMusic(); |
|
800 |
} |
|
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
801 |
|
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
802 |
void HWForm::NetGameMaster() |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
803 |
{ |
1649 | 804 |
ui.pageNetGame->setMasterMode(true); |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
805 |
ui.pageNetGame->restrictJoins->setChecked(false); |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
806 |
ui.pageNetGame->restrictTeamAdds->setChecked(false); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1409
diff
changeset
|
807 |
|
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1409
diff
changeset
|
808 |
if (hwnet) |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1409
diff
changeset
|
809 |
{ |
1828
ba91a89f449a
Fix bug with not working toggles 'rectrict joins' and 'restrict team adding'
unc0rr
parents:
1802
diff
changeset
|
810 |
// 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
|
811 |
ui.pageNetGame->startGame->disconnect(hwnet); |
ba91a89f449a
Fix bug with not working toggles 'rectrict joins' and 'restrict team adding'
unc0rr
parents:
1802
diff
changeset
|
812 |
ui.pageNetGame->restrictJoins->disconnect(hwnet); |
ba91a89f449a
Fix bug with not working toggles 'rectrict joins' and 'restrict team adding'
unc0rr
parents:
1802
diff
changeset
|
813 |
ui.pageNetGame->restrictTeamAdds->disconnect(hwnet); |
1413 | 814 |
connect(ui.pageNetGame->startGame, SIGNAL(triggered()), hwnet, SLOT(startGame())); |
815 |
connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins())); |
|
816 |
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
|
817 |
} |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
818 |
} |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
819 |
|
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
820 |
void HWForm::NetGameSlave() |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
821 |
{ |
1649 | 822 |
ui.pageNetGame->setMasterMode(false); |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
823 |
} |
1600 | 824 |
|
825 |
void HWForm::NetLeftRoom() |
|
826 |
{ |
|
827 |
if (ui.Pages->currentIndex() == ID_PAGE_NETGAME) |
|
828 |
GoBack(); |
|
829 |
else |
|
830 |
qWarning("Left room while not in room"); |
|
831 |
} |