From 9bf99b4b56c7adb6925d33c918d5bd63350a7345 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 2 Jan 2023 23:58:54 +0000 Subject: [PATCH] Clean up ammo sorting in the HUD to not reference items directly --- qcsrc/client/hud/panel/ammo.qc | 11 ++++------- qcsrc/common/resources/resources.qh | 14 ++++++++++++++ qcsrc/common/weapons/all.qc | 14 -------------- qcsrc/common/weapons/weapon.qh | 2 -- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/qcsrc/client/hud/panel/ammo.qc b/qcsrc/client/hud/panel/ammo.qc index 0cc1f2395..1f748d542 100644 --- a/qcsrc/client/hud/panel/ammo.qc +++ b/qcsrc/client/hud/panel/ammo.qc @@ -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) diff --git a/qcsrc/common/resources/resources.qh b/qcsrc/common/resources/resources.qh index 0ecd29da2..fa7ce8b73 100644 --- a/qcsrc/common/resources/resources.qh +++ b/qcsrc/common/resources/resources.qh @@ -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); diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 709377164..effa087e6 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -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) diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 677d5d1b2..cf0f637f0 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -231,8 +231,6 @@ string GetAmmoName(Resource ammotype); entity GetAmmoItem(Resource ammotype); #ifdef CSQC -Resource GetAmmoTypeFromNum(int i); - int GetAmmoStat(Resource ammotype); #endif -- 2.39.2