Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
notify.qc
Go to the documentation of this file.
1#include "notify.qh"
2
3#include <client/draw.qh>
5#include <client/view.qh>
6
7// Notifications (#4)
8
9void HUD_Notify_Export(int fh)
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}
18
19void HUD_Notify_Push(string icon, string attacker, string victim)
20{
21 if (icon == "")
22 return;
23
26
27 if (notify_index == -1)
29
30 // Free old strings
37
38 // Allocate new strings
39 if (victim != "")
40 {
43 }
44 else
45 {
46 // In case of a notification without a victim, the attacker
47 // is displayed on the victim's side. Instead of special
48 // treatment later on, we can simply switch them here.
51 }
52
55}
56
58{
60 return;
61
63
65 {
66 float minalpha = 1;
67 if (notify_count == 0)
68 minalpha = 0; // hide if empty
71 {
72 minalpha = 0.5; // transparent if it may overlap the scoreboard
73 }
74 float f = max(minalpha, (1 - scoreboard_fade_alpha));
75 if (f <= 0)
76 return;
77 panel_bg_alpha *= f;
78 panel_fg_alpha *= f;
79 }
80
83 else
86
88 return;
89
90 vector pos = panel_pos;
92
94 {
95 pos += '1 1 0' * panel_bg_padding;
96 size -= '2 2 0' * panel_bg_padding;
97 }
98
100 if (intermission) // fade out in half the time
103 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
104
105 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
106 float entry_height = size.y / entry_count;
107
108 float panel_width_half = size.x * 0.5;
109 float icon_width_half = entry_height * icon_aspect * 0.5;
110 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
111
112 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
113 vector icon_size = vec2(icon_aspect, 1) * entry_height;
114 vector icon_left = eX * (panel_width_half - icon_width_half);
115 vector attacker_right = eX * name_maxwidth;
116 vector victim_left = eX * (size.x - name_maxwidth);
117
118 vector attacker_pos, victim_pos, icon_pos;
119 string attacker, victim, icon;
120
121 int i, step, limit;
123 {
124 // Order items from the top down
125 i = 0;
126 step = +1;
127 limit = entry_count;
128 }
129 else
130 {
131 // Order items from the bottom up
132 i = entry_count - 1;
133 step = -1;
134 limit = -1;
135 }
136
137 float alpha;
138 vector name_top;
139 int count = 0;
140 for (int j = notify_index; i != limit; i += step, ++j, ++count)
141 {
143 {
144 attacker = sprintf(_("Player %d"), count + 1);
145 victim = sprintf(_("Player %d"), count + 2);
146 icon = REGISTRY_GET(Weapons, min(WEP_FIRST + count * 2, WEP_LAST)).model2;
147 alpha = bound(0, 1.2 - count / entry_count, 1);
148 }
149 else
150 {
151 if (j == NOTIFY_MAX_ENTRIES)
152 j = 0;
153
154 if (notify_times[j] + fade_start > time)
155 alpha = 1;
156 else if (fade_time != 0)
157 {
159 if (alpha == 0)
160 break;
161 }
162 else
163 break;
164
165 attacker = notify_attackers[j];
166 victim = notify_victims[j];
167 icon = notify_icons[j];
168 }
169
170 if (icon != "" && victim != "")
171 {
172 name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
173
174 icon_pos = pos + icon_left + eY * i * entry_height;
175 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
176
177 victim = textShortenToWidth(ColorTranslateRGB(victim), name_maxwidth, font_size, stringwidth_colors);
178 victim_pos = pos + victim_left + name_top;
179 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
180
181 if (attacker != "")
182 {
183 attacker = textShortenToWidth(ColorTranslateRGB(attacker), name_maxwidth, font_size, stringwidth_colors);
184 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
185 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
186 }
187 }
188 }
189
191}
#define drawcolorcodedstring(position, text, scale, alpha, flag)
Definition draw.qh:30
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:78
float count
Definition powerups.qc:22
float alpha
Definition items.qc:13
float fade_start
Definition item.qh:86
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1071
const float DRAWFLAG_NORMAL
float time
vector size
float intermission
#define stringwidth
Weapons
Definition guide.qh:113
void HUD_Panel_LoadCvars()
Definition hud.qc:215
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
const float NOTIFY_ICON_MARGIN
Definition hud.qh:440
vector panel_size
Definition hud.qh:163
float notify_times[NOTIFY_MAX_ENTRIES]
Definition hud.qh:444
float panel_fg_alpha
Definition hud.qh:169
string notify_icons[NOTIFY_MAX_ENTRIES]
Definition hud.qh:447
float panel_bg_padding
Definition hud.qh:174
const int NOTIFY_MAX_ENTRIES
Definition hud.qh:439
int notify_count
Definition hud.qh:443
#define HUD_Panel_DrawBg()
Definition hud.qh:55
int notify_index
Definition hud.qh:442
string notify_attackers[NOTIFY_MAX_ENTRIES]
Definition hud.qh:445
vector panel_pos
Definition hud.qh:162
float panel_bg_alpha
Definition hud.qh:170
string notify_victims[NOTIFY_MAX_ENTRIES]
Definition hud.qh:446
#define HUD_Write_Cvar(cvar)
Definition hud_config.qh:40
bool autocvar__hud_configure
Definition hud_config.qh:3
float bound(float min, float value, float max)
float min(float f,...)
void strunzone(string s)
float floor(float f)
string strzone(string s)
float max(float f,...)
string string_null
Definition nil.qh:9
void HUD_Notify_Push(string icon, string attacker, string victim)
Definition notify.qc:19
void HUD_Notify()
Definition notify.qc:57
void HUD_Notify_Export(int fh)
Definition notify.qc:9
float autocvar_hud_panel_notify_flip
Definition notify.qh:7
bool autocvar_hud_panel_notify
Definition notify.qh:4
float autocvar_hud_panel_notify_time
Definition notify.qh:9
float autocvar_hud_panel_notify_fontsize
Definition notify.qh:8
bool autocvar_hud_panel_notify_dynamichud
Definition notify.qh:5
float autocvar_hud_panel_notify_fadetime
Definition notify.qh:6
float autocvar_hud_panel_notify_icon_aspect
Definition notify.qh:10
#define REGISTRY_GET(id, i)
Definition registry.qh:43
float scoreboard_right
Definition scoreboard.qh:24
float scoreboard_top
Definition scoreboard.qh:21
float scoreboard_left
Definition scoreboard.qh:23
float scoreboard_fade_alpha
Definition scoreboard.qh:17
float scoreboard_bottom
Definition scoreboard.qh:22
vector
Definition self.qh:92
float fade_time
Definition common.qh:23
ERASEABLE string ColorTranslateRGB(string s)
Definition string.qh:196
float stringwidth_colors(string s, vector theSize)
Definition string.qh:30
const vector eY
Definition vector.qh:45
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 vector eX
Definition vector.qh:44
#define vec2(...)
Definition vector.qh:90
float intermission_time
Definition view.qh:131
#define WEP_LAST
Definition all.qh:327
const int WEP_FIRST
Definition all.qh:326