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