2 // Notification area (#4)
4 void HUD_Notify_Push(string icon, string attacker, string victim)
12 if (notify_index == -1)
13 notify_index = NOTIFY_MAX_ENTRIES-1;
16 if (notify_attackers[notify_index])
17 strunzone(notify_attackers[notify_index]);
19 if (notify_victims[notify_index])
20 strunzone(notify_victims[notify_index]);
22 if (notify_icons[notify_index])
23 strunzone(notify_icons[notify_index]);
25 // Allocate new strings
28 notify_attackers[notify_index] = strzone(attacker);
29 notify_victims[notify_index] = strzone(victim);
33 // In case of a notification without a victim, the attacker
34 // is displayed on the victim's side. Instead of special
35 // treatment later on, we can simply switch them here.
36 notify_attackers[notify_index] = string_null;
37 notify_victims[notify_index] = strzone(attacker);
40 notify_icons[notify_index] = strzone(icon);
41 notify_times[notify_index] = time;
46 if (!autocvar__hud_configure)
47 if (!autocvar_hud_panel_notify)
50 HUD_Panel_UpdateCvars();
53 if (!autocvar__hud_configure)
54 if (notify_count == 0)
63 pos += '1 1 0' * panel_bg_padding;
64 size -= '2 2 0' * panel_bg_padding;
67 float fade_start = max(0, autocvar_hud_panel_notify_time);
68 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
69 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
71 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
72 float entry_height = size.y / entry_count;
74 float panel_width_half = size.x * 0.5;
75 float icon_width_half = entry_height * icon_aspect / 2;
76 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
78 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
79 vector icon_size = (eX * icon_aspect + eY) * entry_height;
80 vector icon_left = eX * (panel_width_half - icon_width_half);
81 vector attacker_right = eX * name_maxwidth;
82 vector victim_left = eX * (size.x - name_maxwidth);
84 vector attacker_pos, victim_pos, icon_pos;
85 string attacker, victim, icon;
86 int i, j, count, step, limit;
89 if (autocvar_hud_panel_notify_flip)
91 // Order items from the top down
98 // Order items from the bottom up
104 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
106 if(autocvar__hud_configure)
108 attacker = sprintf(_("Player %d"), count + 1);
109 victim = sprintf(_("Player %d"), count + 2);
110 icon = Weapons_from(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
111 alpha = bound(0, 1.2 - count / entry_count, 1);
115 if (j == NOTIFY_MAX_ENTRIES)
118 if (notify_times[j] + fade_start > time)
120 else if (fade_time != 0)
122 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
129 attacker = notify_attackers[j];
130 victim = notify_victims[j];
131 icon = notify_icons[j];
134 if (icon != "" && victim != "")
136 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
138 icon_pos = pos + icon_left + eY * i * entry_height;
139 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
141 victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
142 victim_pos = pos + victim_left + name_top;
143 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
147 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
148 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
149 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
154 notify_count = count;