author | unc0rr |
Mon, 24 Jul 2006 22:37:34 +0000 | |
changeset 84 | 0f6669da2fcb |
parent 60 | 7fbfa2f13f6f |
child 85 | 44d9045b26ff |
permissions | -rw-r--r-- |
20 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*/ |
|
33 |
||
34 |
#include <QtGui> |
|
35 |
#include <QStringList> |
|
36 |
#include <QProcess> |
|
37 |
#include <QDir> |
|
38 |
#include <QPixmap> |
|
39 |
#include <QRegExp> |
|
40 |
#include <QIcon> |
|
41 |
#include <QFile> |
|
42 |
#include <QTextStream> |
|
43 |
||
44 |
#include "hwform.h" |
|
45 |
#include "sdlkeys.h" |
|
46 |
#include "hwconsts.h" |
|
84 | 47 |
#include "gameconfig.h" |
20 | 48 |
|
49 |
HWForm::HWForm(QWidget *parent) |
|
50 |
: QMainWindow(parent) |
|
51 |
{ |
|
52 |
ui.setupUi(this); |
|
53 |
TeamNameEdit = new QLineEdit(ui.GBoxTeam); |
|
54 |
TeamNameEdit->setGeometry(QRect(10, 20, 141, 20)); |
|
55 |
TeamNameEdit->setMaxLength(15); |
|
56 |
for(int i = 0; i < 8; i++) |
|
57 |
{ |
|
58 |
HHNameEdit[i] = new QLineEdit(ui.GBoxHedgehogs); |
|
59 |
HHNameEdit[i]->setGeometry(QRect(10, 20 + i * 30, 141, 20)); |
|
60 |
HHNameEdit[i]->setMaxLength(15); |
|
61 |
} |
|
25 | 62 |
|
20 | 63 |
QStringList binds; |
64 |
for(int i = 0; strlen(sdlkeys[i][1]) > 0; i++) |
|
65 |
{ |
|
66 |
binds << sdlkeys[i][1]; |
|
67 |
} |
|
25 | 68 |
|
26 | 69 |
quint16 widind = 0, top = 0; |
70 |
for(quint8 i = 0; i < BINDS_NUMBER; i++) |
|
20 | 71 |
{ |
26 | 72 |
LBind[i] = new QLabel(ui.BindsBox->widget(widind)); |
41 | 73 |
LBind[i]->setGeometry(QRect(10, top + 3, 70, 20)); |
20 | 74 |
LBind[i]->setText(cbinds[i].name); |
75 |
LBind[i]->setAlignment(Qt::AlignRight); |
|
26 | 76 |
CBBind[i] = new QComboBox(ui.BindsBox->widget(widind)); |
41 | 77 |
CBBind[i]->setGeometry(QRect(90, top, 80, 20)); |
20 | 78 |
CBBind[i]->addItems(binds); |
26 | 79 |
if (cbinds[i].chwidget) |
80 |
{ |
|
81 |
top = 0; |
|
82 |
widind++; |
|
83 |
} else |
|
84 |
{ |
|
41 | 85 |
top += 28; |
26 | 86 |
} |
20 | 87 |
} |
25 | 88 |
|
20 | 89 |
QDir tmpdir; |
90 |
tmpdir.cd(DATA_PATH); |
|
91 |
tmpdir.cd("Forts"); |
|
92 |
tmpdir.setFilter(QDir::Files); |
|
25 | 93 |
|
20 | 94 |
ui.CBFort->addItems(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L.png"), "\\1")); |
25 | 95 |
|
20 | 96 |
tmpdir.cd("../Graphics/Graves"); |
97 |
QStringList list = tmpdir.entryList(QStringList("*.png")); |
|
98 |
for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
|
99 |
{ |
|
100 |
ui.CBGrave->addItem((*it).replace(QRegExp("^(.*).png"), "\\1")); |
|
101 |
} |
|
102 |
||
84 | 103 |
config = new GameConfig(this); |
104 |
||
105 |
QStringList teamslist = config->GetTeamsList(); |
|
25 | 106 |
|
84 | 107 |
if(teamslist.empty()) { |
44 | 108 |
HWTeam defaultTeam("DefaultTeam"); |
84 | 109 |
defaultTeam.SetCfgDir(config->cfgdir.absolutePath()); |
44 | 110 |
defaultTeam.SaveToFile(); |
84 | 111 |
teamslist.push_back("DefaultTeam"); |
44 | 112 |
} |
113 |
||
60
7fbfa2f13f6f
vector removed & teamselwidget moved to constructor
displacer
parents:
52
diff
changeset
|
114 |
pts=new TeamSelWidget(ui.Pages->widget(ID_PAGE_SINGLEPLAYER)); |
7fbfa2f13f6f
vector removed & teamselwidget moved to constructor
displacer
parents:
52
diff
changeset
|
115 |
|
84 | 116 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) |
21 | 117 |
{ |
50 | 118 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1"); |
60
7fbfa2f13f6f
vector removed & teamselwidget moved to constructor
displacer
parents:
52
diff
changeset
|
119 |
pts->addTeam(tmpTeamStr); |
50 | 120 |
ui.CBTeamName->addItem(tmpTeamStr); |
21 | 121 |
} |
25 | 122 |
|
28 | 123 |
connect(ui.BtnSPBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
124 |
connect(ui.BtnDemosBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
125 |
connect(ui.BtnSetupBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
126 |
connect(ui.BtnMPBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
127 |
connect(ui.BtnNetBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
128 |
connect(ui.BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
129 |
connect(ui.BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
130 |
connect(ui.BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
131 |
connect(ui.BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
132 |
connect(ui.BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
133 |
connect(ui.BtnNetCFGBack, SIGNAL(clicked()), this, SLOT(GoToNetChat())); |
28 | 134 |
connect(ui.BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
135 |
connect(ui.BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
136 |
connect(ui.BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
137 |
connect(ui.BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
138 |
connect(ui.BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
|
84 | 139 |
connect(ui.BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
28 | 140 |
connect(ui.BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
141 |
connect(ui.BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
|
142 |
connect(ui.BtnNetChatDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect())); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
143 |
connect(ui.BtnNetChatJoin, SIGNAL(clicked()), this, SLOT(NetJoin())); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
144 |
connect(ui.BtnNetChatCreate, SIGNAL(clicked()), this, SLOT(NetCreate())); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
145 |
connect(ui.BtnNetCFGAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
146 |
connect(ui.BtnNetCFGGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
28 | 147 |
connect(ui.CBGrave, SIGNAL(activated(const QString &)), this, SLOT(CBGrave_activated(const QString &))); |
148 |
connect(ui.CBFort, SIGNAL(activated(const QString &)), this, SLOT(CBFort_activated(const QString &))); |
|
20 | 149 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
150 |
} |
|
151 |
||
152 |
void HWForm::GoToMain() |
|
153 |
{ |
|
154 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
|
155 |
} |
|
156 |
||
157 |
void HWForm::GoToSinglePlayer() |
|
158 |
{ |
|
159 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER); |
|
50 | 160 |
|
161 |
pts->resize(500, 350); |
|
162 |
pts->show(); |
|
20 | 163 |
} |
164 |
||
165 |
void HWForm::GoToSetup() |
|
166 |
{ |
|
167 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
168 |
} |
|
169 |
||
25 | 170 |
void HWForm::GoToMultiplayer() |
171 |
{ |
|
172 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
|
173 |
} |
|
26 | 174 |
|
175 |
void HWForm::GoToDemos() |
|
176 |
{ |
|
177 |
QDir tmpdir; |
|
178 |
tmpdir.cd(DATA_PATH); |
|
179 |
tmpdir.cd("Demos"); |
|
180 |
tmpdir.setFilter(QDir::Files); |
|
28 | 181 |
ui.DemosList->clear(); |
26 | 182 |
ui.DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); |
183 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
|
184 |
} |
|
185 |
||
28 | 186 |
void HWForm::GoToNet() |
187 |
{ |
|
188 |
ui.Pages->setCurrentIndex(ID_PAGE_NET); |
|
189 |
} |
|
190 |
||
191 |
void HWForm::GoToNetChat() |
|
192 |
{ |
|
193 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT); |
|
194 |
} |
|
195 |
||
20 | 196 |
void HWForm::NewTeam() |
197 |
{ |
|
25 | 198 |
tmpTeam = new HWTeam("unnamed"); |
84 | 199 |
tmpTeam->SetCfgDir(config->cfgdir.absolutePath()); |
21 | 200 |
tmpTeam->SetToPage(this); |
20 | 201 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
202 |
} |
|
203 |
||
204 |
void HWForm::EditTeam() |
|
205 |
{ |
|
25 | 206 |
tmpTeam = new HWTeam(ui.CBTeamName->currentText()); |
84 | 207 |
tmpTeam->SetCfgDir(config->cfgdir.absolutePath()); |
21 | 208 |
tmpTeam->LoadFromFile(); |
209 |
tmpTeam->SetToPage(this); |
|
20 | 210 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
211 |
} |
|
212 |
||
213 |
void HWForm::TeamSave() |
|
214 |
{ |
|
21 | 215 |
tmpTeam->GetFromPage(this); |
216 |
tmpTeam->SaveToFile(); |
|
217 |
delete tmpTeam; |
|
20 | 218 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
219 |
} |
|
220 |
||
221 |
void HWForm::TeamDiscard() |
|
222 |
{ |
|
223 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
224 |
} |
|
225 |
||
226 |
void HWForm::SimpleGame() |
|
227 |
{ |
|
84 | 228 |
game = new HWGame(config); |
45
1072e7fe85c8
DefaultTeam is now default to play with single and network game
displacer
parents:
44
diff
changeset
|
229 |
game->AddTeam("DefaultTeam"); |
1072e7fe85c8
DefaultTeam is now default to play with single and network game
displacer
parents:
44
diff
changeset
|
230 |
game->AddTeam("DefaultTeam"); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
231 |
game->StartLocal(); |
20 | 232 |
} |
233 |
||
234 |
void HWForm::CBGrave_activated(const QString & gravename) |
|
235 |
{ |
|
236 |
QPixmap pix(QString(DATA_PATH) + "/Graphics/Graves/" + gravename + ".png"); |
|
237 |
ui.GravePreview->setPixmap(pix.copy(0, 0, 32, 32)); |
|
238 |
} |
|
239 |
||
240 |
void HWForm::CBFort_activated(const QString & fortname) |
|
241 |
{ |
|
242 |
QPixmap pix(QString(DATA_PATH) + "/Forts/" + fortname + "L.png"); |
|
243 |
ui.FortPreview->setPixmap(pix); |
|
244 |
} |
|
245 |
||
26 | 246 |
void HWForm::PlayDemo() |
247 |
{ |
|
248 |
QListWidgetItem * curritem = ui.DemosList->currentItem(); |
|
249 |
if (!curritem) |
|
250 |
{ |
|
251 |
QMessageBox::critical(this, |
|
252 |
tr("Error"), |
|
253 |
tr("Please, select demo from the list above"), |
|
254 |
tr("OK")); |
|
255 |
return ; |
|
256 |
} |
|
84 | 257 |
game = new HWGame(config); |
26 | 258 |
game->PlayDemo(QString(DATA_PATH) + "/Demos/" + curritem->text() + ".hwd_1"); |
259 |
} |
|
260 |
||
28 | 261 |
void HWForm::NetConnect() |
262 |
{ |
|
84 | 263 |
hwnet = new HWNet(config); |
28 | 264 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
265 |
connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &))); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
266 |
connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
267 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
36 | 268 |
hwnet->Connect("172.19.5.168", 6667, ui.editNetNick->text()); |
28 | 269 |
} |
26 | 270 |
|
28 | 271 |
void HWForm::NetDisconnect() |
272 |
{ |
|
273 |
hwnet->Disconnect(); |
|
274 |
GoToNet(); |
|
275 |
} |
|
276 |
||
277 |
void HWForm::AddGame(const QString & chan) |
|
278 |
{ |
|
279 |
ui.ChannelsList->addItem(chan); |
|
280 |
} |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
281 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
282 |
void HWForm::NetGameEnter() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
283 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
284 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
285 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
286 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
287 |
void HWForm::NetJoin() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
288 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
289 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
290 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
291 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
292 |
void HWForm::NetCreate() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
293 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
294 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
295 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
296 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
297 |
void HWForm::NetAddTeam() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
298 |
{ |
45
1072e7fe85c8
DefaultTeam is now default to play with single and network game
displacer
parents:
44
diff
changeset
|
299 |
HWTeam team("DefaultTeam"); |
84 | 300 |
team.SetCfgDir(config->cfgdir.absolutePath()); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
301 |
team.LoadFromFile(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
302 |
hwnet->AddTeam(team); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
303 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
304 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
305 |
void HWForm::NetStartGame() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
306 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
307 |
hwnet->StartGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
308 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
309 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
310 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
311 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
312 |
ui.listNetTeams->clear(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
313 |
ui.listNetTeams->addItems(teams); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
314 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
315 |