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