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 <qmessagebox.h> |
|
35 #include <qdir.h> |
|
36 #include <qtextstream.h> |
|
37 #include <qregexp.h> |
|
38 #include "game.h" |
|
39 #include "hwconsts.h" |
|
40 #include "sdlkeys.h" |
|
41 |
|
42 class QHostAddress; |
|
43 class QDir; |
|
44 class QMessageBox; |
|
45 class QFile; |
|
46 class QTextStream; |
|
47 class QStream; |
|
48 class QPixmap; |
|
49 |
|
50 |
|
51 void HWForm::ButtonLGame_clicked() |
|
52 { |
|
53 engineprocess->clearArguments(); |
|
54 engineprocess->addArgument("hw"); |
|
55 engineprocess->addArgument(resolutions[0][ CBResolutions->currentItem() ]); |
|
56 engineprocess->addArgument(resolutions[1][ CBResolutions->currentItem() ]); |
|
57 engineprocess->addArgument("avematan"); |
|
58 engineprocess->addArgument("46631"); |
|
59 engineprocess->addArgument("=seed="); |
|
60 engineprocess->addArgument("1"); |
|
61 if (!engineprocess->start()) |
|
62 { |
|
63 QMessageBox::critical( this, |
|
64 tr("Fatal error"), |
|
65 tr("Could not start engine."), |
|
66 tr("Quit")); |
|
67 } |
|
68 } |
|
69 |
|
70 |
|
71 void HWForm::init() |
|
72 { |
|
73 QHostAddress addr((Q_UINT32)0x7f000001); |
|
74 ipcserv = new IPCServer(addr, 46631, this); |
|
75 |
|
76 engineprocess = new QProcess; |
|
77 |
|
78 cfgdir.setPath(cfgdir.homeDirPath()); |
|
79 if (!cfgdir.exists(".hedgewars")) |
|
80 { |
|
81 if (!cfgdir.mkdir(".hedgewars")) |
|
82 { |
|
83 QMessageBox::critical(this, |
|
84 tr("Error"), |
|
85 tr("Cannot create directory %s").arg("/.hedgewars"), |
|
86 tr("Quit")); |
|
87 } |
|
88 return ; |
|
89 } |
|
90 cfgdir.cd(".hedgewars"); |
|
91 |
|
92 QFile settings(cfgdir.absPath() + "/options"); |
|
93 if (!settings.open(IO_ReadOnly)) |
|
94 { |
|
95 return ; |
|
96 } |
|
97 QTextStream stream(&settings); |
|
98 stream.setEncoding(QTextStream::Unicode); |
|
99 QString str; |
|
100 |
|
101 while (!stream.atEnd()) |
|
102 { |
|
103 str = stream.readLine(); |
|
104 if (str.startsWith(";")) continue; |
|
105 if (str.startsWith("resolution ")) |
|
106 { |
|
107 str.remove(0, 11); |
|
108 CBResolutions->setCurrentItem(str.toLong()); |
|
109 } else |
|
110 if (str.startsWith("fullscreen ")) |
|
111 { |
|
112 str.remove(0, 11); |
|
113 CBFullscreen->setChecked(str.toLong()); |
|
114 } |
|
115 } |
|
116 settings.close(); |
|
117 |
|
118 QDir tmpdir; |
|
119 tmpdir.cd("../hedgewars/Data/Forts"); |
|
120 tmpdir.setFilter(QDir::Files); |
|
121 CBForts->insertStringList(tmpdir.entryList("*L.png").gres(QRegExp("^(.*)L.png"), "\\1")); |
|
122 CBForts->setCurrentItem(0); |
|
123 |
|
124 tmpdir.cd("../Graphics/Graves"); |
|
125 QStringList list = tmpdir.entryList("*.png"); |
|
126 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
|
127 { |
|
128 QPixmap pix("Data/Graphics/Graves/" + *it); |
|
129 pix.resize(32, 32); |
|
130 CBGraves->insertItem(pix, (*it).replace(QRegExp("^(.*).png"), "\\1")); |
|
131 } |
|
132 |
|
133 QStringList binds; |
|
134 for(int i = 0; strlen(keys[i][1]) > 0; i++) |
|
135 { |
|
136 binds << keys[i][1]; |
|
137 } |
|
138 CBindUp ->insertStringList( binds ); |
|
139 CBindLeft ->insertStringList( binds ); |
|
140 CBindRight ->insertStringList( binds ); |
|
141 CBindDown ->insertStringList( binds ); |
|
142 CBindLJump ->insertStringList( binds ); |
|
143 CBindHJump ->insertStringList( binds ); |
|
144 CBindAttack->insertStringList( binds ); |
|
145 CBindSwitch->insertStringList( binds ); |
|
146 |
|
147 } |
|
148 |
|
149 void HWForm::destroy() |
|
150 { |
|
151 } |
|
152 |
|
153 |
|
154 void HWForm::GoPageOptions() |
|
155 { |
|
156 Pages->raiseWidget(PageOptions); |
|
157 } |
|
158 |
|
159 |
|
160 void HWForm::GoPageMain() |
|
161 { |
|
162 Pages->raiseWidget(PageMain); |
|
163 } |
|
164 |
|
165 |
|
166 void HWForm::SaveSettings() |
|
167 { |
|
168 QFile settings(cfgdir.absPath() + "/options"); |
|
169 if (!settings.open(IO_WriteOnly)) |
|
170 { |
|
171 QMessageBox::critical(this, |
|
172 tr("Error"), |
|
173 tr("Cannot save options to file %s").arg(settings.name()), |
|
174 tr("Quit")); |
|
175 return ; |
|
176 } |
|
177 QTextStream stream(&settings); |
|
178 stream.setEncoding(QTextStream::Unicode); |
|
179 stream << "; Generated by Hedgewars, do not modify" << endl; |
|
180 stream << "resolution " << CBResolutions->currentItem() << endl; |
|
181 stream << "fullscreen " << CBFullscreen->isOn() << endl; |
|
182 settings.close(); |
|
183 } |
|
184 |
|
185 void HWForm::ButtonNetGame_clicked() |
|
186 { |
|
187 Pages->raiseWidget(PageNetGame); |
|
188 } |
|
189 |
|
190 |
|
191 void HWForm::GoPageTeamSettings() |
|
192 { |
|
193 Pages->raiseWidget(PageTeamSettings); |
|
194 } |
|
195 |
|
196 void HWForm::ButtonDemos_clicked() |
|
197 { |
|
198 Pages->raiseWidget(PageDemos); |
|
199 } |
|
200 |
|
201 void HWForm::NewTeam() |
|
202 { |
|
203 HWTeam tmpTeam(this); |
|
204 tmpTeam.ToPage(); |
|
205 } |
|
206 |
|
207 |
|
208 void HWForm::EditTeam() |
|
209 { |
|
210 HWTeam tmpTeam(this); |
|
211 tmpTeam.LoadFromFile(cfgdir.absPath() + "/team.cfg"); |
|
212 tmpTeam.ToPage(); |
|
213 } |
|
214 |
|
215 |
|
216 void HWForm::SaveTeamFromPage() |
|
217 { |
|
218 HWTeam tmpTeam(this); |
|
219 tmpTeam.FromPage(); |
|
220 tmpTeam.SaveToFile(cfgdir.absPath() + "/team.cfg"); |
|
221 } |
|
222 |
|
223 |
|
224 void HWForm::CBForts_activated( const QString & fortname) |
|
225 { |
|
226 QPixmap pix("Data/Forts/" + fortname + "L.png"); |
|
227 FortPreview->setPixmap(pix); |
|
228 } |
|