3 #include <client/draw.qh>
7 void HUD_Chat_Export(int fh)
9 // allow saving cvars that aesthetically change the panel into hud skin files
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)
16 if(!autocvar__con_chat_maximized)
21 mousepos.x = nPrimary;
22 mousepos.y = nSecondary;
29 // at this point bInputType can only be 0 or 1 (key pressed or released)
30 bool key_pressed = (bInputType == 0);
32 if(nPrimary == K_MWHEELUP)
36 chat_maximized_scroll_ofs += 5 * cvar("con_chatsize");
39 else if(nPrimary == K_MWHEELDOWN)
43 chat_maximized_scroll_ofs -= 5 * cvar("con_chatsize");
44 if (chat_maximized_scroll_ofs < 0)
45 chat_maximized_scroll_ofs = 0;
48 else if(nPrimary == K_PGUP)
52 chat_maximized_scroll_ofs += vid_conheight / 2;
55 else if(nPrimary == K_PGDN)
59 chat_maximized_scroll_ofs -= vid_conheight / 2;
60 if (chat_maximized_scroll_ofs < 0)
61 chat_maximized_scroll_ofs = 0;
70 if(!autocvar__hud_configure)
72 if (!autocvar_hud_panel_chat && !autocvar__con_chat_maximized)
74 if (autocvar_con_chatrect)
75 cvar_set("con_chatrect", "0");
76 if (autocvar_con_chat != -1)
77 cvar_set("con_chat", "-1");
81 if(autocvar__con_chat_maximized)
83 if(!hud_draw_maximized) return;
85 chat_maximized_reset_scroll_time = time + 3;
89 if(chat_panel_modified)
91 panel.update_time = time; // forces reload of panel attributes
92 chat_panel_modified = false;
94 if (time > chat_maximized_reset_scroll_time)
95 chat_maximized_scroll_ofs = 0;
99 chat_maximized_scroll_ofs = 0;
101 HUD_Panel_LoadCvars();
103 if(intermission == 2)
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;
112 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
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
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;
125 panel_bg_alpha = max(0.75, panel_bg_alpha);
126 panel_size.y += chat_maximized_scroll_ofs;
133 // chat messages don't scale properly since they are displayed directly by the engine
139 pos += '1 1 0' * panel_bg_padding;
140 mySize -= '2 2 0' * panel_bg_padding;
143 if (!autocvar_con_chatrect)
144 cvar_set("con_chatrect", "1");
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)));
160 if(autocvar__hud_configure)
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)
168 // engine displays chat text at full alpha
169 drawcolorcodedstring(pos, str, chatsize, 1, DRAWFLAG_NORMAL);