3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <common/items/_mod.qh>
10 // Powerup item fields (reusing existing fields)
11 .string message; // Human readable name
12 .string netname; // Icon name
13 .vector colormod; // Color
14 .float count; // Time left
15 .float lifetime; // Maximum time
18 int powerupItemsCount;
20 void resetPowerupItems()
23 for(item = powerupItems; item; item = item.chain)
26 powerupItemsCount = 0;
29 void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime)
32 powerupItems = spawn();
35 for(item = powerupItems; item.count; item = item.chain)
41 item.colormod = color;
42 item.count = currentTime;
43 item.lifetime = lifeTime;
48 int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
50 TC(int, align); TC(int, column); TC(int, row); TC(int, columns); TC(int, rows); TC(bool, isVertical);
54 bool isTop = isVertical && rows > 1 && row == 0;
55 bool isBottom = isVertical && rows > 1 && row == rows-1;
56 bool isLeft = !isVertical && columns > 1 && column == 0;
57 bool isRight = !isVertical && columns > 1 && column == columns-1;
59 if(isTop || isLeft) return (align == 2) ? 1 : 0;
60 if(isBottom || isRight) return (align == 2) ? 0 : 1;
67 int allItems = STAT(ITEMS);
68 int allBuffs = STAT(BUFFS);
69 float strengthTime, shieldTime, superTime;
72 if(!autocvar__hud_configure)
74 if((!autocvar_hud_panel_powerups) || (spectatee_status == -1))
76 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_powerups_hide_ondeath)
78 //if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return;
80 strengthTime = bound(0, STAT(STRENGTH_FINISHED) - time, 99);
81 shieldTime = bound(0, STAT(INVINCIBLE_FINISHED) - time, 99);
82 superTime = bound(0, STAT(SUPERWEAPONS_FINISHED) - time, 99);
84 if(allItems & IT_UNLIMITED_SUPERWEAPONS)
87 // Prevent stuff to show up on mismatch that will be fixed next frame
88 if(!(allItems & IT_SUPERWEAPON))
99 // Add items to linked list
103 addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30);
105 addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30);
106 if(superTime && !(allItems & IT_UNLIMITED_SUPERWEAPONS))
107 addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
109 MUTATOR_CALLHOOK(HUD_Powerups_add);
111 if(!powerupItemsCount)
114 // Draw panel background
115 HUD_Panel_LoadCvars();
117 if (autocvar_hud_panel_powerups_dynamichud)
124 vector pos = panel_pos;
125 vector size = panel_size;
126 bool isVertical = size.y > size.x;
130 pos += '1 1 0' * panel_bg_padding;
131 size -= '2 2 0' * panel_bg_padding;
134 // Find best partitioning of the drawing area
135 const float DESIRED_ASPECT = 6;
143 c = floor(powerupItemsCount / i);
144 r = ceil(powerupItemsCount / c);
145 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
147 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
154 while(++i <= powerupItemsCount);
156 // Prevent single items from getting too wide
157 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
162 pos.y += size.y * 0.5;
167 pos.x += size.x * 0.5;
171 // Draw items from linked list
172 vector itemPos = pos;
173 vector itemSize = vec2(size.x / columns, size.y / rows);
174 vector textColor = '1 1 1';
181 draw_beginBoldFont();
182 for(entity item = powerupItems; item.count; item = item.chain)
184 itemPos = vec2(pos.x + column * itemSize.x, pos.y + row * itemSize.y);
187 if(autocvar_hud_panel_powerups_progressbar)
189 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
190 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
193 // Draw icon and text
194 if(autocvar_hud_panel_powerups_text)
196 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
197 fullSeconds = ceil(item.count);
198 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
201 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
203 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
206 // Determine next section
209 if(++column >= columns)