QTfrontend/mapContainer.cpp
branchexperimental3D
changeset 4004 b1c2c2f6fc5e
parent 3951 c9a63db3e603
child 4125 877ecc9d9d82
equal deleted inserted replaced
3698:793386610068 4004:b1c2c2f6fc5e
    54     imageButt->setObjectName("imageButt");
    54     imageButt->setObjectName("imageButt");
    55     imageButt->setFixedSize(256 + 6, 128 + 6);
    55     imageButt->setFixedSize(256 + 6, 128 + 6);
    56     imageButt->setFlat(true);
    56     imageButt->setFlat(true);
    57     imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum);
    57     imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum);
    58     mainLayout.addWidget(imageButt, 0, 0, 1, 2);
    58     mainLayout.addWidget(imageButt, 0, 0, 1, 2);
    59     connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
    59     //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
    60     connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme()));
    60     //connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme()));
       
    61     connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap()));
    61 
    62 
    62     chooseMap = new QComboBox(this);
    63     chooseMap = new QComboBox(this);
    63     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    64     chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    64     chooseMap->addItem(QComboBox::tr("generated map..."));
    65     chooseMap->addItem(QIcon(":/res/mapRandom.png"), QComboBox::tr("generated map..."));
    65     chooseMap->addItem(QComboBox::tr("generated maze..."));
    66     chooseMap->addItem(QIcon(":/res/mapMaze.png"), QComboBox::tr("generated maze..."));
    66     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    67     chooseMap->insertSeparator(chooseMap->count()); // separator between generators and missions
    67 
    68 
    68     int missionindex = chooseMap->count();
    69     int missionindex = chooseMap->count();
       
    70     numMissions = 0;
    69     for (int i = 0; i < mapList->size(); ++i) {
    71     for (int i = 0; i < mapList->size(); ++i) {
    70         QString map = (*mapList)[i];
    72         QString map = (*mapList)[i];
    71         QFile mapCfgFile(
    73         QFile mapCfgFile(
    72                 QString("%1/Maps/%2/map.cfg")
    74                 QString("%1/Maps/%2/map.cfg")
    73                 .arg(datadir->absolutePath())
    75                 .arg(datadir->absolutePath())
    90                 mapInfo.push_back(limit);
    92                 mapInfo.push_back(limit);
    91             else
    93             else
    92                 mapInfo.push_back(18);
    94                 mapInfo.push_back(18);
    93             mapInfo.push_back(mapLuaFile.exists());
    95             mapInfo.push_back(mapLuaFile.exists());
    94             if(mapLuaFile.exists())
    96             if(mapLuaFile.exists())
    95                 chooseMap->insertItem(missionindex++, QComboBox::tr("Mission") + ": " + map, mapInfo);
    97             {
       
    98                 chooseMap->insertItem(missionindex++, QIcon(":/res/mapMission.png"), QComboBox::tr("Mission") + ": " + map, mapInfo);
       
    99                 numMissions++;
       
   100             }
    96             else
   101             else
    97                 chooseMap->addItem(map, mapInfo);
   102                 chooseMap->addItem(QIcon(":/res/mapCustom.png"), map, mapInfo);
    98             mapCfgFile.close();
   103             mapCfgFile.close();
    99         }
   104         }
   100     }
   105     }
   101     chooseMap->insertSeparator(missionindex); // separator between missions and maps
   106     chooseMap->insertSeparator(missionindex); // separator between missions and maps
   102 
   107 
   147     QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes);
   152     QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes);
   148     gbTLayout->setContentsMargins(0, 0, 0 ,0);
   153     gbTLayout->setContentsMargins(0, 0, 0 ,0);
   149     gbTLayout->setSpacing(0);
   154     gbTLayout->setSpacing(0);
   150     lwThemes = new QListWidget(this);
   155     lwThemes = new QListWidget(this);
   151     lwThemes->setMinimumHeight(30);
   156     lwThemes->setMinimumHeight(30);
   152     lwThemes->setFixedWidth(120);
   157     lwThemes->setFixedWidth(140);
   153     for (int i = 0; i < Themes->size(); ++i) {
   158     for (int i = 0; i < Themes->size(); ++i) {
   154         QListWidgetItem * lwi = new QListWidgetItem();
   159         QListWidgetItem * lwi = new QListWidgetItem();
   155         lwi->setText(Themes->at(i));
   160         lwi->setText(Themes->at(i));
   156         lwi->setTextAlignment(Qt::AlignHCenter);
   161         lwi->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(Themes->at(i))));
       
   162         //lwi->setTextAlignment(Qt::AlignHCenter);
   157         lwThemes->addItem(lwi);
   163         lwThemes->addItem(lwi);
   158     }
   164     }
   159     connect(lwThemes, SIGNAL(currentRowChanged(int)), this, SLOT(themeSelected(int)));
   165     connect(lwThemes, SIGNAL(currentRowChanged(int)), this, SLOT(themeSelected(int)));
   160 
   166 
   161     // override default style to tighten up theme scroller
   167     // override default style to tighten up theme scroller
   165             "border-width: 0px;"
   171             "border-width: 0px;"
   166             "border-radius: 0px;"
   172             "border-radius: 0px;"
   167             "border-color: transparent;"
   173             "border-color: transparent;"
   168             "background-color: #0d0544;"
   174             "background-color: #0d0544;"
   169             "color: #ffcc00;"
   175             "color: #ffcc00;"
   170             "font: bold 14px;"
   176             "font: bold 13px;"
   171             "}"
   177             "}"
   172         )
   178         )
   173     );
   179     );
   174 
   180 
   175     gbTLayout->addWidget(lwThemes);
   181     gbTLayout->addWidget(lwThemes);
   387 {
   393 {
   388     QList<QListWidgetItem *> items = lwThemes->findItems(theme, Qt::MatchExactly);
   394     QList<QListWidgetItem *> items = lwThemes->findItems(theme, Qt::MatchExactly);
   389     if(items.size())
   395     if(items.size())
   390         lwThemes->setCurrentItem(items.at(0));
   396         lwThemes->setCurrentItem(items.at(0));
   391 }
   397 }
       
   398 #include <QMessageBox>
       
   399 void HWMapContainer::setRandomMap()
       
   400 {
       
   401     switch(chooseMap->currentIndex())
       
   402     {
       
   403     case MAPGEN_REGULAR:
       
   404     case MAPGEN_MAZE:
       
   405         setRandomSeed();
       
   406         setRandomTheme();
       
   407         break;
       
   408     default:
       
   409         if(chooseMap->currentIndex() < numMissions + 3)
       
   410             setRandomMission();
       
   411         else
       
   412             setRandomStatic();
       
   413         break;
       
   414     }
       
   415 }
       
   416 
       
   417 void HWMapContainer::setRandomStatic()
       
   418 {
       
   419     chooseMap->setCurrentIndex(4 + numMissions + rand() % (chooseMap->count() - 4 - numMissions));
       
   420     m_seed = QUuid::createUuid().toString();
       
   421 }
       
   422 
       
   423 void HWMapContainer::setRandomMission()
       
   424 {
       
   425     chooseMap->setCurrentIndex(3 + rand() % numMissions);
       
   426     m_seed = QUuid::createUuid().toString();
       
   427 }
   392 
   428 
   393 void HWMapContainer::setRandomSeed()
   429 void HWMapContainer::setRandomSeed()
   394 {
   430 {
   395     m_seed = QUuid::createUuid().toString();
   431     m_seed = QUuid::createUuid().toString();
   396     emit seedChanged(m_seed);
   432     emit seedChanged(m_seed);