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