# HG changeset patch # User displacer # Date 1163893704 0 # Node ID ff85fa02954127b0921e82d3fa01c36d30b938ea # Parent aab204fe5061257a031f2bba7924c3214f2b62a2 map choose from files added diff -r aab204fe5061 -r ff85fa029541 QTfrontend/game.cpp --- a/QTfrontend/game.cpp Sat Nov 18 18:17:03 2006 +0000 +++ b/QTfrontend/game.cpp Sat Nov 18 23:48:24 2006 +0000 @@ -54,8 +54,14 @@ void HWGame::SendConfig() { SendIPC(QString("eseed %1").arg(seed).toAscii()); -// SendIPC(QString("emap %1").arg("mushrooms").toAscii()); - SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii()); + try { + QString currentMap=gamecfg->getCurrentMap(); + SendIPC((QString("emap ")+currentMap).toAscii()); + SendIPC(QString("etheme %1").arg(gamecfg->getCurrentTheme()).toAscii()); + } + catch(const MapFileErrorException& e) { + SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii()); + } SendIPC("TL"); SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii()); diff -r aab204fe5061 -r ff85fa029541 QTfrontend/gamecfgwidget.cpp --- a/QTfrontend/gamecfgwidget.cpp Sat Nov 18 18:17:03 2006 +0000 +++ b/QTfrontend/gamecfgwidget.cpp Sat Nov 18 23:48:24 2006 +0000 @@ -62,3 +62,13 @@ { return pMapContainer->getCurrentSeed(); } + +QString GameCFGWidget::getCurrentMap() const +{ + return pMapContainer->getCurrentMap(); +} + +QString GameCFGWidget::getCurrentTheme() const +{ + return pMapContainer->getCurrentTheme(); +} diff -r aab204fe5061 -r ff85fa029541 QTfrontend/gamecfgwidget.h --- a/QTfrontend/gamecfgwidget.h Sat Nov 18 18:17:03 2006 +0000 +++ b/QTfrontend/gamecfgwidget.h Sat Nov 18 23:48:24 2006 +0000 @@ -33,6 +33,8 @@ GameCFGWidget(QWidget* parent=0); quint32 getGameFlags(); QString getCurrentSeed() const; + QString getCurrentMap() const; + QString getCurrentTheme() const; private slots: diff -r aab204fe5061 -r ff85fa029541 QTfrontend/mapContainer.cpp --- a/QTfrontend/mapContainer.cpp Sat Nov 18 18:17:03 2006 +0000 +++ b/QTfrontend/mapContainer.cpp Sat Nov 18 23:48:24 2006 +0000 @@ -25,6 +25,9 @@ #include #include #include +#include + +#include "hwconsts.h" HWMapContainer::HWMapContainer(QWidget * parent) : QWidget(parent), mainLayout(this) @@ -36,6 +39,18 @@ mainLayout.addWidget(imageButt); connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage())); changeImage(); + + chooseMap=new QComboBox(this); + QDir tmpdir; + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Maps"); + tmpdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); + QStringList mapList=tmpdir.entryList(QStringList("*")); + mapList.push_front("generated map..."); + chooseMap->addItems(mapList); + connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int))); + + mainLayout.addWidget(chooseMap); } void HWMapContainer::setImage(const QImage newImage) @@ -54,9 +69,25 @@ p.fillRect(QRect(0, 0, 256, 128), linearGrad); p.drawPixmap(QPoint(0, 0), px); - imageButt->setIcon(pxres); imageButt->setIconSize(QSize(256, 128)); + chooseMap->setCurrentIndex(0); +} + +void HWMapContainer::mapChanged(int index) +{ + if(!index) { + changeImage(); + return; + } + + QPixmap mapImage; + if(!mapImage.load(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.png")) { + changeImage(); + chooseMap->setCurrentIndex(0); + return; + } + imageButt->setIcon(mapImage.scaled(256,128)); } void HWMapContainer::changeImage() @@ -72,6 +103,28 @@ return m_seed; } +QString HWMapContainer::getCurrentMap() const +{ + if(!chooseMap->currentIndex()) throw MapFileErrorException(); + return chooseMap->currentText(); +} + +QString HWMapContainer::getCurrentTheme() const +{ + if(!chooseMap->currentIndex()) throw MapFileErrorException(); + QFile mapCfgFile(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.cfg"); + if (mapCfgFile.open(QFile::ReadOnly)) { + QTextStream input(&mapCfgFile); + QString theme; + input >> theme; + if(theme.length()>256) throw MapFileErrorException(); // theme name too long + return theme; + mapCfgFile.close(); + } else { + throw MapFileErrorException(); + } +} + void HWMapContainer::resizeEvent ( QResizeEvent * event ) { //imageButt->setIconSize(imageButt->size()); diff -r aab204fe5061 -r ff85fa029541 QTfrontend/mapContainer.h --- a/QTfrontend/mapContainer.h Sat Nov 18 18:17:03 2006 +0000 +++ b/QTfrontend/mapContainer.h Sat Nov 18 23:48:24 2006 +0000 @@ -23,9 +23,14 @@ #include #include +#include class QPushButton; +class MapFileErrorException +{ +}; + class HWMapContainer : public QWidget { Q_OBJECT @@ -33,12 +38,15 @@ public: HWMapContainer(QWidget * parent=0); QString getCurrentSeed() const; + QString getCurrentMap() const; + QString getCurrentTheme() const; public slots: void changeImage(); private slots: void setImage(const QImage newImage); + void mapChanged(int index); protected: virtual void resizeEvent ( QResizeEvent * event ); @@ -46,6 +54,7 @@ private: QVBoxLayout mainLayout; QPushButton* imageButt; + QComboBox* chooseMap; HWMap* pMap; QString m_seed; };