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