3 #include <client/draw.qh>
4 #include <client/hud/panel/scoreboard.qh>
5 #include <client/view.qh>
9 void HUD_Notify_Export(int fh)
11 // allow saving cvars that aesthetically change the panel into hud skin files
12 HUD_Write_Cvar("hud_panel_notify_flip");
13 HUD_Write_Cvar("hud_panel_notify_fontsize");
14 HUD_Write_Cvar("hud_panel_notify_time");
15 HUD_Write_Cvar("hud_panel_notify_fadetime");
16 HUD_Write_Cvar("hud_panel_notify_icon_aspect");
19 void HUD_Notify_Push(string icon, string attacker, string victim)
27 if (notify_index == -1)
28 notify_index = NOTIFY_MAX_ENTRIES-1;
31 if (notify_attackers[notify_index])
32 strunzone(notify_attackers[notify_index]);
34 if (notify_victims[notify_index])
35 strunzone(notify_victims[notify_index]);
37 if (notify_icons[notify_index])
38 strunzone(notify_icons[notify_index]);
40 // Allocate new strings
43 notify_attackers[notify_index] = strzone(attacker);
44 notify_victims[notify_index] = strzone(victim);
48 // In case of a notification without a victim, the attacker
49 // is displayed on the victim's side. Instead of special
50 // treatment later on, we can simply switch them here.
51 notify_attackers[notify_index] = string_null;
52 notify_victims[notify_index] = strzone(attacker);
55 notify_icons[notify_index] = strzone(icon);
56 notify_times[notify_index] = time;
61 if (!autocvar__hud_configure)
62 if (!autocvar_hud_panel_notify)
65 HUD_Panel_LoadCvars();
67 if (scoreboard_fade_alpha)
70 if (notify_count == 0)
71 minalpha = 0; // hide if empty
72 else if (boxesoverlap(panel_pos, panel_pos + panel_size,
73 eX * scoreboard_left + eY * scoreboard_top, eX * scoreboard_right + eY * scoreboard_bottom))
75 minalpha = 0.5; // transparent if it may overlap the scoreboard
77 float f = max(minalpha, (1 - scoreboard_fade_alpha));
84 if (autocvar_hud_panel_notify_dynamichud)
90 if (!autocvar__hud_configure)
91 if (notify_count == 0)
100 pos += '1 1 0' * panel_bg_padding;
101 size -= '2 2 0' * panel_bg_padding;
104 float fade_start = max(0, autocvar_hud_panel_notify_time);
105 if (intermission) // fade out in half the time
106 fade_start -= (time - intermission_time);
107 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
108 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
110 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
111 float entry_height = size.y / entry_count;
113 float panel_width_half = size.x * 0.5;
114 float icon_width_half = entry_height * icon_aspect / 2;
115 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
117 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
118 vector icon_size = vec2(icon_aspect, 1) * entry_height;
119 vector icon_left = eX * (panel_width_half - icon_width_half);
120 vector attacker_right = eX * name_maxwidth;
121 vector victim_left = eX * (size.x - name_maxwidth);
123 vector attacker_pos, victim_pos, icon_pos;
124 string attacker, victim, icon;
125 int i, j, count, step, limit;
128 if (autocvar_hud_panel_notify_flip)
130 // Order items from the top down
137 // Order items from the bottom up
143 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
145 if(autocvar__hud_configure)
147 attacker = sprintf(_("Player %d"), count + 1);
148 victim = sprintf(_("Player %d"), count + 2);
149 icon = REGISTRY_GET(Weapons, min(WEP_FIRST + count * 2, WEP_LAST)).model2;
150 alpha = bound(0, 1.2 - count / entry_count, 1);
154 if (j == NOTIFY_MAX_ENTRIES)
157 if (notify_times[j] + fade_start > time)
159 else if (fade_time != 0)
161 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
168 attacker = notify_attackers[j];
169 victim = notify_victims[j];
170 icon = notify_icons[j];
173 if (icon != "" && victim != "")
175 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
177 icon_pos = pos + icon_left + eY * i * entry_height;
178 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
180 victim = textShortenToWidth(ColorTranslateRGB(victim), name_maxwidth, font_size, stringwidth_colors);
181 victim_pos = pos + victim_left + name_top;
182 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
186 attacker = textShortenToWidth(ColorTranslateRGB(attacker), name_maxwidth, font_size, stringwidth_colors);
187 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
188 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
193 notify_count = count;