Make campaign names translatable
authorWuzzy <almikes@aol.com>
Wed, 04 May 2016 07:41:46 +0200
changeset 11957 1201fc039e24
parent 11956 221b38978401
child 11958 de66192866d3
Make campaign names translatable Also add German translation for both campaigns
QTfrontend/campaign.cpp
QTfrontend/campaign.h
QTfrontend/hwform.cpp
share/hedgewars/Data/Locale/campaigns_de.txt
share/hedgewars/Data/Locale/campaigns_en.txt
--- a/QTfrontend/campaign.cpp	Wed May 04 05:23:58 2016 +0200
+++ b/QTfrontend/campaign.cpp	Wed May 04 07:41:46 2016 +0200
@@ -82,6 +82,40 @@
     return won;
 }
 
+QSettings* getCampMetaInfo()
+{
+    DataManager & dataMgr = DataManager::instance();
+    // get locale
+    QSettings settings(dataMgr.settingsFileName(),
+    QSettings::IniFormat);
+    QString loc = settings.value("misc/locale", "").toString();
+    if (loc.isEmpty())
+        loc = QLocale::system().name();
+    QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
+    // if file is non-existant try with language only
+    if (!QFile::exists(campaignDescFile))
+    campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
+
+    // fallback if file for current locale is non-existant
+    if (!QFile::exists(campaignDescFile))
+        campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
+
+    QSettings* m_info = new QSettings(campaignDescFile, QSettings::IniFormat, 0);
+    m_info->setIniCodec("UTF-8");
+
+    return m_info;
+}
+
+/** Returns the localized campaign name */
+QString getRealCampName(QString & campaignName)
+{
+    QSettings* m_info = getCampMetaInfo();
+    if(m_info->contains(campaignName+".name"))
+       return m_info->value(campaignName+".name").toString();
+    else
+       return campaignName.replace(QString("_"), QString(" "));
+}
+
 QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName)
 {
     QList<MissionInfo> missionInfoList;
@@ -93,24 +127,7 @@
     QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
     campfile.setIniCodec("UTF-8");
 
-    DataManager & dataMgr = DataManager::instance();
-        // get locale
-        QSettings settings(dataMgr.settingsFileName(),
-                           QSettings::IniFormat);
-        QString loc = settings.value("misc/locale", "").toString();
-        if (loc.isEmpty())
-            loc = QLocale::system().name();
-        QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
-        // if file is non-existant try with language only
-        if (!QFile::exists(campaignDescFile))
-            campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
-
-        // fallback if file for current locale is non-existant
-        if (!QFile::exists(campaignDescFile))
-            campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
-
-        QSettings m_info(campaignDescFile, QSettings::IniFormat, 0);
-        m_info.setIniCodec("UTF-8");
+    QSettings* m_info = getCampMetaInfo();
 
     if(progress>=0 and unlockedMissions==0)
     {
@@ -121,7 +138,7 @@
             if(!script.isNull()) {
                 missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
                 missionInfo.script = script;
-                missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
+                missionInfo.description = m_info->value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
                                             QObject::tr("No description available")).toString();
                 QString image = campfile.value(QString("Mission %1/Script").arg(i)).toString().replace(QString(".lua"),QString(".png"));
                 missionInfo.image = ":/res/campaign/"+campaignName+"/"+image;
@@ -141,7 +158,7 @@
             missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
             QString script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString();
             missionInfo.script = script;
-            missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
+            missionInfo.description = m_info->value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc",
                                             QObject::tr("No description available")).toString();
             QString image = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString().replace(QString(".lua"),QString(".png"));
             missionInfo.image = ":/res/campaign/"+campaignName+"/"+image;
--- a/QTfrontend/campaign.h	Wed May 04 05:23:58 2016 +0200
+++ b/QTfrontend/campaign.h	Wed May 04 07:41:46 2016 +0200
@@ -33,8 +33,10 @@
 
 
 QSettings* getCampTeamFile(QString & campaignName, QString & teamName);
+QSettings* getCampMetaInfo();
 bool isCampWon(QString & campaignName, QString & teamName);
 bool isMissionWon(QString & campaignName, int missionInList, QString & teamName);
+QString getRealCampName(QString & campaignName);
 QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName);
 
 #endif
--- a/QTfrontend/hwform.cpp	Wed May 04 05:23:58 2016 +0200
+++ b/QTfrontend/hwform.cpp	Wed May 04 07:41:46 2016 +0200
@@ -1702,7 +1702,7 @@
 void HWForm::StartCampaign()
 {
     CreateGame(0, 0, 0);
-    QString camp = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
+    QString camp = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
     QString miss = campaignMissionInfo[ui.pageCampaign->CBMission->currentIndex()].script;
     QString campTeam = ui.pageCampaign->CBTeam->currentText();
     game->StartCampaign(camp, miss, campTeam);
@@ -1864,9 +1864,9 @@
 
     for(unsigned int i = 0; i < n; i++)
     {
-        QString campaignName = QString(entries[i]).replace(QString("_"),QString(" "));
+        QString campaignName = QString(entries[i]);
         QString tName = team.name();
-        ui.pageCampaign->CBCampaign->addItem(campaignName, campaignName);
+        ui.pageCampaign->CBCampaign->addItem(getRealCampName(campaignName), campaignName);
     }
 }
 
@@ -1874,7 +1874,7 @@
 {
     Q_UNUSED(index);
     HWTeam team(ui.pageCampaign->CBTeam->currentText());
-    QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
+    QString campaignName = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
     QString tName = team.name();
 
     campaignMissionInfo = getCampMissionList(campaignName,tName);
@@ -1917,7 +1917,7 @@
 void HWForm::UpdateCampaignPageMission(int index)
 {
     // update thumbnail and description
-    QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
+    QString campaignName = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
     // this will cause segfault. This check prevents illegal memory reads
     if(index > -1 && index < campaignMissionInfo.count()) {
@@ -1942,7 +1942,7 @@
         }
     }
     int i = ui.pageCampaign->CBCampaign->currentIndex();
-    QString campaignName = ui.pageCampaign->CBCampaign->currentText().replace(QString(" "),QString("_"));
+    QString campaignName = ui.pageCampaign->CBCampaign->itemData(i).toString();
     HWTeam team(ui.pageCampaign->CBTeam->currentText());
     QString tName = team.name();
     if(isCampWon(campaignName, tName))
--- a/share/hedgewars/Data/Locale/campaigns_de.txt	Wed May 04 05:23:58 2016 +0200
+++ b/share/hedgewars/Data/Locale/campaigns_de.txt	Wed May 04 07:41:46 2016 +0200
@@ -1,3 +1,5 @@
+A_Classic_Fairytale.name="Ein klassisches Märchen"
+
 A_Classic_Fairytale-first_blood.desc="Hilf Undichte Stelle dabei, sein Training zu absolvieren und zu einem richtigen Igelkrieger zu werden. Du wirst in der Kunst des Seils, Fallschirms, Shoryukens und der Desert Eagle trainiert."
 
 A_Classic_Fairytale-shadow.desc="Undichte Stelle und Dichte Wolke gehen für die Jagd raus. Sei auf Gefahren im Wald gefasst. Denk dran, bedenke deine Entscheidungen gut."
@@ -18,6 +20,8 @@
 
 A_Classic_Fairytale-epil.desc="Gratulation! Undichte Stelle kann endlich in Frieden gehen und von seinen neuen Freunden und seinem Stamm angepriesen werden. Sei stolz auf das, was du erreicht hast! Du kannst vorherige Missionen wieder spielen und andere mögliche Enden sehen."
 
+A_Space_Adventure.name="Ein Weltraumabenteuer"
+
 A_Space_Adventure-cosmos.desc="Hogera, der Igelplanet, wird bald von einem riesigen Meteroid getroffen. In diesem Wettlauf ums Überleben musst du PAdIs besten Piloten, Igel Einsam, in einer Weltraumreise um die Nachbarplaneten führen, um alle 4 Teil des lang verschollenem Antigravitationsgeräts zu finden!"
 
 A_Space_Adventure-moon01.desc="Igel Einsam ist auf dem Mond gelandet, um seine fliegende Untertasse aufzutanken, aber Prof. Bösigel war zuerst da und hat einen Hinterhalt aufgestellt! Rette die gefangenen PAdI-Forscher und verscheuche Prof. Bösigel!"
--- a/share/hedgewars/Data/Locale/campaigns_en.txt	Wed May 04 05:23:58 2016 +0200
+++ b/share/hedgewars/Data/Locale/campaigns_en.txt	Wed May 04 07:41:46 2016 +0200
@@ -1,3 +1,5 @@
+A_Classic_Fairytale.name="A Classic Fairytale"
+
 A_Classic_Fairytale-first_blood.desc="Help Leaks a lot to complete his training and become a proper hedgehog warrior. You will be trained in the art of rope, parachute, shoryuken and desert eagle."
 
 A_Classic_Fairytale-shadow.desc="Leaks a lot and Dense Cloud are going for hunting. Be prepared for the dangers awaiting you at the forest. Remember, make your choices wisely."
@@ -18,6 +20,7 @@
 
 A_Classic_Fairytale-epil.desc="Congratulations! Leaks a lot can finally leave in peace and get praised by his new friends and his tribe. Be proud for what you succeed! You can play again previous missions and see the other possible endings."
 
+A_Space_Adventure.name="A Space Adventure"
 A_Space_Adventure-cosmos.desc="Hogera, the planet of hogs is about to be hit by a gigantic meteorite. In this race for survival you have to lead PAotH's best pilot, Hog Solo, in a space trip around the neighbor planets to collect all the 4 pieces of the long lost anti gravity device!"
 A_Space_Adventure-moon01.desc="Hog Solo has landed on the moon to refuel his saucer but professor Hogevil has gone there first and set an ambush! Rescue the captured PAotH researchers and drive Professor Hogevil away!"
 A_Space_Adventure-moon02.desc="Hog Solo visits an hermit, old PAotH veteran, who lives on the moon in order to gather some intel about Prof. Hogevil. However, he has to beat the hermit, Soneek the Crazy Runner, in a chase game first!"