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