]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/chat.qc
Avoid settings cvars every frame to optimize code and to avoid console spam with...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / chat.qc
index d8945991ece5c7b28506a178526a11b7965b3a2b..972848260dcc94ab74d4c5fafa735517782d2625 100644 (file)
@@ -1,5 +1,14 @@
 #include "chat.qh"
-/** Handle chat as a panel (#12) */
+
+#include <client/draw.qh>
+
+// Chat (#12)
+
+void HUD_Chat_Export(int fh)
+{
+       // allow saving cvars that aesthetically change the panel into hud skin files
+}
+
 void HUD_Chat()
 {
        if(!autocvar__hud_configure)
@@ -21,7 +30,7 @@ void HUD_Chat()
                }
        }
 
-       HUD_Panel_UpdateCvars();
+       HUD_Panel_LoadCvars();
 
        if(intermission == 2)
        {
@@ -42,20 +51,19 @@ void HUD_Chat()
                        panel_bg = strcat(hud_skin_path, "/border_default");
                        if(precache_pic(panel_bg) == "")
                                panel_bg = "gfx/hud/default/border_default";
-                       if(panel.current_panel_bg)
-                               strunzone(panel.current_panel_bg);
-                       panel.current_panel_bg = strzone(panel_bg);
+                       strcpy(panel.current_panel_bg, panel_bg);
                        chat_panel_modified = true;
                }
-               panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
+               panel_bg_alpha = max(0.75, panel_bg_alpha);
        }
 
        vector pos, mySize;
        pos = panel_pos;
        mySize = panel_size;
 
+       // chat messages don't scale properly since they are displayed directly by the engine
        HUD_Scale_Disable();
-       HUD_Panel_DrawBg(1);
+       HUD_Panel_DrawBg();
 
        if(panel_bg_padding)
        {
@@ -66,25 +74,29 @@ void HUD_Chat()
        if (!autocvar_con_chatrect)
                cvar_set("con_chatrect", "1");
 
-       cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
-       cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
-
-       cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
-       cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
+       // can't use a name ending with _x, _y and _z for a float autocvar as for autocvar specs
+       // it prevents ambiguity with component names of vector autocvars
+       if (cvar_string("con_chatrect_x") != ftos(pos.x / vid_conwidth))
+               cvar_set("con_chatrect_x", ftos(pos.x / vid_conwidth));
+       if (cvar_string("con_chatrect_y") != ftos(pos.y / vid_conheight))
+               cvar_set("con_chatrect_y", ftos(pos.y / vid_conheight));
+       // can't use direct comparison here, it would always returns true even if
+       // both arguments are equal because con_chatwidth is saved with cvar_set
+       //if (autocvar_con_chatwidth != mySize.x / vid_conwidth)
+       if (fabs(autocvar_con_chatwidth - mySize.x / vid_conwidth) > 0.00001)
+               cvar_set("con_chatwidth", ftos(mySize.x / vid_conwidth));
+       if (autocvar_con_chat != floor(mySize.y / autocvar_con_chatsize - 0.5))
+               cvar_set("con_chat", ftos(floor(mySize.y / autocvar_con_chatsize - 0.5)));
 
        if(autocvar__hud_configure)
        {
-               vector chatsize;
-               chatsize = '1 1 0' * autocvar_con_chatsize;
-               cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
-               float i, a;
-               for(i = 0; i < autocvar_con_chat; ++i)
+               vector chatsize = '1 1 0' * autocvar_con_chatsize;
+               cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
+               string str = textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors);
+               for(int i = 0; i < autocvar_con_chat; ++i)
                {
-                       if(i == autocvar_con_chat - 1)
-                               a = panel_fg_alpha;
-                       else
-                               a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
-                       drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
+                       // engine displays chat text at full alpha
+                       drawcolorcodedstring(pos, str, chatsize, 1, DRAWFLAG_NORMAL);
                        pos.y += chatsize.y;
                }
        }