Frontend: Select appropriate localized Default voicepack for new teams
authorWuzzy <Wuzzy2@mail.ru>
Tue, 14 May 2019 01:03:23 +0200
changeset 14955 0ec0ed2d9045
parent 14954 873dda2325c1
child 14956 4accf3e18dbc
Frontend: Select appropriate localized Default voicepack for new teams
QTfrontend/hwform.cpp
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/util/namegen.cpp
QTfrontend/util/namegen.h
--- a/QTfrontend/hwform.cpp	Mon May 13 23:44:00 2019 +0200
+++ b/QTfrontend/hwform.cpp	Tue May 14 01:03:23 2019 +0200
@@ -547,6 +547,7 @@
         // TODO: Remove DLC filtering when it isn't neccessary anymore
         HWNamegen::teamRandomGrave(defaultTeam, false);
         HWNamegen::teamRandomFort(defaultTeam, false);
+        HWNamegen::teamLocalizedDefaultVoice(defaultTeam);
         defaultTeam.saveToFile();
         teamslist.push_back(teamName);
 
@@ -560,6 +561,7 @@
             HWTeam numberTeam(teamName);
             HWNamegen::teamRandomGrave(numberTeam, false);
             HWNamegen::teamRandomFort(numberTeam, false);
+            HWNamegen::teamLocalizedDefaultVoice(numberTeam);
             numberTeam.saveToFile();
             teamslist.push_back(teamName);
         }
@@ -571,6 +573,7 @@
             HWTeam numberTeam(teamName);
             HWNamegen::teamRandomGrave(numberTeam, false);
             HWNamegen::teamRandomFort(numberTeam, false);
+            HWNamegen::teamLocalizedDefaultVoice(numberTeam);
             numberTeam.setDifficulty(6-i);
             numberTeam.saveToFile();
             teamslist.push_back(teamName);
--- a/QTfrontend/ui/page/pageeditteam.cpp	Mon May 13 23:44:00 2019 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Tue May 14 01:03:23 2019 +0200
@@ -468,12 +468,13 @@
     lazyLoad();
     OldTeamName = name;
 
-    // Mostly create a default team, with 2 important exceptions:
+    // Mostly create a default team, with some important exceptions:
     HWTeam newTeam(name);
     // Randomize grave to make it less likely that default teams have equal graves (important for resurrector)
     HWNamegen::teamRandomGrave(newTeam, false);
     // Randomize fort for greater variety in fort mode with default teams
     HWNamegen::teamRandomFort(newTeam, false);
+    HWNamegen::teamLocalizedDefaultVoice(newTeam);
     // DLC forts and graves intentionally filtered out to prevent desyncs and missing grave error
     // TODO: Remove DLC filter as soon it is not needed anymore
     loadTeam(newTeam);
--- a/QTfrontend/util/namegen.cpp	Mon May 13 23:44:00 2019 +0200
+++ b/QTfrontend/util/namegen.cpp	Tue May 14 01:03:23 2019 +0200
@@ -228,6 +228,11 @@
     team.setHedgehog(HedgehogNumber, hh);
 }
 
+void HWNamegen::teamLocalizedDefaultVoice(HWTeam & team)
+{
+    team.setVoicepack(getLocalizedDefaultVoice());
+}
+
 QStringList HWNamegen::dictContents(const QString filename)
 {
     QStringList list;
@@ -488,3 +493,26 @@
     //pick a random voice
     return Voices[rand()%(Voices.size())];
 }
+
+QString HWNamegen::getLocalizedDefaultVoice()
+{
+    QStringList entries = DataManager::instance().entryList(
+        "Sounds/voices",
+        QDir::Dirs | QDir::NoDotAndDotDot,
+        QStringList("*"),
+        false);
+
+    QString loc = QLocale().name();
+    if(entries.contains("Default_" + loc))
+    {
+        return QString("Default_" + loc);
+    }
+    else if(entries.contains("Default_" + loc.left(2)))
+    {
+        return QString("Default_" + loc.left(2));
+    }
+    else
+    {
+        return QString("Default");
+    }
+}
--- a/QTfrontend/util/namegen.h	Mon May 13 23:44:00 2019 +0200
+++ b/QTfrontend/util/namegen.h	Tue May 14 01:03:23 2019 +0200
@@ -38,6 +38,7 @@
         static void teamRandomHogNames(HWTeam & team);
         static void teamRandomHogName(HWTeam & team, const int HedgehogNumber);
         static void teamRandomEverything(HWTeam & team);
+        static void teamLocalizedDefaultVoice(HWTeam & team);
 
     private:
         HWNamegen();
@@ -48,6 +49,7 @@
         static QString getRandomFort(bool withDLC = true);
         static QString getRandomFlag(bool withDLC = true);
         static QString getRandomVoice(bool withDLC = true);
+        static QString getLocalizedDefaultVoice();
 
         static QList<QStringList> TypesTeamnames;
         static QList<QStringList> TypesHatnames;