23 #include <QUuid> |
23 #include <QUuid> |
24 #include <QBitmap> |
24 #include <QBitmap> |
25 #include <QPainter> |
25 #include <QPainter> |
26 #include <QLinearGradient> |
26 #include <QLinearGradient> |
27 #include <QColor> |
27 #include <QColor> |
|
28 #include <QTextStream> |
|
29 |
|
30 #include "hwconsts.h" |
28 |
31 |
29 HWMapContainer::HWMapContainer(QWidget * parent) : |
32 HWMapContainer::HWMapContainer(QWidget * parent) : |
30 QWidget(parent), mainLayout(this) |
33 QWidget(parent), mainLayout(this) |
31 { |
34 { |
32 imageButt=new QPushButton(this); |
35 imageButt=new QPushButton(this); |
34 imageButt->setFlat(true); |
37 imageButt->setFlat(true); |
35 imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
38 imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
36 mainLayout.addWidget(imageButt); |
39 mainLayout.addWidget(imageButt); |
37 connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage())); |
40 connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage())); |
38 changeImage(); |
41 changeImage(); |
|
42 |
|
43 chooseMap=new QComboBox(this); |
|
44 QDir tmpdir; |
|
45 tmpdir.cd(datadir->absolutePath()); |
|
46 tmpdir.cd("Maps"); |
|
47 tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|
48 QStringList mapList=tmpdir.entryList(QStringList("*")); |
|
49 mapList.push_front("generated map..."); |
|
50 chooseMap->addItems(mapList); |
|
51 connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int))); |
|
52 |
|
53 mainLayout.addWidget(chooseMap); |
39 } |
54 } |
40 |
55 |
41 void HWMapContainer::setImage(const QImage newImage) |
56 void HWMapContainer::setImage(const QImage newImage) |
42 { |
57 { |
43 QPixmap px(256, 128); |
58 QPixmap px(256, 128); |
52 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
67 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
53 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
68 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
54 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
69 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
55 p.drawPixmap(QPoint(0, 0), px); |
70 p.drawPixmap(QPoint(0, 0), px); |
56 |
71 |
57 |
|
58 imageButt->setIcon(pxres); |
72 imageButt->setIcon(pxres); |
59 imageButt->setIconSize(QSize(256, 128)); |
73 imageButt->setIconSize(QSize(256, 128)); |
|
74 chooseMap->setCurrentIndex(0); |
|
75 } |
|
76 |
|
77 void HWMapContainer::mapChanged(int index) |
|
78 { |
|
79 if(!index) { |
|
80 changeImage(); |
|
81 return; |
|
82 } |
|
83 |
|
84 QPixmap mapImage; |
|
85 if(!mapImage.load(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.png")) { |
|
86 changeImage(); |
|
87 chooseMap->setCurrentIndex(0); |
|
88 return; |
|
89 } |
|
90 imageButt->setIcon(mapImage.scaled(256,128)); |
60 } |
91 } |
61 |
92 |
62 void HWMapContainer::changeImage() |
93 void HWMapContainer::changeImage() |
63 { |
94 { |
64 pMap=new HWMap(); |
95 pMap=new HWMap(); |
70 QString HWMapContainer::getCurrentSeed() const |
101 QString HWMapContainer::getCurrentSeed() const |
71 { |
102 { |
72 return m_seed; |
103 return m_seed; |
73 } |
104 } |
74 |
105 |
|
106 QString HWMapContainer::getCurrentMap() const |
|
107 { |
|
108 if(!chooseMap->currentIndex()) throw MapFileErrorException(); |
|
109 return chooseMap->currentText(); |
|
110 } |
|
111 |
|
112 QString HWMapContainer::getCurrentTheme() const |
|
113 { |
|
114 if(!chooseMap->currentIndex()) throw MapFileErrorException(); |
|
115 QFile mapCfgFile(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.cfg"); |
|
116 if (mapCfgFile.open(QFile::ReadOnly)) { |
|
117 QTextStream input(&mapCfgFile); |
|
118 QString theme; |
|
119 input >> theme; |
|
120 if(theme.length()>256) throw MapFileErrorException(); // theme name too long |
|
121 return theme; |
|
122 mapCfgFile.close(); |
|
123 } else { |
|
124 throw MapFileErrorException(); |
|
125 } |
|
126 } |
|
127 |
75 void HWMapContainer::resizeEvent ( QResizeEvent * event ) |
128 void HWMapContainer::resizeEvent ( QResizeEvent * event ) |
76 { |
129 { |
77 //imageButt->setIconSize(imageButt->size()); |
130 //imageButt->setIconSize(imageButt->size()); |
78 } |
131 } |