]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Guide: sort Items and Powerups by type by loading them from default_order_items
authorterencehill <piuntn@gmail.com>
Tue, 24 Dec 2024 02:05:31 +0000 (03:05 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 24 Dec 2024 02:05:31 +0000 (03:05 +0100)
qcsrc/common/items/all.qh
qcsrc/menu/xonotic/guide/guide.qh

index e956d297295e7f7407f3cf223cb70216db16596d..8294f638b3976d9cc7ad27fc2919e927b3c13ffa 100644 (file)
@@ -12,7 +12,7 @@ REGISTRY_DEPENDS(Items, Models)
 REGISTER_REGISTRY(Items)
 #define REGISTER_ITEM(id, inst) REGISTER(Items, ITEM, id, m_id, inst)
 
-#ifdef CSQC
+#ifndef SVQC
 // Copy Items registry here before it gets sorted alphabetically by REGISTRY_SORT
 // so we can keep items sorted by categories (as they appear in the code)
 IntrusiveList default_order_items;
index de9d085fcaa51d6f2658e2c3001191e7da1a7e9f..93ae97c779d1f930d32d735e2def1aa9b1b27df5 100644 (file)
@@ -33,13 +33,23 @@ ENDCLASS(DebugSource)
 
 .bool m_hidden;
 
-#define _REGISTRY_SOURCE(id, arr_name, register_arr, cond) \
+#define _REGISTRY_SOURCE_FOREACH FOREACH
+#define _REGISTRY_SOURCE_MAX(register_arr) // empty since register_arr##_MAX is already defined
+
+#define _IL_SOURCE_FOREACH IL_EACH
+#define _IL_SOURCE_MAX(il_arr) \
+       int il_arr##_MAX = 0; \
+       IL_EACH(il_arr, !it.m_hidden, { il_arr##_MAX++; });
+
+#define _LIST_SOURCE(id, arr_name, list_arr, cond, _LIST_SOURCE_MAX, _LIST_SOURCE_FOREACH) \
 ArrayList arr_name##_MENU; \
 int arr_name##_MENU_COUNT; \
 STATIC_INIT_LATE(arr_name##_MENU) \
 { \
-       AL_NEW(arr_name##_MENU, register_arr##_MAX, NULL, e); \
-       FOREACH(register_arr, !it.m_hidden && (cond), { \
+       _LIST_SOURCE_MAX(list_arr) \
+       \
+       AL_NEW(arr_name##_MENU, list_arr##_MAX, NULL, e); \
+       _LIST_SOURCE_FOREACH(list_arr, !it.m_hidden && (cond), { \
                AL_sete(arr_name##_MENU, arr_name##_MENU_COUNT, it); \
                arr_name##_MENU_COUNT++; \
        }); \
@@ -55,8 +65,13 @@ CLASS(id, DataSource) \
 ENDCLASS(id)
 
 #define REGISTRY_SOURCE(...) EVAL(OVERLOAD(REGISTRY_SOURCE, __VA_ARGS__))
-#define REGISTRY_SOURCE_3(id, arr_name, register_arr)       _REGISTRY_SOURCE(id, arr_name, register_arr, true)
-#define REGISTRY_SOURCE_4(id, arr_name, register_arr, cond) _REGISTRY_SOURCE(id, arr_name, register_arr, cond)
+#define REGISTRY_SOURCE_3(id, arr_name, register_arr)       _LIST_SOURCE(id, arr_name, register_arr, true, _REGISTRY_SOURCE_MAX, _REGISTRY_SOURCE_FOREACH)
+#define REGISTRY_SOURCE_4(id, arr_name, register_arr, cond) _LIST_SOURCE(id, arr_name, register_arr, cond, _REGISTRY_SOURCE_MAX, _REGISTRY_SOURCE_FOREACH)
+
+#define IL_SOURCE(...) EVAL(OVERLOAD(IL_SOURCE, __VA_ARGS__))
+#define IL_SOURCE_3(id, arr_name, il_arr)       _LIST_SOURCE(id, arr_name, il_arr, true, _IL_SOURCE_MAX, _IL_SOURCE_FOREACH)
+#define IL_SOURCE_4(id, arr_name, il_arr, cond) _LIST_SOURCE(id, arr_name, il_arr, cond, _IL_SOURCE_MAX, _IL_SOURCE_FOREACH)
+
 
 REGISTRY_SOURCE(FreetextSource, Guide, GuidePages)
 
@@ -69,11 +84,11 @@ REGISTRY_SOURCE(BuffSource, Buffs, StatusEffect, it.instanceOfBuff)
 // The descriptions for these are in common/mutators/mutator/buffs/all.inc
 
 #include <common/mutators/mutator/powerups/powerup/_mod.qh>
-REGISTRY_SOURCE(PowerupSource, Powerups, Items, it.instanceOfPowerup)
+IL_SOURCE(PowerupSource, Powerups, default_order_items, it.instanceOfPowerup)
 // The descriptions for these are in common/mutators/mutator/powerups/powerup/*.qc and common/items/item/jetpack.qc
 
 #include <common/items/all.qh>
-REGISTRY_SOURCE(ItemSource, Items, Items, !it.instanceOfPowerup)
+IL_SOURCE(ItemSource, Items, default_order_items, !it.instanceOfPowerup)
 // The descriptions for these are in common/items/item/*.qc and common/mutators/mutator/instagib/items.qc
 
 #include <common/mutators/mutator/nades/nades.qh>