3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <common/items/_mod.qh>
10 void HUD_Powerups_Export(int fh)
12 // allow saving cvars that aesthetically change the panel into hud skin files
13 HUD_Write_Cvar("hud_panel_powerups_iconalign");
14 HUD_Write_Cvar("hud_panel_powerups_baralign");
15 HUD_Write_Cvar("hud_panel_powerups_progressbar");
16 HUD_Write_Cvar("hud_panel_powerups_text");
19 // Powerup item fields (reusing existing fields)
20 .string message; // Human readable name
21 .string netname; // Icon name
22 .vector colormod; // Color
23 .float count; // Time left
24 .float lifetime; // Maximum time
27 int powerupItemsCount;
29 void resetPowerupItems()
32 for(item = powerupItems; item; item = item.chain)
35 powerupItemsCount = 0;
38 void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime)
41 powerupItems = spawn();
44 for(item = powerupItems; item.count; item = item.chain)
50 item.colormod = color;
51 item.count = currentTime;
52 item.lifetime = lifeTime;
57 int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
59 TC(int, align); TC(int, column); TC(int, row); TC(int, columns); TC(int, rows); TC(bool, isVertical);
63 bool isTop = isVertical && rows > 1 && row == 0;
64 bool isBottom = isVertical && rows > 1 && row == rows-1;
65 bool isLeft = !isVertical && columns > 1 && column == 0;
66 bool isRight = !isVertical && columns > 1 && column == columns-1;
68 if(isTop || isLeft) return (align == 2) ? 1 : 0;
69 if(isBottom || isRight) return (align == 2) ? 0 : 1;
76 int allItems = STAT(ITEMS);
77 int allBuffs = STAT(BUFFS);
78 float strengthTime, shieldTime, superTime;
81 if(!autocvar__hud_configure)
83 if((!autocvar_hud_panel_powerups) || (spectatee_status == -1))
85 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_powerups_hide_ondeath)
87 //if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return;
89 strengthTime = bound(0, STAT(STRENGTH_FINISHED) - time, 99);
90 shieldTime = bound(0, STAT(INVINCIBLE_FINISHED) - time, 99);
91 superTime = bound(0, STAT(SUPERWEAPONS_FINISHED) - time, 99);
93 if(allItems & IT_UNLIMITED_SUPERWEAPONS)
96 // Prevent stuff to show up on mismatch that will be fixed next frame
97 if(!(allItems & IT_SUPERWEAPON))
108 // Add items to linked list
112 addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30);
114 addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30);
115 if(superTime && !(allItems & IT_UNLIMITED_SUPERWEAPONS))
116 addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
118 MUTATOR_CALLHOOK(HUD_Powerups_add);
120 if(!powerupItemsCount)
123 // Draw panel background
124 HUD_Panel_LoadCvars();
126 if (autocvar_hud_panel_powerups_dynamichud)
133 vector pos = panel_pos;
134 vector size = panel_size;
135 bool isVertical = size.y > size.x;
139 pos += '1 1 0' * panel_bg_padding;
140 size -= '2 2 0' * panel_bg_padding;
143 // Find best partitioning of the drawing area
144 const float DESIRED_ASPECT = 6;
152 c = floor(powerupItemsCount / i);
153 r = ceil(powerupItemsCount / c);
154 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
156 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
163 while(++i <= powerupItemsCount);
165 // Prevent single items from getting too wide
166 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
171 pos.y += size.y * 0.5;
176 pos.x += size.x * 0.5;
180 // Draw items from linked list
181 vector itemPos = pos;
182 vector itemSize = vec2(size.x / columns, size.y / rows);
183 vector textColor = '1 1 1';
190 draw_beginBoldFont();
191 for(entity item = powerupItems; item.count; item = item.chain)
193 itemPos = vec2(pos.x + column * itemSize.x, pos.y + row * itemSize.y);
196 if(autocvar_hud_panel_powerups_progressbar)
198 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
199 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
202 // Draw icon and text
203 if(autocvar_hud_panel_powerups_text)
205 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
206 fullSeconds = ceil(item.count);
207 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
210 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
212 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
215 // Determine next section
218 if(++column >= columns)