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