]> de.git.xonotic.org Git - voretournament/voretournament.git/blobdiff - data/qcsrc/client/hud.qc
Finish my last commit
[voretournament/voretournament.git] / data / qcsrc / client / hud.qc
index e0723db1625cf9db6298071587f14b920ef82d0e..0852aa6fbad3ae119369ad706ea1c507757bf67a 100644 (file)
@@ -25,6 +25,9 @@ float sbar_accuracy_hud;
 float sbar_scoreboard_alpha_name;\r
 float sbar_scoreboard_alpha_name_self;\r
 \r
+string portrait_image, portrait_name;\r
+float portrait_time;\r
+\r
 float ps_primary, ps_secondary;\r
 float ts_primary, ts_secondary;\r
 \r
@@ -1677,6 +1680,57 @@ void Sbar_DrawRaceStatus(vector pos)
        }\r
 }\r
 \r
+void Sbar_Portrait()\r
+{\r
+       // draws the portrait, using the values set in Ent_ReadPortrait\r
+\r
+       // make the portrait slide in and out of the left edge\r
+       float fade_time;\r
+       float fade1_start, fade1_end, fade2_start, fade2_end;\r
+       float fade_in, fade_out;\r
+\r
+       fade_time = cvar("sbar_portrait_time") * bound(0, cvar("sbar_portrait_fade"), 0.5);\r
+\r
+       fade1_start = portrait_time + cvar("sbar_portrait_time") - fade_time;\r
+       fade1_end = portrait_time + cvar("sbar_portrait_time");\r
+       fade2_start = portrait_time;\r
+       fade2_end = portrait_time + fade_time;\r
+\r
+       fade_in = bound(0, (time / fade1_end - 1) / (fade1_start / fade1_end - 1), 1);\r
+       fade_out = 1 - bound(0, (time / fade2_end - 1) / (fade2_start / fade2_end - 1), 1);\r
+\r
+       vector left, fade_pos;\r
+       left_x = 0;\r
+       left_y = vid_conheight / 2;\r
+       fade_pos_x = -130 * fade_in * fade_out;\r
+\r
+       if(!cvar("sbar_portrait"))\r
+               return;\r
+\r
+       if(portrait_time + cvar("sbar_portrait_time") >= time)\r
+       {\r
+               if(portrait_image && portrait_name) // prevent using bad strings\r
+               {\r
+                       drawpic(left - '120 80 0' - fade_pos, portrait_image, '120 160 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
+                       drawcolorcodedstring(left - '120 -80 0' - fade_pos, textShortenToWidth(portrait_name, 120, '12 12 0', stringwidth_colors), '12 12 0', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               // free unused strings from memory\r
+               if(portrait_image)\r
+               {\r
+                       strunzone(portrait_image);\r
+                       portrait_image = string_null;\r
+               }\r
+               if(portrait_name)\r
+               {\r
+                       strunzone(portrait_name);\r
+                       portrait_name = string_null;\r
+               }\r
+       }\r
+}\r
+\r
 void Sbar_Score()\r
 {\r
        float score, distribution, leader;\r
@@ -1961,6 +2015,10 @@ void Sbar_Status()
        health_pos -= '1 0 0' * stringwidth(ftos(x), FALSE, '22 22 0') * 0.5;\r
        Sbar_DrawXNum(health_pos, x, 3, 0, 22, Sbar_NumColor(x), sbar_alpha_fg, DRAWFLAG_NORMAL);\r
 \r
+       // if we are dead, we can skip the HUD from here\r
+       if(health <= 0)\r
+               return;\r
+\r
        // ammo\r
        pos_x = bottom_x + 140;\r
        pos_y = bottom_y - 20;\r
@@ -3064,6 +3122,7 @@ void Sbar_Draw (void)
                Sbar_DrawScoreboard();\r
                Sbar_Score();\r
                Sbar_Timer();\r
+               Sbar_Portrait();\r
                if(getstati(STAT_VORE_EATEN))\r
                        Sbar_Status();\r
 \r
@@ -3093,6 +3152,7 @@ void Sbar_Draw (void)
                                drawpic(warn_pos - '128 0 0', "gfx/hud/sb_power_fail", '256 256 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
                                drawpic(warn_pos - '16 0 0' + '0 150 0', "gfx/hud/sb_power_fail_icon", '32 32 0', '1 1 1', sbar_alpha_fg * (0.5 + sin(time * 5) / 2), DRAWFLAG_NORMAL);\r
                                power_boot = time + g_power_reboot;\r
+                               Sbar_Portrait(); // draw the portrait still\r
                                return; // skip drawing the HUD\r
                        }\r
                        else if(time <= power_boot)\r
@@ -3100,6 +3160,7 @@ void Sbar_Draw (void)
                                // subsystems are rebooting\r
                                drawpic(warn_pos - '128 0 0', "gfx/hud/sb_power_reboot", '256 256 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
                                drawpic(warn_pos - '16 0 0' + '0 150 0', "gfx/hud/sb_power_reboot_icon", '32 32 0', '1 1 1', sbar_alpha_fg * (0.5 + sin(time * 5) / 2), DRAWFLAG_NORMAL);\r
+                               Sbar_Portrait(); // draw the portrait still\r
                                return; // skip drawing the HUD\r
                        }\r
                }\r
@@ -3150,7 +3211,7 @@ void Sbar_Draw (void)
                                status_pos = bottomleft - '-43 168 0';\r
                                status_size = 16;\r
                        }\r
-                       else if(g_healthsize_center >= 0) // no point in showing it otherwise\r
+                       else\r
                        {\r
                                status_text = strcat(status_color, ftos(stomach_maxload));\r
                                status_pos = bottomleft - '-43 170 0';\r
@@ -3207,11 +3268,12 @@ void Sbar_Draw (void)
                        Sbar_PrintStomachboardItemPred(bottomleft - '-76 150 0', pred);\r
                }\r
 \r
-               // draw status, scores, timer, and ring\r
+               // draw status, scores, timer, ring and portrait\r
                Sbar_Status();\r
                Sbar_Score();\r
                Sbar_Timer();\r
                Sbar_Ring();\r
+               Sbar_Portrait();\r
 \r
                // draw strength/invincibility icon and timer\r
                CSQC_Strength_Timer();\r
@@ -3550,3 +3612,48 @@ void CSQC_race_hud(void)
        }\r
        drawfont = sbar_font;\r
 }\r
+\r
+void Ent_ReadPortrait()\r
+{\r
+       // receives portrait values, which are used in Sbar_Portrait\r
+\r
+       string pl_model, pl_name, img;\r
+       float pl_skin;\r
+\r
+       pl_model = ReadString();\r
+       pl_skin = ReadByte();\r
+       pl_name = ReadString();\r
+\r
+       // update existing portraits\r
+       if(portrait_name)\r
+               strunzone(portrait_name);\r
+       if(portrait_image)\r
+               strunzone(portrait_image);\r
+\r
+       portrait_time = time;\r
+       portrait_name = strzone(pl_name);\r
+\r
+       // obtain the image name from the text file\r
+       float glob, i, fh;\r
+       string fn;\r
+\r
+       glob = search_begin("models/player/*.txt", TRUE, TRUE);\r
+       if(glob < 0)\r
+               return;\r
+       for(i = 0; i < search_getsize(glob); ++i)\r
+       {\r
+               fn = search_getfilename(glob, i);\r
+               fh = fopen(fn, FILE_READ);\r
+               if(fh < 0)\r
+                       continue;\r
+\r
+               fgets(fh); // skip name\r
+               img = fgets(fh);\r
+               if(pl_skin == stof(fgets(fh)))\r
+               if(pl_model == fgets(fh))\r
+                       portrait_image = strzone(img);\r
+\r
+               fclose(fh);\r
+       }\r
+       search_end(glob);\r
+}\r