author | unc0rr |
Tue, 25 Jul 2006 20:19:46 +0000 | |
changeset 86 | 664b536a1c27 |
parent 85 | 44d9045b26ff |
child 87 | ff213e443336 |
permissions | -rw-r--r-- |
20 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
20 | 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" |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
47 |
#include "gameuiconfig.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 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
103 |
config = new GameUIConfig(this); |
84 | 104 |
|
105 |
QStringList teamslist = config->GetTeamsList(); |
|
25 | 106 |
|
84 | 107 |
if(teamslist.empty()) { |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
108 |
HWTeam defaultTeam("DefaultTeam", config); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
109 |
defaultTeam.SaveToFile(); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
110 |
teamslist.push_back("DefaultTeam"); |
44 | 111 |
} |
112 |
||
84 | 113 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) |
21 | 114 |
{ |
50 | 115 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1"); |
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
116 |
ui.PageLGTeamsSelect->addTeam(tmpTeamStr); |
50 | 117 |
ui.CBTeamName->addItem(tmpTeamStr); |
21 | 118 |
} |
25 | 119 |
|
28 | 120 |
connect(ui.BtnSPBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
121 |
connect(ui.BtnDemosBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
122 |
connect(ui.BtnSetupBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
123 |
connect(ui.BtnMPBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
124 |
connect(ui.BtnNetBack, SIGNAL(clicked()), this, SLOT(GoToMain())); |
|
125 |
connect(ui.BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); |
|
126 |
connect(ui.BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); |
|
127 |
connect(ui.BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); |
|
128 |
connect(ui.BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); |
|
129 |
connect(ui.BtnNet, SIGNAL(clicked()), this, SLOT(GoToNet())); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
130 |
connect(ui.BtnNetCFGBack, SIGNAL(clicked()), this, SLOT(GoToNetChat())); |
28 | 131 |
connect(ui.BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); |
132 |
connect(ui.BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); |
|
133 |
connect(ui.BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); |
|
134 |
connect(ui.BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); |
|
135 |
connect(ui.BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); |
|
84 | 136 |
connect(ui.BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); |
28 | 137 |
connect(ui.BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); |
138 |
connect(ui.BtnNetConnect, SIGNAL(clicked()), this, SLOT(NetConnect())); |
|
139 |
connect(ui.BtnNetChatDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect())); |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
140 |
connect(ui.BtnNetChatJoin, SIGNAL(clicked()), this, SLOT(NetJoin())); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
141 |
connect(ui.BtnNetChatCreate, SIGNAL(clicked()), this, SLOT(NetCreate())); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
142 |
connect(ui.BtnNetCFGAddTeam, SIGNAL(clicked()), this, SLOT(NetAddTeam())); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
143 |
connect(ui.BtnNetCFGGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
28 | 144 |
connect(ui.CBGrave, SIGNAL(activated(const QString &)), this, SLOT(CBGrave_activated(const QString &))); |
145 |
connect(ui.CBFort, SIGNAL(activated(const QString &)), this, SLOT(CBFort_activated(const QString &))); |
|
20 | 146 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
147 |
} |
|
148 |
||
149 |
void HWForm::GoToMain() |
|
150 |
{ |
|
151 |
ui.Pages->setCurrentIndex(ID_PAGE_MAIN); |
|
152 |
} |
|
153 |
||
154 |
void HWForm::GoToSinglePlayer() |
|
155 |
{ |
|
156 |
ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER); |
|
157 |
} |
|
158 |
||
159 |
void HWForm::GoToSetup() |
|
160 |
{ |
|
161 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
162 |
} |
|
163 |
||
25 | 164 |
void HWForm::GoToMultiplayer() |
165 |
{ |
|
166 |
ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); |
|
167 |
} |
|
26 | 168 |
|
169 |
void HWForm::GoToDemos() |
|
170 |
{ |
|
171 |
QDir tmpdir; |
|
172 |
tmpdir.cd(DATA_PATH); |
|
173 |
tmpdir.cd("Demos"); |
|
174 |
tmpdir.setFilter(QDir::Files); |
|
28 | 175 |
ui.DemosList->clear(); |
26 | 176 |
ui.DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); |
177 |
ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); |
|
178 |
} |
|
179 |
||
28 | 180 |
void HWForm::GoToNet() |
181 |
{ |
|
182 |
ui.Pages->setCurrentIndex(ID_PAGE_NET); |
|
183 |
} |
|
184 |
||
185 |
void HWForm::GoToNetChat() |
|
186 |
{ |
|
187 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT); |
|
188 |
} |
|
189 |
||
20 | 190 |
void HWForm::NewTeam() |
191 |
{ |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
192 |
tmpTeam = new HWTeam("unnamed", config); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
193 |
|
20 | 194 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
195 |
} |
|
196 |
||
197 |
void HWForm::EditTeam() |
|
198 |
{ |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
199 |
tmpTeam = new HWTeam(ui.CBTeamName->currentText(), config); |
21 | 200 |
tmpTeam->LoadFromFile(); |
201 |
tmpTeam->SetToPage(this); |
|
20 | 202 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM); |
203 |
} |
|
204 |
||
205 |
void HWForm::TeamSave() |
|
206 |
{ |
|
21 | 207 |
tmpTeam->GetFromPage(this); |
208 |
tmpTeam->SaveToFile(); |
|
209 |
delete tmpTeam; |
|
20 | 210 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
211 |
} |
|
212 |
||
213 |
void HWForm::TeamDiscard() |
|
214 |
{ |
|
215 |
ui.Pages->setCurrentIndex(ID_PAGE_SETUP); |
|
216 |
} |
|
217 |
||
218 |
void HWForm::SimpleGame() |
|
219 |
{ |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
220 |
game = new HWGame(config, ui.pageLGGameCFG); |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
221 |
game->StartQuick(); |
20 | 222 |
} |
223 |
||
224 |
void HWForm::CBGrave_activated(const QString & gravename) |
|
225 |
{ |
|
226 |
QPixmap pix(QString(DATA_PATH) + "/Graphics/Graves/" + gravename + ".png"); |
|
227 |
ui.GravePreview->setPixmap(pix.copy(0, 0, 32, 32)); |
|
228 |
} |
|
229 |
||
230 |
void HWForm::CBFort_activated(const QString & fortname) |
|
231 |
{ |
|
232 |
QPixmap pix(QString(DATA_PATH) + "/Forts/" + fortname + "L.png"); |
|
233 |
ui.FortPreview->setPixmap(pix); |
|
234 |
} |
|
235 |
||
26 | 236 |
void HWForm::PlayDemo() |
237 |
{ |
|
238 |
QListWidgetItem * curritem = ui.DemosList->currentItem(); |
|
239 |
if (!curritem) |
|
240 |
{ |
|
241 |
QMessageBox::critical(this, |
|
242 |
tr("Error"), |
|
243 |
tr("Please, select demo from the list above"), |
|
244 |
tr("OK")); |
|
245 |
return ; |
|
246 |
} |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
247 |
game = new HWGame(config, 0); |
26 | 248 |
game->PlayDemo(QString(DATA_PATH) + "/Demos/" + curritem->text() + ".hwd_1"); |
249 |
} |
|
250 |
||
28 | 251 |
void HWForm::NetConnect() |
252 |
{ |
|
84 | 253 |
hwnet = new HWNet(config); |
28 | 254 |
connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat())); |
255 |
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
|
256 |
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
|
257 |
connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &))); |
36 | 258 |
hwnet->Connect("172.19.5.168", 6667, ui.editNetNick->text()); |
28 | 259 |
} |
26 | 260 |
|
28 | 261 |
void HWForm::NetDisconnect() |
262 |
{ |
|
263 |
hwnet->Disconnect(); |
|
264 |
GoToNet(); |
|
265 |
} |
|
266 |
||
267 |
void HWForm::AddGame(const QString & chan) |
|
268 |
{ |
|
269 |
ui.ChannelsList->addItem(chan); |
|
270 |
} |
|
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
271 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
272 |
void HWForm::NetGameEnter() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
273 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
274 |
ui.Pages->setCurrentIndex(ID_PAGE_NETCFG); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
275 |
} |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
276 |
|
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
277 |
void HWForm::NetJoin() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
278 |
{ |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
279 |
hwnet->JoinGame("#hw"); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
280 |
} |
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::NetCreate() |
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 |
hwnet->JoinGame("#hw"); |
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::NetAddTeam() |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
288 |
{ |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
85
diff
changeset
|
289 |
HWTeam team("DefaultTeam", config); |
31
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
290 |
team.LoadFromFile(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
291 |
hwnet->AddTeam(team); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
292 |
} |
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 |
void HWForm::NetStartGame() |
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 |
hwnet->StartGame(); |
99888245a4e8
Now net game is near available, but exception occurs...
unc0rr
parents:
28
diff
changeset
|
297 |
} |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
298 |
|
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
299 |
void HWForm::ChangeInNetTeams(const QStringList & teams) |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
300 |
{ |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
301 |
ui.listNetTeams->clear(); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
302 |
ui.listNetTeams->addItems(teams); |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
303 |
} |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
31
diff
changeset
|
304 |