1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2011 Igor Ulyanov <iulyanov@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 <QPushButton> |
|
20 #include <QBuffer> |
|
21 #include <QUuid> |
|
22 #include <QBitmap> |
|
23 #include <QPainter> |
|
24 #include <QLinearGradient> |
|
25 #include <QColor> |
|
26 #include <QTextStream> |
|
27 #include <QLabel> |
|
28 #include <QListView> |
|
29 #include <QVBoxLayout> |
|
30 #include <QIcon> |
|
31 #include <QLineEdit> |
|
32 #include <QMessageBox> |
|
33 #include <QStringListModel> |
|
34 |
|
35 #include "hwconsts.h" |
|
36 #include "mapContainer.h" |
|
37 #include "igbox.h" |
|
38 #include "HWApplication.h" |
|
39 |
|
40 HWMapContainer::HWMapContainer(QWidget * parent) : |
|
41 QWidget(parent), |
|
42 mainLayout(this), |
|
43 pMap(0), |
|
44 mapgen(MAPGEN_REGULAR) |
|
45 { |
|
46 hhSmall.load(":/res/hh_small.png"); |
|
47 hhLimit = 18; |
|
48 templateFilter = 0; |
|
49 |
|
50 mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
|
51 1, |
|
52 HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
|
53 HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
|
54 |
|
55 QWidget* mapWidget = new QWidget(this); |
|
56 mainLayout.addWidget(mapWidget, 0, 0, Qt::AlignHCenter); |
|
57 |
|
58 QGridLayout* mapLayout = new QGridLayout(mapWidget); |
|
59 mapLayout->setMargin(0); |
|
60 |
|
61 imageButt = new QPushButton(mapWidget); |
|
62 imageButt->setObjectName("imageButt"); |
|
63 imageButt->setFixedSize(256 + 6, 128 + 6); |
|
64 imageButt->setFlat(true); |
|
65 imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
66 mapLayout->addWidget(imageButt, 0, 0, 1, 2); |
|
67 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap())); |
|
68 |
|
69 chooseMap = new QComboBox(mapWidget); |
|
70 chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
71 chooseMap->addItem( |
|
72 // FIXME - need real icons. Disabling until then |
|
73 //QIcon(":/res/mapRandom.png"), |
|
74 QComboBox::tr("generated map...")); |
|
75 chooseMap->addItem( |
|
76 // FIXME - need real icons. Disabling until then |
|
77 //QIcon(":/res/mapMaze.png"), |
|
78 QComboBox::tr("generated maze...")); |
|
79 |
|
80 chooseMap->addItem(QComboBox::tr("hand drawn map...")); |
|
81 chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions |
|
82 |
|
83 chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions |
|
84 |
|
85 int missionindex = chooseMap->count(); |
|
86 numMissions = 0; |
|
87 QFile mapLuaFile; |
|
88 QFile mapCfgFile; |
|
89 for (int i = 0; i < mapList->size(); ++i) { |
|
90 QString map = (*mapList)[i]; |
|
91 mapCfgFile.setFileName( |
|
92 QString("%1/Data/Maps/%2/map.cfg") |
|
93 .arg(cfgdir->absolutePath()) |
|
94 .arg(map)); |
|
95 if (mapCfgFile.exists()) { |
|
96 mapLuaFile.setFileName( |
|
97 QString("%1/Data/Maps/%2/map.lua") |
|
98 .arg(cfgdir->absolutePath()) |
|
99 .arg(map)); |
|
100 } else { |
|
101 mapCfgFile.setFileName( |
|
102 QString("%1/Maps/%2/map.cfg") |
|
103 .arg(datadir->absolutePath()) |
|
104 .arg(map)); |
|
105 mapLuaFile.setFileName( |
|
106 QString("%1/Maps/%2/map.lua") |
|
107 .arg(datadir->absolutePath()) |
|
108 .arg(map)); |
|
109 } |
|
110 |
|
111 if (mapCfgFile.open(QFile::ReadOnly)) { |
|
112 QString theme; |
|
113 quint32 limit = 0; |
|
114 QString scheme; |
|
115 QString weapons; |
|
116 QList<QVariant> mapInfo; |
|
117 QTextStream input(&mapCfgFile); |
|
118 input >> theme; |
|
119 input >> limit; |
|
120 input >> scheme; |
|
121 input >> weapons; |
|
122 mapInfo.push_back(map); |
|
123 mapInfo.push_back(theme); |
|
124 if (limit) |
|
125 mapInfo.push_back(limit); |
|
126 else |
|
127 mapInfo.push_back(18); |
|
128 mapInfo.push_back(mapLuaFile.exists()); |
|
129 if (scheme.isEmpty()) |
|
130 scheme = "locked"; |
|
131 scheme.replace("_", " "); |
|
132 if (weapons.isEmpty()) |
|
133 weapons = "locked"; |
|
134 weapons.replace("_", " "); |
|
135 mapInfo.push_back(scheme); |
|
136 mapInfo.push_back(weapons); |
|
137 if(mapLuaFile.exists()) |
|
138 { |
|
139 chooseMap->insertItem(missionindex++, |
|
140 // FIXME - need real icons. Disabling until then |
|
141 //QIcon(":/res/mapMission.png"), |
|
142 QComboBox::tr("Mission") + ": " + map, mapInfo); |
|
143 numMissions++; |
|
144 } |
|
145 else |
|
146 chooseMap->addItem( |
|
147 // FIXME - need real icons. Disabling until then |
|
148 //QIcon(":/res/mapCustom.png"), |
|
149 map, mapInfo); |
|
150 mapCfgFile.close(); |
|
151 } |
|
152 } |
|
153 chooseMap->insertSeparator(missionindex); // separator between missions and maps |
|
154 |
|
155 connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int))); |
|
156 mapLayout->addWidget(chooseMap, 1, 1); |
|
157 |
|
158 QLabel * lblMap = new QLabel(tr("Map"), mapWidget); |
|
159 mapLayout->addWidget(lblMap, 1, 0); |
|
160 |
|
161 lblFilter = new QLabel(tr("Filter"), mapWidget); |
|
162 mapLayout->addWidget(lblFilter, 2, 0); |
|
163 |
|
164 cbTemplateFilter = new QComboBox(mapWidget); |
|
165 cbTemplateFilter->addItem(tr("All"), 0); |
|
166 cbTemplateFilter->addItem(tr("Small"), 1); |
|
167 cbTemplateFilter->addItem(tr("Medium"), 2); |
|
168 cbTemplateFilter->addItem(tr("Large"), 3); |
|
169 cbTemplateFilter->addItem(tr("Cavern"), 4); |
|
170 cbTemplateFilter->addItem(tr("Wacky"), 5); |
|
171 mapLayout->addWidget(cbTemplateFilter, 2, 1); |
|
172 |
|
173 connect(cbTemplateFilter, SIGNAL(activated(int)), this, SLOT(setTemplateFilter(int))); |
|
174 |
|
175 maze_size_label = new QLabel(tr("Type"), mapWidget); |
|
176 mapLayout->addWidget(maze_size_label, 2, 0); |
|
177 maze_size_label->hide(); |
|
178 cbMazeSize = new QComboBox(mapWidget); |
|
179 cbMazeSize->addItem(tr("Small tunnels"), 0); |
|
180 cbMazeSize->addItem(tr("Medium tunnels"), 1); |
|
181 cbMazeSize->addItem(tr("Large tunnels"), 2); |
|
182 cbMazeSize->addItem(tr("Small floating islands"), 3); |
|
183 cbMazeSize->addItem(tr("Medium floating islands"), 4); |
|
184 cbMazeSize->addItem(tr("Large floating islands"), 5); |
|
185 cbMazeSize->setCurrentIndex(1); |
|
186 |
|
187 mapLayout->addWidget(cbMazeSize, 2, 1); |
|
188 cbMazeSize->hide(); |
|
189 connect(cbMazeSize, SIGNAL(activated(int)), this, SLOT(setMazeSize(int))); |
|
190 |
|
191 gbThemes = new IconedGroupBox(mapWidget); |
|
192 gbThemes->setTitleTextPadding(80); |
|
193 gbThemes->setContentTopPadding(15); |
|
194 gbThemes->setTitle(tr("Themes")); |
|
195 |
|
196 //gbThemes->setStyleSheet("padding: 0px"); // doesn't work - stylesheet is set with icon |
|
197 mapLayout->addWidget(gbThemes, 0, 2, 3, 1); |
|
198 |
|
199 QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes); |
|
200 gbTLayout->setContentsMargins(0, 0, 0 ,0); |
|
201 gbTLayout->setSpacing(0); |
|
202 lvThemes = new QListView(mapWidget); |
|
203 lvThemes->setMinimumHeight(30); |
|
204 lvThemes->setFixedWidth(140); |
|
205 lvThemes->setModel(themesModel); |
|
206 lvThemes->setIconSize(QSize(16, 16)); |
|
207 lvThemes->setEditTriggers(QListView::NoEditTriggers); |
|
208 |
|
209 connect(lvThemes->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT(themeSelected( const QModelIndex &, const QModelIndex &))); |
|
210 |
|
211 // override default style to tighten up theme scroller |
|
212 lvThemes->setStyleSheet(QString( |
|
213 "QListView{" |
|
214 "border: solid;" |
|
215 "border-width: 0px;" |
|
216 "border-radius: 0px;" |
|
217 "border-color: transparent;" |
|
218 "background-color: #0d0544;" |
|
219 "color: #ffcc00;" |
|
220 "font: bold 13px;" |
|
221 "}" |
|
222 ) |
|
223 ); |
|
224 |
|
225 gbTLayout->addWidget(lvThemes); |
|
226 lvThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); |
|
227 |
|
228 mapLayout->setSizeConstraint(QLayout::SetFixedSize); |
|
229 |
|
230 QWidget* seedWidget = new QWidget(this); |
|
231 mainLayout.addWidget(seedWidget, 1, 0); |
|
232 |
|
233 QGridLayout* seedLayout = new QGridLayout(seedWidget); |
|
234 seedLayout->setMargin(0); |
|
235 |
|
236 seedLabel = new QLabel(tr("Seed"), seedWidget); |
|
237 seedLayout->addWidget(seedLabel, 3, 0); |
|
238 seedEdit = new QLineEdit(seedWidget); |
|
239 seedEdit->setMaxLength(54); |
|
240 connect(seedEdit, SIGNAL(returnPressed()), this, SLOT(seedEdited())); |
|
241 seedLayout->addWidget(seedEdit, 3, 1); |
|
242 seedLayout->setColumnStretch(1, 5); |
|
243 seedSet = new QPushButton(seedWidget); |
|
244 seedSet->setText(QPushButton::tr("more")); |
|
245 connect(seedSet, SIGNAL(clicked()), this, SLOT(seedEdited())); |
|
246 seedLayout->setColumnStretch(2, 1); |
|
247 seedLayout->addWidget(seedSet, 3, 2); |
|
248 |
|
249 seedLabel->setVisible(false); |
|
250 seedEdit->setVisible(false); |
|
251 |
|
252 setRandomSeed(); |
|
253 setRandomTheme(); |
|
254 } |
|
255 |
|
256 void HWMapContainer::setImage(const QImage newImage) |
|
257 { |
|
258 QPixmap px(256, 128); |
|
259 QPixmap pxres(256, 128); |
|
260 QPainter p(&pxres); |
|
261 |
|
262 px.fill(Qt::yellow); |
|
263 QBitmap bm = QBitmap::fromImage(newImage); |
|
264 px.setMask(bm); |
|
265 |
|
266 QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128)); |
|
267 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
|
268 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
|
269 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
|
270 p.drawPixmap(QPoint(0, 0), px); |
|
271 |
|
272 addInfoToPreview(pxres); |
|
273 //chooseMap->setCurrentIndex(mapgen); |
|
274 pMap = 0; |
|
275 } |
|
276 |
|
277 void HWMapContainer::setHHLimit(int newHHLimit) |
|
278 { |
|
279 hhLimit = newHHLimit; |
|
280 } |
|
281 |
|
282 void HWMapContainer::mapChanged(int index) |
|
283 { |
|
284 switch(index) { |
|
285 case MAPGEN_REGULAR: |
|
286 mapgen = MAPGEN_REGULAR; |
|
287 updatePreview(); |
|
288 gbThemes->show(); |
|
289 lblFilter->show(); |
|
290 cbTemplateFilter->show(); |
|
291 maze_size_label->hide(); |
|
292 cbMazeSize->hide(); |
|
293 emit mapChanged("+rnd+"); |
|
294 emit themeChanged(chooseMap->itemData(index).toList()[1].toString()); |
|
295 break; |
|
296 case MAPGEN_MAZE: |
|
297 mapgen = MAPGEN_MAZE; |
|
298 updatePreview(); |
|
299 gbThemes->show(); |
|
300 lblFilter->hide(); |
|
301 cbTemplateFilter->hide(); |
|
302 maze_size_label->show(); |
|
303 cbMazeSize->show(); |
|
304 emit mapChanged("+maze+"); |
|
305 emit themeChanged(chooseMap->itemData(index).toList()[1].toString()); |
|
306 break; |
|
307 case MAPGEN_DRAWN: |
|
308 mapgen = MAPGEN_DRAWN; |
|
309 updatePreview(); |
|
310 gbThemes->show(); |
|
311 lblFilter->hide(); |
|
312 cbTemplateFilter->hide(); |
|
313 maze_size_label->hide(); |
|
314 cbMazeSize->hide(); |
|
315 emit mapChanged("+drawn+"); |
|
316 emit themeChanged(chooseMap->itemData(index).toList()[1].toString()); |
|
317 break; |
|
318 default: |
|
319 mapgen = MAPGEN_MAP; |
|
320 updatePreview(); |
|
321 gbThemes->hide(); |
|
322 lblFilter->hide(); |
|
323 cbTemplateFilter->hide(); |
|
324 maze_size_label->hide(); |
|
325 cbMazeSize->hide(); |
|
326 emit mapChanged(chooseMap->itemData(index).toList()[0].toString()); |
|
327 } |
|
328 |
|
329 emit mapgenChanged(mapgen); |
|
330 } |
|
331 |
|
332 // Should this add text to identify map size? |
|
333 void HWMapContainer::addInfoToPreview(QPixmap image) |
|
334 { |
|
335 QPixmap finalImage = QPixmap(image.size()); |
|
336 finalImage.fill(QColor(0, 0, 0, 0)); |
|
337 |
|
338 QPainter p(&finalImage); |
|
339 p.drawPixmap(image.rect(), image); |
|
340 //p.setPen(QColor(0xf4,0x9e,0xe9)); |
|
341 p.setPen(QColor(0xff,0xcc,0x00)); |
|
342 p.setBrush(QColor(0, 0, 0)); |
|
343 p.drawRect(image.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20); |
|
344 p.setFont(QFont("MS Shell Dlg", 10)); |
|
345 p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, QString::number(hhLimit)); |
|
346 p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall); |
|
347 |
|
348 imageButt->setIcon(finalImage); |
|
349 imageButt->setIconSize(image.size()); |
|
350 } |
|
351 |
|
352 void HWMapContainer::askForGeneratedPreview() |
|
353 { |
|
354 if (pMap) |
|
355 { |
|
356 disconnect(pMap, 0, this, SLOT(setImage(const QImage))); |
|
357 disconnect(pMap, 0, this, SLOT(setHHLimit(int))); |
|
358 pMap = 0; |
|
359 } |
|
360 |
|
361 pMap = new HWMap(); |
|
362 connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage))); |
|
363 connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int))); |
|
364 pMap->getImage(m_seed, |
|
365 getTemplateFilter(), |
|
366 get_mapgen(), |
|
367 getMazeSize(), |
|
368 getDrawnMapData() |
|
369 ); |
|
370 } |
|
371 |
|
372 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &) |
|
373 { |
|
374 QString theme = current.data().toString(); |
|
375 QList<QVariant> mapInfo; |
|
376 mapInfo.push_back(QString("+rnd+")); |
|
377 mapInfo.push_back(theme); |
|
378 mapInfo.push_back(18); |
|
379 mapInfo.push_back(false); |
|
380 chooseMap->setItemData(0, mapInfo); |
|
381 mapInfo[0] = QString("+maze+"); |
|
382 chooseMap->setItemData(1, mapInfo); |
|
383 mapInfo[0] = QString("+drawn+"); |
|
384 chooseMap->setItemData(2, mapInfo); |
|
385 |
|
386 gbThemes->setIcon(qVariantValue<QIcon>(current.data(Qt::UserRole))); |
|
387 emit themeChanged(theme); |
|
388 } |
|
389 |
|
390 QString HWMapContainer::getCurrentSeed() const |
|
391 { |
|
392 return m_seed; |
|
393 } |
|
394 |
|
395 QString HWMapContainer::getCurrentMap() const |
|
396 { |
|
397 if(chooseMap->currentIndex() < MAPGEN_MAP) return QString(); |
|
398 return chooseMap->itemData(chooseMap->currentIndex()).toList()[0].toString(); |
|
399 } |
|
400 |
|
401 QString HWMapContainer::getCurrentTheme() const |
|
402 { |
|
403 return chooseMap->itemData(chooseMap->currentIndex()).toList()[1].toString(); |
|
404 } |
|
405 |
|
406 bool HWMapContainer::getCurrentIsMission() const |
|
407 { |
|
408 if(!chooseMap->currentIndex()) return false; |
|
409 return chooseMap->itemData(chooseMap->currentIndex()).toList()[3].toBool(); |
|
410 } |
|
411 |
|
412 int HWMapContainer::getCurrentHHLimit() const |
|
413 { |
|
414 return hhLimit; |
|
415 } |
|
416 |
|
417 QString HWMapContainer::getCurrentScheme() const |
|
418 { |
|
419 return chooseMap->itemData(chooseMap->currentIndex()).toList()[4].toString(); |
|
420 } |
|
421 |
|
422 QString HWMapContainer::getCurrentWeapons() const |
|
423 { |
|
424 return chooseMap->itemData(chooseMap->currentIndex()).toList()[5].toString(); |
|
425 } |
|
426 |
|
427 quint32 HWMapContainer::getTemplateFilter() const |
|
428 { |
|
429 return cbTemplateFilter->itemData(cbTemplateFilter->currentIndex()).toInt(); |
|
430 } |
|
431 |
|
432 void HWMapContainer::resizeEvent ( QResizeEvent * event ) |
|
433 { |
|
434 Q_UNUSED(event); |
|
435 //imageButt->setIconSize(imageButt->size()); |
|
436 } |
|
437 |
|
438 void HWMapContainer::intSetSeed(const QString & seed) |
|
439 { |
|
440 m_seed = seed; |
|
441 if (seed != seedEdit->text()) |
|
442 seedEdit->setText(seed); |
|
443 } |
|
444 |
|
445 void HWMapContainer::setSeed(const QString & seed) |
|
446 { |
|
447 intSetSeed(seed); |
|
448 if (chooseMap->currentIndex() < MAPGEN_DRAWN) |
|
449 updatePreview(); |
|
450 } |
|
451 |
|
452 void HWMapContainer::intSetMap(const QString & map) |
|
453 { |
|
454 int id = 0; |
|
455 for(int i = 0; i < chooseMap->count(); i++) |
|
456 if(!chooseMap->itemData(i).isNull() && chooseMap->itemData(i).toList()[0].toString() == map) |
|
457 { |
|
458 id = i; |
|
459 break; |
|
460 } |
|
461 |
|
462 if(id > 0) { |
|
463 if (pMap) |
|
464 { |
|
465 disconnect(pMap, 0, this, SLOT(setImage(const QImage))); |
|
466 disconnect(pMap, 0, this, SLOT(setHHLimit(int))); |
|
467 pMap = 0; |
|
468 } |
|
469 chooseMap->setCurrentIndex(id); |
|
470 } |
|
471 } |
|
472 |
|
473 void HWMapContainer::setMap(const QString &map) |
|
474 { |
|
475 intSetMap(map); |
|
476 updatePreview(); |
|
477 } |
|
478 |
|
479 void HWMapContainer::setTheme(const QString & theme) |
|
480 { |
|
481 QModelIndexList mdl = themesModel->match(themesModel->index(0), Qt::DisplayRole, theme); |
|
482 |
|
483 if(mdl.size()) |
|
484 lvThemes->setCurrentIndex(mdl.at(0)); |
|
485 } |
|
486 |
|
487 void HWMapContainer::setRandomMap() |
|
488 { |
|
489 setRandomSeed(); |
|
490 switch(chooseMap->currentIndex()) |
|
491 { |
|
492 case MAPGEN_REGULAR: |
|
493 case MAPGEN_MAZE: |
|
494 setRandomTheme(); |
|
495 break; |
|
496 case MAPGEN_DRAWN: |
|
497 emit drawMapRequested(); |
|
498 break; |
|
499 default: |
|
500 if(chooseMap->currentIndex() <= numMissions + MAPGEN_MAP + 1) |
|
501 setRandomMission(); |
|
502 else |
|
503 setRandomStatic(); |
|
504 break; |
|
505 } |
|
506 } |
|
507 |
|
508 void HWMapContainer::setRandomStatic() |
|
509 { |
|
510 int i = MAPGEN_MAP + 3 + numMissions + rand() % (chooseMap->count() - MAPGEN_MAP - 3 - numMissions); |
|
511 chooseMap->setCurrentIndex(i); |
|
512 mapChanged(i); |
|
513 } |
|
514 |
|
515 void HWMapContainer::setRandomMission() |
|
516 { |
|
517 int i = MAPGEN_MAP + 2 + rand() % numMissions; |
|
518 chooseMap->setCurrentIndex(i); |
|
519 mapChanged(i); |
|
520 } |
|
521 |
|
522 void HWMapContainer::setRandomSeed() |
|
523 { |
|
524 m_seed = QUuid::createUuid().toString(); |
|
525 seedEdit->setText(m_seed); |
|
526 emit seedChanged(m_seed); |
|
527 if (chooseMap->currentIndex() < MAPGEN_MAP) |
|
528 updatePreview(); |
|
529 } |
|
530 |
|
531 void HWMapContainer::setRandomTheme() |
|
532 { |
|
533 if(!themesModel->rowCount()) return; |
|
534 quint32 themeNum = rand() % themesModel->rowCount(); |
|
535 lvThemes->setCurrentIndex(themesModel->index(themeNum)); |
|
536 } |
|
537 |
|
538 void HWMapContainer::intSetTemplateFilter(int filter) |
|
539 { |
|
540 cbTemplateFilter->setCurrentIndex(filter); |
|
541 emit newTemplateFilter(filter); |
|
542 } |
|
543 |
|
544 void HWMapContainer::setTemplateFilter(int filter) |
|
545 { |
|
546 intSetTemplateFilter(filter); |
|
547 updatePreview(); |
|
548 } |
|
549 |
|
550 MapGenerator HWMapContainer::get_mapgen(void) const |
|
551 { |
|
552 return mapgen; |
|
553 } |
|
554 |
|
555 int HWMapContainer::getMazeSize(void) const |
|
556 { |
|
557 return cbMazeSize->currentIndex(); |
|
558 } |
|
559 |
|
560 void HWMapContainer::intSetMazeSize(int size) |
|
561 { |
|
562 cbMazeSize->setCurrentIndex(size); |
|
563 emit mazeSizeChanged(size); |
|
564 } |
|
565 |
|
566 void HWMapContainer::setMazeSize(int size) |
|
567 { |
|
568 intSetMazeSize(size); |
|
569 updatePreview(); |
|
570 } |
|
571 |
|
572 void HWMapContainer::intSetMapgen(MapGenerator m) |
|
573 { |
|
574 mapgen = m; |
|
575 |
|
576 if(m != MAPGEN_MAP) |
|
577 chooseMap->setCurrentIndex(m); |
|
578 |
|
579 emit mapgenChanged(m); |
|
580 } |
|
581 |
|
582 void HWMapContainer::setMapgen(MapGenerator m) |
|
583 { |
|
584 intSetMapgen(m); |
|
585 updatePreview(); |
|
586 } |
|
587 |
|
588 void HWMapContainer::setDrawnMapData(const QByteArray & ar) |
|
589 { |
|
590 drawMapScene.decode(ar); |
|
591 updatePreview(); |
|
592 } |
|
593 |
|
594 QByteArray HWMapContainer::getDrawnMapData() |
|
595 { |
|
596 return drawMapScene.encode(); |
|
597 } |
|
598 |
|
599 void HWMapContainer::seedEdited() |
|
600 { |
|
601 if (seedLabel->isVisible() == false ) |
|
602 { |
|
603 seedLabel->setVisible(true); |
|
604 seedEdit->setVisible(true); |
|
605 seedSet->setText(tr("Set")); |
|
606 return; |
|
607 } |
|
608 |
|
609 if (seedEdit->text().isEmpty()) |
|
610 seedEdit->setText(m_seed); |
|
611 else |
|
612 { |
|
613 setSeed(seedEdit->text()); |
|
614 emit seedChanged(seedEdit->text()); |
|
615 } |
|
616 } |
|
617 |
|
618 DrawMapScene * HWMapContainer::getDrawMapScene() |
|
619 { |
|
620 return &drawMapScene; |
|
621 } |
|
622 |
|
623 void HWMapContainer::mapDrawingFinished() |
|
624 { |
|
625 emit drawnMapChanged(getDrawnMapData()); |
|
626 |
|
627 updatePreview(); |
|
628 } |
|
629 |
|
630 void HWMapContainer::updatePreview() |
|
631 { |
|
632 int curIndex = chooseMap->currentIndex(); |
|
633 |
|
634 switch(curIndex) |
|
635 { |
|
636 case MAPGEN_REGULAR: |
|
637 askForGeneratedPreview(); |
|
638 break; |
|
639 case MAPGEN_MAZE: |
|
640 askForGeneratedPreview(); |
|
641 break; |
|
642 case MAPGEN_DRAWN: |
|
643 askForGeneratedPreview(); |
|
644 break; |
|
645 default: |
|
646 QPixmap mapImage; |
|
647 QFile tmpfile; |
|
648 tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png"); |
|
649 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png"); |
|
650 if(!mapImage.load(QFileInfo(tmpfile).absoluteFilePath())) { |
|
651 imageButt->setIcon(QIcon()); |
|
652 return; |
|
653 } |
|
654 |
|
655 hhLimit = chooseMap->itemData(curIndex).toList()[2].toInt(); |
|
656 addInfoToPreview(mapImage); |
|
657 } |
|
658 } |
|
659 |
|
660 void HWMapContainer::setAllMapParameters(const QString &map, MapGenerator m, int mazesize, const QString &seed, int tmpl) |
|
661 { |
|
662 intSetMap(map); |
|
663 intSetMapgen(m); |
|
664 intSetMazeSize(mazesize); |
|
665 intSetSeed(seed); |
|
666 intSetTemplateFilter(tmpl); |
|
667 |
|
668 updatePreview(); |
|
669 } |
|