]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/pickup.qc
Item Pickup panel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / pickup.qc
1 #include "pickup.qh"
2
3 #include <client/draw.qh>
4 #include <client/hud/hud.qh>
5 #include <client/hud/panel/timer.qh>
6 #include <common/items/inventory.qh>
7
8 // Pickup (#26)
9
10 void HUD_Pickup_Export(int fh)
11 {
12         // allow saving cvars that aesthetically change the panel into hud skin files
13 }
14
15 void Pickup_Update(entity it, int count)
16 {
17         if(last_pickup_item != it || time - STAT(LAST_PICKUP) > autocvar_hud_panel_pickup_time)
18                 last_pickup_count = 0;
19         last_pickup_item = it;
20         last_pickup_count += count;
21 }
22
23 float 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
33 void HUD_Pickup()
34 {
35         if(!autocvar_hud_panel_pickup) return;
36
37         HUD_Panel_LoadCvars();
38         vector pos, mySize;
39         pos = panel_pos;
40         mySize = panel_size;
41
42         if (autocvar_hud_panel_pickup_dynamichud)
43                 HUD_Scale_Enable();
44         else
45                 HUD_Scale_Disable();
46         HUD_Panel_DrawBg();
47         if(panel_bg_padding)
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);
55         entity it = last_pickup_item;
56
57         if((last_pickup_time && last_pickup_time > time - display_time && it) || autocvar__hud_configure) {
58                 string str_timer, str_name, icon;
59                 vector sz, sz2;
60                 vector fontsize = '1 1 0' * mySize.y;
61                 vector iconsize = fontsize * autocvar_hud_panel_pickup_iconsize;
62
63                 if(autocvar__hud_configure)
64                         icon = strcat(hud_skin_path, "/armor_mega");
65                 else
66                         icon = strcat(hud_skin_path, "/", ((it.model2) ? it.model2 : it.m_icon));
67
68                 sz = draw_getimagesize(icon);
69                 sz2 = vec2(iconsize.y*(sz.x/sz.y), iconsize.y);
70                 if(autocvar__hud_configure)
71                         str_name = "Mega armor";
72                 else
73                         str_name = ((last_pickup_count > 1) ? sprintf("%s (x%d)", it.m_name, last_pickup_count) : it.m_name);
74
75                 float a;
76                 float fade_out_time = min(display_time, autocvar_hud_panel_pickup_fade_out);
77
78                 if(autocvar__hud_configure)
79                         a = 1;
80                 else if(time < last_pickup_time + display_time - fade_out_time)
81                         a = 1;
82                 else
83                         a = (last_pickup_time + display_time - time) / fade_out_time;
84
85                 if(autocvar_hud_panel_pickup_showtimer) {
86                         // 1 will show the timer always
87                         // 2 will show the timer only if spectating
88                         // forbid serverflag will force the 2nd behavior
89                         if((autocvar_hud_panel_pickup_showtimer == 1 && !(serverflags & SERVERFLAG_FORBID_PICKUPTIMER)) || spectatee_status)
90                         {
91                                 if(autocvar__hud_configure)
92                                         str_timer = "13:02";
93                                 else
94                                         str_timer = seconds_tostring(HUD_Pickup_Time(last_pickup_time));
95                                 drawstring(pos, str_timer, fontsize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
96                                 pos.x += stringwidth(str_timer, false, fontsize) + fontsize.x * 0.25;
97                         }
98                 }
99
100                 drawpic(pos - eY * ((iconsize.y - fontsize.y) / 2), icon, sz2, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
101                 pos.x += sz2.x + fontsize.x * 0.25;
102                 str_name = textShortenToWidth(str_name, mySize.x - (pos.x - panel_pos.x), fontsize, stringwidth_nocolors);
103                 drawstring(pos, str_name, fontsize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
104         }
105 }