Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
chat.qc
Go to the documentation of this file.
1#include "chat.qh"
2
3#include <client/draw.qh>
4
5// Chat (#12)
6
7void HUD_Chat_Export(int fh)
8{
9 // allow saving cvars that aesthetically change the panel into hud skin files
10}
11
14float HUD_Panel_Chat_InputEvent(float bInputType, float nPrimary, float nSecondary)
15{
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");
46 return true;
47 }
48 else if (nPrimary == K_PGUP)
49 {
50 if (!key_pressed)
51 return true;
53 return true;
54 }
55 else if (nPrimary == K_PGDN)
56 {
57 if (!key_pressed)
58 return true;
62 return true;
63 }
64
65 return false;
66}
67
69{
71 {
73 {
75 cvar_set("con_chatrect", "0");
76 if (autocvar_con_chat != -1)
77 cvar_set("con_chat", "-1");
78 return;
79 }
80
82 {
84 return;
86 }
87 else
88 {
90 {
91 panel.update_time = time; // forces reload of panel attributes
92 chat_panel_modified = false;
93 }
96 }
97 }
98 else
100
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
111 }
112 if (autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
113 {
116 if (panel.current_panel_bg == "0") // force a border when maximized
117 {
118 string panel_bg = strcat(hud_skin_path, "/border_default");
119 if (precache_pic(panel_bg) == "")
120 panel_bg = "gfx/hud/default/border_default";
121 strcpy(panel.current_panel_bg, panel_bg);
122 chat_panel_modified = true;
123 }
126 }
127
128 vector pos = panel_pos;
129 vector mySize = panel_size;
130
131 // chat messages don't scale properly since they are displayed directly by the engine
134
136 {
137 pos += '1 1 0' * panel_bg_padding;
138 mySize -= '2 2 0' * panel_bg_padding;
139 }
140
142 cvar_set("con_chatrect", "1");
143
144 // can't use a name ending with _x, _y and _z for a float autocvar as for autocvar specs
145 // it prevents ambiguity with component names of vector autocvars
146 if (cvar_string("con_chatrect_x") != ftos(pos.x / vid_conwidth))
147 cvar_set("con_chatrect_x", ftos(pos.x / vid_conwidth));
148 if (cvar_string("con_chatrect_y") != ftos(pos.y / vid_conheight))
149 cvar_set("con_chatrect_y", ftos(pos.y / vid_conheight));
150 // can't use direct comparison here, it would always returns true even if
151 // both arguments are equal because con_chatwidth is saved with cvar_set
152 //if (autocvar_con_chatwidth != mySize.x / vid_conwidth)
153 if (fabs(autocvar_con_chatwidth - mySize.x / vid_conwidth) > 0.00001)
154 cvar_set("con_chatwidth", ftos(mySize.x / vid_conwidth));
155 if (autocvar_con_chat != floor(mySize.y / autocvar_con_chatsize - 0.5))
156 cvar_set("con_chat", ftos(floor(mySize.y / autocvar_con_chatsize - 0.5)));
157
159 {
160 float alpha = 1; // engine can display chat only at full alpha
162 alpha = hud_fade_alpha; // fade only when the settings menu of another panel is open
163 vector chatsize = '1 1 0' * autocvar_con_chatsize;
164 if (cvar_string("con_chatrect_x") != "9001")
165 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
166 string str = textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors);
167 for (int i = 0; i < autocvar_con_chat; ++i)
168 {
169 drawcolorcodedstring(pos, str, chatsize, alpha, DRAWFLAG_NORMAL);
170 pos.y += chatsize.y;
171 }
172 }
173}
#define drawcolorcodedstring(position, text, scale, alpha, flag)
Definition draw.qh:30
void HUD_Chat()
Definition chat.qc:68
float chat_maximized_scroll_ofs
Definition chat.qc:12
float HUD_Panel_Chat_InputEvent(float bInputType, float nPrimary, float nSecondary)
Definition chat.qc:14
void HUD_Chat_Export(int fh)
Definition chat.qc:7
float chat_maximized_reset_scroll_time
Definition chat.qc:13
bool autocvar_con_chat
Definition chat.qh:7
float autocvar_con_chatwidth
Definition chat.qh:15
bool autocvar_hud_panel_chat
Definition chat.qh:4
bool autocvar_con_chatrect
Definition chat.qh:12
bool autocvar__con_chat_maximized
Definition chat.qh:6
float autocvar_con_chatsize
Definition chat.qh:8
float alpha
Definition items.qc:13
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1071
const float DRAWFLAG_NORMAL
float time
float intermission
void HUD_Panel_LoadCvars()
Definition hud.qc:215
void HUD_Scale_Disable()
Definition hud.qc:84
entity highlightedPanel
Definition hud.qh:107
vector panel_size
Definition hud.qh:163
float panel_bg_padding
Definition hud.qh:174
bool hud_draw_maximized
Definition hud.qh:69
float panel_bg_border
Definition hud.qh:172
float chat_sizey
Definition hud.qh:183
float hud_fade_alpha
Definition hud.qh:134
#define HUD_Panel_DrawBg()
Definition hud.qh:55
string hud_skin_path
Definition hud.qh:136
vector panel_pos
Definition hud.qh:162
float chat_posy
Definition hud.qh:182
float panel_bg_alpha
Definition hud.qh:170
vector mousepos
Definition hud.qh:103
entity panel
Definition hud.qh:147
bool chat_panel_modified
Definition hud.qh:74
bool autocvar__hud_configure
Definition hud_config.qh:3
float hud_configure_menu_open
Definition hud_config.qh:22
float K_PGDN
Definition keycodes.qc:39
float K_MWHEELDOWN
Definition keycodes.qc:133
float K_PGUP
Definition keycodes.qc:40
float K_MWHEELUP
Definition keycodes.qc:132
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
void cvar_set(string name, string value)
float cvar(string name)
string precache_pic(string name,...)
const string cvar_string(string name)
float min(float f,...)
string ftos(float f)
float fabs(float f)
float floor(float f)
float max(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
vector
Definition self.qh:92
#define strcpy(this, s)
Definition string.qh:52
float stringwidth_colors(string s, vector theSize)
Definition string.qh:30