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