]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/chat.qc
Fix #2674 "Voting screens in demos respond visually to client cursor making them...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / chat.qc
1 #include "chat.qh"
2
3 #include <client/draw.qh>
4
5 // Chat (#12)
6
7 void HUD_Chat_Export(int fh)
8 {
9         // allow saving cvars that aesthetically change the panel into hud skin files
10 }
11
12 float chat_maximized_scroll_ofs;
13 float chat_maximized_reset_scroll_time;
14 float HUD_Panel_Chat_InputEvent(float bInputType, float nPrimary, float nSecondary)
15 {
16         if(!autocvar__con_chat_maximized)
17                 return false;
18
19         if(bInputType == 3)
20         {
21                 mousepos.x = nPrimary;
22                 mousepos.y = nSecondary;
23                 return true;
24         }
25
26         if(bInputType == 2)
27                 return false;
28
29         // at this point bInputType can only be 0 or 1 (key pressed or released)
30         bool key_pressed = (bInputType == 0);
31
32         if(nPrimary == K_MWHEELUP)
33         {
34                 if (!key_pressed)
35                         return true;
36                 chat_maximized_scroll_ofs += 5 * cvar("con_chatsize");
37                 return true;
38         }
39         else if(nPrimary == K_MWHEELDOWN)
40         {
41                 if (!key_pressed)
42                         return true;
43                 chat_maximized_scroll_ofs -= 5 * cvar("con_chatsize");
44                 if (chat_maximized_scroll_ofs < 0)
45                         chat_maximized_scroll_ofs = 0;
46                 return true;
47         }
48         else if(nPrimary == K_PGUP)
49         {
50                 if (!key_pressed)
51                         return true;
52                 chat_maximized_scroll_ofs += vid_conheight / 2;
53                 return true;
54         }
55         else if(nPrimary == K_PGDN)
56         {
57                 if (!key_pressed)
58                         return true;
59                 chat_maximized_scroll_ofs -= vid_conheight / 2;
60                 if (chat_maximized_scroll_ofs < 0)
61                         chat_maximized_scroll_ofs = 0;
62                 return true;
63         }
64
65         return false;
66 }
67
68 void HUD_Chat()
69 {
70         if(!autocvar__hud_configure)
71         {
72                 if (!autocvar_hud_panel_chat && !autocvar__con_chat_maximized)
73                 {
74                         if (autocvar_con_chatrect)
75                                 cvar_set("con_chatrect", "0");
76                         if (autocvar_con_chat != -1)
77                                 cvar_set("con_chat", "-1");
78                         return;
79                 }
80
81                 if(autocvar__con_chat_maximized)
82                 {
83                         if(!hud_draw_maximized) return;
84
85                         chat_maximized_reset_scroll_time = time + 3;
86                 }
87                 else
88                 {
89                         if(chat_panel_modified)
90                         {
91                                 panel.update_time = time; // forces reload of panel attributes
92                                 chat_panel_modified = false;
93                         }
94                         if (time > chat_maximized_reset_scroll_time)
95                                 chat_maximized_scroll_ofs = 0;
96                 }
97         }
98         else
99                 chat_maximized_scroll_ofs = 0;
100
101         HUD_Panel_LoadCvars();
102
103         if(intermission == 2)
104         {
105                 // reserve some more space to the mapvote panel
106                 // by resizing and moving chat panel to the bottom
107                 panel_size.y = min(panel_size.y, vid_conheight * 0.2);
108                 panel_pos.y = vid_conheight - panel_size.y - panel_bg_border * 2;
109                 chat_posy = panel_pos.y;
110                 chat_sizey = panel_size.y;
111         }
112         if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
113         {
114                 panel_pos.y = panel_bg_border;
115                 panel_size.y = vid_conheight - panel_bg_border * 2;
116                 if(panel.current_panel_bg == "0") // force a border when maximized
117                 {
118                         string panel_bg;
119                         panel_bg = strcat(hud_skin_path, "/border_default");
120                         if(precache_pic(panel_bg) == "")
121                                 panel_bg = "gfx/hud/default/border_default";
122                         strcpy(panel.current_panel_bg, panel_bg);
123                         chat_panel_modified = true;
124                 }
125                 panel_bg_alpha = max(0.75, panel_bg_alpha);
126                 panel_size.y += chat_maximized_scroll_ofs;
127         }
128
129         vector pos, mySize;
130         pos = panel_pos;
131         mySize = panel_size;
132
133         // chat messages don't scale properly since they are displayed directly by the engine
134         HUD_Scale_Disable();
135         HUD_Panel_DrawBg();
136
137         if(panel_bg_padding)
138         {
139                 pos += '1 1 0' * panel_bg_padding;
140                 mySize -= '2 2 0' * panel_bg_padding;
141         }
142
143         if (!autocvar_con_chatrect)
144                 cvar_set("con_chatrect", "1");
145
146         // can't use a name ending with _x, _y and _z for a float autocvar as for autocvar specs
147         // it prevents ambiguity with component names of vector autocvars
148         if (cvar_string("con_chatrect_x") != ftos(pos.x / vid_conwidth))
149                 cvar_set("con_chatrect_x", ftos(pos.x / vid_conwidth));
150         if (cvar_string("con_chatrect_y") != ftos(pos.y / vid_conheight))
151                 cvar_set("con_chatrect_y", ftos(pos.y / vid_conheight));
152         // can't use direct comparison here, it would always returns true even if
153         // both arguments are equal because con_chatwidth is saved with cvar_set
154         //if (autocvar_con_chatwidth != mySize.x / vid_conwidth)
155         if (fabs(autocvar_con_chatwidth - mySize.x / vid_conwidth) > 0.00001)
156                 cvar_set("con_chatwidth", ftos(mySize.x / vid_conwidth));
157         if (autocvar_con_chat != floor(mySize.y / autocvar_con_chatsize - 0.5))
158                 cvar_set("con_chat", ftos(floor(mySize.y / autocvar_con_chatsize - 0.5)));
159
160         if(autocvar__hud_configure)
161         {
162                 vector chatsize = '1 1 0' * autocvar_con_chatsize;
163                 if (cvar_string("con_chatrect_x") != "9001")
164                         cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
165                 string str = textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors);
166                 for(int i = 0; i < autocvar_con_chat; ++i)
167                 {
168                         // engine displays chat text at full alpha
169                         drawcolorcodedstring(pos, str, chatsize, 1, DRAWFLAG_NORMAL);
170                         pos.y += chatsize.y;
171                 }
172         }
173 }