Xonotic
notify.qc File Reference
#include "notify.qh"
#include <client/draw.qh>
#include <client/hud/panel/scoreboard.qh>
#include <client/view.qh>
+ Include dependency graph for notify.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HUD_Notify ()
 
void HUD_Notify_Export (int fh)
 
void HUD_Notify_Push (string icon, string attacker, string victim)
 

Function Documentation

◆ HUD_Notify()

void HUD_Notify ( )

Definition at line 59 of file notify.qc.

References alpha, autocvar__hud_configure, autocvar_hud_panel_notify, autocvar_hud_panel_notify_dynamichud, autocvar_hud_panel_notify_fadetime, autocvar_hud_panel_notify_flip, autocvar_hud_panel_notify_fontsize, autocvar_hud_panel_notify_icon_aspect, autocvar_hud_panel_notify_time, bound(), boxesoverlap(), count, eX, eY, fade_start, fade_time, floor(), HUD_Panel_DrawBg, HUD_Panel_LoadCvars(), HUD_Scale_Disable(), HUD_Scale_Enable(), intermission, intermission_time, max(), notify_count, NOTIFY_ICON_MARGIN, notify_index, NOTIFY_MAX_ENTRIES, panel_bg_alpha, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, scoreboard_bottom, scoreboard_fade_alpha, scoreboard_left, scoreboard_right, scoreboard_top, size, time, vec2, and vector().

60 {
62  return;
63 
65 
67  {
68  float minalpha = 1;
69  if (notify_count == 0)
70  minalpha = 0; // hide if empty
73  {
74  minalpha = 0.5; // transparent if it may overlap the scoreboard
75  }
76  float f = max(minalpha, (1 - scoreboard_fade_alpha));
77  if (f <= 0)
78  return;
79  panel_bg_alpha *= f;
80  panel_fg_alpha *= f;
81  }
82 
85  else
88 
90  return;
91 
92  vector pos, size;
93  pos = panel_pos;
94  size = panel_size;
95 
96  if (panel_bg_padding)
97  {
98  pos += '1 1 0' * panel_bg_padding;
99  size -= '2 2 0' * panel_bg_padding;
100  }
101 
103  if (intermission) // fade out in half the time
104  fade_start -= (time - intermission_time);
106  float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
107 
108  int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
109  float entry_height = size.y / entry_count;
110 
111  float panel_width_half = size.x * 0.5;
112  float icon_width_half = entry_height * icon_aspect / 2;
113  float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
114 
115  vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
116  vector icon_size = vec2(icon_aspect, 1) * entry_height;
117  vector icon_left = eX * (panel_width_half - icon_width_half);
118  vector attacker_right = eX * name_maxwidth;
119  vector victim_left = eX * (size.x - name_maxwidth);
120 
121  vector attacker_pos, victim_pos, icon_pos;
122  string attacker, victim, icon;
123  int i, j, count, step, limit;
124  float alpha;
125 
127  {
128  // Order items from the top down
129  i = 0;
130  step = +1;
131  limit = entry_count;
132  }
133  else
134  {
135  // Order items from the bottom up
136  i = entry_count - 1;
137  step = -1;
138  limit = -1;
139  }
140 
141  for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
142  {
144  {
145  attacker = sprintf(_("Player %d"), count + 1);
146  victim = sprintf(_("Player %d"), count + 2);
147  icon = REGISTRY_GET(Weapons, min(WEP_FIRST + count * 2, WEP_LAST)).model2;
148  alpha = bound(0, 1.2 - count / entry_count, 1);
149  }
150  else
151  {
152  if (j == NOTIFY_MAX_ENTRIES)
153  j = 0;
154 
155  if (notify_times[j] + fade_start > time)
156  alpha = 1;
157  else if (fade_time != 0)
158  {
159  alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
160  if (alpha == 0)
161  break;
162  }
163  else
164  break;
165 
166  attacker = notify_attackers[j];
167  victim = notify_victims[j];
168  icon = notify_icons[j];
169  }
170 
171  if (icon != "" && victim != "")
172  {
173  vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
174 
175  icon_pos = pos + icon_left + eY * i * entry_height;
176  drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
177 
178  victim = textShortenToWidth(ColorTranslateRGB(victim), name_maxwidth, font_size, stringwidth_colors);
179  victim_pos = pos + victim_left + name_top;
180  drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
181 
182  if (attacker != "")
183  {
184  attacker = textShortenToWidth(ColorTranslateRGB(attacker), name_maxwidth, font_size, stringwidth_colors);
185  attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
186  drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
187  }
188  }
189  }
190 
192 }
string notify_attackers[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:435
float scoreboard_left
Definition: scoreboard.qh:16
float alpha
Definition: items.qc:14
float panel_fg_alpha
Definition: hud.qh:166
const int WEP_FIRST
Definition: all.qh:304
const vector eY
Definition: vector.qh:45
bool autocvar__hud_configure
Definition: hud_config.qh:3
float autocvar_hud_panel_notify_fontsize
Definition: notify.qh:8
#define stringwidth
Definition: csprogsdefs.qh:29
vector panel_size
Definition: hud.qh:160
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
float fade_start
Definition: models.qh:23
float intermission
Definition: csprogsdefs.qc:148
float intermission_time
Definition: view.qh:127
void HUD_Scale_Disable()
Definition: hud.qc:83
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:956
#define WEP_LAST
Definition: all.qh:305
vector size
Definition: csprogsdefs.qc:114
float autocvar_hud_panel_notify_icon_aspect
Definition: notify.qh:10
float notify_times[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:434
float autocvar_hud_panel_notify_flip
Definition: notify.qh:7
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
void HUD_Scale_Enable()
Definition: hud.qc:90
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:78
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
requires that m2>m1 in all coordinates, and that m4>m3
Definition: vector.qh:73
const int NOTIFY_MAX_ENTRIES
Definition: hud.qh:429
bool autocvar_hud_panel_notify_dynamichud
Definition: notify.qh:5
ERASEABLE string ColorTranslateRGB(string s)
Definition: string.qh:177
float scoreboard_right
Definition: scoreboard.qh:17
float panel_bg_alpha
Definition: hud.qh:167
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
string notify_icons[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:437
vector panel_pos
Definition: hud.qh:159
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const float NOTIFY_ICON_MARGIN
Definition: hud.qh:430
const vector eX
Definition: vector.qh:44
float count
Definition: powerups.qc:22
float fade_time
Definition: common.qh:22
bool autocvar_hud_panel_notify
Definition: notify.qh:4
#define vec2(...)
Definition: vector.qh:90
float scoreboard_bottom
Definition: scoreboard.qh:15
float autocvar_hud_panel_notify_time
Definition: notify.qh:9
float time
Definition: csprogsdefs.qc:16
int notify_index
Definition: hud.qh:432
float scoreboard_top
Definition: scoreboard.qh:14
string notify_victims[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:436
float scoreboard_fade_alpha
Definition: scoreboard.qh:10
float autocvar_hud_panel_notify_fadetime
Definition: notify.qh:6
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
int notify_count
Definition: hud.qh:433
float panel_bg_padding
Definition: hud.qh:171
+ Here is the call graph for this function:

◆ HUD_Notify_Export()

void HUD_Notify_Export ( int  fh)

Definition at line 9 of file notify.qc.

References HUD_Write_Cvar.

10 {
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");
17 }
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38

◆ HUD_Notify_Push()

void HUD_Notify_Push ( string  icon,
string  attacker,
string  victim 
)

Definition at line 19 of file notify.qc.

References notify_attackers, notify_count, notify_icons, notify_index, NOTIFY_MAX_ENTRIES, notify_times, notify_victims, string_null, strunzone(), strzone(), and time.

Referenced by Local_Notification_sprintf(), and minigame_prompt().

20 {
21  if (icon == "")
22  return;
23 
24  ++notify_count;
25  --notify_index;
26 
27  if (notify_index == -1)
29 
30  // Free old strings
32  strunzone(notify_attackers[notify_index]);
33 
34  if (notify_victims[notify_index])
35  strunzone(notify_victims[notify_index]);
36 
37  if (notify_icons[notify_index])
38  strunzone(notify_icons[notify_index]);
39 
40  // Allocate new strings
41  if (victim != "")
42  {
45  }
46  else
47  {
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.
52  notify_victims[notify_index] = strzone(attacker);
53  }
54 
57 }
string notify_attackers[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:435
string string_null
Definition: nil.qh:9
float notify_times[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:434
const int NOTIFY_MAX_ENTRIES
Definition: hud.qh:429
string notify_icons[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:437
float time
Definition: csprogsdefs.qc:16
int notify_index
Definition: hud.qh:432
string notify_victims[NOTIFY_MAX_ENTRIES]
Definition: hud.qh:436
int notify_count
Definition: hud.qh:433
+ Here is the call graph for this function:
+ Here is the caller graph for this function: