]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up ammo sorting in the HUD to not reference items directly
authorMario <mario.mario@y7mail.com>
Mon, 2 Jan 2023 23:58:54 +0000 (23:58 +0000)
committerterencehill <piuntn@gmail.com>
Mon, 2 Jan 2023 23:58:54 +0000 (23:58 +0000)
qcsrc/client/hud/panel/ammo.qc
qcsrc/common/resources/resources.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/weapon.qh

index 0cc1f23956aa417f554c186183ff2f0438d6f53d..1f748d5427f7129c98b74765baddd6d4ff4fdfc7 100644 (file)
@@ -218,16 +218,13 @@ void HUD_Ammo()
        else
        {
                row = column = 0;
-               // disabling new-style loop for now to restore original order of ammo types
-               //FOREACH(Resources, it.instanceOfAmmoResource && !it.m_hidden,
-               for(int j = 0; j < AMMO_COUNT; ++j)
+               IL_EACH(default_order_resources, it.instanceOfAmmoResource && !it.m_hidden,
                {
-                       Resource ammotype = GetAmmoTypeFromNum(j);
                        DrawAmmoItem(
                                pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
                                ammo_size,
-                               ammotype,
-                               (wep.ammo_type == ammotype),
+                               it,
+                               (wep.ammo_type == it),
                                infinite_ammo
                        );
 
@@ -237,7 +234,7 @@ void HUD_Ammo()
                                row = 0;
                                column = column + 1;
                        }
-               }
+               });
        }
 
        if (draw_nades)
index 0ecd29da2779ce403619bf02dde0a594785f7cb5..fa7ce8b73bf448e928a254fb1f62e687d581e0fc 100644 (file)
@@ -35,6 +35,20 @@ ENDCLASS(Resource)
 #define REGISTER_RESOURCE(id, inst) REGISTER(Resources, RES, id, m_id, inst)
 REGISTRY(Resources, BITS(4));
 REGISTER_REGISTRY(Resources)
+
+#ifdef CSQC
+// Copy Resources registry here before it gets sorted alphabetically by REGISTRY_SORT
+// so we can keep resources sorted by categories (as they appear in the code)
+IntrusiveList default_order_resources;
+STATIC_INIT(default_order_resources)
+{
+       default_order_resources = IL_NEW();
+       FOREACH(Resources, true, {
+               IL_PUSH(default_order_resources, it);
+       });
+}
+#endif
+
 REGISTRY_SORT(Resources);
 REGISTRY_CHECK(Resources);
 
index 70937716490921edcd0e01e07b889bf97ab565e0..effa087e65c57ce2efabc3d2a5d9ad54622d7c74 100644 (file)
@@ -233,20 +233,6 @@ entity GetAmmoItem(Resource ammotype)
 }
 
 #ifdef CSQC
-Resource GetAmmoTypeFromNum(int i)
-{
-       switch (i)
-       {
-               case 0: return RES_SHELLS;
-               case 1: return RES_BULLETS;
-               case 2: return RES_ROCKETS;
-               case 3: return RES_CELLS;
-               case 4: return RES_PLASMA;
-               case 5: return RES_FUEL;
-               default: return RES_NONE;
-       }
-}
-
 int GetAmmoStat(Resource ammotype)
 {
        switch (ammotype)
index 677d5d1b2ad813809c02e2b09a60f19bfa329282..cf0f637f0324d614da2ffe5212cf408a5988f357 100644 (file)
@@ -231,8 +231,6 @@ string GetAmmoName(Resource ammotype);
 entity GetAmmoItem(Resource ammotype);
 
 #ifdef CSQC
-Resource GetAmmoTypeFromNum(int i);
-
 int GetAmmoStat(Resource ammotype);
 #endif