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