+ display lack of map in a nice way, don't generate bogus preview in the background
authorsheepluva
Thu, 03 May 2012 12:33:08 +0200
changeset 7014 c0b32404ef74
parent 7013 54db061b5710
child 7015 08642c7da4a3
+ display lack of map in a nice way, don't generate bogus preview in the background * improve map selection behavior in online mode, so that players can load a missing map and have it correctly selected after pressing F5 without any rejoin, map-reselection. also doesn't cause "different maps generated" anymore if map is missing, instead the person lacking the map gets "invalid genmap" and drops out of game immediatly
QTfrontend/ui/widget/mapContainer.cpp
--- a/QTfrontend/ui/widget/mapContainer.cpp	Thu May 03 12:21:16 2012 +0400
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Thu May 03 12:33:08 2012 +0200
@@ -211,6 +211,9 @@
 
 void HWMapContainer::mapChanged(int index)
 {
+    if (index < 0)
+        return;
+
     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
     m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
     m_curMap = chooseMap->currentText();
@@ -379,15 +382,19 @@
 {
     int id = m_mapModel->indexOf(map);
 
-    if(id >= 0)
+    if (pMap)
     {
-        if (pMap)
-        {
-            disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
-            disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
-            pMap = 0;
-        }
-        chooseMap->setCurrentIndex(id);
+        disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
+        disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
+        pMap = 0;
+    }
+
+    chooseMap->setCurrentIndex(id);
+
+    if(id < 0)
+    {
+        m_mapInfo.type = MapModel::Invalid;
+        m_curMap = map;
     }
 }
 
@@ -426,7 +433,7 @@
             chooseMap->setCurrentIndex(idx);
             break;
         case MapModel::Invalid:
-            Q_ASSERT(false);
+            chooseMap->setCurrentIndex(0);
     }
 }
 
@@ -538,8 +545,15 @@
 
 void HWMapContainer::updatePreview()
 {
+    QPixmap failIcon;
+
     switch(m_mapInfo.type)
     {
+        case MapModel::Invalid:
+            failIcon = QPixmap(":/res/btnDisabled.png");
+            imageButt->setIcon(failIcon);
+            imageButt->setIconSize(failIcon.size());
+            break;
         case MapModel::GeneratedMap:
             askForGeneratedPreview();
             break;
@@ -594,13 +608,7 @@
 
     // restore map selection
     if (!m_curMap.isEmpty())
-    {
-        int idx = chooseMap->findText(m_curMap);
-        if (idx >= 0)
-            chooseMap->setCurrentIndex(idx);
-        else
-            chooseMap->setCurrentIndex(0);
-    }
+        setMap(m_curMap);
 
 }