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 MUTATOR_CALLHOOK(HUD_Powerups_add);
102 if(!powerupItemsCount)
105 // Draw panel background
106 HUD_Panel_UpdateCvars();
110 vector pos = panel_pos;
111 vector size = panel_size;
112 bool isVertical = size.y > size.x;
116 pos += '1 1 0' * panel_bg_padding;
117 size -= '2 2 0' * panel_bg_padding;
120 // Find best partitioning of the drawing area
121 const float DESIRED_ASPECT = 6;
129 c = floor(powerupItemsCount / i);
130 r = ceil(powerupItemsCount / c);
131 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
133 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
140 while(++i <= powerupItemsCount);
142 // Prevent single items from getting too wide
143 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
148 pos.y += size.y * 0.5;
153 pos.x += size.x * 0.5;
157 // Draw items from linked list
158 vector itemPos = pos;
159 vector itemSize = eX * (size.x / columns) + eY * (size.y / rows);
160 vector textColor = '1 1 1';
167 draw_beginBoldFont();
168 for(entity item = powerupItems; item.count; item = item.chain)
170 itemPos = eX * (pos.x + column * itemSize.x) + eY * (pos.y + row * itemSize.y);
173 if(autocvar_hud_panel_powerups_progressbar)
175 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
176 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
179 // Draw icon and text
180 if(autocvar_hud_panel_powerups_text)
182 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
183 fullSeconds = ceil(item.count);
184 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
187 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
189 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
192 // Determine next section
195 if(++column >= columns)