QTfrontend/mapContainer.cpp
changeset 3870 e3f778c95d1c
parent 3869 d3d39bbb05f2
child 3951 c9a63db3e603
--- 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()
 {