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