Frontend: Sort ammos like in-game
authorWuzzy <Wuzzy2@mail.ru>
Thu, 25 Jun 2020 22:16:11 +0200
changeset 15660 1ee7790caa0f
parent 15659 fd1a580a35d6
child 15661 afeffdb4a712
Frontend: Sort ammos like in-game
ChangeLog.txt
QTfrontend/hwconsts.cpp.in
QTfrontend/hwconsts.h
QTfrontend/ui/widget/selectWeapon.cpp
--- a/ChangeLog.txt	Thu Jun 25 18:13:20 2020 +0200
+++ b/ChangeLog.txt	Thu Jun 25 22:16:11 2020 +0200
@@ -41,6 +41,7 @@
  + Various small HUD tweaks
 
 Frontend:
+ + Sort ammos in weapon scheme editor
  * Fix weapon schemes sometimes not being saved properly
  * Fix world edge not being changable under macOS
 
--- a/QTfrontend/hwconsts.cpp.in	Thu Jun 25 18:13:20 2020 +0200
+++ b/QTfrontend/hwconsts.cpp.in	Thu Jun 25 22:16:11 2020 +0200
@@ -54,6 +54,8 @@
 QString * cEmptyAmmoStore =   new QString( AMMOLINE_EMPTY_QT AMMOLINE_EMPTY_PROB
                                            AMMOLINE_EMPTY_DELAY AMMOLINE_EMPTY_CRATE );
 int cAmmoNumber = cDefaultAmmoStore->size() / 4;
+unsigned int ammoMenuAmmos[] = HW_AMMOMENU_ARRAY;
+int cAmmoMenuRows = 6;
 
 QList< QPair<QString, QString> > cDefaultAmmos =
         QList< QPair<QString, QString> >()
--- a/QTfrontend/hwconsts.h	Thu Jun 25 18:13:20 2020 +0200
+++ b/QTfrontend/hwconsts.h	Thu Jun 25 22:16:11 2020 +0200
@@ -51,6 +51,8 @@
 extern QStringList cQuickGameMaps;
 
 extern unsigned int colors[];
+extern unsigned int ammoMenuAmmos[];
+extern int cAmmoMenuRows;
 
 extern QString * netHost;
 extern quint16 netPort;
@@ -119,3 +121,18 @@
                               0xffffff01, /* yellow */ \
                               /* add new colors here */ \
                               0 }
+
+/* The ammo types, sorted in the same way as in the ammo menu */
+#define HW_AMMOMENU_ARRAY {\
+  3,  4, 22, 29, 51, 55,\
+  1,  2, 26, 27, 40, 44,\
+  5, 10, 38, 45, 54, 59,\
+ 12, 13, 14, 23, 25, 48,\
+  9, 11, 24, 30, 31, 47,\
+ 16, 17, 28, 43, 50, 57,\
+  6, 18, 19, 46, 53, 56,\
+  8, 15, 20, 39, 41, 42,\
+ 34, 36, 37, 49, 52, 58,\
+  7, 21, 32, 33, 35\
+}
+
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Thu Jun 25 18:13:20 2020 +0200
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Thu Jun 25 22:16:11 2020 +0200
@@ -193,25 +193,34 @@
     int i = 0, k = 0;
     for(; i < m_numItems; ++i)
     {
-        // Hide amSkip (6) and amCreeper (57)
-        // TODO: Unhide amCreeper when this weapon is done
-        if (i == 6 || i == 57) continue;
-        if (k % 4 == 0) ++j;
-        SelWeaponItem * swi = new SelWeaponItem(true, i, readWeaponValue(currentState[i], 9), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this);
-        weaponItems[i].append(swi);
-        p1Layout->addWidget(swi, j, k % 4);
+        if (k % cAmmoMenuRows == 0)
+            ++j;
+        unsigned int ammo = ammoMenuAmmos[i];
+        // Hide amSkip (7)
+        if (ammo == 7)
+            continue;
+        // Hide unused amCreeper (58)
+        else if (ammo == 58)
+        {
+            ++k;
+            continue;
+        }
+        int a = ammo-1; // ammo ID for SelWeaponItem
+        SelWeaponItem * swi = new SelWeaponItem(true, a, readWeaponValue(currentState[a], 9), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this);
+        weaponItems[a].append(swi);
+        p1Layout->addWidget(swi, j, k % cAmmoMenuRows);
 
-        SelWeaponItem * pwi = new SelWeaponItem(false, i, readWeaponValue(currentState[numItems + i], 8), QImage(":/res/ammopicbox.png"), QImage(":/res/ammopicboxgrey.png"), this);
-        weaponItems[i].append(pwi);
-        p2Layout->addWidget(pwi, j, k % 4);
+        SelWeaponItem * pwi = new SelWeaponItem(false, a, readWeaponValue(currentState[numItems + a], 8), QImage(":/res/ammopicbox.png"), QImage(":/res/ammopicboxgrey.png"), this);
+        weaponItems[a].append(pwi);
+        p2Layout->addWidget(pwi, j, k % cAmmoMenuRows);
 
-        SelWeaponItem * dwi = new SelWeaponItem(false, i, readWeaponValue(currentState[numItems*2 + i], 8), QImage(":/res/ammopicdelay.png"), QImage(":/res/ammopicdelaygrey.png"), this);
-        weaponItems[i].append(dwi);
-        p3Layout->addWidget(dwi, j, k % 4);
+        SelWeaponItem * dwi = new SelWeaponItem(false, a, readWeaponValue(currentState[numItems*2 + a], 8), QImage(":/res/ammopicdelay.png"), QImage(":/res/ammopicdelaygrey.png"), this);
+        weaponItems[a].append(dwi);
+        p3Layout->addWidget(dwi, j, k % cAmmoMenuRows);
 
-        SelWeaponItem * awi = new SelWeaponItem(false, i, readWeaponValue(currentState[numItems*3 + i], 8), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this);
-        weaponItems[i].append(awi);
-        p4Layout->addWidget(awi, j, k % 4);
+        SelWeaponItem * awi = new SelWeaponItem(false, a, readWeaponValue(currentState[numItems*3 + a], 8), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this);
+        weaponItems[a].append(awi);
+        p4Layout->addWidget(awi, j, k % cAmmoMenuRows);
 
         ++k;
     }