Merge branch 'master' into terencehill/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 9dfae2c903b1ef8d73bae21336bb2ee8c3e906df..74d10d970a38550a8ce1ea81cf9caf0843e76aa4 100644 (file)
@@ -1504,7 +1504,6 @@ void HUD_WeaponIcons_Clear()
 }
 
 entity weaponorder[WEP_MAXCOUNT];
-
 void weaponorder_swap(float i, float j, entity pass)
 {
        entity h;
@@ -1513,6 +1512,7 @@ void weaponorder_swap(float i, float j, entity pass)
        weaponorder[j] = h;
 }
 
+string weaponorder_cmp_str_save;
 string weaponorder_cmp_str;
 float weaponorder_cmp(float i, float j, entity pass)
 {
@@ -1533,19 +1533,34 @@ void HUD_WeaponIcons(void)
        mySize = HUD_Panel_GetSize(id);
 
        stat_weapons = getstati(STAT_WEAPONS);
+       weapon_cnt = 0;
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
                self = get_weaponinfo(i);
                if(self.impulse >= 0)
-               {
-                       weaponorder[weapon_cnt] = self;
                        ++weapon_cnt;
-               }
        }
 
        // TODO make this configurable
        weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
-       heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
+
+       if(weaponorder_cmp_str != weaponorder_cmp_str_save)
+       {
+               if(weaponorder_cmp_str_save)
+                       strunzone(weaponorder_cmp_str_save);
+               weaponorder_cmp_str_save = strzone(weaponorder_cmp_str);
+               weapon_cnt = 0;
+               for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+               {
+                       self = get_weaponinfo(i);
+                       if(self.impulse >= 0)
+                       {
+                               weaponorder[weapon_cnt] = self;
+                               ++weapon_cnt;
+                       }
+               }
+               heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
+       }
 
        HUD_Panel_DrawBg(id, pos, mySize, 0);
        float padding;