QTfrontend/mapContainer.cpp
changeset 3008 e57cafce4227
parent 2948 3f21a9dc93d0
child 3009 8f4e6de8e4ef
equal deleted inserted replaced
3007:489ae87cdf9b 3008:e57cafce4227
    64         QString map = (*mapList)[i];
    64         QString map = (*mapList)[i];
    65         QFile mapCfgFile(
    65         QFile mapCfgFile(
    66                 QString("%1/Maps/%2/map.cfg")
    66                 QString("%1/Maps/%2/map.cfg")
    67                 .arg(datadir->absolutePath())
    67                 .arg(datadir->absolutePath())
    68                 .arg(map));
    68                 .arg(map));
       
    69         QFile mapLuaFile(
       
    70                 QString("%1/Maps/%2/map.lua")
       
    71                 .arg(datadir->absolutePath())
       
    72                 .arg(map));
    69 
    73 
    70         if (mapCfgFile.open(QFile::ReadOnly)) {
    74         if (mapCfgFile.open(QFile::ReadOnly)) {
    71             QString theme;
    75             QString theme;
    72             quint32 limit = 0;
    76             quint32 limit = 0;
    73             QList<QVariant> mapInfo;
    77             QList<QVariant> mapInfo;
    74             QTextStream input(&mapCfgFile);
    78             QTextStream input(&mapCfgFile);
    75             input >> theme;
    79             input >> theme;
    76             input >> limit;
    80             input >> limit;
       
    81             mapInfo.push_back(map);
    77             mapInfo.push_back(theme);
    82             mapInfo.push_back(theme);
    78             if (limit)
    83             if (limit)
    79                 mapInfo.push_back(limit);
    84                 mapInfo.push_back(limit);
    80             else
    85             else
    81                 mapInfo.push_back(18);
    86                 mapInfo.push_back(18);
    82             chooseMap->addItem(map, mapInfo);
    87             mapInfo.push_back(mapLuaFile.exists());
       
    88             chooseMap->addItem(mapLuaFile.exists() ? (QComboBox::tr("Mission") + ": " + map) : map, mapInfo);
    83             mapCfgFile.close();
    89             mapCfgFile.close();
    84         }
    90         }
    85     }
    91     }
    86 
    92 
    87     connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
    93     connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int)));
   181         changeImage();
   187         changeImage();
   182         gbThemes->show();
   188         gbThemes->show();
   183         lblFilter->show();
   189         lblFilter->show();
   184         CB_TemplateFilter->show();
   190         CB_TemplateFilter->show();
   185         emit mapChanged("+rnd+");
   191         emit mapChanged("+rnd+");
   186         emit themeChanged(chooseMap->itemData(0).toList()[0].toString());
   192         emit themeChanged(chooseMap->itemData(0).toList()[1].toString());
   187     } else
   193     } else
   188     {
   194     {
   189         loadMap(index);
   195         loadMap(index);
   190         gbThemes->hide();
   196         gbThemes->hide();
   191         lblFilter->hide();
   197         lblFilter->hide();
   192         CB_TemplateFilter->hide();
   198         CB_TemplateFilter->hide();
   193         emit mapChanged(chooseMap->currentText());
   199         emit mapChanged(chooseMap->itemData(0).toList()[0].toString());
   194     }
   200     }
   195 }
   201 }
   196 
   202 
   197 void HWMapContainer::loadMap(int index)
   203 void HWMapContainer::loadMap(int index)
   198 {
   204 {
   199     QPixmap mapImage;
   205     QPixmap mapImage;
   200     if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/preview.png")) {
   206     if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->itemData(index).toList()[0].toString() + "/preview.png")) {
   201         changeImage();
   207         changeImage();
   202         chooseMap->setCurrentIndex(0);
   208         chooseMap->setCurrentIndex(0);
   203         return;
   209         return;
   204     }
   210     }
   205 
   211 
   206     hhLimit = chooseMap->itemData(index).toList()[1].toInt();
   212     hhLimit = chooseMap->itemData(index).toList()[2].toInt();
   207     addInfoToPreview(mapImage);
   213     addInfoToPreview(mapImage);
   208 }
   214 }
   209 
   215 
   210 // Should this add text to identify map size?
   216 // Should this add text to identify map size?
   211 void HWMapContainer::addInfoToPreview(QPixmap image)
   217 void HWMapContainer::addInfoToPreview(QPixmap image)
   244 
   250 
   245 void HWMapContainer::themeSelected(int currentRow)
   251 void HWMapContainer::themeSelected(int currentRow)
   246 {
   252 {
   247     QString theme = Themes->at(currentRow);
   253     QString theme = Themes->at(currentRow);
   248     QList<QVariant> mapInfo;
   254     QList<QVariant> mapInfo;
       
   255     mapInfo.push_back(QString("+rnd+"));
   249     mapInfo.push_back(theme);
   256     mapInfo.push_back(theme);
   250     mapInfo.push_back(18);
   257     mapInfo.push_back(18);
   251     chooseMap->setItemData(0, mapInfo);
   258     chooseMap->setItemData(0, mapInfo);
   252     gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(theme)));
   259     gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(theme)));
   253     emit themeChanged(theme);
   260     emit themeChanged(theme);
   259 }
   266 }
   260 
   267 
   261 QString HWMapContainer::getCurrentMap() const
   268 QString HWMapContainer::getCurrentMap() const
   262 {
   269 {
   263     if(!chooseMap->currentIndex()) return QString();
   270     if(!chooseMap->currentIndex()) return QString();
   264     return chooseMap->currentText();
   271     return chooseMap->itemData(chooseMap->currentIndex()).toList()[0].toString();
   265 }
   272 }
   266 
   273 
   267 QString HWMapContainer::getCurrentTheme() const
   274 QString HWMapContainer::getCurrentTheme() const
   268 {
   275 {
   269     return chooseMap->itemData(chooseMap->currentIndex()).toList()[0].toString();
   276     return chooseMap->itemData(chooseMap->currentIndex()).toList()[1].toString();
       
   277 }
       
   278 
       
   279 bool HWMapContainer::getCurrentIsMission() const
       
   280 {
       
   281     if(!chooseMap->currentIndex()) return false;
       
   282     return chooseMap->itemData(chooseMap->currentIndex()).toList()[3].toBool();
   270 }
   283 }
   271 
   284 
   272 int HWMapContainer::getCurrentHHLimit() const
   285 int HWMapContainer::getCurrentHHLimit() const
   273 {
   286 {
   274     return hhLimit;
   287     return hhLimit;
   296     {
   309     {
   297         changeImage();
   310         changeImage();
   298         return;
   311         return;
   299     }
   312     }
   300 
   313 
   301     int id = chooseMap->findText(map);
   314     int id = 0;
       
   315     for(int i = 0; i < chooseMap->count(); i++)
       
   316         if(chooseMap->itemData(i).toList()[0].toString() == map)
       
   317         {
       
   318             id = i;
       
   319             break;
       
   320         }
       
   321 
   302     if(id > 0) {
   322     if(id > 0) {
   303         if (pMap)
   323         if (pMap)
   304         {
   324         {
   305             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   325             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   306             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   326             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));