Names of new or copied game schemes are now unique
authorWuzzy <almikes@aol.com>
Sat, 07 Oct 2017 18:43:31 +0200
changeset 12666 1d25f5555c38
parent 12665 5664ec82aed7
child 12667 2e0a38566178
Names of new or copied game schemes are now unique
ChangeLog.txt
QTfrontend/model/ammoSchemeModel.cpp
QTfrontend/model/ammoSchemeModel.h
share/hedgewars/Data/Locale/hedgewars_de.ts
share/hedgewars/Data/Locale/hedgewars_en.ts
--- a/ChangeLog.txt	Sat Oct 07 03:43:06 2017 +0200
+++ b/ChangeLog.txt	Sat Oct 07 18:43:31 2017 +0200
@@ -265,6 +265,7 @@
  + Hedgewars creates 4 human teams and 2 computer teams on its first launch
  + Allow to randomize hog names, hats, team name, flag, grave, voice and fort separately
  + “Random team” button is now able to randomly select from all available hats
+ + Creating new game/weapon schemes guarantees unique names
  * Fix flag being selectable for computer players although it had no effect
  * Campaign screen does no longer show AI-controlled teams
  * Campaign names and campaign mission names can now be translated
--- a/QTfrontend/model/ammoSchemeModel.cpp	Sat Oct 07 03:43:06 2017 +0200
+++ b/QTfrontend/model/ammoSchemeModel.cpp	Sat Oct 07 18:43:31 2017 +0200
@@ -724,6 +724,18 @@
         return defaultScheme.size();
 }
 
+bool AmmoSchemeModel::hasScheme(QString name)
+{
+    for(int i=0; i<schemes.size(); i++)
+    {
+        if(schemes[i][0] == name)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
 {
     Q_UNUSED(index);
@@ -757,13 +769,29 @@
     if (row == -1)
     {
         QList<QVariant> newScheme = defaultScheme;
-        newScheme[0] = QVariant(tr("New"));
+
+        QString newName = tr("New");
+        if(hasScheme(newName))
+        {
+            //name already used -> look for an appropriate name:
+            int i=2;
+            while(hasScheme(newName = tr("New (%1)").arg(i++))) ;
+        }
+        newScheme[0] = QVariant(newName);
         schemes.insert(schemes.size(), newScheme);
     }
     else
     {
         QList<QVariant> newScheme = schemes[row];
-        newScheme[0] = QVariant(tr("Copy of %1").arg(newScheme[0].toString()));
+        QString oldName = newScheme[0].toString();
+        QString newName = tr("Copy of %1").arg(oldName);
+        if(hasScheme(newName))
+        {
+            //name already used -> look for an appropriate name:
+            int i=2;
+            while(hasScheme(newName = tr("Copy of %1 (%2)").arg(oldName).arg(i++)));
+        }
+        newScheme[0] = QVariant(newName);
         schemes.insert(schemes.size(), newScheme);
     }
 
--- a/QTfrontend/model/ammoSchemeModel.h	Sat Oct 07 03:43:06 2017 +0200
+++ b/QTfrontend/model/ammoSchemeModel.h	Sat Oct 07 18:43:31 2017 +0200
@@ -34,6 +34,7 @@
         QVariant headerData(int section, Qt::Orientation orientation, int role) const;
         int rowCount(const QModelIndex & parent) const;
         int columnCount(const QModelIndex & parent) const;
+        bool hasScheme(QString name);
         Qt::ItemFlags flags(const QModelIndex & index) const;
         bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
         bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
--- a/share/hedgewars/Data/Locale/hedgewars_de.ts	Sat Oct 07 03:43:06 2017 +0200
+++ b/share/hedgewars/Data/Locale/hedgewars_de.ts	Sat Oct 07 18:43:31 2017 +0200
@@ -120,6 +120,14 @@
         <source>Copy of %1</source>
         <translation>Kopie von %1</translation>
     </message>
+    <message>
+        <source>New (%1)</source>
+        <translation>Neu (%1)</translation>
+    </message>
+    <message>
+        <source>Copy of %1 (%2)</source>
+        <translation>Kopie von %1 (%2)</translation>
+    </message>
 </context>
 <context>
     <name>BanDialog</name>
@@ -3670,6 +3678,7 @@
     </message>
     <message>
         <source>toggle team bars</source>
+        <extracomment>This refers to the team info bars (name/flag/health) of all teams. These are shown at the bottom center of the screen</extracomment>
         <translation>Teamleisten umschalten</translation>
     </message>
 </context>
--- a/share/hedgewars/Data/Locale/hedgewars_en.ts	Sat Oct 07 03:43:06 2017 +0200
+++ b/share/hedgewars/Data/Locale/hedgewars_en.ts	Sat Oct 07 18:43:31 2017 +0200
@@ -100,6 +100,14 @@
         <source>Copy of %1</source>
         <translation>Copy of %1</translation>
     </message>
+    <message>
+        <source>New (%1)</source>
+        <translation>New (%1)</translation>
+    </message>
+    <message>
+        <source>Copy of %1 (%2)</source>
+        <translation>Copy of %1 (%2)</translation>
+    </message>
 </context>
 <context>
     <name>BanDialog</name>
@@ -562,6 +570,7 @@
     </message>
     <message>
         <source>Team %1</source>
+        <extracomment>Default team name</extracomment>
         <translation>Team %1</translation>
     </message>
     <message>
@@ -576,6 +585,11 @@
 
 Password:</translation>
     </message>
+    <message>
+        <source>Computer %1</source>
+        <extracomment>Default computer team name</extracomment>
+        <translation>Computer %1</translation>
+    </message>
 </context>
 <context>
     <name>HWGame</name>
@@ -3455,6 +3469,7 @@
     </message>
     <message>
         <source>toggle team bars</source>
+        <extracomment>This refers to the team info bars (name/flag/health) of all teams. These are shown at the bottom center of the screen</extracomment>
         <translation>toggle team bars</translation>
     </message>
 </context>