3 #include <client/autocvars.qh>
4 #include <client/draw.qh>
8 void HUD_Notify_Export(int fh)
10 // allow saving cvars that aesthetically change the panel into hud skin files
11 HUD_Write_Cvar("hud_panel_notify_flip");
12 HUD_Write_Cvar("hud_panel_notify_fontsize");
13 HUD_Write_Cvar("hud_panel_notify_time");
14 HUD_Write_Cvar("hud_panel_notify_fadetime");
15 HUD_Write_Cvar("hud_panel_notify_icon_aspect");
18 void HUD_Notify_Push(string icon, string attacker, string victim)
26 if (notify_index == -1)
27 notify_index = NOTIFY_MAX_ENTRIES-1;
30 if (notify_attackers[notify_index])
31 strunzone(notify_attackers[notify_index]);
33 if (notify_victims[notify_index])
34 strunzone(notify_victims[notify_index]);
36 if (notify_icons[notify_index])
37 strunzone(notify_icons[notify_index]);
39 // Allocate new strings
42 notify_attackers[notify_index] = strzone(attacker);
43 notify_victims[notify_index] = strzone(victim);
47 // In case of a notification without a victim, the attacker
48 // is displayed on the victim's side. Instead of special
49 // treatment later on, we can simply switch them here.
50 notify_attackers[notify_index] = string_null;
51 notify_victims[notify_index] = strzone(attacker);
54 notify_icons[notify_index] = strzone(icon);
55 notify_times[notify_index] = time;
60 if (!autocvar__hud_configure)
61 if (!autocvar_hud_panel_notify)
64 HUD_Panel_LoadCvars();
66 if (autocvar_hud_panel_notify_dynamichud)
72 if (!autocvar__hud_configure)
73 if (notify_count == 0)
82 pos += '1 1 0' * panel_bg_padding;
83 size -= '2 2 0' * panel_bg_padding;
86 float fade_start = max(0, autocvar_hud_panel_notify_time);
87 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
88 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
90 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
91 float entry_height = size.y / entry_count;
93 float panel_width_half = size.x * 0.5;
94 float icon_width_half = entry_height * icon_aspect / 2;
95 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
97 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
98 vector icon_size = vec2(icon_aspect, 1) * entry_height;
99 vector icon_left = eX * (panel_width_half - icon_width_half);
100 vector attacker_right = eX * name_maxwidth;
101 vector victim_left = eX * (size.x - name_maxwidth);
103 vector attacker_pos, victim_pos, icon_pos;
104 string attacker, victim, icon;
105 int i, j, count, step, limit;
108 if (autocvar_hud_panel_notify_flip)
110 // Order items from the top down
117 // Order items from the bottom up
123 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
125 if(autocvar__hud_configure)
127 attacker = sprintf(_("Player %d"), count + 1);
128 victim = sprintf(_("Player %d"), count + 2);
129 icon = REGISTRY_GET(Weapons, min(WEP_FIRST + count * 2, WEP_LAST)).model2;
130 alpha = bound(0, 1.2 - count / entry_count, 1);
134 if (j == NOTIFY_MAX_ENTRIES)
137 if (notify_times[j] + fade_start > time)
139 else if (fade_time != 0)
141 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
148 attacker = notify_attackers[j];
149 victim = notify_victims[j];
150 icon = notify_icons[j];
153 if (icon != "" && victim != "")
155 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
157 icon_pos = pos + icon_left + eY * i * entry_height;
158 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
160 victim = textShortenToWidth(ColorTranslateRGB(victim), name_maxwidth, font_size, stringwidth_colors);
161 victim_pos = pos + victim_left + name_top;
162 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
166 attacker = textShortenToWidth(ColorTranslateRGB(attacker), name_maxwidth, font_size, stringwidth_colors);
167 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
168 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
173 notify_count = count;