Purge client/defs.qh
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / chat.qc
1 #include "chat.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/miscfunctions.qh>
5
6 // Chat (#12)
7
8 void HUD_Chat_Export(int fh)
9 {
10         // allow saving cvars that aesthetically change the panel into hud skin files
11 }
12
13 void HUD_Chat()
14 {
15         if(!autocvar__hud_configure)
16         {
17                 if (!autocvar_hud_panel_chat)
18                 {
19                         if (!autocvar_con_chatrect)
20                                 cvar_set("con_chatrect", "0");
21                         return;
22                 }
23                 if(autocvar__con_chat_maximized)
24                 {
25                         if(!hud_draw_maximized) return;
26                 }
27                 else if(chat_panel_modified)
28                 {
29                         panel.update_time = time; // forces reload of panel attributes
30                         chat_panel_modified = false;
31                 }
32         }
33
34         HUD_Panel_LoadCvars();
35
36         if(intermission == 2)
37         {
38                 // reserve some more space to the mapvote panel
39                 // by resizing and moving chat panel to the bottom
40                 panel_size.y = min(panel_size.y, vid_conheight * 0.2);
41                 panel_pos.y = vid_conheight - panel_size.y - panel_bg_border * 2;
42                 chat_posy = panel_pos.y;
43                 chat_sizey = panel_size.y;
44         }
45         if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
46         {
47                 panel_pos.y = panel_bg_border;
48                 panel_size.y = vid_conheight - panel_bg_border * 2;
49                 if(panel.current_panel_bg == "0") // force a border when maximized
50                 {
51                         string panel_bg;
52                         panel_bg = strcat(hud_skin_path, "/border_default");
53                         if(precache_pic(panel_bg) == "")
54                                 panel_bg = "gfx/hud/default/border_default";
55                         strcpy(panel.current_panel_bg, panel_bg);
56                         chat_panel_modified = true;
57                 }
58                 panel_bg_alpha = max(0.75, panel_bg_alpha);
59         }
60
61         vector pos, mySize;
62         pos = panel_pos;
63         mySize = panel_size;
64
65         // chat messages don't scale properly since they are displayed directly by the engine
66         HUD_Scale_Disable();
67         HUD_Panel_DrawBg();
68
69         if(panel_bg_padding)
70         {
71                 pos += '1 1 0' * panel_bg_padding;
72                 mySize -= '2 2 0' * panel_bg_padding;
73         }
74
75         if (!autocvar_con_chatrect)
76                 cvar_set("con_chatrect", "1");
77
78         cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
79         cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
80
81         cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
82         cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
83
84         if(autocvar__hud_configure)
85         {
86                 vector chatsize = '1 1 0' * autocvar_con_chatsize;
87                 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
88                 string str = textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors);
89                 for(int i = 0; i < autocvar_con_chat; ++i)
90                 {
91                         // engine displays chat text at full alpha
92                         drawcolorcodedstring(pos, str, chatsize, 1, DRAWFLAG_NORMAL);
93                         pos.y += chatsize.y;
94                 }
95         }
96 }