]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Merge branch 'terencehill/newpanelhud' into fruitiex/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index da5c237d8f460914e780be1a463b12d09f66b3d7..6dc62337d52dea5e320795bdd1c847ba454cd7fe 100644 (file)
@@ -131,7 +131,7 @@ float stringwidth_nocolors(string s, vector theSize)
 #define CENTERPRINT_MAX_LINES 30
 string centerprint_messages[CENTERPRINT_MAX_LINES];
 float centerprint_width[CENTERPRINT_MAX_LINES];
-vector centerprint_start;
+float centerprint_time;
 float centerprint_expire;
 float centerprint_num;
 float centerprint_offset_hint;
@@ -182,6 +182,8 @@ void centerprint(string strMessage)
                while(getWrappedLine_remaining)
                {
                        s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
+                       if(centerprint_messages[i] != s) // don't fade the same message in, looks stupid
+                               centerprint_time = time;
                        if(centerprint_messages[i])
                                strunzone(centerprint_messages[i]);
                        centerprint_messages[i] = strzone(s);
@@ -208,8 +210,6 @@ void centerprint(string strMessage)
        if(havail > vid_conheight - 70)
                havail = vid_conheight - 70; // avoid overlapping HUD
 
-       centerprint_start_x = 0;
-
 #if 0
        float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
 
@@ -260,17 +260,10 @@ void centerprint(string strMessage)
                centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
        }
 #else
-       centerprint_start_y =
-               min(
-                       max(
-                               max(scoreboard_bottom, vid_conheight * 0.5 + 16),
-                               (havail - h)/2
-                       ),
-                       havail - h
-               );
 #endif
 
        centerprint_num = i;
+
        centerprint_expire = time + cvar("scr_centertime");
 }
 
@@ -279,32 +272,39 @@ void HUD_DrawCenterPrint (void)
        float i;
        vector pos;
        string ts;
-       float a;
+       float a, sz;
 
-       //if(time > centerprint_expire)
-       //      return;
-
-       //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
-       a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
-       //sz = 1.2 / (a + 0.2);
+       if(time - centerprint_time < 0.25)
+               a = (time - centerprint_time) / 0.25;
+       else
+               a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
 
        if(a <= 0)
                return;
 
+       sz = 0.8 + (a / 5);
+
+       if(centerprint_num * cvar("scr_centersize") > 24 && HUD_WouldDrawScoreboard()) // 24 = height of Scoreboard text
+       {
+               centerprint_start_y = scoreboard_bottom + centerprint_fontsize_y;
+       }
        pos = centerprint_start;
        for (i=0; i<centerprint_num; i = i + 1)
        {
-               pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
                ts = centerprint_messages[i];
+               drawfontscale = sz * '1 1 0';
+               drawfont = hud_bigfont;
+               pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
                if (ts != "")
                {
-                       drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
-                       //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
+                       drawcolorcodedstring(pos + '0 1 0' * (1 - sz) * 0.5 *centerprint_fontsize_y, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
                        pos_y = pos_y + centerprint_fontsize_y;
                }
                else
                        // half height for empty lines looks better
-                       pos_y = pos_y + centerprint_fontsize_y * 0.5;
+                       pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
+               drawfontscale = '1 1 0';
+               drawfont = hud_font;
        }
 }
 
@@ -453,6 +453,9 @@ void HUD_Panel_ExportCfg(string cfgname)
                fputs(fh, strcat("seta hud_configure_grid_ysize \"", cvar_string("hud_configure_grid_ysize"), "\"", "\n"));
                fputs(fh, "\n");
 
+               fputs(fh, strcat("seta scr_centerpos \"", cvar_string("scr_centerpos"), "\"", "\n"));
+               fputs(fh, "\n");
+
                // common cvars for all panels
                float i;
                for (i = 0; i < HUD_PANEL_NUM; ++i)
@@ -508,6 +511,9 @@ void HUD_Panel_ExportCfg(string cfgname)
                                case HUD_PANEL_PRESSEDKEYS:
                                        fputs(fh, strcat("seta hud_panel_", panel_name, "_aspect \"", cvar_string(strcat("hud_panel_", panel_name, "_aspect")), "\"", "\n"));
                                        break;
+                               case HUD_PANEL_INFOMESSAGES:
+                                       fputs(fh, strcat("seta hud_panel_", panel_name, "_flip \"", cvar_string(strcat("hud_panel_", panel_name, "_flip")), "\"", "\n"));
+                                       break;
                        }
                        fputs(fh, "\n");
                }
@@ -2611,8 +2617,13 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
                else if(type == KILL_FIRST_BLOOD)
                        print("^1",s1, "^1 drew first blood", "\n");
                // TODO: icon!
-               else if (type == DEATH_TELEFRAG)
-                       print ("^1",s1, "^1 was telefragged by ", s2, "\n");
+               else if (type == DEATH_TELEFRAG) {
+                       HUD_KillNotify_Push(s2, s1, 1, DEATH_TELEFRAG);
+                       if(gentle)
+                               print ("^1",s1, "^1 tried to occupy ", s2, "^1's teleport destination space\n");
+                       else
+                               print ("^1",s1, "^1 was telefragged by ", s2, "\n");
+               }
                else if (type == DEATH_DROWN) {
                        HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
                        if(alsoprint)
@@ -2890,7 +2901,7 @@ void HUD_Centerprint(string s1, string s2, float type, float msg)
                                centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
                } else if (type == DEATH_QUIET) {
                        // do nothing
-               } else if (type == DEATH_KILL) {
+               } else { // generic message
                        if(gentle)
                                centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
                        else
@@ -2933,7 +2944,7 @@ void HUD_Centerprint(string s1, string s2, float type, float msg)
                        } else {
                                centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
                        }
-               } else if (type == KILL_FRAGGED) {
+               } else { // generic message
                        if(gentle) {
                                centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
                        } else {
@@ -2984,7 +2995,7 @@ void HUD_Notify (void)
        float width_attacker;
        string attacker, victim;
 
-       float i, j;
+       float i, j, w;
        for(j = 0; j < entries; ++j)
        {
                s = "";
@@ -3008,7 +3019,7 @@ void HUD_Notify (void)
                                a = 0;
                }
 
-               float w;
+               w = -1;
                w = DEATH_WEAPONOF(killnotify_deathtype[j]);
 
                // TODO: maybe print in team colors?
@@ -3162,6 +3173,10 @@ void HUD_Notify (void)
                        {
                                s = "notify_teamkill_red";
                        }
+                       else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
+                       {
+                               s = "notify_telefrag";
+                       }
                        else if(killnotify_deathtype[j] == DEATH_DROWN)
                        {
                                s = "notify_water";
@@ -4521,6 +4536,12 @@ void HUD_InfoMessages(void)
        vector fontsize;
        fontsize = '0.20 0.20 0' * mySize_y;
        
+       float a;
+       if(spectatee_status != 0)
+               a = 1;
+       else
+               a = panel_fg_alpha;
+
        string s;
        if(!autocvar__hud_configure)
        {
@@ -4533,7 +4554,7 @@ void HUD_InfoMessages(void)
 
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
 
                        if(spectatee_status == -1)
@@ -4542,7 +4563,7 @@ void HUD_InfoMessages(void)
                                s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
 
                        if(spectatee_status == -1)
@@ -4551,13 +4572,13 @@ void HUD_InfoMessages(void)
                                s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
 
                        s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
 
                        if(gametype == GAME_ARENA)
@@ -4577,7 +4598,7 @@ void HUD_InfoMessages(void)
                                s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
 
                        //show restart countdown:
@@ -4586,7 +4607,7 @@ void HUD_InfoMessages(void)
                                //we need to ceil, otherwise the countdown would be off by .5 when using round()
                                countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
                                s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
-                               drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                                o += eY * fontsize_y;
                        }
                }
@@ -4595,7 +4616,7 @@ void HUD_InfoMessages(void)
                        s = "^2Currently in ^1warmup^2 stage!";
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
                }
 
@@ -4623,7 +4644,7 @@ void HUD_InfoMessages(void)
                        }
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
                }
                else if(warmup_stage && !intermission && !spectatee_status)
@@ -4631,7 +4652,7 @@ void HUD_InfoMessages(void)
                        s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
                        if(autocvar_hud_panel_infomessages_flip)
                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                        o += eY * fontsize_y;
                }
 
@@ -4661,7 +4682,7 @@ void HUD_InfoMessages(void)
 
                                        if(autocvar_hud_panel_infomessages_flip)
                                                o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-                                       drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                                       drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                                        o += eY * fontsize_y;
                                }
                        }
@@ -4672,22 +4693,22 @@ void HUD_InfoMessages(void)
                s = "^7Press ^3ESC ^7to show HUD options.";
                if(autocvar_hud_panel_infomessages_flip)
                        o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                o += eY * fontsize_y;
                s = "^3Doubleclick ^7a panel for panel-specific options.";
                if(autocvar_hud_panel_infomessages_flip)
                        o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                o += eY * fontsize_y;
                s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
                if(autocvar_hud_panel_infomessages_flip)
                        o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                o += eY * fontsize_y;
                s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
                if(autocvar_hud_panel_infomessages_flip)
                        o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize); 
-               drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
                o += eY * fontsize_y;
        }
 }
@@ -4841,10 +4862,19 @@ void HUD_Main (void)
 {
        hud_skin_path = strcat("gfx/hud/", autocvar_hud_skin);
 
+       // global hud alpha fade
        if(disable_menu_alphacheck == 1)
-               menu_fade_alpha = 1;
+               hud_fade_alpha = 1;
        else
-               menu_fade_alpha = (1 - autocvar__menu_alpha);
+               hud_fade_alpha = (1 - autocvar__menu_alpha);
+
+       if(scoreboard_fade_alpha)
+               hud_fade_alpha = (1 - scoreboard_fade_alpha);
+
+       if(intermission == 2) // no hud during mapvote
+               hud_fade_alpha = 0;
+       else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
+               hud_fade_alpha = 1;
 
        hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
        hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
@@ -4898,7 +4928,7 @@ void HUD_Main (void)
                if(precache_pic(pic) == "") {
                        pic = "gfx/hud/default/dock";
                }
-               drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * menu_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
+               drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
        }
 
        // cache the panel order into the panel_order array