]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/notify.qc
479800f9061e6018f5febf8e6cc1572a4933f134
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / notify.qc
1 #include "notify.qh"
2 // Notification area (#4)
3
4 void HUD_Notify_Push(string icon, string attacker, string victim)
5 {
6         if (icon == "")
7                 return;
8
9         ++notify_count;
10         --notify_index;
11
12         if (notify_index == -1)
13                 notify_index = NOTIFY_MAX_ENTRIES-1;
14
15         // Free old strings
16         if (notify_attackers[notify_index])
17                 strunzone(notify_attackers[notify_index]);
18
19         if (notify_victims[notify_index])
20                 strunzone(notify_victims[notify_index]);
21
22         if (notify_icons[notify_index])
23                 strunzone(notify_icons[notify_index]);
24
25         // Allocate new strings
26         if (victim != "")
27         {
28                 notify_attackers[notify_index] = strzone(attacker);
29                 notify_victims[notify_index] = strzone(victim);
30         }
31         else
32         {
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);
38         }
39
40         notify_icons[notify_index] = strzone(icon);
41         notify_times[notify_index] = time;
42 }
43
44 void HUD_Notify()
45 {
46         if (!autocvar__hud_configure)
47                 if (!autocvar_hud_panel_notify)
48                         return;
49
50         if(1 - scoreboard_fade_alpha <= 0)
51                 return;
52         HUD_Panel_UpdateCvars(1 - scoreboard_fade_alpha);
53         if (autocvar_hud_panel_notify_dynamichud)
54                 HUD_Scale_Enable();
55         else
56                 HUD_Scale_Disable();
57         HUD_Panel_DrawBg();
58
59         if (!autocvar__hud_configure)
60                 if (notify_count == 0)
61                         return;
62
63         vector pos, size;
64         pos  = panel_pos;
65         size = panel_size;
66
67         if (panel_bg_padding)
68         {
69                 pos  += '1 1 0' * panel_bg_padding;
70                 size -= '2 2 0' * panel_bg_padding;
71         }
72
73         float fade_start = max(0, autocvar_hud_panel_notify_time);
74         float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
75         float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
76
77         int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
78         float entry_height = size.y / entry_count;
79
80         float panel_width_half = size.x * 0.5;
81         float icon_width_half = entry_height * icon_aspect / 2;
82         float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
83
84         vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
85         vector icon_size = (eX * icon_aspect + eY) * entry_height;
86         vector icon_left = eX * (panel_width_half - icon_width_half);
87         vector attacker_right = eX * name_maxwidth;
88         vector victim_left = eX * (size.x - name_maxwidth);
89
90         vector attacker_pos, victim_pos, icon_pos;
91         string attacker, victim, icon;
92         int i, j, count, step, limit;
93         float alpha;
94
95         if (autocvar_hud_panel_notify_flip)
96         {
97                 // Order items from the top down
98                 i = 0;
99                 step = +1;
100                 limit = entry_count;
101         }
102         else
103         {
104                 // Order items from the bottom up
105                 i = entry_count - 1;
106                 step = -1;
107                 limit = -1;
108         }
109
110         for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
111         {
112                 if(autocvar__hud_configure)
113                 {
114                         attacker = sprintf(_("Player %d"), count + 1);
115                         victim = sprintf(_("Player %d"), count + 2);
116                         icon = Weapons_from(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
117                         alpha = bound(0, 1.2 - count / entry_count, 1);
118                 }
119                 else
120                 {
121                         if (j == NOTIFY_MAX_ENTRIES)
122                                 j = 0;
123
124                         if (notify_times[j] + fade_start > time)
125                                 alpha = 1;
126                         else if (fade_time != 0)
127                         {
128                                 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
129                                 if (alpha == 0)
130                                         break;
131                         }
132                         else
133                                 break;
134
135                         attacker = notify_attackers[j];
136                         victim = notify_victims[j];
137                         icon = notify_icons[j];
138                 }
139
140                 if (icon != "" && victim != "")
141                 {
142                         vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
143
144                         icon_pos = pos + icon_left + eY * i * entry_height;
145                         drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
146
147                         victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
148                         victim_pos = pos + victim_left + name_top;
149                         drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
150
151                         if (attacker != "")
152                         {
153                                 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
154                                 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
155                                 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
156                         }
157                 }
158         }
159
160         notify_count = count;
161 }