Try to keep old weapon sets (not tested at all)
authorunc0rr
Wed, 01 Jan 2014 13:42:38 +0400
changeset 9900 34ba1d8e0e9a
parent 9898 b87695f82d2e
child 9902 eb8e8b09b2f0
Try to keep old weapon sets (not tested at all)
QTfrontend/ui/widget/selectWeapon.cpp
QTfrontend/ui/widget/selectWeapon.h
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Wed Jan 01 13:22:46 2014 +0400
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Wed Jan 01 13:42:38 2014 +0400
@@ -93,7 +93,7 @@
     for(int i = 0; i < keys.size(); i++)
     {
         if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size())
-            wconf->remove(keys[i]);
+            wconf->setValue(keys[i], fixWeaponSet(wconf->value(keys[i]).toString()));
     }
 
     QString currentState = *cDefaultAmmoStore;
@@ -333,3 +333,22 @@
         setWeapons(ammo);
     }
 }
+
+QString SelWeaponWidget::fixWeaponSet(const QString &s)
+{
+    int neededLength = cDefaultAmmoStore->size() / 4;
+    int thisSetLength = s.size() / 4;
+
+    QStringList sl;
+    sl
+            << s.left(thisSetLength)
+            << s.mid(thisSetLength, thisSetLength)
+            << s.mid(thisSetLength * 2, thisSetLength)
+            << s.right(thisSetLength)
+               ;
+
+    for(int i = sl.length() - 1; i >= 0; --i)
+        sl[i] = sl[i].leftJustified(neededLength, '0', true);
+
+    return sl.join(QString());
+}
--- a/QTfrontend/ui/widget/selectWeapon.h	Wed Jan 01 13:22:46 2014 +0400
+++ b/QTfrontend/ui/widget/selectWeapon.h	Wed Jan 01 13:42:38 2014 +0400
@@ -87,6 +87,8 @@
         QGridLayout* p2Layout;
         QGridLayout* p3Layout;
         QGridLayout* p4Layout;
+
+        QString fixWeaponSet(const QString & s);
 };
 
 #endif // _SELECT_WEAPON_INCLUDED