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