3 // Powerup item fields (reusing existing fields)
4 .string message; // Human readable name
5 .string netname; // Icon name
6 .vector colormod; // Color
7 .float count; // Time left
8 .float lifetime; // Maximum time
11 int powerupItemsCount;
13 void resetPowerupItems()
16 for(item = powerupItems; item; item = item.chain)
19 powerupItemsCount = 0;
22 void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime)
25 powerupItems = spawn();
28 for(item = powerupItems; item.count; item = item.chain)
34 item.colormod = color;
35 item.count = currentTime;
36 item.lifetime = lifeTime;
41 int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
46 bool isTop = isVertical && rows > 1 && row == 0;
47 bool isBottom = isVertical && rows > 1 && row == rows-1;
48 bool isLeft = !isVertical && columns > 1 && column == 0;
49 bool isRight = !isVertical && columns > 1 && column == columns-1;
51 if(isTop || isLeft) return (align == 2) ? 1 : 0;
52 if(isBottom || isRight) return (align == 2) ? 0 : 1;
59 int allItems = getstati(STAT_ITEMS, 0, 24);
60 int allBuffs = STAT(BUFFS);
61 int strengthTime, shieldTime, superTime;
64 if(!autocvar__hud_configure)
66 if(!autocvar_hud_panel_powerups) return;
67 if(spectatee_status == -1) return;
68 if(getstati(STAT_HEALTH) <= 0) return;
69 if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return;
71 strengthTime = bound(0, STAT(STRENGTH_FINISHED) - time, 99);
72 shieldTime = bound(0, STAT(INVINCIBLE_FINISHED) - time, 99);
73 superTime = bound(0, STAT(SUPERWEAPONS_FINISHED) - time, 99);
75 if(allItems & IT_UNLIMITED_SUPERWEAPONS)
78 // Prevent stuff to show up on mismatch that will be fixed next frame
79 if(!(allItems & IT_SUPERWEAPON))
90 // Add items to linked list
94 addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30);
96 addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30);
98 addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
100 FOREACH(Buffs, it.m_itemid & allBuffs, LAMBDA(
101 addPowerupItem(it.m_prettyName, strcat("buff_", it.m_name), it.m_color, bound(0, getstatf(STAT_BUFF_TIME) - time, 99), 60);
104 if(!powerupItemsCount)
107 // Draw panel background
108 HUD_Panel_UpdateCvars();
112 vector pos = panel_pos;
113 vector size = panel_size;
114 bool isVertical = size.y > size.x;
118 pos += '1 1 0' * panel_bg_padding;
119 size -= '2 2 0' * panel_bg_padding;
122 // Find best partitioning of the drawing area
123 const float DESIRED_ASPECT = 6;
131 c = floor(powerupItemsCount / i);
132 r = ceil(powerupItemsCount / c);
133 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
135 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
142 while(++i <= powerupItemsCount);
144 // Prevent single items from getting too wide
145 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
150 pos.y += size.y * 0.5;
155 pos.x += size.x * 0.5;
159 // Draw items from linked list
160 vector itemPos = pos;
161 vector itemSize = eX * (size.x / columns) + eY * (size.y / rows);
162 vector textColor = '1 1 1';
169 draw_beginBoldFont();
170 for(entity item = powerupItems; item.count; item = item.chain)
172 itemPos = eX * (pos.x + column * itemSize.x) + eY * (pos.y + row * itemSize.y);
175 if(autocvar_hud_panel_powerups_progressbar)
177 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
178 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
181 // Draw icon and text
182 if(autocvar_hud_panel_powerups_text)
184 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
185 fullSeconds = ceil(item.count);
186 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
189 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
191 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
194 // Determine next section
197 if(++column >= columns)