author | unc0rr |
Sun, 08 Mar 2009 18:43:15 +0000 | |
changeset 1873 | 815a3ff1fe4b |
parent 1872 | abfce825a14f |
child 1874 | 1b145e099b75 |
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 |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
555 |
//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
|
556 |
|
425 | 557 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 558 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 559 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 560 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&))); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
561 |
//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
|
562 |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
563 |
|
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
564 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1872
diff
changeset
|
565 |
hwnet->Connect(hostName, port, nick); |
184 | 566 |
} |
567 |
||
314 | 568 |
void HWForm::NetConnect() |
569 |
{ |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
570 |
HWHostPortDialog * hpd = new HWHostPortDialog(this); |
654 | 571 |
hpd->leHost->setText(*netHost); |
572 |
hpd->sbPort->setValue(netPort); |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
573 |
|
654 | 574 |
if (hpd->exec() == QDialog::Accepted) |
575 |
{ |
|
576 |
config->SaveOptions(); |
|
577 |
delete netHost; |
|
578 |
netHost = new QString(hpd->leHost->text()); |
|
579 |
netPort = hpd->sbPort->value(); |
|
1418 | 580 |
NetConnectServer(*netHost, netPort); |
654 | 581 |
} |
314 | 582 |
} |
583 |
||
584 |
void HWForm::NetStartServer() |
|
585 |
{ |
|
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
|
586 |
config->SaveOptions(); |
636 | 587 |
|
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
|
588 |
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
|
589 |
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
|
590 |
{ |
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
|
591 |
QMessageBox::critical(0, tr("Error"), |
1509 | 592 |
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
} |
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 |
|
1418 | 598 |
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
|
599 |
|
1418 | 600 |
pRegisterServer = new HWNetUdpServer(0, |
601 |
ui.pageNetServer->leServerDescr->text(), |
|
602 |
ui.pageNetServer->sbPort->value()); |
|
603 |
} |
|
604 |
||
605 |
void HWForm::AsyncNetServerStart() |
|
606 |
{ |
|
607 |
NetConnectServer("localhost", pnetserver->getRunningPort()); |
|
314 | 608 |
} |
609 |
||
184 | 610 |
void HWForm::NetDisconnect() |
611 |
{ |
|
1800 | 612 |
qDebug("NetDisconnect"); |
1509 | 613 |
if(hwnet) { |
614 |
hwnet->Disconnect(); |
|
615 |
delete hwnet; |
|
616 |
hwnet = 0; |
|
617 |
} |
|
618 |
if(pnetserver) { |
|
619 |
if (pRegisterServer) |
|
620 |
{ |
|
621 |
pRegisterServer->unregister(); |
|
622 |
pRegisterServer = 0; |
|
623 |
} |
|
659 | 624 |
|
1509 | 625 |
pnetserver->StopServer(); |
626 |
delete pnetserver; |
|
627 |
pnetserver = 0; |
|
628 |
} |
|
184 | 629 |
} |
630 |
||
383 | 631 |
void HWForm::ForcedDisconnect() |
632 |
{ |
|
1418 | 633 |
if(pnetserver) return; // we have server - let it care of all things |
634 |
if (hwnet) { |
|
635 |
hwnet->deleteLater(); |
|
636 |
hwnet = 0; |
|
637 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
|
638 |
QMessageBox::tr("Connection to server is lost")); |
|
1800 | 639 |
|
1418 | 640 |
} |
1800 | 641 |
if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); |
383 | 642 |
} |
643 |
||
1311 | 644 |
void HWForm::NetConnected() |
645 |
{ |
|
646 |
GoToPage(ID_PAGE_ROOMSLIST); |
|
647 |
} |
|
648 |
||
184 | 649 |
void HWForm::NetGameEnter() |
650 |
{ |
|
1593 | 651 |
ui.pageNetGame->pChatWidget->clear(); |
1354
a8dcdeb88a43
Various small insignificant improvements everywhere
unc0rr
parents:
1347
diff
changeset
|
652 |
GoToPage(ID_PAGE_NETGAME); |
184 | 653 |
} |
654 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
655 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 656 |
{ |
1418 | 657 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 658 |
} |
659 |
||
660 |
void HWForm::StartMPGame() |
|
661 |
{ |
|
1531 | 662 |
QString ammo; |
663 |
ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData( |
|
664 |
ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex() |
|
665 |
).toString(); |
|
696 | 666 |
|
667 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo); |
|
306 | 668 |
|
184 | 669 |
game->StartLocal(); |
670 |
} |
|
306 | 671 |
|
672 |
void HWForm::GameStateChanged(GameState gameState) |
|
673 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
674 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
675 |
case gsStarted: { |
1268
34c3795ecb63
Fix music starting to play after the round even if it was turned off
unc0rr
parents:
1235
diff
changeset
|
676 |
Music(false); |
1223
41d7283934c1
Hackish way to play music in frontend... to be fixed
unc0rr
parents:
1165
diff
changeset
|
677 |
GoToPage(ID_PAGE_INGAME); |
1622 | 678 |
ui.pageGameStats->clear(); |
661
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
679 |
if (pRegisterServer) |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
680 |
{ |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
681 |
pRegisterServer->unregister(); |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
682 |
pRegisterServer = 0; |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
683 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
684 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
685 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
686 |
case gsFinished: { |
686 | 687 |
GoBack(); |
1268
34c3795ecb63
Fix music starting to play after the round even if it was turned off
unc0rr
parents:
1235
diff
changeset
|
688 |
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
|
689 |
GoToPage(ID_PAGE_GAMESTATS); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1343
diff
changeset
|
690 |
if (hwnet) hwnet->gameFinished(); |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
691 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
692 |
} |
686 | 693 |
default: { |
694 |
quint8 id = ui.Pages->currentIndex(); |
|
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
695 |
if (id == ID_PAGE_INGAME) { |
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
696 |
GoBack(); |
1268
34c3795ecb63
Fix music starting to play after the round even if it was turned off
unc0rr
parents:
1235
diff
changeset
|
697 |
Music(ui.pageOptions->CBEnableMusic->isChecked()); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1343
diff
changeset
|
698 |
if (hwnet) hwnet->gameFinished(); |
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1223
diff
changeset
|
699 |
} |
686 | 700 |
}; |
307 | 701 |
} |
702 |
} |
|
703 |
||
696 | 704 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo) |
306 | 705 |
{ |
696 | 706 |
game = new HWGame(config, gamecfg, ammo, pTeamSelWidget); |
306 | 707 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
1622 | 708 |
connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &))); |
425 | 709 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 710 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 711 |
} |
425 | 712 |
|
713 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
714 |
{ |
|
715 |
QMessageBox::warning(this, |
|
716 |
"Hedgewars", |
|
717 |
msg); |
|
718 |
} |
|
533 | 719 |
|
720 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
721 |
{ |
|
722 |
QString filename; |
|
723 |
QByteArray demo = record; |
|
1487
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
724 |
QString recordFileName = |
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
725 |
config->appendDateTimeToRecordName() ? |
1664 | 726 |
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
|
727 |
"LastRound"; |
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
728 |
|
533 | 729 |
if (isDemo) |
730 |
{ |
|
731 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
732 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
989 | 733 |
demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD")); |
1487
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
734 |
filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + ".hwd_" + *cProtoVer; |
533 | 735 |
} else |
736 |
{ |
|
737 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
738 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
1487
b4cc59a6d50a
Add an option to name records with current date and time
unc0rr
parents:
1427
diff
changeset
|
739 |
filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + ".hws_" + *cProtoVer; |
533 | 740 |
} |
741 |
||
742 |
||
743 |
QFile demofile(filename); |
|
744 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
745 |
{ |
|
746 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
747 |
return ; |
|
748 |
} |
|
749 |
demofile.write(demo.constData(), demo.size()); |
|
750 |
demofile.close(); |
|
751 |
} |
|
587 | 752 |
|
753 |
void HWForm::StartTraining() |
|
754 |
{ |
|
696 | 755 |
CreateGame(0, 0, 0); |
587 | 756 |
|
757 |
game->StartTraining(); |
|
758 |
} |
|
660 | 759 |
|
760 |
void HWForm::CreateNetGame() |
|
761 |
{ |
|
697 | 762 |
QString ammo; |
1517 | 763 |
ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData( |
764 |
ui.pageNetGame->pGameCFG->WeaponsName->currentIndex() |
|
765 |
).toString(); |
|
766 |
||
696 | 767 |
CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo); |
660 | 768 |
|
769 |
connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
|
1356 | 770 |
connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &))); |
660 | 771 |
connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
1356 | 772 |
connect(hwnet, SIGNAL(chatStringFromNet(const QString &)), game, SLOT(FromNetChat(const QString &))); |
660 | 773 |
|
774 |
game->StartNet(); |
|
775 |
} |
|
674 | 776 |
|
777 |
void HWForm::closeEvent(QCloseEvent *event) |
|
778 |
{ |
|
779 |
config->SaveOptions(); |
|
780 |
event->accept(); |
|
781 |
} |
|
1235 | 782 |
|
783 |
void HWForm::Music(bool checked) |
|
784 |
{ |
|
785 |
if (checked) |
|
786 |
sdli.StartMusic(); |
|
787 |
else |
|
788 |
sdli.StopMusic(); |
|
789 |
} |
|
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
790 |
|
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
791 |
void HWForm::NetGameMaster() |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
792 |
{ |
1649 | 793 |
ui.pageNetGame->setMasterMode(true); |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
794 |
ui.pageNetGame->restrictJoins->setChecked(false); |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
795 |
ui.pageNetGame->restrictTeamAdds->setChecked(false); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1409
diff
changeset
|
796 |
|
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1409
diff
changeset
|
797 |
if (hwnet) |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1409
diff
changeset
|
798 |
{ |
1828
ba91a89f449a
Fix bug with not working toggles 'rectrict joins' and 'restrict team adding'
unc0rr
parents:
1802
diff
changeset
|
799 |
// 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
|
800 |
ui.pageNetGame->startGame->disconnect(hwnet); |
ba91a89f449a
Fix bug with not working toggles 'rectrict joins' and 'restrict team adding'
unc0rr
parents:
1802
diff
changeset
|
801 |
ui.pageNetGame->restrictJoins->disconnect(hwnet); |
ba91a89f449a
Fix bug with not working toggles 'rectrict joins' and 'restrict team adding'
unc0rr
parents:
1802
diff
changeset
|
802 |
ui.pageNetGame->restrictTeamAdds->disconnect(hwnet); |
1413 | 803 |
connect(ui.pageNetGame->startGame, SIGNAL(triggered()), hwnet, SLOT(startGame())); |
804 |
connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins())); |
|
805 |
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
|
806 |
} |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
807 |
} |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
808 |
|
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
809 |
void HWForm::NetGameSlave() |
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
810 |
{ |
1649 | 811 |
ui.pageNetGame->setMasterMode(false); |
1409
d1cbe4a57ebf
Add button for controlling room options (no usefull yet)
unc0rr
parents:
1405
diff
changeset
|
812 |
} |
1600 | 813 |
|
814 |
void HWForm::NetLeftRoom() |
|
815 |
{ |
|
816 |
if (ui.Pages->currentIndex() == ID_PAGE_NETGAME) |
|
817 |
GoBack(); |
|
818 |
else |
|
819 |
qWarning("Left room while not in room"); |
|
820 |
} |