author | unc0rr |
Thu, 07 Dec 2006 17:04:55 +0000 | |
changeset 289 | 604c4a779c20 |
parent 271 | f2f9a3d5b441 |
child 290 | 09738170c557 |
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 |
||
43 |
config = new GameUIConfig(this); |
|
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 |
|
184 | 86 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
87 |
} |
|
88 |
||
245 | 89 |
void HWForm::UpdateTeamsLists() |
90 |
{ |
|
91 |
QStringList teamslist = config->GetTeamsList(); |
|
92 |
||
93 |
if(teamslist.empty()) { |
|
94 |
HWTeam defaultTeam("DefaultTeam"); |
|
95 |
defaultTeam.SaveToFile(); |
|
96 |
teamslist.push_back("DefaultTeam"); |
|
97 |
} |
|
98 |
||
99 |
ui.pageOptions->CBTeamName->clear(); |
|
100 |
ui.pageOptions->CBTeamName->addItems(teamslist); |
|
101 |
} |
|
102 |
||
184 | 103 |
void HWForm::GoToMain() |
104 |
{ |
|
289 | 105 |
GoToPage(ID_PAGE_MAIN); |
184 | 106 |
} |
107 |
||
108 |
void HWForm::GoToSinglePlayer() |
|
109 |
{ |
|
289 | 110 |
GoToPage(ID_PAGE_SINGLEPLAYER); |
184 | 111 |
} |
112 |
||
113 |
void HWForm::GoToSetup() |
|
114 |
{ |
|
289 | 115 |
GoToPage(ID_PAGE_SETUP); |
184 | 116 |
} |
117 |
||
187 | 118 |
void HWForm::GoToInfo() |
119 |
{ |
|
289 | 120 |
GoToPage(ID_PAGE_INFO); |
187 | 121 |
} |
122 |
||
184 | 123 |
void HWForm::GoToMultiplayer() |
124 |
{ |
|
231 | 125 |
QStringList tmNames=config->GetTeamsList(); |
126 |
QList<HWTeam> teamsList; |
|
127 |
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
|
128 |
HWTeam team(*it); |
|
129 |
team.LoadFromFile(); |
|
130 |
teamsList.push_back(team); |
|
131 |
} |
|
132 |
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList); |
|
184 | 133 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
134 |
} |
|
135 |
||
136 |
void HWForm::GoToDemos() |
|
137 |
{ |
|
138 |
QDir tmpdir; |
|
139 |
tmpdir.cd(cfgdir->absolutePath()); |
|
140 |
tmpdir.cd("Demos"); |
|
141 |
tmpdir.setFilter(QDir::Files); |
|
142 |
ui.pagePlayDemo->DemosList->clear(); |
|
271 | 143 |
ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_" + cProtoVer)) |
144 |
.replaceInStrings(QRegExp("^(.*).hwd_" + cProtoVer), "\\1")); |
|
184 | 145 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
146 |
} |
|
147 |
||
148 |
void HWForm::GoToNet() |
|
149 |
{ |
|
289 | 150 |
GoToPage(ID_PAGE_NET); |
184 | 151 |
} |
152 |
||
153 |
void HWForm::GoToNetChat() |
|
154 |
{ |
|
289 | 155 |
GoToPage(ID_PAGE_NETCHAT); |
156 |
} |
|
157 |
||
158 |
void HWForm::GoToPage(quint8 id) |
|
159 |
{ |
|
160 |
PagesStack.push(ui.Pages->currentIndex()); |
|
161 |
ui.Pages->setCurrentIndex(id); |
|
162 |
} |
|
163 |
||
164 |
void HWForm::GoBack() |
|
165 |
{ |
|
166 |
quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); |
|
167 |
ui.Pages->setCurrentIndex(id); |
|
184 | 168 |
} |
169 |
||
170 |
void HWForm::NewTeam() |
|
171 |
{ |
|
245 | 172 |
editedTeam = new HWTeam("unnamed"); |
173 |
editedTeam->SetToPage(this); |
|
184 | 174 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
175 |
} |
|
176 |
||
177 |
void HWForm::EditTeam() |
|
178 |
{ |
|
245 | 179 |
editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); |
180 |
editedTeam->LoadFromFile(); |
|
181 |
editedTeam->SetToPage(this); |
|
184 | 182 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
183 |
} |
|
184 |
||
185 |
void HWForm::TeamSave() |
|
186 |
{ |
|
245 | 187 |
editedTeam->GetFromPage(this); |
188 |
editedTeam->SaveToFile(); |
|
189 |
delete editedTeam; |
|
190 |
UpdateTeamsLists(); |
|
184 | 191 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
192 |
} |
|
193 |
||
194 |
void HWForm::TeamDiscard() |
|
195 |
{ |
|
245 | 196 |
delete editedTeam; |
184 | 197 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
198 |
} |
|
199 |
||
200 |
void HWForm::SimpleGame() |
|
201 |
{ |
|
202 |
game = new HWGame(config, ui.pageLocalGame->gameCFG); |
|
203 |
game->StartQuick(); |
|
204 |
} |
|
205 |
||
206 |
void HWForm::PlayDemo() |
|
207 |
{ |
|
208 |
QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); |
|
209 |
if (!curritem) |
|
210 |
{ |
|
211 |
QMessageBox::critical(this, |
|
212 |
tr("Error"), |
|
213 |
tr("Please, select demo from the list above"), |
|
214 |
tr("OK")); |
|
215 |
return ; |
|
216 |
} |
|
217 |
game = new HWGame(config, 0); |
|
271 | 218 |
game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer); |
184 | 219 |
} |
220 |
||
221 |
void HWForm::NetConnect() |
|
222 |
{ |
|
223 |
hwnet = new HWNet(config); |
|
224 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
|
225 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
|
226 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
|
227 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
|
228 |
hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text()); |
|
229 |
config->SaveOptions(); |
|
230 |
} |
|
231 |
||
232 |
void HWForm::NetDisconnect() |
|
233 |
{ |
|
234 |
hwnet->Disconnect(); |
|
235 |
GoToNet(); |
|
236 |
} |
|
237 |
||
238 |
void HWForm::AddGame(const QString & chan) |
|
239 |
{ |
|
240 |
ui.pageNetChat->ChannelsList->addItem(chan); |
|
241 |
} |
|
242 |
||
243 |
void HWForm::NetGameEnter() |
|
244 |
{ |
|
245 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
|
246 |
} |
|
247 |
||
248 |
void HWForm::NetJoin() |
|
249 |
{ |
|
250 |
hwnet->JoinGame("#hw"); |
|
251 |
} |
|
252 |
||
253 |
void HWForm::NetCreate() |
|
254 |
{ |
|
255 |
hwnet->JoinGame("#hw"); |
|
256 |
} |
|
257 |
||
258 |
void HWForm::NetAddTeam() |
|
259 |
{ |
|
260 |
HWTeam team("DefaultTeam"); |
|
261 |
team.LoadFromFile(); |
|
262 |
hwnet->AddTeam(team); |
|
263 |
} |
|
264 |
||
265 |
void HWForm::NetStartGame() |
|
266 |
{ |
|
267 |
hwnet->StartGame(); |
|
268 |
} |
|
269 |
||
270 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
|
271 |
{ |
|
272 |
ui.pageNetGame->listNetTeams->clear(); |
|
273 |
ui.pageNetGame->listNetTeams->addItems(teams); |
|
274 |
} |
|
275 |
||
276 |
void HWForm::StartMPGame() |
|
277 |
{ |
|
278 |
game = new HWGame(config, ui.pageMultiplayer->gameCFG); |
|
279 |
list<HWTeam> teamslist=ui.pageMultiplayer->teamsSelect->getPlayingTeams(); |
|
280 |
for (list<HWTeam>::const_iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
207 | 281 |
HWTeamTempParams params=ui.pageMultiplayer->teamsSelect->getTeamParams(it->TeamName); |
213 | 282 |
game->AddTeam(it->TeamName, params); |
184 | 283 |
} |
284 |
game->StartLocal(); |
|
285 |
} |