author | unc0rr |
Sat, 15 Dec 2007 19:44:05 +0000 | |
changeset 666 | 07fa9a74a074 |
parent 665 | 5c7bfc8bac6a |
child 668 | 0d7683a66d61 |
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> |
636 | 33 |
#include <QRadioButton> |
654 | 34 |
#include <QSpinBox> |
184 | 35 |
|
36 |
#include "hwform.h" |
|
37 |
#include "game.h" |
|
38 |
#include "team.h" |
|
39 |
#include "teamselect.h" |
|
40 |
#include "gameuiconfig.h" |
|
41 |
#include "pages.h" |
|
42 |
#include "hwconsts.h" |
|
314 | 43 |
#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
|
44 |
#include "gamecfgwidget.h" |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
45 |
#include "netserverslist.h" |
634 | 46 |
#include "netudpserver.h" |
47 |
#include "netwwwserver.h" |
|
461 | 48 |
#include "chatwidget.h" |
579 | 49 |
#include "playrecordpage.h" |
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
50 |
#include "input_ip.h" |
184 | 51 |
|
52 |
HWForm::HWForm(QWidget *parent) |
|
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
53 |
: QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) |
184 | 54 |
{ |
55 |
ui.setupUi(this); |
|
301 | 56 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 57 |
|
245 | 58 |
UpdateTeamsLists(); |
184 | 59 |
|
60 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
61 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
62 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
579 | 63 |
connect(ui.pageMain->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); |
184 | 64 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
65 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
187 | 66 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
530 | 67 |
connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); |
68 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); |
|
184 | 69 |
|
585
7531ae5b146e
Rename PageLocalGame -> PageSimpleGame due to future changes
unc0rr
parents:
581
diff
changeset
|
70 |
connect(ui.pageSimpleGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
7531ae5b146e
Rename PageLocalGame -> PageSimpleGame due to future changes
unc0rr
parents:
581
diff
changeset
|
71 |
connect(ui.pageSimpleGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
184 | 72 |
|
73 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
74 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
75 |
||
289 | 76 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 77 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
493 | 78 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), |
492 | 79 |
ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); |
586 | 80 |
connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 81 |
|
289 | 82 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 83 |
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
|
84 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 85 |
|
289 | 86 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 87 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
88 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
89 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
312 | 90 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); |
600 | 91 |
connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); |
184 | 92 |
|
289 | 93 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
94 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnectServer())); |
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
95 |
connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); |
646 | 96 |
connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(GoToNetServer())); |
666 | 97 |
connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); |
646 | 98 |
|
99 |
connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
100 |
connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); |
|
184 | 101 |
|
289 | 102 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 103 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
493 | 104 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
492 | 105 |
ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
106 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
184 | 107 |
|
289 | 108 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 109 |
|
306 | 110 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
111 |
||
586 | 112 |
connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(GoToSimpleGame())); |
587 | 113 |
connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining())); |
586 | 114 |
connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
311 | 115 |
|
587 | 116 |
connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); |
117 |
connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
|
118 |
||
600 | 119 |
connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
120 |
||
290 | 121 |
GoToPage(ID_PAGE_MAIN); |
184 | 122 |
} |
123 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
124 |
void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
245 | 125 |
{ |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
126 |
QStringList teamslist; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
127 |
if(editable_teams) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
128 |
teamslist=*editable_teams; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
129 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
130 |
teamslist = config->GetTeamsList(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
131 |
} |
245 | 132 |
|
133 |
if(teamslist.empty()) { |
|
134 |
HWTeam defaultTeam("DefaultTeam"); |
|
135 |
defaultTeam.SaveToFile(); |
|
136 |
teamslist.push_back("DefaultTeam"); |
|
137 |
} |
|
138 |
||
139 |
ui.pageOptions->CBTeamName->clear(); |
|
140 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
141 |
} |
|
142 |
||
184 | 143 |
void HWForm::GoToMain() |
144 |
{ |
|
289 | 145 |
GoToPage(ID_PAGE_MAIN); |
184 | 146 |
} |
147 |
||
148 |
void HWForm::GoToSinglePlayer() |
|
149 |
{ |
|
289 | 150 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 151 |
} |
152 |
||
586 | 153 |
void HWForm::GoToSimpleGame() |
154 |
{ |
|
155 |
GoToPage(ID_PAGE_SIMPLEGAME); |
|
156 |
} |
|
157 |
||
587 | 158 |
void HWForm::GoToTraining() |
159 |
{ |
|
160 |
GoToPage(ID_PAGE_TRAINING); |
|
161 |
} |
|
162 |
||
184 | 163 |
void HWForm::GoToSetup() |
164 |
{ |
|
289 | 165 |
GoToPage(ID_PAGE_SETUP); |
184 | 166 |
} |
167 |
||
600 | 168 |
void HWForm::GoToSelectWeapon() |
169 |
{ |
|
170 |
GoToPage(ID_PAGE_SELECTWEAPON); |
|
171 |
} |
|
172 |
||
187 | 173 |
void HWForm::GoToInfo() |
174 |
{ |
|
289 | 175 |
GoToPage(ID_PAGE_INFO); |
187 | 176 |
} |
177 |
||
184 | 178 |
void HWForm::GoToMultiplayer() |
179 |
{ |
|
290 | 180 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 181 |
} |
182 |
||
579 | 183 |
void HWForm::GoToSaves() |
184 |
{ |
|
581 | 185 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Save); |
579 | 186 |
|
187 |
GoToPage(ID_PAGE_DEMOS); |
|
188 |
} |
|
189 |
||
184 | 190 |
void HWForm::GoToDemos() |
191 |
{ |
|
581 | 192 |
ui.pagePlayDemo->FillFromDir(PagePlayDemo::RT_Demo); |
579 | 193 |
|
290 | 194 |
GoToPage(ID_PAGE_DEMOS); |
184 | 195 |
} |
196 |
||
197 |
void HWForm::GoToNet() |
|
198 |
{ |
|
646 | 199 |
ui.pageNet->updateServersList(); |
632
5e09ae25729f
Half implement possibility for different backends of servers list
unc0rr
parents:
625
diff
changeset
|
200 |
|
289 | 201 |
GoToPage(ID_PAGE_NET); |
184 | 202 |
} |
203 |
||
646 | 204 |
void HWForm::GoToNetServer() |
205 |
{ |
|
206 |
GoToPage(ID_PAGE_NETSERVER); |
|
207 |
} |
|
208 |
||
496 | 209 |
void HWForm::OnPageShown(quint8 id, quint8 lastid) |
311 | 210 |
{ |
322 | 211 |
if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETCFG) { |
311 | 212 |
QStringList tmNames=config->GetTeamsList(); |
322 | 213 |
TeamSelWidget* curTeamSelWidget; |
496 | 214 |
if(id == ID_PAGE_MULTIPLAYER) { |
215 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
|
216 |
} else { |
|
322 | 217 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
496 | 218 |
} |
311 | 219 |
QList<HWTeam> teamsList; |
220 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
221 |
HWTeam team(*it); |
|
222 |
team.LoadFromFile(); |
|
223 |
teamsList.push_back(team); |
|
224 |
} |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
225 |
if(lastid==ID_PAGE_SETUP) { // _TEAM |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
226 |
if (editedTeam) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
227 |
curTeamSelWidget->addTeam(*editedTeam); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
228 |
} |
496 | 229 |
} else { |
230 |
curTeamSelWidget->resetPlayingTeams(teamsList); |
|
231 |
} |
|
311 | 232 |
} |
233 |
} |
|
234 |
||
289 | 235 |
void HWForm::GoToPage(quint8 id) |
236 |
{ |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
237 |
quint8 lastid=ui.Pages->currentIndex(); |
289 | 238 |
PagesStack.push(ui.Pages->currentIndex()); |
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
239 |
OnPageShown(id, lastid); |
289 | 240 |
ui.Pages->setCurrentIndex(id); |
241 |
} |
|
242 |
||
243 |
void HWForm::GoBack() |
|
244 |
{ |
|
350 | 245 |
if (!PagesStack.isEmpty() && PagesStack.top() == ID_PAGE_NET) { |
383 | 246 |
if(hwnet || pnetserver) NetDisconnect(); |
350 | 247 |
} |
289 | 248 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
496 | 249 |
OnPageShown(id, ui.Pages->currentIndex()); |
289 | 250 |
ui.Pages->setCurrentIndex(id); |
184 | 251 |
} |
252 |
||
530 | 253 |
void HWForm::btnExitPressed() |
254 |
{ |
|
255 |
eggTimer.start(); |
|
256 |
} |
|
257 |
||
258 |
void HWForm::btnExitClicked() |
|
259 |
{ |
|
260 |
if (eggTimer.elapsed() < 3000) |
|
261 |
close(); |
|
262 |
else |
|
263 |
{ |
|
264 |
QPushButton * btn = findChild<QPushButton *>("imageButt"); |
|
265 |
if (btn) |
|
266 |
{ |
|
267 |
btn->setIcon(QIcon(":/res/bonus.png")); |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
||
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
272 |
void HWForm::IntermediateSetup() |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
273 |
{ |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
274 |
quint8 id=ui.Pages->currentIndex(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
275 |
TeamSelWidget* curTeamSelWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
276 |
if(id == ID_PAGE_MULTIPLAYER) { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
277 |
curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
278 |
} else { |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
279 |
curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
280 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
281 |
QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams(); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
282 |
QStringList tmnames; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
283 |
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
|
284 |
tmnames+=it->TeamName; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
285 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
286 |
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
|
287 |
|
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
288 |
GoToPage(ID_PAGE_SETUP); |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
289 |
} |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
290 |
|
184 | 291 |
void HWForm::NewTeam() |
292 |
{ |
|
245 | 293 |
editedTeam = new HWTeam("unnamed"); |
294 |
editedTeam->SetToPage(this); |
|
290 | 295 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 296 |
} |
297 |
||
298 |
void HWForm::EditTeam() |
|
299 |
{ |
|
245 | 300 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
301 |
editedTeam->LoadFromFile(); |
|
302 |
editedTeam->SetToPage(this); |
|
290 | 303 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 304 |
} |
305 |
||
306 |
void HWForm::TeamSave() |
|
307 |
{ |
|
245 | 308 |
editedTeam->GetFromPage(this); |
309 |
editedTeam->SaveToFile(); |
|
535
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
310 |
delete editedTeam; |
a14eaf35cf4b
"Setup" button instead of "New team", exclude playing teams from setup
displacer
parents:
533
diff
changeset
|
311 |
editedTeam=0; |
245 | 312 |
UpdateTeamsLists(); |
290 | 313 |
GoBack(); |
184 | 314 |
} |
315 |
||
316 |
void HWForm::TeamDiscard() |
|
317 |
{ |
|
245 | 318 |
delete editedTeam; |
496 | 319 |
editedTeam=0; |
290 | 320 |
GoBack(); |
184 | 321 |
} |
322 |
||
323 |
void HWForm::SimpleGame() |
|
324 |
{ |
|
585
7531ae5b146e
Rename PageLocalGame -> PageSimpleGame due to future changes
unc0rr
parents:
581
diff
changeset
|
325 |
CreateGame(ui.pageSimpleGame->gameCFG, 0); |
184 | 326 |
game->StartQuick(); |
327 |
} |
|
328 |
||
329 |
void HWForm::PlayDemo() |
|
330 |
{ |
|
331 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
332 |
if (!curritem) |
|
333 |
{ |
|
334 |
QMessageBox::critical(this, |
|
335 |
tr("Error"), |
|
581 | 336 |
tr("Please, select record from the list above"), |
184 | 337 |
tr("OK")); |
338 |
return ; |
|
339 |
} |
|
341 | 340 |
CreateGame(0, 0); |
580 | 341 |
game->PlayDemo(curritem->data(Qt::UserRole).toString()); |
184 | 342 |
} |
343 |
||
666 | 344 |
void HWForm::NetConnectServer(const QString & host, quint16 port) |
416 | 345 |
{ |
666 | 346 |
_NetConnect(host, port, ui.pageOptions->editNetNick->text()); |
416 | 347 |
} |
348 |
||
314 | 349 |
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
184 | 350 |
{ |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
351 |
if(hwnet) { |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
352 |
hwnet->Disconnect(); |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
353 |
delete hwnet; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
354 |
hwnet=0; |
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
355 |
} |
465 | 356 |
ui.pageNetGame->pChatWidget->clear(); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
357 |
hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
637
8fa7ed5e13bd
Fix bad behavior when quickly click Connect button more than once
unc0rr
parents:
636
diff
changeset
|
358 |
|
660 | 359 |
connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
184 | 360 |
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
|
361 |
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
|
362 |
|
471 | 363 |
connect(hwnet, SIGNAL(chatStringFromNet(const QStringList&)), |
461 | 364 |
ui.pageNetGame->pChatWidget, SLOT(onChatStringFromNet(const QStringList&))); |
365 |
connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
|
366 |
hwnet, SLOT(chatLineToNet(const QString&))); |
|
471 | 367 |
connect(hwnet, SIGNAL(nickAdded(const QString&)), |
465 | 368 |
ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&))); |
471 | 369 |
connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
465 | 370 |
ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&))); |
461 | 371 |
|
352 | 372 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)), |
373 |
hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&))); |
|
372 | 374 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)), |
375 |
hwnet, SLOT(onTeamColorChanged(const HWTeam&))); |
|
327 | 376 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
373 | 377 |
connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam))); |
347 | 378 |
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
|
379 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
|
383 | 387 |
connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect())); |
330 | 388 |
connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setSeed(const QString &))); |
389 |
connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setMap(const QString &))); |
|
390 |
connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(setTheme(const QString &))); |
|
391 |
connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setInitHealth(quint32))); |
|
392 |
connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(setTurnTime(quint32))); |
|
393 |
connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(setFortsMode(bool))); |
|
425 | 394 |
connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)), |
352 | 395 |
ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&))); |
425 | 396 |
connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)), |
372 | 397 |
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
|
398 |
|
314 | 399 |
hwnet->Connect(hostName, port, nick); |
184 | 400 |
} |
401 |
||
314 | 402 |
void HWForm::NetConnect() |
403 |
{ |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
404 |
HWHostPortDialog * hpd = new HWHostPortDialog(this); |
654 | 405 |
hpd->leHost->setText(*netHost); |
406 |
hpd->sbPort->setValue(netPort); |
|
653
4f44fc06ca45
Class to ask host/port to connect to ('Specify' button on PageNet)
unc0rr
parents:
647
diff
changeset
|
407 |
|
654 | 408 |
if (hpd->exec() == QDialog::Accepted) |
409 |
{ |
|
410 |
config->SaveOptions(); |
|
411 |
delete netHost; |
|
412 |
netHost = new QString(hpd->leHost->text()); |
|
413 |
netPort = hpd->sbPort->value(); |
|
414 |
_NetConnect(*netHost, netPort, ui.pageOptions->editNetNick->text()); |
|
415 |
} |
|
314 | 416 |
} |
417 |
||
418 |
void HWForm::NetStartServer() |
|
419 |
{ |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
420 |
config->SaveOptions(); |
314 | 421 |
pnetserver = new HWNetServer; |
658 | 422 |
pnetserver->StartServer(ui.pageNetServer->sbPort->value()); |
647 | 423 |
_NetConnect("localhost", pnetserver->getRunningPort(), ui.pageOptions->editNetNick->text()); |
636 | 424 |
|
425 |
if (ui.pageNet->rbLocalGame->isChecked()) |
|
659 | 426 |
pRegisterServer = new HWNetUdpServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value()); |
636 | 427 |
else |
659 | 428 |
pRegisterServer = new HWNetWwwServer(0, ui.pageNetServer->leServerDescr->text(), ui.pageNetServer->sbPort->value()); |
314 | 429 |
} |
430 |
||
184 | 431 |
void HWForm::NetDisconnect() |
432 |
{ |
|
383 | 433 |
if(hwnet) { |
434 |
hwnet->Disconnect(); |
|
435 |
delete hwnet; |
|
436 |
hwnet=0; |
|
437 |
} |
|
314 | 438 |
if(pnetserver) { |
660 | 439 |
if (pRegisterServer) |
440 |
{ |
|
441 |
pRegisterServer->unregister(); |
|
442 |
pRegisterServer = 0; |
|
443 |
} |
|
659 | 444 |
|
314 | 445 |
pnetserver->StopServer(); |
446 |
delete pnetserver; |
|
447 |
pnetserver=0; |
|
448 |
} |
|
184 | 449 |
} |
450 |
||
383 | 451 |
void HWForm::ForcedDisconnect() |
452 |
{ |
|
453 |
if(pnetserver) return; // we have server - let it care of all things |
|
454 |
if (hwnet) { |
|
455 |
hwnet->deleteLater(); |
|
456 |
hwnet=0; |
|
425 | 457 |
QMessageBox::warning(this, QMessageBox::tr("Network"), |
407 | 458 |
QMessageBox::tr("Connection to server is lost")); |
383 | 459 |
} |
460 |
GoBack(); |
|
461 |
} |
|
462 |
||
184 | 463 |
void HWForm::NetGameEnter() |
464 |
{ |
|
290 | 465 |
GoToPage(ID_PAGE_NETCFG); |
184 | 466 |
} |
467 |
||
468 |
void HWForm::NetStartGame() |
|
469 |
{ |
|
448 | 470 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Waiting")); |
471 |
ui.pageNetGame->BtnGo->setEnabled(false); |
|
472 |
hwnet->StartGame(); |
|
184 | 473 |
} |
474 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
475 |
void HWForm::AddNetTeam(const HWTeam& team) |
184 | 476 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
477 |
ui.pageNetGame->pNetTeamsWidget->addTeam(team); |
184 | 478 |
} |
479 |
||
480 |
void HWForm::StartMPGame() |
|
481 |
{ |
|
341 | 482 |
CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect); |
306 | 483 |
|
184 | 484 |
game->StartLocal(); |
485 |
} |
|
306 | 486 |
|
487 |
void HWForm::GameStateChanged(GameState gameState) |
|
488 |
{ |
|
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
489 |
switch(gameState) { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
490 |
case gsStarted: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
491 |
ui.pageGameStats->labelGameStats->setText(""); |
661
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
492 |
if (pRegisterServer) |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
493 |
{ |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
494 |
pRegisterServer->unregister(); |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
495 |
pRegisterServer = 0; |
0523b15353a2
Unregister server in servers list when the game is started
unc0rr
parents:
660
diff
changeset
|
496 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
497 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
498 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
499 |
case gsFinished: { |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
500 |
GoToPage(ID_PAGE_GAMESTATS); |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
501 |
break; |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
502 |
} |
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
503 |
default: ; |
307 | 504 |
} |
324
f4c109c82a0c
Don't show game stats in case of interrupted by command '/quit' game
unc0rr
parents:
323
diff
changeset
|
505 |
|
660 | 506 |
if (hwnet) |
507 |
{ |
|
508 |
ui.pageNetGame->BtnGo->setText(QPushButton::tr("Go!")); |
|
509 |
ui.pageNetGame->BtnGo->setEnabled(true); |
|
510 |
} |
|
307 | 511 |
} |
512 |
||
513 |
void HWForm::AddStatText(const QString & msg) |
|
514 |
{ |
|
515 |
ui.pageGameStats->labelGameStats->setText( |
|
516 |
ui.pageGameStats->labelGameStats->text() + msg); |
|
306 | 517 |
} |
518 |
||
519 |
void HWForm::GameStats(char type, const QString & info) |
|
520 |
{ |
|
521 |
switch(type) { |
|
307 | 522 |
case 'r' : { |
523 |
AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
|
524 |
break; |
|
525 |
} |
|
526 |
case 'D' : { |
|
527 |
int i = info.indexOf(' '); |
|
528 |
QString message = QLabel::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
|
529 |
.arg(info.mid(i + 1), info.left(i)); |
|
530 |
AddStatText(message); |
|
531 |
break; |
|
532 |
} |
|
533 |
case 'K' : { |
|
534 |
QString message = QLabel::tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info); |
|
535 |
AddStatText(message); |
|
536 |
break; |
|
537 |
} |
|
306 | 538 |
} |
539 |
} |
|
540 |
||
341 | 541 |
void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) |
306 | 542 |
{ |
341 | 543 |
game = new HWGame(config, gamecfg, pTeamSelWidget); |
306 | 544 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
545 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
425 | 546 |
connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
533 | 547 |
connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &))); |
306 | 548 |
} |
425 | 549 |
|
550 |
void HWForm::ShowErrorMessage(const QString & msg) |
|
551 |
{ |
|
552 |
QMessageBox::warning(this, |
|
553 |
"Hedgewars", |
|
554 |
msg); |
|
555 |
} |
|
533 | 556 |
|
557 |
void HWForm::GetRecord(bool isDemo, const QByteArray & record) |
|
558 |
{ |
|
559 |
QString filename; |
|
560 |
QByteArray demo = record; |
|
561 |
if (isDemo) |
|
562 |
{ |
|
563 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
|
564 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
|
579 | 565 |
filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer; |
533 | 566 |
} else |
567 |
{ |
|
568 |
demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS")); |
|
569 |
demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS")); |
|
579 | 570 |
filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer; |
533 | 571 |
} |
572 |
||
573 |
||
574 |
QFile demofile(filename); |
|
575 |
if (!demofile.open(QIODevice::WriteOnly)) |
|
576 |
{ |
|
577 |
ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); |
|
578 |
return ; |
|
579 |
} |
|
580 |
demofile.write(demo.constData(), demo.size()); |
|
581 |
demofile.close(); |
|
582 |
} |
|
587 | 583 |
|
584 |
void HWForm::StartTraining() |
|
585 |
{ |
|
586 |
CreateGame(0, 0); |
|
587 |
||
588 |
game->StartTraining(); |
|
589 |
} |
|
660 | 590 |
|
591 |
void HWForm::CreateNetGame() |
|
592 |
{ |
|
593 |
CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
|
594 |
||
595 |
connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &))); |
|
596 |
connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &))); |
|
597 |
||
598 |
game->StartNet(); |
|
599 |
} |