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