QTfrontend/hwform.cpp
changeset 14607 14b295892fb7
parent 14606 1d3f8cf48831
child 14651 e3e6b0c6543f
equal deleted inserted replaced
14606:1d3f8cf48831 14607:14b295892fb7
  2086 
  2086 
  2087 void HWForm::UpdateCampaignPage(int index)
  2087 void HWForm::UpdateCampaignPage(int index)
  2088 {
  2088 {
  2089     Q_UNUSED(index);
  2089     Q_UNUSED(index);
  2090     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  2090     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  2091     QString campaignName = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
  2091     QString campaignName = ui.pageCampaign->CBCampaign->currentData().toString();
  2092     QString tName = team.name();
  2092     QString tName = team.name();
  2093 
  2093 
  2094     campaignMissionInfo = getCampMissionList(campaignName,tName);
  2094     campaignMissionInfo = getCampMissionList(campaignName,tName);
  2095     ui.pageCampaign->CBMission->clear();
  2095     ui.pageCampaign->CBMission->clear();
  2096 
  2096 
       
  2097     // Populate mission list
  2097     for(int i=0;i<campaignMissionInfo.size();i++)
  2098     for(int i=0;i<campaignMissionInfo.size();i++)
  2098     {
  2099     {
  2099         ui.pageCampaign->CBMission->addItem(QString(campaignMissionInfo[i].realName), QString(campaignMissionInfo[i].name));
  2100         ui.pageCampaign->CBMission->addItem(QString(campaignMissionInfo[i].realName), QString(campaignMissionInfo[i].name));
  2100         if(isCampMissionWon(campaignName, i, tName))
  2101         if(isCampMissionWon(campaignName, i, tName))
  2101             ui.pageCampaign->CBMission->setItemIcon(i, finishedIcon);
  2102             ui.pageCampaign->CBMission->setItemIcon(i, finishedIcon);
  2102         else
  2103         else
  2103             ui.pageCampaign->CBMission->setItemIcon(i, notFinishedIcon);
  2104             ui.pageCampaign->CBMission->setItemIcon(i, notFinishedIcon);
  2104     }
  2105     }
       
  2106 
       
  2107     // Select first open mission
       
  2108     int missionIndex = ui.pageCampaign->CBMission->currentIndex();
       
  2109     if(isCampMissionWon(campaignName, missionIndex, tName))
       
  2110     {
       
  2111         for(int m = 0; m < ui.pageCampaign->CBMission->count(); m++)
       
  2112         {
       
  2113             if(!isCampMissionWon(campaignName, m, tName))
       
  2114             {
       
  2115                 ui.pageCampaign->CBMission->setCurrentIndex(m);
       
  2116                 break;
       
  2117             }
       
  2118         }
       
  2119     }
  2105 }
  2120 }
  2106 
  2121 
  2107 void HWForm::UpdateCampaignPageTeam(int index)
  2122 void HWForm::UpdateCampaignPageTeam(int index)
  2108 {
  2123 {
  2109     Q_UNUSED(index);
  2124     Q_UNUSED(index);
  2116                                   QStringList("[^\\.]*")
  2131                                   QStringList("[^\\.]*")
  2117                               );
  2132                               );
  2118 
  2133 
  2119     unsigned int n = entries.count();
  2134     unsigned int n = entries.count();
  2120 
  2135 
       
  2136     // Update campaign status
  2121     for(unsigned int i = 0; i < n; i++)
  2137     for(unsigned int i = 0; i < n; i++)
  2122     {
  2138     {
  2123         QString campaignName = QString(entries[i]).replace(QString(" "),QString("_"));
  2139         QString campaignName = QString(entries[i]).replace(QString(" "),QString("_"));
  2124         if(isCampWon(campaignName, tName))
  2140         if(isCampWon(campaignName, tName))
  2125             ui.pageCampaign->CBCampaign->setItemIcon(i, finishedIcon);
  2141             ui.pageCampaign->CBCampaign->setItemIcon(i, finishedIcon);
  2129 }
  2145 }
  2130 
  2146 
  2131 void HWForm::UpdateCampaignPageMission(int index)
  2147 void HWForm::UpdateCampaignPageMission(int index)
  2132 {
  2148 {
  2133     // update thumbnail and description
  2149     // update thumbnail and description
  2134     QString campaignName = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
  2150     QString campaignName = ui.pageCampaign->CBCampaign->currentData().toString();
  2135     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
  2151     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
  2136     // this will cause segfault. This check prevents illegal memory reads
  2152     // this will cause segfault. This check prevents illegal memory reads
  2137     if(index > -1 && index < campaignMissionInfo.count()) {
  2153     if(index > -1 && index < campaignMissionInfo.count()) {
  2138         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
  2154         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
  2139         ui.pageCampaign->lbldescription->setText(campaignMissionInfo[index].description);
  2155         ui.pageCampaign->lbldescription->setText(campaignMissionInfo[index].description);