QTfrontend/mapContainer.cpp
branchexperimental3D
changeset 4812 f924be23ffb4
parent 4701 7ed88cfc99b1
child 4936 d65d438acd23
equal deleted inserted replaced
4347:0ddb100fea61 4812:f924be23ffb4
    27 #include <QApplication>
    27 #include <QApplication>
    28 #include <QLabel>
    28 #include <QLabel>
    29 #include <QListWidget>
    29 #include <QListWidget>
    30 #include <QVBoxLayout>
    30 #include <QVBoxLayout>
    31 #include <QIcon>
    31 #include <QIcon>
       
    32 #include <QLineEdit>
       
    33 #include <QMessageBox>
    32 
    34 
    33 #include "hwconsts.h"
    35 #include "hwconsts.h"
    34 #include "mapContainer.h"
    36 #include "mapContainer.h"
    35 #include "igbox.h"
    37 #include "igbox.h"
    36 
    38 
    37 HWMapContainer::HWMapContainer(QWidget * parent) :
    39 HWMapContainer::HWMapContainer(QWidget * parent) :
    38     QWidget(parent),
    40     QWidget(parent),
    39     mainLayout(this),
    41     mainLayout(this),
    40     pMap(0),
    42     pMap(0),
    41     mapgen(MAPGEN_REGULAR),
    43     mapgen(MAPGEN_REGULAR)
    42     maze_size(0)
       
    43 {
    44 {
    44     hhSmall.load(":/res/hh_small.png");
    45     hhSmall.load(":/res/hh_small.png");
    45     hhLimit = 18;
    46     hhLimit = 18;
    46     templateFilter = 0;
    47     templateFilter = 0;
    47 
    48 
    48     mainLayout.setContentsMargins(QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
    49     mainLayout.setContentsMargins(QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
    49         1,
    50         1,
    50         QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
    51         QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
    51         QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
    52         QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
    52 
    53 
    53     imageButt = new QPushButton(this);
    54     QWidget* mapWidget = new QWidget(this);
       
    55     mainLayout.addWidget(mapWidget, 0, 0, Qt::AlignHCenter);
       
    56 
       
    57     QGridLayout* mapLayout = new QGridLayout(mapWidget);
       
    58     mapLayout->setMargin(0);
       
    59 
       
    60     imageButt = new QPushButton(mapWidget);
    54     imageButt->setObjectName("imageButt");
    61     imageButt->setObjectName("imageButt");
    55     imageButt->setFixedSize(256 + 6, 128 + 6);
    62     imageButt->setFixedSize(256 + 6, 128 + 6);
    56     imageButt->setFlat(true);
    63     imageButt->setFlat(true);
    57     imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum);
    64     imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum);
    58     mainLayout.addWidget(imageButt, 0, 0, 1, 2);
    65     mapLayout->addWidget(imageButt, 0, 0, 1, 2);
    59     //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
    66     //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
    60     //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme()));
    67     //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme()));
    61     connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap()));
    68     connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap()));
    62 
    69 
    63     chooseMap = new QComboBox(this);
    70     chooseMap = new QComboBox(mapWidget);
    64     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    71     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    65     chooseMap->addItem(
    72     chooseMap->addItem(
    66 // FIXME - need real icons. Disabling until then
    73 // FIXME - need real icons. Disabling until then
    67 //QIcon(":/res/mapRandom.png"), 
    74 //QIcon(":/res/mapRandom.png"), 
    68 QComboBox::tr("generated map..."));
    75 QComboBox::tr("generated map..."));
    69     chooseMap->addItem(
    76     chooseMap->addItem(
    70 // FIXME - need real icons. Disabling until then
    77 // FIXME - need real icons. Disabling until then
    71 //QIcon(":/res/mapMaze.png"), 
    78 //QIcon(":/res/mapMaze.png"), 
    72 QComboBox::tr("generated maze..."));
    79 QComboBox::tr("generated maze..."));
       
    80 
       
    81     chooseMap->addItem(QComboBox::tr("hand drawn map..."));
       
    82     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
       
    83 
    73     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    84     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    74 
    85 
    75     int missionindex = chooseMap->count();
    86     int missionindex = chooseMap->count();
    76     numMissions = 0;
    87     numMissions = 0;
    77     for (int i = 0; i < mapList->size(); ++i) {
    88     for (int i = 0; i < mapList->size(); ++i) {
    86                 .arg(map));
    97                 .arg(map));
    87 
    98 
    88         if (mapCfgFile.open(QFile::ReadOnly)) {
    99         if (mapCfgFile.open(QFile::ReadOnly)) {
    89             QString theme;
   100             QString theme;
    90             quint32 limit = 0;
   101             quint32 limit = 0;
       
   102             QString scheme;
       
   103             QString weapons;
    91             QList<QVariant> mapInfo;
   104             QList<QVariant> mapInfo;
    92             QTextStream input(&mapCfgFile);
   105             QTextStream input(&mapCfgFile);
    93             input >> theme;
   106             input >> theme;
    94             input >> limit;
   107             input >> limit;
       
   108             input >> scheme;
       
   109             input >> weapons;
    95             mapInfo.push_back(map);
   110             mapInfo.push_back(map);
    96             mapInfo.push_back(theme);
   111             mapInfo.push_back(theme);
    97             if (limit)
   112             if (limit)
    98                 mapInfo.push_back(limit);
   113                 mapInfo.push_back(limit);
    99             else
   114             else
   100                 mapInfo.push_back(18);
   115                 mapInfo.push_back(18);
   101             mapInfo.push_back(mapLuaFile.exists());
   116             mapInfo.push_back(mapLuaFile.exists());
       
   117             if (scheme.isEmpty())
       
   118                 scheme = "locked";
       
   119             scheme.replace("_", " ");
       
   120             if (weapons.isEmpty())
       
   121                 weapons = "locked";
       
   122             weapons.replace("_", " ");
       
   123             mapInfo.push_back(scheme);
       
   124             mapInfo.push_back(weapons);
   102             if(mapLuaFile.exists())
   125             if(mapLuaFile.exists())
   103             {
   126             {
   104                 chooseMap->insertItem(missionindex++, 
   127                 chooseMap->insertItem(missionindex++, 
   105 // FIXME - need real icons. Disabling until then
   128 // FIXME - need real icons. Disabling until then
   106 //QIcon(":/res/mapMission.png"), 
   129 //QIcon(":/res/mapMission.png"), 
   116         }
   139         }
   117     }
   140     }
   118     chooseMap->insertSeparator(missionindex); // separator between missions and maps
   141     chooseMap->insertSeparator(missionindex); // separator between missions and maps
   119 
   142 
   120     connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
   143     connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
   121     mainLayout.addWidget(chooseMap, 1, 1);
   144     mapLayout->addWidget(chooseMap, 1, 1);
   122 
   145 
   123     QLabel * lblMap = new QLabel(tr("Map"), this);
   146     QLabel * lblMap = new QLabel(tr("Map"), mapWidget);
   124     mainLayout.addWidget(lblMap, 1, 0);
   147     mapLayout->addWidget(lblMap, 1, 0);
   125 
   148 
   126     lblFilter = new QLabel(tr("Filter"), this);
   149     lblFilter = new QLabel(tr("Filter"), mapWidget);
   127     mainLayout.addWidget(lblFilter, 2, 0);
   150     mapLayout->addWidget(lblFilter, 2, 0);
   128 
   151 
   129     CB_TemplateFilter = new QComboBox(this);
   152     CB_TemplateFilter = new QComboBox(mapWidget);
   130     CB_TemplateFilter->addItem(tr("All"), 0);
   153     CB_TemplateFilter->addItem(tr("All"), 0);
   131     CB_TemplateFilter->addItem(tr("Small"), 1);
   154     CB_TemplateFilter->addItem(tr("Small"), 1);
   132     CB_TemplateFilter->addItem(tr("Medium"), 2);
   155     CB_TemplateFilter->addItem(tr("Medium"), 2);
   133     CB_TemplateFilter->addItem(tr("Large"), 3);
   156     CB_TemplateFilter->addItem(tr("Large"), 3);
   134     CB_TemplateFilter->addItem(tr("Cavern"), 4);
   157     CB_TemplateFilter->addItem(tr("Cavern"), 4);
   135     CB_TemplateFilter->addItem(tr("Wacky"), 5);
   158     CB_TemplateFilter->addItem(tr("Wacky"), 5);
   136     mainLayout.addWidget(CB_TemplateFilter, 2, 1);
   159     mapLayout->addWidget(CB_TemplateFilter, 2, 1);
   137 
   160 
   138     connect(CB_TemplateFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(templateFilterChanged(int)));
   161     connect(CB_TemplateFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(templateFilterChanged(int)));
   139 
   162 
   140     maze_size_label = new QLabel(tr("Type"), this);
   163     maze_size_label = new QLabel(tr("Type"), mapWidget);
   141     mainLayout.addWidget(maze_size_label, 2, 0);
   164     mainLayout.addWidget(maze_size_label, 2, 0);
   142     maze_size_label->hide();
   165     maze_size_label->hide();
   143     maze_size_selection = new QComboBox(this);
   166     maze_size_selection = new QComboBox(mapWidget);
   144     maze_size_selection->addItem(tr("Small tunnels"), 0);
   167     maze_size_selection->addItem(tr("Small tunnels"), 0);
   145     maze_size_selection->addItem(tr("Medium tunnels"), 1);
   168     maze_size_selection->addItem(tr("Medium tunnels"), 1);
   146     maze_size_selection->addItem(tr("Large tunnels"), 2);
   169     maze_size_selection->addItem(tr("Large tunnels"), 2);
   147     maze_size_selection->addItem(tr("Small floating islands"), 3);
   170     maze_size_selection->addItem(tr("Small floating islands"), 3);
   148     maze_size_selection->addItem(tr("Medium floating islands"), 4);
   171     maze_size_selection->addItem(tr("Medium floating islands"), 4);
   149     maze_size_selection->addItem(tr("Large floating islands"), 5);
   172     maze_size_selection->addItem(tr("Large floating islands"), 5);
   150     maze_size_selection->setCurrentIndex(1);
   173     maze_size_selection->setCurrentIndex(1);
   151     maze_size = 1;
   174 
   152     mainLayout.addWidget(maze_size_selection, 2, 1);
   175     mapLayout->addWidget(maze_size_selection, 2, 1);
   153     maze_size_selection->hide();
   176     maze_size_selection->hide();
   154     connect(maze_size_selection, SIGNAL(currentIndexChanged(int)), this, SLOT(setMaze_size(int)));
   177     connect(maze_size_selection, SIGNAL(currentIndexChanged(int)), this, SLOT(setMaze_size(int)));
   155 
   178 
   156     gbThemes = new IconedGroupBox(this);
   179     gbThemes = new IconedGroupBox(mapWidget);
   157     gbThemes->setTitleTextPadding(60);
   180     gbThemes->setTitleTextPadding(80);
   158     gbThemes->setContentTopPadding(6);
   181     gbThemes->setContentTopPadding(15);
   159     gbThemes->setTitle(tr("Themes"));
   182     gbThemes->setTitle(tr("Themes"));
   160 
   183 
   161     //gbThemes->setStyleSheet("padding: 0px"); // doesn't work - stylesheet is set with icon
   184     //gbThemes->setStyleSheet("padding: 0px"); // doesn't work - stylesheet is set with icon
   162     mainLayout.addWidget(gbThemes, 0, 2, 3, 1);
   185     mapLayout->addWidget(gbThemes, 0, 2, 3, 1);
   163 
   186 
   164     QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes);
   187     QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes);
   165     gbTLayout->setContentsMargins(0, 0, 0 ,0);
   188     gbTLayout->setContentsMargins(0, 0, 0 ,0);
   166     gbTLayout->setSpacing(0);
   189     gbTLayout->setSpacing(0);
   167     lwThemes = new QListWidget(this);
   190     lwThemes = new QListWidget(mapWidget);
   168     lwThemes->setMinimumHeight(30);
   191     lwThemes->setMinimumHeight(30);
   169     lwThemes->setFixedWidth(140);
   192     lwThemes->setFixedWidth(140);
   170     for (int i = 0; i < Themes->size(); ++i) {
   193     for (int i = 0; i < Themes->size(); ++i) {
   171         QListWidgetItem * lwi = new QListWidgetItem();
   194         QListWidgetItem * lwi = new QListWidgetItem();
   172         lwi->setText(Themes->at(i));
   195         lwi->setText(Themes->at(i));
   191     );
   214     );
   192 
   215 
   193     gbTLayout->addWidget(lwThemes);
   216     gbTLayout->addWidget(lwThemes);
   194     lwThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
   217     lwThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
   195 
   218 
   196     mainLayout.setSizeConstraint(QLayout::SetFixedSize);//SetMinimumSize
   219     mapLayout->setSizeConstraint(QLayout::SetFixedSize);
       
   220 
       
   221     QWidget* seedWidget = new QWidget(this);
       
   222     mainLayout.addWidget(seedWidget, 1, 0);
       
   223 
       
   224     QGridLayout* seedLayout = new QGridLayout(seedWidget);
       
   225     seedLayout->setMargin(0);
       
   226 
       
   227     seedLabel = new QLabel(tr("Seed"), seedWidget);
       
   228     seedLayout->addWidget(seedLabel, 3, 0);
       
   229     seedEdit = new QLineEdit(seedWidget);
       
   230     seedEdit->setMaxLength(54);
       
   231     connect(seedEdit, SIGNAL(returnPressed()), this, SLOT(seedEdited()));
       
   232     seedLayout->addWidget(seedEdit, 3, 1);
       
   233     seedLayout->setColumnStretch(1, 5);
       
   234     seedSet = new QPushButton(seedWidget);
       
   235     seedSet->setText(QPushButton::tr("more"));
       
   236     connect(seedSet, SIGNAL(clicked()), this, SLOT(seedEdited()));
       
   237     seedLayout->setColumnStretch(2, 1);
       
   238     seedLayout->addWidget(seedSet, 3, 2);
       
   239 
       
   240     seedLabel->setVisible(false);
       
   241     seedEdit->setVisible(false);
   197 
   242 
   198     setRandomSeed();
   243     setRandomSeed();
   199     setRandomTheme();
   244     setRandomTheme();
   200 }
   245 }
   201 
   246 
   214     linearGrad.setColorAt(0, QColor(66, 115, 225));
   259     linearGrad.setColorAt(0, QColor(66, 115, 225));
   215     p.fillRect(QRect(0, 0, 256, 128), linearGrad);
   260     p.fillRect(QRect(0, 0, 256, 128), linearGrad);
   216     p.drawPixmap(QPoint(0, 0), px);
   261     p.drawPixmap(QPoint(0, 0), px);
   217 
   262 
   218     addInfoToPreview(pxres);
   263     addInfoToPreview(pxres);
   219     chooseMap->setCurrentIndex(mapgen);
   264     //chooseMap->setCurrentIndex(mapgen);
   220     pMap = 0;
   265     pMap = 0;
   221 }
   266 }
   222 
   267 
   223 void HWMapContainer::setHHLimit(int newHHLimit)
   268 void HWMapContainer::setHHLimit(int newHHLimit)
   224 {
   269 {
   228 void HWMapContainer::mapChanged(int index)
   273 void HWMapContainer::mapChanged(int index)
   229 {
   274 {
   230     switch(index) {
   275     switch(index) {
   231     case MAPGEN_REGULAR:
   276     case MAPGEN_REGULAR:
   232         mapgen = MAPGEN_REGULAR;
   277         mapgen = MAPGEN_REGULAR;
   233         changeImage();
   278         updatePreview();
   234         gbThemes->show();
   279         gbThemes->show();
   235         lblFilter->show();
   280         lblFilter->show();
   236         CB_TemplateFilter->show();
   281         CB_TemplateFilter->show();
   237         maze_size_label->hide();
   282         maze_size_label->hide();
   238         maze_size_selection->hide();
   283         maze_size_selection->hide();
   240         emit mapgenChanged(mapgen);
   285         emit mapgenChanged(mapgen);
   241         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   286         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   242         break;
   287         break;
   243     case MAPGEN_MAZE:
   288     case MAPGEN_MAZE:
   244         mapgen = MAPGEN_MAZE;
   289         mapgen = MAPGEN_MAZE;
   245         changeImage();
   290         updatePreview();
   246         gbThemes->show();
   291         gbThemes->show();
   247         lblFilter->hide();
   292         lblFilter->hide();
   248         CB_TemplateFilter->hide();
   293         CB_TemplateFilter->hide();
   249         maze_size_label->show();
   294         maze_size_label->show();
   250         maze_size_selection->show();
   295         maze_size_selection->show();
   251         emit mapChanged("+maze+");
   296         emit mapChanged("+maze+");
   252         emit mapgenChanged(mapgen);
   297         emit mapgenChanged(mapgen);
   253         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   298         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   254         break;
   299         break;
       
   300     case MAPGEN_DRAWN:
       
   301         mapgen = MAPGEN_DRAWN;
       
   302         updatePreview();
       
   303         gbThemes->show();
       
   304         lblFilter->hide();
       
   305         CB_TemplateFilter->hide();
       
   306         maze_size_label->hide();
       
   307         maze_size_selection->hide();
       
   308         emit mapChanged("+drawn+");
       
   309         emit mapgenChanged(mapgen);
       
   310         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
       
   311         break;
   255     default:
   312     default:
   256         loadMap(index);
   313         updatePreview();
   257         gbThemes->hide();
   314         gbThemes->hide();
   258         lblFilter->hide();
   315         lblFilter->hide();
   259         CB_TemplateFilter->hide();
   316         CB_TemplateFilter->hide();
   260         maze_size_label->hide();
   317         maze_size_label->hide();
   261         maze_size_selection->hide();
   318         maze_size_selection->hide();
   262         emit mapChanged(chooseMap->itemData(index).toList()[0].toString());
   319         emit mapChanged(chooseMap->itemData(index).toList()[0].toString());
   263     }
   320     }
   264 }
       
   265 
       
   266 void HWMapContainer::loadMap(int index)
       
   267 {
       
   268     QPixmap mapImage;
       
   269     if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->itemData(index).toList()[0].toString() + "/preview.png")) {
       
   270         changeImage();
       
   271         chooseMap->setCurrentIndex(0);
       
   272         return;
       
   273     }
       
   274 
       
   275     hhLimit = chooseMap->itemData(index).toList()[2].toInt();
       
   276     addInfoToPreview(mapImage);
       
   277 }
   321 }
   278 
   322 
   279 // Should this add text to identify map size?
   323 // Should this add text to identify map size?
   280 void HWMapContainer::addInfoToPreview(QPixmap image)
   324 void HWMapContainer::addInfoToPreview(QPixmap image)
   281 {
   325 {
   294 
   338 
   295     imageButt->setIcon(finalImage);
   339     imageButt->setIcon(finalImage);
   296     imageButt->setIconSize(image.size());
   340     imageButt->setIconSize(image.size());
   297 }
   341 }
   298 
   342 
   299 void HWMapContainer::changeImage()
   343 void HWMapContainer::askForGeneratedPreview()
   300 {
   344 {
   301     if (pMap)
   345     if (pMap)
   302     {
   346     {
   303         disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   347         disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   304         disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   348         disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   306     }
   350     }
   307 
   351 
   308     pMap = new HWMap();
   352     pMap = new HWMap();
   309     connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
   353     connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
   310     connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int)));
   354     connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int)));
   311     pMap->getImage(m_seed.toStdString(), getTemplateFilter(), mapgen, maze_size);
   355     pMap->getImage(m_seed,
       
   356                    getTemplateFilter(),
       
   357                    get_mapgen(),
       
   358                    get_maze_size(),
       
   359                    getDrawnMapData()
       
   360             );
   312 }
   361 }
   313 
   362 
   314 void HWMapContainer::themeSelected(int currentRow)
   363 void HWMapContainer::themeSelected(int currentRow)
   315 {
   364 {
   316     QString theme = Themes->at(currentRow);
   365     QString theme = Themes->at(currentRow);
   317     QList<QVariant> mapInfoRegular;
   366     QList<QVariant> mapInfo;
   318     mapInfoRegular.push_back(QString("+rnd+"));
   367     mapInfo.push_back(QString("+rnd+"));
   319     mapInfoRegular.push_back(theme);
   368     mapInfo.push_back(theme);
   320     mapInfoRegular.push_back(18);
   369     mapInfo.push_back(18);
   321     mapInfoRegular.push_back(false);
   370     mapInfo.push_back(false);
   322     chooseMap->setItemData(0, mapInfoRegular);
   371     chooseMap->setItemData(0, mapInfo);
   323     QList<QVariant> mapInfoMaze;
   372     mapInfo[0] = QString("+maze+");
   324     mapInfoMaze.push_back(QString("+maze+"));
   373     chooseMap->setItemData(1, mapInfo);
   325     mapInfoMaze.push_back(theme);
   374     mapInfo[0] = QString("+drawn+");
   326     mapInfoMaze.push_back(18);
   375     chooseMap->setItemData(2, mapInfo);
   327     mapInfoMaze.push_back(false);
   376     gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon@2x.png").arg(datadir->absolutePath()).arg(theme)));
   328     chooseMap->setItemData(1, mapInfoMaze);
       
   329     gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(theme)));
       
   330     emit themeChanged(theme);
   377     emit themeChanged(theme);
   331 }
   378 }
   332 
   379 
   333 QString HWMapContainer::getCurrentSeed() const
   380 QString HWMapContainer::getCurrentSeed() const
   334 {
   381 {
   335     return m_seed;
   382     return m_seed;
   336 }
   383 }
   337 
   384 
   338 QString HWMapContainer::getCurrentMap() const
   385 QString HWMapContainer::getCurrentMap() const
   339 {
   386 {
   340     if(chooseMap->currentIndex() <= 1) return QString();
   387     if(chooseMap->currentIndex() < MAPGEN_MAP) return QString();
   341     return chooseMap->itemData(chooseMap->currentIndex()).toList()[0].toString();
   388     return chooseMap->itemData(chooseMap->currentIndex()).toList()[0].toString();
   342 }
   389 }
   343 
   390 
   344 QString HWMapContainer::getCurrentTheme() const
   391 QString HWMapContainer::getCurrentTheme() const
   345 {
   392 {
   355 int HWMapContainer::getCurrentHHLimit() const
   402 int HWMapContainer::getCurrentHHLimit() const
   356 {
   403 {
   357     return hhLimit;
   404     return hhLimit;
   358 }
   405 }
   359 
   406 
       
   407 QString HWMapContainer::getCurrentScheme() const
       
   408 {
       
   409     return chooseMap->itemData(chooseMap->currentIndex()).toList()[4].toString();
       
   410 }
       
   411 
       
   412 QString HWMapContainer::getCurrentWeapons() const
       
   413 {
       
   414     return chooseMap->itemData(chooseMap->currentIndex()).toList()[5].toString();
       
   415 }
       
   416 
   360 quint32 HWMapContainer::getTemplateFilter() const
   417 quint32 HWMapContainer::getTemplateFilter() const
   361 {
   418 {
   362     return CB_TemplateFilter->itemData(CB_TemplateFilter->currentIndex()).toInt();
   419     return CB_TemplateFilter->itemData(CB_TemplateFilter->currentIndex()).toInt();
   363 }
   420 }
   364 
   421 
   365 void HWMapContainer::resizeEvent ( QResizeEvent * event )
   422 void HWMapContainer::resizeEvent ( QResizeEvent * event )
   366 {
   423 {
       
   424     Q_UNUSED(event);
   367   //imageButt->setIconSize(imageButt->size());
   425   //imageButt->setIconSize(imageButt->size());
   368 }
   426 }
   369 
   427 
   370 void HWMapContainer::setSeed(const QString & seed)
   428 void HWMapContainer::setSeed(const QString & seed)
   371 {
   429 {
   372     m_seed = seed;
   430     m_seed = seed;
   373     changeImage();
   431     if (seed != seedEdit->text())
       
   432         seedEdit->setText(seed);
       
   433     if (chooseMap->currentIndex() < MAPGEN_MAP)
       
   434         updatePreview();
   374 }
   435 }
   375 
   436 
   376 void HWMapContainer::setMap(const QString & map)
   437 void HWMapContainer::setMap(const QString & map)
   377 {
   438 {
   378     if(map == "+rnd+" || map == "+maze+")
       
   379     {
       
   380         changeImage();
       
   381         return;
       
   382     }
       
   383 
       
   384     int id = 0;
   439     int id = 0;
   385     for(int i = 0; i < chooseMap->count(); i++)
   440     for(int i = 0; i < chooseMap->count(); i++)
   386         if(!chooseMap->itemData(i).isNull() && chooseMap->itemData(i).toList()[0].toString() == map)
   441         if(!chooseMap->itemData(i).isNull() && chooseMap->itemData(i).toList()[0].toString() == map)
   387         {
   442         {
   388             id = i;
   443             id = i;
   395             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   450             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   396             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   451             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   397             pMap = 0;
   452             pMap = 0;
   398         }
   453         }
   399         chooseMap->setCurrentIndex(id);
   454         chooseMap->setCurrentIndex(id);
   400         loadMap(id);
   455         updatePreview();
   401     }
   456     }
   402 }
   457 }
   403 
   458 
   404 void HWMapContainer::setTheme(const QString & theme)
   459 void HWMapContainer::setTheme(const QString & theme)
   405 {
   460 {
   406     QList<QListWidgetItem *> items = lwThemes->findItems(theme, Qt::MatchExactly);
   461     QList<QListWidgetItem *> items = lwThemes->findItems(theme, Qt::MatchExactly);
   407     if(items.size())
   462     if(items.size())
   408         lwThemes->setCurrentItem(items.at(0));
   463         lwThemes->setCurrentItem(items.at(0));
   409 }
   464 }
   410 #include <QMessageBox>
   465 
   411 void HWMapContainer::setRandomMap()
   466 void HWMapContainer::setRandomMap()
   412 {
   467 {
       
   468     setRandomSeed();
   413     switch(chooseMap->currentIndex())
   469     switch(chooseMap->currentIndex())
   414     {
   470     {
   415     case MAPGEN_REGULAR:
   471     case MAPGEN_REGULAR:
   416     case MAPGEN_MAZE:
   472     case MAPGEN_MAZE:
   417         setRandomSeed();
       
   418         setRandomTheme();
   473         setRandomTheme();
   419         break;
   474         break;
       
   475     case MAPGEN_DRAWN:
       
   476         emit drawMapRequested();
       
   477         break;
   420     default:
   478     default:
   421         if(chooseMap->currentIndex() < numMissions + 3)
   479         if(chooseMap->currentIndex() <= numMissions + MAPGEN_MAP + 1)
   422             setRandomMission();
   480             setRandomMission();
   423         else
   481         else
   424             setRandomStatic();
   482             setRandomStatic();
   425         break;
   483         break;
   426     }
   484     }
   427 }
   485 }
   428 
   486 
   429 void HWMapContainer::setRandomStatic()
   487 void HWMapContainer::setRandomStatic()
   430 {
   488 {
   431     chooseMap->setCurrentIndex(4 + numMissions + rand() % (chooseMap->count() - 4 - numMissions));
   489     int i = MAPGEN_MAP + 3 + numMissions + rand() % (chooseMap->count() - MAPGEN_MAP - 3 - numMissions);
       
   490     chooseMap->setCurrentIndex(i);
       
   491     setRandomSeed();
       
   492 }
       
   493 
       
   494 void HWMapContainer::setRandomMission()
       
   495 {
       
   496     int i = MAPGEN_MAP + 2 + rand() % numMissions;
       
   497     qDebug() << i << MAPGEN_MAP << numMissions;
       
   498     chooseMap->setCurrentIndex(i);
       
   499     setRandomSeed();
       
   500 }
       
   501 
       
   502 void HWMapContainer::setRandomSeed()
       
   503 {
   432     m_seed = QUuid::createUuid().toString();
   504     m_seed = QUuid::createUuid().toString();
   433 }
   505     seedEdit->setText(m_seed);
   434 
       
   435 void HWMapContainer::setRandomMission()
       
   436 {
       
   437     chooseMap->setCurrentIndex(3 + rand() % numMissions);
       
   438     m_seed = QUuid::createUuid().toString();
       
   439 }
       
   440 
       
   441 void HWMapContainer::setRandomSeed()
       
   442 {
       
   443     m_seed = QUuid::createUuid().toString();
       
   444     emit seedChanged(m_seed);
   506     emit seedChanged(m_seed);
   445     changeImage();
   507     if (chooseMap->currentIndex() < MAPGEN_MAP)
       
   508         updatePreview();
   446 }
   509 }
   447 
   510 
   448 void HWMapContainer::setRandomTheme()
   511 void HWMapContainer::setRandomTheme()
   449 {
   512 {
   450     if(!Themes->size()) return;
   513     if(!Themes->size()) return;
   458 }
   521 }
   459 
   522 
   460 void HWMapContainer::templateFilterChanged(int filter)
   523 void HWMapContainer::templateFilterChanged(int filter)
   461 {
   524 {
   462     emit newTemplateFilter(filter);
   525     emit newTemplateFilter(filter);
   463     changeImage();
   526     updatePreview();
   464 }
   527 }
   465 
   528 
   466 MapGenerator HWMapContainer::get_mapgen(void) const
   529 MapGenerator HWMapContainer::get_mapgen(void) const
   467 {
   530 {
   468     return mapgen;
   531     return mapgen;
   469 }
   532 }
   470 
   533 
   471 int HWMapContainer::get_maze_size(void) const
   534 int HWMapContainer::get_maze_size(void) const
   472 {
   535 {
   473     return maze_size;
   536     return maze_size_selection->currentIndex();
   474 }
   537 }
   475 
   538 
   476 void HWMapContainer::setMaze_size(int size)
   539 void HWMapContainer::setMaze_size(int size)
   477 {
   540 {
   478     maze_size = size;
       
   479     maze_size_selection->setCurrentIndex(size);
   541     maze_size_selection->setCurrentIndex(size);
   480     emit maze_sizeChanged(size);
   542     emit maze_sizeChanged(size);
   481     changeImage();
   543     updatePreview();
   482 }
   544 }
   483 
   545 
   484 void HWMapContainer::setMapgen(MapGenerator m)
   546 void HWMapContainer::setMapgen(MapGenerator m)
   485 {
   547 {
   486     mapgen = m;
   548     mapgen = m;
       
   549     chooseMap->setCurrentIndex(m);
   487     emit mapgenChanged(m);
   550     emit mapgenChanged(m);
   488     changeImage();
   551     updatePreview();
   489 }
   552 }
       
   553 
       
   554 void HWMapContainer::setDrawnMapData(const QByteArray & ar)
       
   555 {
       
   556     drawMapScene.decode(ar);
       
   557     updatePreview();
       
   558 }
       
   559 
       
   560 QByteArray HWMapContainer::getDrawnMapData()
       
   561 {
       
   562     return drawMapScene.encode();
       
   563 }
       
   564 
       
   565 void HWMapContainer::seedEdited()
       
   566 {
       
   567     if (seedLabel->isVisible() == false )
       
   568     {
       
   569         seedLabel->setVisible(true);
       
   570         seedEdit->setVisible(true);
       
   571         seedSet->setText(tr("Set"));
       
   572         return;
       
   573     }
       
   574 
       
   575     if (seedEdit->text().isEmpty())
       
   576         seedEdit->setText(m_seed);
       
   577     else
       
   578     {
       
   579         setSeed(seedEdit->text());
       
   580         emit seedChanged(seedEdit->text());
       
   581     }
       
   582 }
       
   583 
       
   584 DrawMapScene * HWMapContainer::getDrawMapScene()
       
   585 {
       
   586     return &drawMapScene;
       
   587 }
       
   588 
       
   589 void HWMapContainer::mapDrawingFinished()
       
   590 {
       
   591     emit drawnMapChanged(getDrawnMapData());
       
   592 
       
   593     updatePreview();
       
   594 }
       
   595 
       
   596 void HWMapContainer::updatePreview()
       
   597 {
       
   598     int curIndex = chooseMap->currentIndex();
       
   599 
       
   600     switch(curIndex)
       
   601     {
       
   602     case MAPGEN_REGULAR:
       
   603         askForGeneratedPreview();
       
   604         break;
       
   605     case MAPGEN_MAZE:
       
   606         askForGeneratedPreview();
       
   607         break;
       
   608     case MAPGEN_DRAWN:
       
   609         askForGeneratedPreview();
       
   610         break;
       
   611     default:
       
   612         QPixmap mapImage;
       
   613         qDebug() << "Map data" << curIndex << chooseMap->currentText() << chooseMap->itemData(curIndex);
       
   614         if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png")) {
       
   615             imageButt->setIcon(QIcon());
       
   616             return;
       
   617         }
       
   618 
       
   619         hhLimit = chooseMap->itemData(curIndex).toList()[2].toInt();
       
   620         addInfoToPreview(mapImage);
       
   621     }
       
   622 }