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