3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <common/items/_mod.qh>
7 #include <common/util.qh>
11 void HUD_Powerups_Export(int fh)
13 // allow saving cvars that aesthetically change the panel into hud skin files
14 HUD_Write_Cvar("hud_panel_powerups_iconalign");
15 HUD_Write_Cvar("hud_panel_powerups_baralign");
16 HUD_Write_Cvar("hud_panel_powerups_progressbar");
17 HUD_Write_Cvar("hud_panel_powerups_text");
20 // Powerup item fields (reusing existing fields)
21 .string message; // Human readable name
22 .string netname; // Icon name
23 .vector colormod; // Color
24 .float count; // Time left
25 .float lifetime; // Maximum time
28 int powerupItemsCount;
30 void resetPowerupItems()
33 for(item = powerupItems; item; item = item.chain)
36 powerupItemsCount = 0;
39 void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime)
42 powerupItems = spawn();
45 for(item = powerupItems; item.count; item = item.chain)
51 item.colormod = color;
52 item.count = currentTime;
53 item.lifetime = lifeTime;
58 int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
60 TC(int, align); TC(int, column); TC(int, row); TC(int, columns); TC(int, rows); TC(bool, isVertical);
64 bool isTop = isVertical && rows > 1 && row == 0;
65 bool isBottom = isVertical && rows > 1 && row == rows-1;
66 bool isLeft = !isVertical && columns > 1 && column == 0;
67 bool isRight = !isVertical && columns > 1 && column == columns-1;
69 if(isTop || isLeft) return (align == 2) ? 1 : 0;
70 if(isBottom || isRight) return (align == 2) ? 0 : 1;
77 int allItems = STAT(ITEMS);
78 int allBuffs = STAT(BUFFS);
79 float strengthTime, shieldTime, superTime;
82 if(!autocvar__hud_configure)
84 if((!autocvar_hud_panel_powerups) || (spectatee_status == -1))
86 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_powerups_hide_ondeath)
88 //if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return;
90 strengthTime = bound(0, STAT(STRENGTH_FINISHED) - time, 99);
91 shieldTime = bound(0, STAT(INVINCIBLE_FINISHED) - time, 99);
92 superTime = bound(0, STAT(SUPERWEAPONS_FINISHED) - time, 99);
94 if(allItems & IT_UNLIMITED_SUPERWEAPONS)
97 // Prevent stuff to show up on mismatch that will be fixed next frame
98 if(!(allItems & IT_SUPERWEAPON))
109 // Add items to linked list
113 addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30);
115 addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30);
116 if(superTime && !(allItems & IT_UNLIMITED_SUPERWEAPONS))
117 addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
119 MUTATOR_CALLHOOK(HUD_Powerups_add);
121 if(!powerupItemsCount)
124 // Draw panel background
125 HUD_Panel_LoadCvars();
127 if (autocvar_hud_panel_powerups_dynamichud)
134 vector pos = panel_pos;
135 vector size = panel_size;
136 bool isVertical = size.y > size.x;
140 pos += '1 1 0' * panel_bg_padding;
141 size -= '2 2 0' * panel_bg_padding;
144 // Find best partitioning of the drawing area
145 const float DESIRED_ASPECT = 6;
153 c = floor(powerupItemsCount / i);
154 r = ceil(powerupItemsCount / c);
155 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
157 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
164 while(++i <= powerupItemsCount);
166 // Prevent single items from getting too wide
167 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
172 pos.y += size.y * 0.5;
177 pos.x += size.x * 0.5;
181 // Draw items from linked list
182 vector itemPos = pos;
183 vector itemSize = vec2(size.x / columns, size.y / rows);
184 vector textColor = '1 1 1';
191 draw_beginBoldFont();
192 for(entity item = powerupItems; item.count; item = item.chain)
194 itemPos = vec2(pos.x + column * itemSize.x, pos.y + row * itemSize.y);
197 if(autocvar_hud_panel_powerups_progressbar)
199 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
200 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
203 // Draw icon and text
204 if(autocvar_hud_panel_powerups_text)
206 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
207 fullSeconds = ceil(item.count);
208 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
211 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
213 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
216 // Determine next section
219 if(++column >= columns)