QTfrontend/ui/widget/mapContainer.cpp
changeset 6616 f77bb02b669f
parent 6157 9c474b8a8b5e
child 6700 e04da46ee43c
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
    46     hhSmall.load(":/res/hh_small.png");
    46     hhSmall.load(":/res/hh_small.png");
    47     hhLimit = 18;
    47     hhLimit = 18;
    48     templateFilter = 0;
    48     templateFilter = 0;
    49 
    49 
    50     mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
    50     mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
    51         1,
    51                                   1,
    52         HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
    52                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
    53         HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
    53                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
    54 
    54 
    55     QWidget* mapWidget = new QWidget(this);
    55     QWidget* mapWidget = new QWidget(this);
    56     mainLayout.addWidget(mapWidget, 0, 0, Qt::AlignHCenter);
    56     mainLayout.addWidget(mapWidget, 0, 0, Qt::AlignHCenter);
    57 
    57 
    58     QGridLayout* mapLayout = new QGridLayout(mapWidget);
    58     QGridLayout* mapLayout = new QGridLayout(mapWidget);
    68 
    68 
    69     chooseMap = new QComboBox(mapWidget);
    69     chooseMap = new QComboBox(mapWidget);
    70     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    70     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    71     chooseMap->addItem(
    71     chooseMap->addItem(
    72 // FIXME - need real icons. Disabling until then
    72 // FIXME - need real icons. Disabling until then
    73 //QIcon(":/res/mapRandom.png"), 
    73 //QIcon(":/res/mapRandom.png"),
    74 QComboBox::tr("generated map..."));
    74         QComboBox::tr("generated map..."));
    75     chooseMap->addItem(
    75     chooseMap->addItem(
    76 // FIXME - need real icons. Disabling until then
    76 // FIXME - need real icons. Disabling until then
    77 //QIcon(":/res/mapMaze.png"), 
    77 //QIcon(":/res/mapMaze.png"),
    78 QComboBox::tr("generated maze..."));
    78         QComboBox::tr("generated maze..."));
    79 
    79 
    80     chooseMap->addItem(QComboBox::tr("hand drawn map..."));
    80     chooseMap->addItem(QComboBox::tr("hand drawn map..."));
    81     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    81     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    82 
    82 
    83     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    83     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    84 
    84 
    85     int missionindex = chooseMap->count();
    85     int missionindex = chooseMap->count();
    86     numMissions = 0;
    86     numMissions = 0;
    87     QFile mapLuaFile;
    87     QFile mapLuaFile;
    88     QFile mapCfgFile;
    88     QFile mapCfgFile;
    89     for (int i = 0; i < mapList->size(); ++i) {
    89     for (int i = 0; i < mapList->size(); ++i)
       
    90     {
    90         QString map = (*mapList)[i];
    91         QString map = (*mapList)[i];
    91         mapCfgFile.setFileName(
    92         mapCfgFile.setFileName(
    92                 QString("%1/Data/Maps/%2/map.cfg")
    93             QString("%1/Data/Maps/%2/map.cfg")
       
    94             .arg(cfgdir->absolutePath())
       
    95             .arg(map));
       
    96         if (mapCfgFile.exists())
       
    97         {
       
    98             mapLuaFile.setFileName(
       
    99                 QString("%1/Data/Maps/%2/map.lua")
    93                 .arg(cfgdir->absolutePath())
   100                 .arg(cfgdir->absolutePath())
    94                 .arg(map));
   101                 .arg(map));
    95         if (mapCfgFile.exists()) {
   102         }
       
   103         else
       
   104         {
       
   105             mapCfgFile.setFileName(
       
   106                 QString("%1/Maps/%2/map.cfg")
       
   107                 .arg(datadir->absolutePath())
       
   108                 .arg(map));
    96             mapLuaFile.setFileName(
   109             mapLuaFile.setFileName(
    97                     QString("%1/Data/Maps/%2/map.lua")
   110                 QString("%1/Maps/%2/map.lua")
    98                     .arg(cfgdir->absolutePath())
   111                 .arg(datadir->absolutePath())
    99                     .arg(map));
   112                 .arg(map));
   100         } else {
       
   101             mapCfgFile.setFileName(
       
   102                     QString("%1/Maps/%2/map.cfg")
       
   103                     .arg(datadir->absolutePath())
       
   104                     .arg(map));
       
   105             mapLuaFile.setFileName(
       
   106                     QString("%1/Maps/%2/map.lua")
       
   107                     .arg(datadir->absolutePath())
       
   108                     .arg(map));
       
   109         }
   113         }
   110 
   114 
   111         if (mapCfgFile.open(QFile::ReadOnly)) {
   115         if (mapCfgFile.open(QFile::ReadOnly))
       
   116         {
   112             QString theme;
   117             QString theme;
   113             quint32 limit = 0;
   118             quint32 limit = 0;
   114             QString scheme;
   119             QString scheme;
   115             QString weapons;
   120             QString weapons;
   116             QList<QVariant> mapInfo;
   121             QList<QVariant> mapInfo;
   142             mapInfo.push_back(scheme);
   147             mapInfo.push_back(scheme);
   143             mapInfo.push_back(weapons);
   148             mapInfo.push_back(weapons);
   144 
   149 
   145             if(isMission)
   150             if(isMission)
   146             {
   151             {
   147                 chooseMap->insertItem(missionindex++, 
   152                 chooseMap->insertItem(missionindex++,
   148 // FIXME - need real icons. Disabling until then
   153 // FIXME - need real icons. Disabling until then
   149 //QIcon(":/res/mapMission.png"), 
   154 //QIcon(":/res/mapMission.png"),
   150 QComboBox::tr("Mission") + ": " + map, mapInfo);
   155                                       QComboBox::tr("Mission") + ": " + map, mapInfo);
   151                 numMissions++;
   156                 numMissions++;
   152             }
   157             }
   153             else
   158             else
   154                 chooseMap->addItem(
   159                 chooseMap->addItem(
   155 // FIXME - need real icons. Disabling until then
   160 // FIXME - need real icons. Disabling until then
   156 //QIcon(":/res/mapCustom.png"), 
   161 //QIcon(":/res/mapCustom.png"),
   157 map, mapInfo);
   162                     map, mapInfo);
   158             mapCfgFile.close();
   163             mapCfgFile.close();
   159         }
   164         }
   160     }
   165     }
   161     chooseMap->insertSeparator(missionindex); // separator between missions and maps
   166     chooseMap->insertSeparator(missionindex); // separator between missions and maps
   162 
   167 
   216 
   221 
   217     connect(lvThemes->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT(themeSelected( const QModelIndex &, const QModelIndex &)));
   222     connect(lvThemes->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT(themeSelected( const QModelIndex &, const QModelIndex &)));
   218 
   223 
   219     // override default style to tighten up theme scroller
   224     // override default style to tighten up theme scroller
   220     lvThemes->setStyleSheet(QString(
   225     lvThemes->setStyleSheet(QString(
   221         "QListView{"
   226                                 "QListView{"
   222             "border: solid;"
   227                                 "border: solid;"
   223             "border-width: 0px;"
   228                                 "border-width: 0px;"
   224             "border-radius: 0px;"
   229                                 "border-radius: 0px;"
   225             "border-color: transparent;"
   230                                 "border-color: transparent;"
   226             "background-color: #0d0544;"
   231                                 "background-color: #0d0544;"
   227             "color: #ffcc00;"
   232                                 "color: #ffcc00;"
   228             "font: bold 13px;"
   233                                 "font: bold 13px;"
   229             "}"
   234                                 "}"
   230         )
   235                             )
   231     );
   236                            );
   232 
   237 
   233     gbTLayout->addWidget(lvThemes);
   238     gbTLayout->addWidget(lvThemes);
   234     lvThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
   239     lvThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
   235 
   240 
   236     mapLayout->setSizeConstraint(QLayout::SetFixedSize);
   241     mapLayout->setSizeConstraint(QLayout::SetFixedSize);
   287     hhLimit = newHHLimit;
   292     hhLimit = newHHLimit;
   288 }
   293 }
   289 
   294 
   290 void HWMapContainer::mapChanged(int index)
   295 void HWMapContainer::mapChanged(int index)
   291 {
   296 {
   292     switch(index) {
   297     switch(index)
   293     case MAPGEN_REGULAR:
   298     {
   294         mapgen = MAPGEN_REGULAR;
   299         case MAPGEN_REGULAR:
   295         updatePreview();
   300             mapgen = MAPGEN_REGULAR;
   296         gbThemes->show();
   301             updatePreview();
   297         lblFilter->show();
   302             gbThemes->show();
   298         cbTemplateFilter->show();
   303             lblFilter->show();
   299         maze_size_label->hide();
   304             cbTemplateFilter->show();
   300         cbMazeSize->hide();
   305             maze_size_label->hide();
   301         emit mapChanged("+rnd+");
   306             cbMazeSize->hide();
   302         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   307             emit mapChanged("+rnd+");
   303         break;
   308             emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   304     case MAPGEN_MAZE:
   309             break;
   305         mapgen = MAPGEN_MAZE;
   310         case MAPGEN_MAZE:
   306         updatePreview();
   311             mapgen = MAPGEN_MAZE;
   307         gbThemes->show();
   312             updatePreview();
   308         lblFilter->hide();
   313             gbThemes->show();
   309         cbTemplateFilter->hide();
   314             lblFilter->hide();
   310         maze_size_label->show();
   315             cbTemplateFilter->hide();
   311         cbMazeSize->show();
   316             maze_size_label->show();
   312         emit mapChanged("+maze+");
   317             cbMazeSize->show();
   313         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   318             emit mapChanged("+maze+");
   314         break;
   319             emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   315     case MAPGEN_DRAWN:
   320             break;
   316         mapgen = MAPGEN_DRAWN;
   321         case MAPGEN_DRAWN:
   317         updatePreview();
   322             mapgen = MAPGEN_DRAWN;
   318         gbThemes->show();
   323             updatePreview();
   319         lblFilter->hide();
   324             gbThemes->show();
   320         cbTemplateFilter->hide();
   325             lblFilter->hide();
   321         maze_size_label->hide();
   326             cbTemplateFilter->hide();
   322         cbMazeSize->hide();
   327             maze_size_label->hide();
   323         emit mapChanged("+drawn+");
   328             cbMazeSize->hide();
   324         emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   329             emit mapChanged("+drawn+");
   325         break;
   330             emit themeChanged(chooseMap->itemData(index).toList()[1].toString());
   326     default:
   331             break;
   327         mapgen = MAPGEN_MAP;
   332         default:
   328         updatePreview();
   333             mapgen = MAPGEN_MAP;
   329         gbThemes->hide();
   334             updatePreview();
   330         lblFilter->hide();
   335             gbThemes->hide();
   331         cbTemplateFilter->hide();
   336             lblFilter->hide();
   332         maze_size_label->hide();
   337             cbTemplateFilter->hide();
   333         cbMazeSize->hide();
   338             maze_size_label->hide();
   334         emit mapChanged(chooseMap->itemData(index).toList()[0].toString());
   339             cbMazeSize->hide();
       
   340             emit mapChanged(chooseMap->itemData(index).toList()[0].toString());
   335     }
   341     }
   336 
   342 
   337     emit mapgenChanged(mapgen);
   343     emit mapgenChanged(mapgen);
   338 }
   344 }
   339 
   345 
   372     pMap->getImage(m_seed,
   378     pMap->getImage(m_seed,
   373                    getTemplateFilter(),
   379                    getTemplateFilter(),
   374                    get_mapgen(),
   380                    get_mapgen(),
   375                    getMazeSize(),
   381                    getMazeSize(),
   376                    getDrawnMapData()
   382                    getDrawnMapData()
   377             );
   383                   );
   378 }
   384 }
   379 
   385 
   380 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &)
   386 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &)
   381 {
   387 {
   382     QString theme = current.data().toString();
   388     QString theme = current.data().toString();
   438 }
   444 }
   439 
   445 
   440 void HWMapContainer::resizeEvent ( QResizeEvent * event )
   446 void HWMapContainer::resizeEvent ( QResizeEvent * event )
   441 {
   447 {
   442     Q_UNUSED(event);
   448     Q_UNUSED(event);
   443   //imageButt->setIconSize(imageButt->size());
   449     //imageButt->setIconSize(imageButt->size());
   444 }
   450 }
   445 
   451 
   446 void HWMapContainer::intSetSeed(const QString & seed)
   452 void HWMapContainer::intSetSeed(const QString & seed)
   447 {
   453 {
   448     m_seed = seed;
   454     m_seed = seed;
   465         {
   471         {
   466             id = i;
   472             id = i;
   467             break;
   473             break;
   468         }
   474         }
   469 
   475 
   470     if(id > 0) {
   476     if(id > 0)
       
   477     {
   471         if (pMap)
   478         if (pMap)
   472         {
   479         {
   473             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   480             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   474             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   481             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   475             pMap = 0;
   482             pMap = 0;
   495 void HWMapContainer::setRandomMap()
   502 void HWMapContainer::setRandomMap()
   496 {
   503 {
   497     setRandomSeed();
   504     setRandomSeed();
   498     switch(chooseMap->currentIndex())
   505     switch(chooseMap->currentIndex())
   499     {
   506     {
   500     case MAPGEN_REGULAR:
   507         case MAPGEN_REGULAR:
   501     case MAPGEN_MAZE:
   508         case MAPGEN_MAZE:
   502         setRandomTheme();
   509             setRandomTheme();
   503         break;
   510             break;
   504     case MAPGEN_DRAWN:
   511         case MAPGEN_DRAWN:
   505         emit drawMapRequested();
   512             emit drawMapRequested();
   506         break;
   513             break;
   507     default:
   514         default:
   508         if(chooseMap->currentIndex() <= numMissions + MAPGEN_MAP + 1)
   515             if(chooseMap->currentIndex() <= numMissions + MAPGEN_MAP + 1)
   509             setRandomMission();
   516                 setRandomMission();
   510         else
   517             else
   511             setRandomStatic();
   518                 setRandomStatic();
   512         break;
   519             break;
   513     }
   520     }
   514 }
   521 }
   515 
   522 
   516 void HWMapContainer::setRandomStatic()
   523 void HWMapContainer::setRandomStatic()
   517 {
   524 {
   639 {
   646 {
   640     int curIndex = chooseMap->currentIndex();
   647     int curIndex = chooseMap->currentIndex();
   641 
   648 
   642     switch(curIndex)
   649     switch(curIndex)
   643     {
   650     {
   644     case MAPGEN_REGULAR:
   651         case MAPGEN_REGULAR:
   645         askForGeneratedPreview();
   652             askForGeneratedPreview();
   646         break;
   653             break;
   647     case MAPGEN_MAZE:
   654         case MAPGEN_MAZE:
   648         askForGeneratedPreview();
   655             askForGeneratedPreview();
   649         break;
   656             break;
   650     case MAPGEN_DRAWN:
   657         case MAPGEN_DRAWN:
   651         askForGeneratedPreview();
   658             askForGeneratedPreview();
   652         break;
   659             break;
   653     default:
   660         default:
   654         QPixmap mapImage;
   661             QPixmap mapImage;
   655         QFile tmpfile;
   662             QFile tmpfile;
   656         tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png");
   663             tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png");
   657         if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png");
   664             if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "/Maps/" + chooseMap->itemData(curIndex).toList()[0].toString() + "/preview.png");
   658         if(!mapImage.load(QFileInfo(tmpfile).absoluteFilePath())) {
   665             if(!mapImage.load(QFileInfo(tmpfile).absoluteFilePath()))
   659             imageButt->setIcon(QIcon());
   666             {
   660             return;
   667                 imageButt->setIcon(QIcon());
   661         }
   668                 return;
   662 
   669             }
   663         hhLimit = chooseMap->itemData(curIndex).toList()[2].toInt();
   670 
   664         addInfoToPreview(mapImage);
   671             hhLimit = chooseMap->itemData(curIndex).toList()[2].toInt();
       
   672             addInfoToPreview(mapImage);
   665     }
   673     }
   666 }
   674 }
   667 
   675 
   668 void HWMapContainer::setAllMapParameters(const QString &map, MapGenerator m, int mazesize, const QString &seed, int tmpl)
   676 void HWMapContainer::setAllMapParameters(const QString &map, MapGenerator m, int mazesize, const QString &seed, int tmpl)
   669 {
   677 {