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