QTfrontend/hwform.cpp
changeset 9648 3a3defce1b28
parent 9549 ac5c1f691ce2
parent 9646 7588daa8d28f
child 9932 99572fea028e
child 9950 2759212a27de
child 9998 736015b847e3
equal deleted inserted replaced
9583:37a6d807c140 9648:3a3defce1b28
   196     previousCampaignName = "";
   196     previousCampaignName = "";
   197     previousTeamName = "";
   197     previousTeamName = "";
   198     UpdateTeamsLists();
   198     UpdateTeamsLists();
   199     InitCampaignPage();
   199     InitCampaignPage();
   200     UpdateCampaignPage(0);
   200     UpdateCampaignPage(0);
       
   201     UpdateCampaignPageMission(0);
   201     UpdateWeapons();
   202     UpdateWeapons();
   202 
   203 
   203     // connect all goBack signals
   204     // connect all goBack signals
   204     int nPages = ui.Pages->count();
   205     int nPages = ui.Pages->count();
   205 
   206 
   303     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
   304     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
   304 
   305 
   305     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   306     connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
   306 
   307 
   307     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   308     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
       
   309     connect(ui.pageCampaign->btnPreview, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   308     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   310     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   309     connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   311     connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   310     connect(ui.pageCampaign->CBMission, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPageMission(int)));
   312     connect(ui.pageCampaign->CBMission, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPageMission(int)));
   311 
   313 
   312     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   314     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
  1727 }
  1729 }
  1728 
  1730 
  1729 void HWForm::StartCampaign()
  1731 void HWForm::StartCampaign()
  1730 {
  1732 {
  1731     CreateGame(0, 0, 0);
  1733     CreateGame(0, 0, 0);
  1732 
       
  1733     QComboBox *combo = ui.pageCampaign->CBMission;
       
  1734     QString camp = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
  1734     QString camp = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
  1735     unsigned int mNum = combo->count() - combo->currentIndex();
  1735     QString miss = campaignMissionInfo[ui.pageCampaign->CBMission->currentIndex()].script;
  1736     QString miss = getCampaignScript(camp, mNum);
       
  1737     QString campTeam = ui.pageCampaign->CBTeam->currentText();
  1736     QString campTeam = ui.pageCampaign->CBTeam->currentText();
  1738 
       
  1739     game->StartCampaign(camp, miss, campTeam);
  1737     game->StartCampaign(camp, miss, campTeam);
  1740 }
  1738 }
  1741 
  1739 
  1742 void HWForm::CreateNetGame()
  1740 void HWForm::CreateNetGame()
  1743 {
  1741 {
  1898     {
  1896     {
  1899         ui.pageCampaign->CBCampaign->addItem(QString(entries[i]).replace(QString("_"),QString(" ")), QString(entries[i]).replace(QString("_"),QString(" ")));
  1897         ui.pageCampaign->CBCampaign->addItem(QString(entries[i]).replace(QString("_"),QString(" ")), QString(entries[i]).replace(QString("_"),QString(" ")));
  1900     }
  1898     }
  1901 }
  1899 }
  1902 
  1900 
  1903 
       
  1904 void HWForm::UpdateCampaignPage(int index)
  1901 void HWForm::UpdateCampaignPage(int index)
  1905 {
  1902 {
  1906     Q_UNUSED(index);
  1903     Q_UNUSED(index);
  1907 
       
  1908     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1904     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1909     ui.pageCampaign->CBMission->clear();
       
  1910 
       
  1911     QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
  1905     QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
  1912     QStringList missionEntries = getCampMissionList(campaignName);
  1906     QString tName = team.name();    
  1913     QString tName = team.name();
  1907     
  1914     unsigned int n = missionEntries.count();
  1908     campaignMissionInfo = getCampMissionList(campaignName,tName);    
  1915     unsigned int m = getCampProgress(tName, campaignName);
  1909 	ui.pageCampaign->CBMission->clear();
  1916 
  1910 	
  1917     // if the campaign name changes update the campaignMissionDescriptions list
  1911     for(int i=0;i<campaignMissionInfo.size();i++)
  1918     // this will be used later in UpdateCampaignPageMission() to update
  1912     {
  1919     // the mission description in the campaign page
  1913         ui.pageCampaign->CBMission->addItem(QString(campaignMissionInfo[i].name), QString(campaignMissionInfo[i].name));
  1920     bool updateMissionList = false;
  1914 	}
  1921     QSettings * m_info;
       
  1922     if(previousCampaignName.compare(campaignName)!=0 ||
       
  1923             previousTeamName.compare(tName) != 0)
       
  1924     {
       
  1925         if (previousTeamName.compare(tName) != 0 &&
       
  1926                 previousTeamName.compare("") != 0)
       
  1927             index = qMin(m + 1, n);
       
  1928         previousCampaignName = campaignName;
       
  1929         previousTeamName = tName;
       
  1930         updateMissionList = true;
       
  1931         // the following code was based on pagetraining.cpp
       
  1932         DataManager & dataMgr = DataManager::instance();
       
  1933         // get locale
       
  1934         QSettings settings(dataMgr.settingsFileName(),
       
  1935                            QSettings::IniFormat);
       
  1936         QString loc = settings.value("misc/locale", "").toString();
       
  1937         if (loc.isEmpty())
       
  1938             loc = QLocale::system().name();
       
  1939         QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
       
  1940         // if file is non-existant try with language only
       
  1941         if (!QFile::exists(campaignDescFile))
       
  1942             campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
       
  1943 
       
  1944         // fallback if file for current locale is non-existant
       
  1945         if (!QFile::exists(campaignDescFile))
       
  1946             campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
       
  1947 
       
  1948         m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this);
       
  1949         m_info->setIniCodec("UTF-8");
       
  1950         campaignMissionDescriptions.clear();
       
  1951         ui.pageCampaign->CBMission->clear();
       
  1952     }
       
  1953 
       
  1954     for (unsigned int i = qMin(m + 1, n); i > 0; i--)
       
  1955     {
       
  1956         if(updateMissionList)
       
  1957         {
       
  1958             campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
       
  1959                                             tr("No description available")).toString();
       
  1960         }
       
  1961         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
       
  1962     }
       
  1963     if(updateMissionList)
       
  1964         delete m_info;
       
  1965 
       
  1966     UpdateCampaignPageMission(index);
       
  1967 }
  1915 }
  1968 
  1916 
  1969 void HWForm::UpdateCampaignPageMission(int index)
  1917 void HWForm::UpdateCampaignPageMission(int index)
  1970 {
  1918 {
  1971     // update thumbnail
  1919     // update thumbnail and description
  1972     QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
  1920     QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
  1973     unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex();
       
  1974     QString image = getCampaignImage(campaignName,mNum);
       
  1975     ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+image)));
       
  1976     // update description
       
  1977     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
  1921     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
  1978     // this will cause segfault. This check prevents illegal memory reads
  1922     // this will cause segfault. This check prevents illegal memory reads
  1979     if(index > -1 && index < campaignMissionDescriptions.count()) {
  1923     if(index > -1 && index < campaignMissionInfo.count()) {
  1980         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
  1924         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
  1981         ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
  1925         ui.pageCampaign->lbldescription->setText(campaignMissionInfo[index].description);
       
  1926 		ui.pageCampaign->btnPreview->setIcon(QIcon(campaignMissionInfo[index].image));
  1982     }
  1927     }
  1983 }
  1928 }
  1984 
  1929 
  1985 void HWForm::UpdateCampaignPageProgress(int index)
  1930 void HWForm::UpdateCampaignPageProgress(int index)
  1986 {
  1931 {
  1987     Q_UNUSED(index);
  1932     Q_UNUSED(index);
  1988 
  1933 
  1989     int missionIndex = ui.pageCampaign->CBMission->currentIndex();
  1934     QString missionTitle = ui.pageCampaign->CBMission->currentText();
  1990     UpdateCampaignPage(0);
  1935     UpdateCampaignPage(0);
  1991     ui.pageCampaign->CBMission->setCurrentIndex(missionIndex);
  1936     for(int i=0;i<ui.pageCampaign->CBMission->count();i++)
       
  1937     {
       
  1938 		if (ui.pageCampaign->CBMission->itemText(i)==missionTitle)
       
  1939 		{
       
  1940 			ui.pageCampaign->CBMission->setCurrentIndex(i);
       
  1941 			break;
       
  1942 		}
       
  1943 	}
  1992 }
  1944 }
  1993 
  1945 
  1994 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1946 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1995 QString HWForm::getDemoArguments()
  1947 QString HWForm::getDemoArguments()
  1996 {
  1948 {