author | unc0rr |
Mon, 20 Aug 2007 17:49:39 +0000 | |
changeset 579 | 94db15de0392 |
parent 541 | bc7be7f6d3e8 |
child 580 | d3ebf84e9fad |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2005-2007 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 <QStringList> |
|
20 |
#include <QProcess> |
|
21 |
#include <QDir> |
|
22 |
#include <QPixmap> |
|
23 |
#include <QRegExp> |
|
24 |
#include <QIcon> |
|
25 |
#include <QFile> |
|
26 |
#include <QTextStream> |
|
407 | 27 |
#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
|
28 |
#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
|
29 |
#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
|
30 |
#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
|
31 |
#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
|
32 |
#include <QLabel> |
184 | 33 |
|
34 |
#include "hwform.h" |
|
35 |
#include "game.h" |
|
36 |
#include "team.h" |
|
37 |
#include "teamselect.h" |
|
38 |
#include "gameuiconfig.h" |
|
39 |
#include "pages.h" |
|
40 |
#include "hwconsts.h" |
|
314 | 41 |
#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
|
42 |
#include "gamecfgwidget.h" |
412 | 43 |
#include "netudpserver.h" |
416 | 44 |
#include "netudpwidget.h" |
461 | 45 |
#include "chatwidget.h" |
579 | 46 |
#include "playrecordpage.h" |
184 | 47 |
|
48 |
HWForm::HWForm(QWidget *parent) |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
49 |
: QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0) |
184 | 50 |
{ |
51 |
ui.setupUi(this); |
|
52 |
||
301 | 53 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 54 |
|
245 | 55 |
UpdateTeamsLists(); |
184 | 56 |
|
57 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
58 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
59 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
579 | 60 |
connect(ui.pageMain->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
184 | 61 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
62 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
187 | 63 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
530 | 64 |
connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); |
65 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); |
|
184 | 66 |
|
289 | 67 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 68 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
69 |
||
70 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
71 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
72 |
||
289 | 73 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 74 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
493 | 75 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
492 | 76 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
184 | 77 |
|
289 | 78 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 79 |
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
|
80 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 81 |
|
289 | 82 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 83 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
84 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
85 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 86 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 87 |
|
289 | 88 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 89 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
314 | 90 |
connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
418 | 91 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
416 | 92 |
connect(ui.pageNet->pUpdateUdpButt, SIGNAL(clicked()), ui.pageNet->pUdpClient, SLOT(updateList())); |
93 |
connect(ui.pageNet->pUdpClient->serversList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(NetConnectServer())); |
|
184 | 94 |
|
289 | 95 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 96 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
493 | 97 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
492 | 98 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
99 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 100 |
|
289 | 101 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 102 |
|
306 | 103 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
104 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
105 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
311 | 106 |
|
290 | 107 |
GoToPage(ID_PAGE_MAIN); |
184 | 108 |
} |
109 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
110 |
void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
245 | 111 |
{ |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
112 |
QStringList teamslist; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
113 |
if(editable_teams) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
114 |
teamslist=*editable_teams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
115 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
116 |
teamslist = config->GetTeamsList(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
117 |
} |
245 | 118 |
|
119 |
if(teamslist.empty()) { |
|
120 |
HWTeam defaultTeam("DefaultTeam"); |
|
121 |
defaultTeam.SaveToFile(); |
|
122 |
teamslist.push_back("DefaultTeam"); |
|
123 |
} |
|
124 |
||
125 |
ui.pageOptions->CBTeamName->clear(); |
|
126 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
127 |
} |
|
128 |
||
184 | 129 |
void HWForm::GoToMain() |
130 |
{ |
|
289 | 131 |
GoToPage(ID_PAGE_MAIN); |
184 | 132 |
} |
133 |
||
134 |
void HWForm::GoToSinglePlayer() |
|
135 |
{ |
|
289 | 136 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 137 |
} |
138 |
||
139 |
void HWForm::GoToSetup() |
|
140 |
{ |
|
289 | 141 |
GoToPage(ID_PAGE_SETUP); |
184 | 142 |
} |
143 |
||
187 | 144 |
void HWForm::GoToInfo() |
145 |
{ |
|
289 | 146 |
GoToPage(ID_PAGE_INFO); |
187 | 147 |
} |
148 |
||
184 | 149 |
void HWForm::GoToMultiplayer() |
150 |
{ |
|
290 | 151 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 152 |
} |
153 |
||
579 | 154 |
void HWForm::GoToSaves() |
155 |
{ |
|
156 |
QDir tmpdir; |
|
157 |
tmpdir.cd(cfgdir->absolutePath()); |
|
158 |
tmpdir.cd("Saves"); |
|
159 |
ui.pagePlayDemo->FillFromDir(tmpdir); |
|
160 |
||
161 |
GoToPage(ID_PAGE_DEMOS); |
|
162 |
} |
|
163 |
||
184 | 164 |
void HWForm::GoToDemos() |
165 |
{ |
|
166 |
QDir tmpdir; |
|
167 |
tmpdir.cd(cfgdir->absolutePath()); |
|
168 |
tmpdir.cd("Demos"); |
|
579 | 169 |
ui.pagePlayDemo->FillFromDir(tmpdir); |
170 |
||
290 | 171 |
GoToPage(ID_PAGE_DEMOS); |
184 | 172 |
} |
173 |
||
174 |
void HWForm::GoToNet() |
|
175 |
{ |
|
289 | 176 |
GoToPage(ID_PAGE_NET); |
184 | 177 |
} |
178 |
||
496 | 179 |
void HWForm::OnPageShown(quint8 id, quint8 lastid) |
311 | 180 |
{ |
322 | 181 |
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) { |
311 | 182 |
QStringList tmNames=config->GetTeamsList(); |
322 | 183 |
TeamSelWidget* curTeamSelWidget; |
496 | 184 |
if(id == ID_PAGE_MULTIPLAYER) { |
185 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
|
186 |
} else { |
|
322 | 187 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
496 | 188 |
} |
311 | 189 |
QList<HWTeam> teamsList; |
190 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
191 |
HWTeam team(*it); |
|
192 |
team.LoadFromFile(); |
|
193 |
teamsList.push_back(team); |
|
194 |
} |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
195 |
if(lastid==ID_PAGE_SETUP) { // _TEAM |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
196 |
if (editedTeam) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
197 |
curTeamSelWidget->addTeam(*editedTeam); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
198 |
} |
496 | 199 |
} else { |
200 |
curTeamSelWidget->resetPlayingTeams(teamsList); |
|
201 |
} |
|
311 | 202 |
} |
203 |
} |
|
204 |
||
289 | 205 |
void HWForm::GoToPage(quint8 id) |
206 |
{ |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
207 |
quint8 lastid=ui.Pages->currentIndex(); |
289 | 208 |
PagesStack.push(ui.Pages->currentIndex()); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
209 |
OnPageShown(id, lastid); |
289 | 210 |
ui.Pages->setCurrentIndex(id); |
211 |
} |
|
212 |
||
213 |
void HWForm::GoBack() |
|
214 |
{ |
|
350 | 215 |
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) { |
383 | 216 |
if(hwnet || pnetserver) NetDisconnect(); |
350 | 217 |
} |
289 | 218 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
496 | 219 |
OnPageShown(id, ui.Pages->currentIndex()); |
289 | 220 |
ui.Pages->setCurrentIndex(id); |
184 | 221 |
} |
222 |
||
530 | 223 |
void HWForm::btnExitPressed() |
224 |
{ |
|
225 |
eggTimer.start(); |
|
226 |
} |
|
227 |
||
228 |
void HWForm::btnExitClicked() |
|
229 |
{ |
|
230 |
if (eggTimer.elapsed() < 3000) |
|
231 |
close(); |
|
232 |
else |
|
233 |
{ |
|
234 |
QPushButton * btn = findChild<QPushButton *>("imageButt"); |
|
235 |
if (btn) |
|
236 |
{ |
|
237 |
btn->setIcon(QIcon(":/res/bonus.png")); |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
242 |
void HWForm::IntermediateSetup() |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
243 |
{ |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
244 |
quint8 id=ui.Pages->currentIndex(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
245 |
TeamSelWidget* curTeamSelWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
246 |
if(id == ID_PAGE_MULTIPLAYER) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
247 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
248 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
249 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
250 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
251 |
QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
252 |
QStringList tmnames; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
253 |
for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
254 |
tmnames+=it->TeamName; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
255 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
256 |
UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
257 |
|
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
258 |
GoToPage(ID_PAGE_SETUP); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
259 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
260 |
|
184 | 261 |
void HWForm::NewTeam() |
262 |
{ |
|
245 | 263 |
editedTeam = new HWTeam("unnamed"); |
264 |
editedTeam->SetToPage(this); |
|
290 | 265 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 266 |
} |
267 |
||
268 |
void HWForm::EditTeam() |
|
269 |
{ |
|
245 | 270 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
271 |
editedTeam->LoadFromFile(); |
|
272 |
editedTeam->SetToPage(this); |
|
290 | 273 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 274 |
} |
275 |
||
276 |
void HWForm::TeamSave() |
|
277 |
{ |
|
245 | 278 |
editedTeam->GetFromPage(this); |
279 |
editedTeam->SaveToFile(); |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
280 |
delete editedTeam; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
281 |
editedTeam=0; |
245 | 282 |
UpdateTeamsLists(); |
290 | 283 |
GoBack(); |
184 | 284 |
} |
285 |
||
286 |
void HWForm::TeamDiscard() |
|
287 |
{ |
|
245 | 288 |
delete editedTeam; |
496 | 289 |
editedTeam=0; |
290 | 290 |
GoBack(); |
184 | 291 |
} |
292 |
||
293 |
void HWForm::SimpleGame() |
|
294 |
{ |
|
341 | 295 |
CreateGame(ui.pageLocalGame->gameCFG, 0); |
184 | 296 |
game->StartQuick(); |
297 |
} |
|
298 |
||
299 |
void HWForm::PlayDemo() |
|
300 |
{ |
|
301 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
302 |
if (!curritem) |
|
303 |
{ |
|
304 |
QMessageBox::critical(this, |
|
305 |
tr("Error"), |
|
306 |
tr("Please, select demo from the list above"), |
|
307 |
tr("OK")); |
|
308 |
return ; |
|
309 |
} |
|
341 | 310 |
CreateGame(0, 0); |
579 | 311 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + *cProtoVer); |
184 | 312 |
} |
313 |
||
416 | 314 |
void HWForm::NetConnectServer() |
315 |
{ |
|
316 |
QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem(); |
|
317 |
if (!curritem) { |
|
318 |
QMessageBox::critical(this, |
|
319 |
tr("Error"), |
|
320 |
tr("Please, select server from the list above"), |
|
321 |
tr("OK")); |
|
322 |
return ; |
|
323 |
} |
|
324 |
_NetConnect(curritem->text(), 46631, ui.pageNet->editNetNick->text()); |
|
325 |
} |
|
326 |
||
314 | 327 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 328 |
{ |
465 | 329 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
330 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
448 | 331 |
connect(hwnet, SIGNAL(GameStateChanged(GameState)), this, SLOT(NetGameStateChanged(GameState))); |
184 | 332 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
333 |
connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(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
|
334 |
|
471 | 335 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 336 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
337 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
338 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 339 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 340 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 341 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 342 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 343 |
|
352 | 344 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
345 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 346 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
347 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 348 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 349 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 350 |
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
|
351 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
352 |
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
|
353 |
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
|
354 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(themeChanged(const QString &)), hwnet, SLOT(onThemeChanged(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
|
355 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(initHealthChanged(quint32)), hwnet, SLOT(onInitHealthChanged(quint32))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
356 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(turnTimeChanged(quint32)), hwnet, SLOT(onTurnTimeChanged(quint32))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
357 |
connect(ui.pageNetGame->pGameCFG, SIGNAL(fortsModeChanged(bool)), hwnet, SLOT(onFortsModeChanged(bool))); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
358 |
|
383 | 359 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 360 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
361 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
362 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
363 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
364 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
365 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 366 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 367 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 368 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 369 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(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
|
370 |
|
314 | 371 |
hwnet->Connect(hostName, port, nick); |
184 | 372 |
config->SaveOptions(); |
373 |
} |
|
374 |
||
314 | 375 |
void HWForm::NetConnect() |
376 |
{ |
|
377 |
_NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text()); |
|
378 |
} |
|
379 |
||
380 |
void HWForm::NetStartServer() |
|
381 |
{ |
|
382 |
pnetserver = new HWNetServer; |
|
383 |
pnetserver->StartServer(); |
|
449 | 384 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text()); |
412 | 385 |
pUdpServer = new HWNetUdpServer(); |
314 | 386 |
} |
387 |
||
184 | 388 |
void HWForm::NetDisconnect() |
389 |
{ |
|
383 | 390 |
if(hwnet) { |
391 |
hwnet->Disconnect(); |
|
392 |
delete hwnet; |
|
393 |
hwnet=0; |
|
394 |
} |
|
314 | 395 |
if(pnetserver) { |
412 | 396 |
pUdpServer->deleteLater(); |
314 | 397 |
pnetserver->StopServer(); |
398 |
delete pnetserver; |
|
399 |
pnetserver=0; |
|
400 |
} |
|
184 | 401 |
} |
402 |
||
383 | 403 |
void HWForm::ForcedDisconnect() |
404 |
{ |
|
405 |
if(pnetserver) return; // we have server - let it care of all things |
|
406 |
if (hwnet) { |
|
407 |
hwnet->deleteLater(); |
|
408 |
hwnet=0; |
|
425 | 409 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 410 |
QMessageBox::tr("Connection to server is lost")); |
383 | 411 |
} |
412 |
GoBack(); |
|
413 |
} |
|
414 |
||
184 | 415 |
void HWForm::NetGameEnter() |
416 |
{ |
|
290 | 417 |
GoToPage(ID_PAGE_NETCFG); |
184 | 418 |
} |
419 |
||
420 |
void HWForm::NetStartGame() |
|
421 |
{ |
|
448 | 422 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
423 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
424 |
hwnet->StartGame(); |
|
184 | 425 |
} |
426 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
427 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 428 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
429 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 430 |
} |
431 |
||
432 |
void HWForm::StartMPGame() |
|
433 |
{ |
|
341 | 434 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 435 |
|
184 | 436 |
game->StartLocal(); |
437 |
} |
|
306 | 438 |
|
448 | 439 |
void HWForm::NetGameStateChanged(GameState __attribute__((unused)) gameState) |
440 |
{ |
|
441 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
442 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
443 |
} |
|
444 |
||
306 | 445 |
void HWForm::GameStateChanged(GameState gameState) |
446 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
447 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
448 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
449 |
ui.pageGameStats->labelGameStats->setText(""); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
450 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
451 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
452 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
453 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
454 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
455 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
456 |
default: ; |
307 | 457 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
458 |
|
307 | 459 |
} |
460 |
||
461 |
void HWForm::AddStatText(const QString & msg) |
|
462 |
{ |
|
463 |
ui.pageGameStats->labelGameStats->setText( |
|
464 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 465 |
} |
466 |
||
467 |
void HWForm::GameStats(char type, const QString & info) |
|
468 |
{ |
|
469 |
switch(type) { |
|
307 | 470 |
case 'r' : { |
471 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
472 |
break; |
|
473 |
} |
|
474 |
case 'D' : { |
|
475 |
int i = info.indexOf(' '); |
|
476 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
477 |
.arg(info.mid(i + 1), info.left(i)); |
|
478 |
AddStatText(message); |
|
479 |
break; |
|
480 |
} |
|
481 |
case 'K' : { |
|
482 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
483 |
AddStatText(message); |
|
484 |
break; |
|
485 |
} |
|
306 | 486 |
} |
487 |
} |
|
488 |
||
341 | 489 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 490 |
{ |
341 | 491 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 492 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
493 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 494 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 495 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 496 |
} |
425 | 497 |
|
498 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
499 |
{ |
|
500 |
QMessageBox::warning(this, |
|
501 |
"Hedgewars", |
|
502 |
msg); |
|
503 |
} |
|
533 | 504 |
|
505 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
506 |
{ |
|
507 |
QString filename; |
|
508 |
QByteArray demo = record; |
|
509 |
if (isDemo) |
|
510 |
{ |
|
511 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
512 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
579 | 513 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer; |
533 | 514 |
} else |
515 |
{ |
|
516 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
517 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
579 | 518 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer; |
533 | 519 |
} |
520 |
||
521 |
||
522 |
QFile demofile(filename); |
|
523 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
524 |
{ |
|
525 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
526 |
return ; |
|
527 |
} |
|
528 |
demofile.write(demo.constData(), demo.size()); |
|
529 |
demofile.close(); |
|
530 |
} |