return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string)
}
+#define HUD_WEAPONS_GET_FULL_LAYOUT() MACRO_BEGIN { \
+ int nHidden = 0; \
+ WepSet weapons_stat = WepSet_GetFromStat(); \
+ FOREACH(Weapons, it != WEP_Null, { \
+ if (weapons_stat & it.m_wepset) continue; \
+ if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1; \
+ }); \
+ vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, panel_size, aspect); \
+ columns = table_size.x; \
+ rows = table_size.y; \
+ weapon_size.x = panel_size.x / columns; \
+ weapon_size.y = panel_size.y / rows; \
+} MACRO_END
+
void HUD_Weapons()
{
// declarations
return;
vector old_panel_size = panel_size;
- vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding;
-
- // get the all-weapons layout
- int nHidden = 0;
- WepSet weapons_stat = WepSet_GetFromStat();
- FOREACH(Weapons, it != WEP_Null, {
- if (weapons_stat & it.m_wepset) continue;
- if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
- });
- vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, padded_panel_size, aspect);
- columns = table_size.x;
- rows = table_size.y;
- weapon_size.x = padded_panel_size.x / columns;
- weapon_size.y = padded_panel_size.y / rows;
+ panel_size -= '2 2 0' * panel_bg_padding;
+
+ HUD_WEAPONS_GET_FULL_LAYOUT();
// NOTE: although weapons should aways look the same even if onlyowned is enabled,
// we enlarge them a bit when possible to better match the desired aspect ratio
- if(padded_panel_size.x / padded_panel_size.y < aspect)
+ if(panel_size.x / panel_size.y < aspect)
{
// maximum number of rows that allows to display items with the desired aspect ratio
- int max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect));
+ int max_rows = floor(panel_size.y / (weapon_size.x / aspect));
columns = min(columns, ceil(weapon_count / max_rows));
rows = ceil(weapon_count / columns);
- weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
- weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
+ weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
+ weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
vertical_order = false;
}
else
{
- int max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect));
+ int max_columns = floor(panel_size.x / (weapon_size.y * aspect));
rows = min(rows, ceil(weapon_count / max_columns));
columns = ceil(weapon_count / rows);
- weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
- weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
+ weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
+ weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
vertical_order = true;
}
HUD_Panel_DrawBg(1);
if(center.x == -1)
- return;
+ return; // panel has gone off screen
if(panel_bg_padding)
{
if(!rows) // if rows is > 0 onlyowned code has already updated these vars
{
- int nHidden = 0;
- WepSet weapons_stat = WepSet_GetFromStat();
- FOREACH(Weapons, it != WEP_Null, {
- if (weapons_stat & it.m_wepset) continue;
- if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
- });
- vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, panel_size, aspect);
- columns = table_size.x;
- rows = table_size.y;
- weapon_size.x = panel_size.x / columns;
- weapon_size.y = panel_size.y / rows;
+ HUD_WEAPONS_GET_FULL_LAYOUT();
vertical_order = (panel_size.x / panel_size.y >= aspect);
}