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