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