3 #include <client/draw.qh>
4 #include <common/items/_mod.qh>
5 #include <common/util.qh>
9 void HUD_Powerups_Export(int fh)
11 // allow saving cvars that aesthetically change the panel into hud skin files
12 HUD_Write_Cvar("hud_panel_powerups_iconalign");
13 HUD_Write_Cvar("hud_panel_powerups_baralign");
14 HUD_Write_Cvar("hud_panel_powerups_progressbar");
15 HUD_Write_Cvar("hud_panel_powerups_text");
18 // Powerup item fields (reusing existing fields)
19 .string message; // Human readable name
20 .string netname; // Icon name
21 .vector colormod; // Color
22 .float count; // Time left
23 .float lifetime; // Maximum time
24 .float cnt; // Infinite timer
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, bool isInfinite)
41 powerupItems = spawn();
44 for(item = powerupItems; item.count; item = item.chain)
50 item.colormod = color;
51 item.count = currentTime;
52 item.lifetime = lifeTime;
53 item.cnt = isInfinite;
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;
78 if(!autocvar__hud_configure)
80 if((!autocvar_hud_panel_powerups) || (spectatee_status == -1))
82 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_powerups_hide_ondeath)
86 // Add items to linked list
89 MUTATOR_CALLHOOK(HUD_Powerups_add);
91 if(!powerupItemsCount)
94 // Draw panel background
95 HUD_Panel_LoadCvars();
97 if (autocvar_hud_panel_powerups_dynamichud)
104 vector pos = panel_pos;
105 vector size = panel_size;
106 bool isVertical = size.y > size.x;
110 pos += '1 1 0' * panel_bg_padding;
111 size -= '2 2 0' * panel_bg_padding;
114 // Find best partitioning of the drawing area
115 const float DESIRED_ASPECT = 6;
123 c = floor(powerupItemsCount / i);
124 r = ceil(powerupItemsCount / c);
125 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
127 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
134 while(++i <= powerupItemsCount);
136 // Prevent single items from getting too wide
137 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
142 pos.y += size.y * 0.5;
147 pos.x += size.x * 0.5;
151 // Draw items from linked list
152 vector itemPos = pos;
153 vector itemSize = vec2(size.x / columns, size.y / rows);
154 vector textColor = '1 1 1';
161 draw_beginBoldFont();
162 for(entity item = powerupItems; item.count; item = item.chain)
164 itemPos = vec2(pos.x + column * itemSize.x, pos.y + row * itemSize.y);
167 if(autocvar_hud_panel_powerups_progressbar)
169 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
170 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
173 // Draw icon and text
174 if(autocvar_hud_panel_powerups_text)
176 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
177 fullSeconds = ceil(item.count);
178 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
181 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, true, align, textColor, panel_fg_alpha);
185 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, false, align, textColor, panel_fg_alpha);
187 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, false, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
191 // Determine next section
194 if(++column >= columns)