author | unc0rr |
Thu, 04 Jan 2007 16:27:45 +0000 | |
changeset 306 | 7b61834edcf6 |
parent 301 | 29bf9c1a3ad3 |
child 307 | 96b428ac11f2 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 <QtGui> |
|
20 |
#include <QStringList> |
|
21 |
#include <QProcess> |
|
22 |
#include <QDir> |
|
23 |
#include <QPixmap> |
|
24 |
#include <QRegExp> |
|
25 |
#include <QIcon> |
|
26 |
#include <QFile> |
|
27 |
#include <QTextStream> |
|
28 |
||
29 |
#include "hwform.h" |
|
30 |
#include "game.h" |
|
31 |
#include "team.h" |
|
32 |
#include "netclient.h" |
|
33 |
#include "teamselect.h" |
|
34 |
#include "gameuiconfig.h" |
|
35 |
#include "pages.h" |
|
36 |
#include "hwconsts.h" |
|
37 |
||
38 |
HWForm::HWForm(QWidget *parent) |
|
39 |
: QMainWindow(parent) |
|
40 |
{ |
|
41 |
ui.setupUi(this); |
|
42 |
||
301 | 43 |
config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
184 | 44 |
|
245 | 45 |
UpdateTeamsLists(); |
184 | 46 |
|
47 |
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
48 |
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
49 |
connect(ui.pageMain->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
50 |
connect(ui.pageMain->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
51 |
connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
187 | 52 |
connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo())); |
184 | 53 |
connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close())); |
54 |
||
289 | 55 |
connect(ui.pageLocalGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 56 |
connect(ui.pageLocalGame->BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
57 |
||
58 |
connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
59 |
connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
60 |
||
289 | 61 |
connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 62 |
connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); |
63 |
||
289 | 64 |
connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 65 |
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
|
66 |
connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); |
184 | 67 |
|
289 | 68 |
connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 69 |
connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
70 |
connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
71 |
connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
|
72 |
||
289 | 73 |
connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 74 |
connect(ui.pageNet->BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
75 |
||
289 | 76 |
connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
184 | 77 |
connect(ui.pageNetGame->BtnAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
78 |
connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
|
79 |
||
80 |
connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect())); |
|
81 |
connect(ui.pageNetChat->BtnJoin, SIGNAL(clicked()), this, SLOT(NetJoin())); |
|
82 |
connect(ui.pageNetChat->BtnCreate, SIGNAL(clicked()), this, SLOT(NetCreate())); |
|
83 |
||
289 | 84 |
connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
187 | 85 |
|
306 | 86 |
connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
87 |
||
290 | 88 |
GoToPage(ID_PAGE_MAIN); |
184 | 89 |
} |
90 |
||
245 | 91 |
void HWForm::UpdateTeamsLists() |
92 |
{ |
|
93 |
QStringList teamslist = config->GetTeamsList(); |
|
94 |
||
95 |
if(teamslist.empty()) { |
|
96 |
HWTeam defaultTeam("DefaultTeam"); |
|
97 |
defaultTeam.SaveToFile(); |
|
98 |
teamslist.push_back("DefaultTeam"); |
|
99 |
} |
|
100 |
||
101 |
ui.pageOptions->CBTeamName->clear(); |
|
102 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
103 |
} |
|
104 |
||
184 | 105 |
void HWForm::GoToMain() |
106 |
{ |
|
289 | 107 |
GoToPage(ID_PAGE_MAIN); |
184 | 108 |
} |
109 |
||
110 |
void HWForm::GoToSinglePlayer() |
|
111 |
{ |
|
289 | 112 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 113 |
} |
114 |
||
115 |
void HWForm::GoToSetup() |
|
116 |
{ |
|
289 | 117 |
GoToPage(ID_PAGE_SETUP); |
184 | 118 |
} |
119 |
||
187 | 120 |
void HWForm::GoToInfo() |
121 |
{ |
|
289 | 122 |
GoToPage(ID_PAGE_INFO); |
187 | 123 |
} |
124 |
||
184 | 125 |
void HWForm::GoToMultiplayer() |
126 |
{ |
|
231 | 127 |
QStringList tmNames=config->GetTeamsList(); |
128 |
QList<HWTeam> teamsList; |
|
129 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
130 |
HWTeam team(*it); |
|
131 |
team.LoadFromFile(); |
|
132 |
teamsList.push_back(team); |
|
133 |
} |
|
134 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList); |
|
290 | 135 |
GoToPage(ID_PAGE_MULTIPLAYER); |
184 | 136 |
} |
137 |
||
138 |
void HWForm::GoToDemos() |
|
139 |
{ |
|
140 |
QDir tmpdir; |
|
141 |
tmpdir.cd(cfgdir->absolutePath()); |
|
142 |
tmpdir.cd("Demos"); |
|
143 |
tmpdir.setFilter(QDir::Files); |
|
144 |
ui.pagePlayDemo->DemosList->clear(); |
|
271 | 145 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_" + cProtoVer)) |
146 |
.replaceInStrings(QRegExp("^(.*).hwd_" + cProtoVer), "\\1")); |
|
290 | 147 |
GoToPage(ID_PAGE_DEMOS); |
184 | 148 |
} |
149 |
||
150 |
void HWForm::GoToNet() |
|
151 |
{ |
|
289 | 152 |
GoToPage(ID_PAGE_NET); |
184 | 153 |
} |
154 |
||
155 |
void HWForm::GoToNetChat() |
|
156 |
{ |
|
289 | 157 |
GoToPage(ID_PAGE_NETCHAT); |
158 |
} |
|
159 |
||
160 |
void HWForm::GoToPage(quint8 id) |
|
161 |
{ |
|
162 |
PagesStack.push(ui.Pages->currentIndex()); |
|
163 |
ui.Pages->setCurrentIndex(id); |
|
164 |
} |
|
165 |
||
166 |
void HWForm::GoBack() |
|
167 |
{ |
|
168 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
|
169 |
ui.Pages->setCurrentIndex(id); |
|
184 | 170 |
} |
171 |
||
172 |
void HWForm::NewTeam() |
|
173 |
{ |
|
245 | 174 |
editedTeam = new HWTeam("unnamed"); |
175 |
editedTeam->SetToPage(this); |
|
290 | 176 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 177 |
} |
178 |
||
179 |
void HWForm::EditTeam() |
|
180 |
{ |
|
245 | 181 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
182 |
editedTeam->LoadFromFile(); |
|
183 |
editedTeam->SetToPage(this); |
|
290 | 184 |
GoToPage(ID_PAGE_SETUP_TEAM); |
184 | 185 |
} |
186 |
||
187 |
void HWForm::TeamSave() |
|
188 |
{ |
|
245 | 189 |
editedTeam->GetFromPage(this); |
190 |
editedTeam->SaveToFile(); |
|
191 |
delete editedTeam; |
|
192 |
UpdateTeamsLists(); |
|
290 | 193 |
GoBack(); |
184 | 194 |
} |
195 |
||
196 |
void HWForm::TeamDiscard() |
|
197 |
{ |
|
245 | 198 |
delete editedTeam; |
290 | 199 |
GoBack(); |
184 | 200 |
} |
201 |
||
202 |
void HWForm::SimpleGame() |
|
203 |
{ |
|
306 | 204 |
CreateGame(ui.pageLocalGame->gameCFG); |
184 | 205 |
game->StartQuick(); |
206 |
} |
|
207 |
||
208 |
void HWForm::PlayDemo() |
|
209 |
{ |
|
210 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
211 |
if (!curritem) |
|
212 |
{ |
|
213 |
QMessageBox::critical(this, |
|
214 |
tr("Error"), |
|
215 |
tr("Please, select demo from the list above"), |
|
216 |
tr("OK")); |
|
217 |
return ; |
|
218 |
} |
|
306 | 219 |
CreateGame(0); |
271 | 220 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
184 | 221 |
} |
222 |
||
223 |
void HWForm::NetConnect() |
|
224 |
{ |
|
225 |
hwnet = new HWNet(config); |
|
226 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
|
227 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
|
228 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
|
229 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
|
230 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text()); |
|
231 |
config->SaveOptions(); |
|
232 |
} |
|
233 |
||
234 |
void HWForm::NetDisconnect() |
|
235 |
{ |
|
236 |
hwnet->Disconnect(); |
|
290 | 237 |
GoBack(); |
184 | 238 |
} |
239 |
||
240 |
void HWForm::AddGame(const QString & chan) |
|
241 |
{ |
|
242 |
ui.pageNetChat->ChannelsList->addItem(chan); |
|
243 |
} |
|
244 |
||
245 |
void HWForm::NetGameEnter() |
|
246 |
{ |
|
290 | 247 |
GoToPage(ID_PAGE_NETCFG); |
184 | 248 |
} |
249 |
||
250 |
void HWForm::NetJoin() |
|
251 |
{ |
|
252 |
hwnet->JoinGame("#hw"); |
|
253 |
} |
|
254 |
||
255 |
void HWForm::NetCreate() |
|
256 |
{ |
|
257 |
hwnet->JoinGame("#hw"); |
|
258 |
} |
|
259 |
||
260 |
void HWForm::NetAddTeam() |
|
261 |
{ |
|
262 |
HWTeam team("DefaultTeam"); |
|
263 |
team.LoadFromFile(); |
|
264 |
hwnet->AddTeam(team); |
|
265 |
} |
|
266 |
||
267 |
void HWForm::NetStartGame() |
|
268 |
{ |
|
269 |
hwnet->StartGame(); |
|
270 |
} |
|
271 |
||
272 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
|
273 |
{ |
|
274 |
ui.pageNetGame->listNetTeams->clear(); |
|
275 |
ui.pageNetGame->listNetTeams->addItems(teams); |
|
276 |
} |
|
277 |
||
278 |
void HWForm::StartMPGame() |
|
279 |
{ |
|
306 | 280 |
CreateGame(ui.pageMultiplayer->gameCFG); |
281 |
||
184 | 282 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams(); |
283 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
207 | 284 |
HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName); |
213 | 285 |
game->AddTeam(it->TeamName, params); |
184 | 286 |
} |
287 |
game->StartLocal(); |
|
288 |
} |
|
306 | 289 |
|
290 |
void HWForm::GameStateChanged(GameState gameState) |
|
291 |
{ |
|
292 |
if (gameState == gsStarted) |
|
293 |
GoToPage(ID_PAGE_GAMESTATS); |
|
294 |
} |
|
295 |
||
296 |
void HWForm::GameStats(char type, const QString & info) |
|
297 |
{ |
|
298 |
switch(type) { |
|
299 |
case 'r' : { ui.pageGameStats->labelGameResult->setText(info); break; } |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
void HWForm::CreateGame(GameCFGWidget * gamecfg) |
|
304 |
{ |
|
305 |
game = new HWGame(config, gamecfg); |
|
306 |
connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState))); |
|
307 |
connect(game, SIGNAL(GameStats(char, const QString &)), this, SLOT(GameStats(char, const QString &))); |
|
308 |
} |