QTfrontend/hwform.cpp
branchspacecampaign
changeset 9278 33a30ce9782f
parent 9275 3df990e2ee0e
child 9281 49c77a41ae96
equal deleted inserted replaced
9275:3df990e2ee0e 9278:33a30ce9782f
  1893 }
  1893 }
  1894 
  1894 
  1895 
  1895 
  1896 void HWForm::UpdateCampaignPage(int index)
  1896 void HWForm::UpdateCampaignPage(int index)
  1897 {
  1897 {
       
  1898 	qDebug("UpdateCampaignPage");
  1898     Q_UNUSED(index);
  1899     Q_UNUSED(index);
  1899     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1900     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1900     ui.pageCampaign->CBMission->clear();
  1901     ui.pageCampaign->CBMission->clear();
  1901 
  1902 
  1902     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
  1903     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
  1908 	//unlockedMissionsHash = getUnlockedMissions2(campaignName, tName);
  1909 	//unlockedMissionsHash = getUnlockedMissions2(campaignName, tName);
  1909     // if the campaign name changes update the campaignMissionDescriptions list
  1910     // if the campaign name changes update the campaignMissionDescriptions list
  1910     // this will be used later in UpdateCampaignPageMission() to update
  1911     // this will be used later in UpdateCampaignPageMission() to update
  1911     // the mission description in the campaign page
  1912     // the mission description in the campaign page
  1912     bool updateMissionList = false;
  1913     bool updateMissionList = false;
  1913     QSettings * m_info;
       
  1914     if(previousCampaignName.compare(campaignName)!=0 ||
  1914     if(previousCampaignName.compare(campaignName)!=0 ||
  1915             previousTeamName.compare(tName) != 0)
  1915             previousTeamName.compare(tName) != 0)
  1916     {
  1916     {
  1917         if (previousTeamName.compare(tName) != 0 &&
  1917         if (previousTeamName.compare(tName) != 0 &&
  1918                 previousTeamName.compare("") != 0)
  1918                 previousTeamName.compare("") != 0)
  1919             index = qMin(m + 1, n);
  1919             index = qMin(m + 1, n);
  1920         previousCampaignName = campaignName;
  1920         previousCampaignName = campaignName;
  1921         previousTeamName = tName;
  1921         previousTeamName = tName;
  1922         updateMissionList = true;
  1922         updateMissionList = true;
  1923         // the following code was based on pagetraining.cpp
  1923     }
  1924         DataManager & dataMgr = DataManager::instance();
  1924     campaignMissionDescriptions = getDescriptions(campaignName,tName);
  1925         // get locale
       
  1926         QSettings settings(dataMgr.settingsFileName(),
       
  1927                            QSettings::IniFormat);
       
  1928         QString loc = settings.value("misc/locale", "").toString();
       
  1929         if (loc.isEmpty())
       
  1930             loc = QLocale::system().name();
       
  1931         QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
       
  1932         // if file is non-existant try with language only
       
  1933         if (!QFile::exists(campaignDescFile))
       
  1934             campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
       
  1935 
       
  1936         // fallback if file for current locale is non-existant
       
  1937         if (!QFile::exists(campaignDescFile))
       
  1938             campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
       
  1939 
       
  1940         m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this);
       
  1941         m_info->setIniCodec("UTF-8");
       
  1942         campaignMissionDescriptions.clear();
       
  1943         ui.pageCampaign->CBMission->clear();
       
  1944     }
       
  1945 /*
       
  1946     for (unsigned int i = qMin(m + 1, n); i > 0; i--)
       
  1947     {
       
  1948         if(updateMissionList)
       
  1949         {
       
  1950             campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
       
  1951                                             tr("No description available")).toString();
       
  1952         }
       
  1953         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
       
  1954     }*/
       
  1955     for(int i=0;i<missionEntries.size();i++)
  1925     for(int i=0;i<missionEntries.size();i++)
  1956     {
  1926     {
  1957 		/*if(updateMissionList)
       
  1958         {
       
  1959             campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
       
  1960                                             tr("No description available")).toString();
       
  1961         }*/
       
  1962         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(missionEntries.size()-i) + QString(missionEntries[i]), QString(missionEntries[i]));
  1927         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(missionEntries.size()-i) + QString(missionEntries[i]), QString(missionEntries[i]));
  1963 	}
  1928 	}
  1964     if(updateMissionList)
       
  1965         delete m_info;
       
  1966 
       
  1967     UpdateCampaignPageMission(index);
       
  1968 }
  1929 }
  1969 
  1930 
  1970 void HWForm::UpdateCampaignPageMission(int index)
  1931 void HWForm::UpdateCampaignPageMission(int index)
  1971 {
  1932 {
       
  1933 	qDebug("UpdateCampaignPageMission");
  1972     // update thumbnail
  1934     // update thumbnail
  1973     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
  1935     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
  1974     unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex();
  1936     unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex();
  1975     QString image = getCampaignImage(campaignName,mNum);
  1937     QString image = getCampaignImage(campaignName,mNum);
  1976     ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+image)));
  1938     ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+image)));
  1977     // update description
  1939     // update description
  1978     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
  1940     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
  1979     // this will cause segfault. This check prevents illegal memory reads
  1941     // this will cause segfault. This check prevents illegal memory reads    
       
  1942     qDebug("INDEX IS %d and number of descs is %d",index,campaignMissionDescriptions.count());
  1980     if(index > -1 && index < campaignMissionDescriptions.count()) {
  1943     if(index > -1 && index < campaignMissionDescriptions.count()) {
       
  1944 		qDebug("INSIDE IF *******");
  1981         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
  1945         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
  1982         ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
  1946         ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
  1983     }
  1947     }
  1984 }
  1948 }
  1985 
  1949