Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
pickup.qc
Go to the documentation of this file.
1#include "pickup.qh"
2
3#include <client/draw.qh>
4#include <client/hud/hud.qh>
7
8// Pickup (#26)
9
11{
12 // allow saving cvars that aesthetically change the panel into hud skin files
13}
14
15void Pickup_Update(entity item, int count)
16{
17 if (last_pickup_item != item || time - STAT(LAST_PICKUP) > autocvar_hud_panel_pickup_time)
19 last_pickup_item = item;
21}
22
23float HUD_Pickup_Time(float t)
24{
25 float timelimit = (warmup_stage ? STAT(WARMUP_TIMELIMIT) : STAT(TIMELIMIT) * 60);
26
27 if (autocvar_hud_panel_timer_increment || timelimit <= 0)
28 return floor(t - STAT(GAMESTARTTIME));
29 else
30 return ceil(timelimit + STAT(GAMESTARTTIME) - t);
31}
32
34{
36 return;
37
39 vector pos = panel_pos;
40 vector mySize = panel_size;
41
44 else
48 {
49 pos += '1 1 0' * panel_bg_padding;
50 mySize -= '2 2 0' * panel_bg_padding;
51 }
52
53 float last_pickup_time = STAT(LAST_PICKUP);
54 float display_time = min(5, autocvar_hud_panel_pickup_time);
56
57 if ((last_pickup_time && last_pickup_time > time - display_time && item) || autocvar__hud_configure)
58 {
60 item = ITEM_ArmorMega;
61
62 vector fontsize = '1 1 0' * mySize.y;
63 vector iconsize = fontsize * autocvar_hud_panel_pickup_iconsize;
64
65 string icon = strcat(hud_skin_path, "/", (item.model2) ? item.model2 : item.m_icon);
66 if (precache_pic(icon) == "")
67 icon = strcat("gfx/hud/default/", (item.model2) ? item.model2 : item.m_icon);
68
69 vector sz = draw_getimagesize(icon);
70 sz = vec2(iconsize.y * (sz.y ? sz.x / sz.y : 1), iconsize.y);
71
72 float fade_out_time = min(display_time, autocvar_hud_panel_pickup_fade_out);
73 float a;
75 a = 1;
76 else if (time < last_pickup_time + display_time - fade_out_time)
77 a = 1;
78 else
79 a = (last_pickup_time + display_time - time) / fade_out_time;
80
82 {
83 // 1 will show the timer always
84 // 2 will show the timer only if spectating
85 // forbid serverflag will force the 2nd behavior
88 {
89 string str_timer = autocvar__hud_configure
90 ? "13:02"
91 : seconds_tostring(HUD_Pickup_Time(last_pickup_time));
92 drawstring(pos, str_timer, fontsize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
93 pos.x += stringwidth(str_timer, false, fontsize) + fontsize.x * 0.25;
94 }
95 }
96
97 drawpic(pos - eY * (iconsize.y - fontsize.y) * 0.5, icon, sz, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
98 pos.x += sz.x + fontsize.x * 0.25;
99 string str_name = ((last_pickup_count > 1) ? sprintf("%s (x%d)", item.m_name, last_pickup_count) : item.m_name);
100 str_name = textShortenToWidth(str_name, mySize.x - (pos.x - panel_pos.x), fontsize, stringwidth_nocolors);
101 drawstring(pos, str_name, fontsize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
102 }
103}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define drawstring(position, text, scale, rgb, alpha, flag)
Definition draw.qh:27
#define drawpic(position, pic, size, rgb, alpha, flag)
Definition draw.qh:21
float HUD_Pickup_Time(float t)
Definition pickup.qc:23
void HUD_Pickup()
Definition pickup.qc:33
void HUD_Pickup_Export(int fh)
Definition pickup.qc:10
void Pickup_Update(entity item, int count)
Definition pickup.qc:15
float autocvar_hud_panel_pickup_fade_out
Definition pickup.qh:9
float autocvar_hud_panel_pickup_iconsize
Definition pickup.qh:7
bool autocvar_hud_panel_pickup_dynamichud
Definition pickup.qh:5
bool autocvar_hud_panel_pickup
Definition pickup.qh:4
entity last_pickup_item
Definition pickup.qh:11
float autocvar_hud_panel_pickup_time
Definition pickup.qh:8
int last_pickup_count
Definition pickup.qh:12
int autocvar_hud_panel_pickup_showtimer
Definition pickup.qh:6
float count
Definition powerups.qc:22
int spectatee_status
the -1 disables HUD panels before CSQC receives necessary data
Definition main.qh:197
bool warmup_stage
Definition main.qh:120
int serverflags
Definition main.qh:211
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1071
const int SERVERFLAG_FORBID_PICKUPTIMER
Definition constants.qh:20
const float DRAWFLAG_NORMAL
float time
#define stringwidth
void HUD_Panel_LoadCvars()
Definition hud.qc:215
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
vector panel_size
Definition hud.qh:163
float panel_fg_alpha
Definition hud.qh:169
float panel_bg_padding
Definition hud.qh:174
#define HUD_Panel_DrawBg()
Definition hud.qh:55
string hud_skin_path
Definition hud.qh:136
vector panel_pos
Definition hud.qh:162
bool autocvar__hud_configure
Definition hud_config.qh:3
#define STAT(...)
Definition stats.qh:82
float ceil(float f)
string precache_pic(string name,...)
float min(float f,...)
float floor(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
vector
Definition self.qh:92
ERASEABLE string seconds_tostring(float seconds)
Definition string.qh:126
float stringwidth_nocolors(string s, vector theSize)
Definition string.qh:35
bool autocvar_hud_panel_timer_increment
Definition timer.qh:6
const vector eY
Definition vector.qh:45
#define vec2(...)
Definition vector.qh:90