author | displacer |
Thu, 16 Aug 2007 15:16:56 +0000 | |
changeset 572 | 302ad5c3836d |
parent 541 | bc7be7f6d3e8 |
child 579 | 94db15de0392 |
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 |
tmnames+=it->TeamName; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
245 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
246 |
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
|
247 |
|
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
248 |
GoToPage(ID_PAGE_SETUP); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
249 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
250 |
|
184 | 251 |
void HWForm::NewTeam() |
252 |
{ |
|
245 | 253 |
editedTeam = new HWTeam("unnamed"); |
254 |
editedTeam->SetToPage(this); |
|
290 | 255 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 256 |
} |
257 |
||
258 |
void HWForm::EditTeam() |
|
259 |
{ |
|
245 | 260 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
261 |
editedTeam->LoadFromFile(); |
|
262 |
editedTeam->SetToPage(this); |
|
290 | 263 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 264 |
} |
265 |
||
266 |
void HWForm::TeamSave() |
|
267 |
{ |
|
245 | 268 |
editedTeam->GetFromPage(this); |
269 |
editedTeam->SaveToFile(); |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
270 |
delete editedTeam; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
271 |
editedTeam=0; |
245 | 272 |
UpdateTeamsLists(); |
290 | 273 |
GoBack(); |
184 | 274 |
} |
275 |
||
276 |
void HWForm::TeamDiscard() |
|
277 |
{ |
|
245 | 278 |
delete editedTeam; |
496 | 279 |
editedTeam=0; |
290 | 280 |
GoBack(); |
184 | 281 |
} |
282 |
||
283 |
void HWForm::SimpleGame() |
|
284 |
{ |
|
341 | 285 |
CreateGame(ui.pageLocalGame->gameCFG, 0); |
184 | 286 |
game->StartQuick(); |
287 |
} |
|
288 |
||
289 |
void HWForm::PlayDemo() |
|
290 |
{ |
|
291 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
292 |
if (!curritem) |
|
293 |
{ |
|
294 |
QMessageBox::critical(this, |
|
295 |
tr("Error"), |
|
296 |
tr("Please, select demo from the list above"), |
|
297 |
tr("OK")); |
|
298 |
return ; |
|
299 |
} |
|
341 | 300 |
CreateGame(0, 0); |
271 | 301 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
184 | 302 |
} |
303 |
||
416 | 304 |
void HWForm::NetConnectServer() |
305 |
{ |
|
306 |
QListWidgetItem * curritem = ui.pageNet->pUdpClient->serversList->currentItem(); |
|
307 |
if (!curritem) { |
|
308 |
QMessageBox::critical(this, |
|
309 |
tr("Error"), |
|
310 |
tr("Please, select server from the list above"), |
|
311 |
tr("OK")); |
|
312 |
return ; |
|
313 |
} |
|
314 |
_NetConnect(curritem->text(), 46631, ui.pageNet->editNetNick->text()); |
|
315 |
} |
|
316 |
||
314 | 317 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 318 |
{ |
465 | 319 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
320 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
448 | 321 |
connect(hwnet, SIGNAL(GameStateChanged(GameState)), this, SLOT(NetGameStateChanged(GameState))); |
184 | 322 |
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
|
323 |
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
|
324 |
|
471 | 325 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 326 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
327 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
328 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 329 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 330 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 331 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 332 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 333 |
|
352 | 334 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
335 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 336 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
337 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 338 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 339 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 340 |
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
|
341 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
|
383 | 349 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 350 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
351 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
352 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
353 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
354 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
355 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 356 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 357 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 358 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 359 |
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
|
360 |
|
314 | 361 |
hwnet->Connect(hostName, port, nick); |
184 | 362 |
config->SaveOptions(); |
363 |
} |
|
364 |
||
314 | 365 |
void HWForm::NetConnect() |
366 |
{ |
|
367 |
_NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text()); |
|
368 |
} |
|
369 |
||
370 |
void HWForm::NetStartServer() |
|
371 |
{ |
|
372 |
pnetserver = new HWNetServer; |
|
373 |
pnetserver->StartServer(); |
|
449 | 374 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageNet->editNetNick->text()); |
412 | 375 |
pUdpServer = new HWNetUdpServer(); |
314 | 376 |
} |
377 |
||
184 | 378 |
void HWForm::NetDisconnect() |
379 |
{ |
|
383 | 380 |
if(hwnet) { |
381 |
hwnet->Disconnect(); |
|
382 |
delete hwnet; |
|
383 |
hwnet=0; |
|
384 |
} |
|
314 | 385 |
if(pnetserver) { |
412 | 386 |
pUdpServer->deleteLater(); |
314 | 387 |
pnetserver->StopServer(); |
388 |
delete pnetserver; |
|
389 |
pnetserver=0; |
|
390 |
} |
|
184 | 391 |
} |
392 |
||
383 | 393 |
void HWForm::ForcedDisconnect() |
394 |
{ |
|
395 |
if(pnetserver) return; // we have server - let it care of all things |
|
396 |
if (hwnet) { |
|
397 |
hwnet->deleteLater(); |
|
398 |
hwnet=0; |
|
425 | 399 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 400 |
QMessageBox::tr("Connection to server is lost")); |
383 | 401 |
} |
402 |
GoBack(); |
|
403 |
} |
|
404 |
||
184 | 405 |
void HWForm::NetGameEnter() |
406 |
{ |
|
290 | 407 |
GoToPage(ID_PAGE_NETCFG); |
184 | 408 |
} |
409 |
||
410 |
void HWForm::NetStartGame() |
|
411 |
{ |
|
448 | 412 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
413 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
414 |
hwnet->StartGame(); |
|
184 | 415 |
} |
416 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
417 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 418 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
419 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 420 |
} |
421 |
||
422 |
void HWForm::StartMPGame() |
|
423 |
{ |
|
341 | 424 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 425 |
|
184 | 426 |
game->StartLocal(); |
427 |
} |
|
306 | 428 |
|
448 | 429 |
void HWForm::NetGameStateChanged(GameState __attribute__((unused)) gameState) |
430 |
{ |
|
431 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
432 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
433 |
} |
|
434 |
||
306 | 435 |
void HWForm::GameStateChanged(GameState gameState) |
436 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
437 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
438 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
439 |
ui.pageGameStats->labelGameStats->setText(""); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
440 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
441 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
442 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
443 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
444 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
445 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
446 |
default: ; |
307 | 447 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
448 |
|
307 | 449 |
} |
450 |
||
451 |
void HWForm::AddStatText(const QString & msg) |
|
452 |
{ |
|
453 |
ui.pageGameStats->labelGameStats->setText( |
|
454 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 455 |
} |
456 |
||
457 |
void HWForm::GameStats(char type, const QString & info) |
|
458 |
{ |
|
459 |
switch(type) { |
|
307 | 460 |
case 'r' : { |
461 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
462 |
break; |
|
463 |
} |
|
464 |
case 'D' : { |
|
465 |
int i = info.indexOf(' '); |
|
466 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
467 |
.arg(info.mid(i + 1), info.left(i)); |
|
468 |
AddStatText(message); |
|
469 |
break; |
|
470 |
} |
|
471 |
case 'K' : { |
|
472 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
473 |
AddStatText(message); |
|
474 |
break; |
|
475 |
} |
|
306 | 476 |
} |
477 |
} |
|
478 |
||
341 | 479 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 480 |
{ |
341 | 481 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 482 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
483 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 484 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 485 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 486 |
} |
425 | 487 |
|
488 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
489 |
{ |
|
490 |
QMessageBox::warning(this, |
|
491 |
"Hedgewars", |
|
492 |
msg); |
|
493 |
} |
|
533 | 494 |
|
495 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
496 |
{ |
|
497 |
QString filename; |
|
498 |
QByteArray demo = record; |
|
499 |
if (isDemo) |
|
500 |
{ |
|
501 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
502 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
503 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + cProtoVer; |
|
504 |
} else |
|
505 |
{ |
|
506 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
507 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
508 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + cProtoVer; |
|
509 |
} |
|
510 |
||
511 |
||
512 |
QFile demofile(filename); |
|
513 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
514 |
{ |
|
515 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
516 |
return ; |
|
517 |
} |
|
518 |
demofile.write(demo.constData(), demo.size()); |
|
519 |
demofile.close(); |
|
520 |
} |