Frontend:
authorsmaxx
Tue, 14 Sep 2010 22:13:59 +0200 (2010-09-14)
changeset 3870 e3f778c95d1c
parent 3869 d3d39bbb05f2
child 3871 c91aefe1dca2
Frontend: * Updated random map selection: Clicking on the map preview will now create a new random seed and pick another map of the current type selected (random map, random maze, mission or static map)
QTfrontend/mapContainer.cpp
QTfrontend/mapContainer.h
--- a/QTfrontend/mapContainer.cpp	Tue Sep 14 21:07:06 2010 +0200
+++ b/QTfrontend/mapContainer.cpp	Tue Sep 14 22:13:59 2010 +0200
@@ -56,8 +56,9 @@
     imageButt->setFlat(true);
     imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum);
     mainLayout.addWidget(imageButt, 0, 0, 1, 2);
-    connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
-    connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme()));
+    //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
+    //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme()));
+    connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap()));
 
     chooseMap = new QComboBox(this);
     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
@@ -66,6 +67,7 @@
     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
 
     int missionindex = chooseMap->count();
+    numMissions = 0;
     for (int i = 0; i < mapList->size(); ++i) {
         QString map = (*mapList)[i];
         QFile mapCfgFile(
@@ -92,7 +94,10 @@
                 mapInfo.push_back(18);
             mapInfo.push_back(mapLuaFile.exists());
             if(mapLuaFile.exists())
+            {
                 chooseMap->insertItem(missionindex++, QIcon(":/res/mapMission.png"), QComboBox::tr("Mission") + ": " + map, mapInfo);
+                numMissions++;
+            }
             else
                 chooseMap->addItem(QIcon(":/res/mapCustom.png"), map, mapInfo);
             mapCfgFile.close();
@@ -390,6 +395,36 @@
     if(items.size())
         lwThemes->setCurrentItem(items.at(0));
 }
+#include <QMessageBox>
+void HWMapContainer::setRandomMap()
+{
+    switch(chooseMap->currentIndex())
+    {
+    case MAPGEN_REGULAR:
+    case MAPGEN_MAZE:
+        setRandomSeed();
+        setRandomTheme();
+        break;
+    default:
+        if(chooseMap->currentIndex() < numMissions + 3)
+            setRandomMission();
+        else
+            setRandomStatic();
+        break;
+    }
+}
+
+void HWMapContainer::setRandomStatic()
+{
+    chooseMap->setCurrentIndex(4 + numMissions + rand() % (chooseMap->count() - 4 - numMissions));
+    m_seed = QUuid::createUuid().toString();
+}
+
+void HWMapContainer::setRandomMission()
+{
+    chooseMap->setCurrentIndex(3 + rand() % numMissions);
+    m_seed = QUuid::createUuid().toString();
+}
 
 void HWMapContainer::setRandomSeed()
 {
--- a/QTfrontend/mapContainer.h	Tue Sep 14 21:07:06 2010 +0200
+++ b/QTfrontend/mapContainer.h	Tue Sep 14 22:13:59 2010 +0200
@@ -72,6 +72,9 @@
   void mapChanged(int index);
   void setRandomSeed();
   void setRandomTheme();
+  void setRandomMap();
+  void setRandomStatic();
+  void setRandomMission();
   void themeSelected(int currentRow);
   void addInfoToPreview(QPixmap image);
   void templateFilterChanged(int filter);
@@ -95,6 +98,7 @@
   QLabel *maze_size_label;
   QComboBox *maze_size_selection;
   MapGenerator mapgen;
+  int numMissions;
   int maze_size;
 
   void loadMap(int index);