X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=data%2Fqcsrc%2Fclient%2Fhud.qc;h=2b01044cab9d027db2b105cbb61a70faa3d552d4;hb=7c3df191228a8c3bc4f9384da459527b9c10d395;hp=58c1d3787fabcb67ed7822f100c072fec79756cf;hpb=efc20bdbfdf97b4971dc03897fb553db8442f6cf;p=voretournament%2Fvoretournament.git diff --git a/data/qcsrc/client/hud.qc b/data/qcsrc/client/hud.qc index 58c1d378..2b01044c 100644 --- a/data/qcsrc/client/hud.qc +++ b/data/qcsrc/client/hud.qc @@ -72,15 +72,44 @@ vector Sbar_AccuracyColor(float accuracy) return rgb; } -void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, float lettersize, vector rgb, float alpha, float dflags) +void Sbar_DrawPic(string pic, vector position, vector dimensions, float background) +{ + vector pos, sz; + sz_x = vid_conwidth * dimensions_x; + sz_y = vid_conheight * dimensions_y; + pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); + pos_x -= sz_x / 2; + pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); + pos_y -= sz_y / 2; + + if(background) + { + if(teamplay) + drawpic(pos, pic, sz, GetTeamRGB(myteam) * sbar_color_bg_team, sbar_alpha_bg, DRAWFLAG_NORMAL); // hud color = myteam color + else + drawpic(pos, pic, sz, stov(cvar_string("sbar_color_bg")), sbar_alpha_bg, DRAWFLAG_NORMAL); + } + else + drawpic(pos, pic, sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); +} + +void Sbar_DrawString(string text, vector position, float lettersize) +{ + vector pos, sz; + sz_x = sz_y = lettersize; + pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); + pos_x -= stringwidth(text, FALSE, sz) * 0.5; + pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); + pos_y -= sz_y / 2; + + drawstring(pos, text, sz, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); +} + +void Sbar_DrawXNum (vector position, float num, float digits, float showminusplus, float lettersize, vector rgb, float alpha, float dflags) { float l; string str, tmp, l_length, final_num; float minus, plus; - vector vsize; - - vsize_x = vsize_y = lettersize; - vsize_z = 0; // showminusplus 1: always prefix with minus sign (useful in race distribution display) // showminusplus 2: always prefix with plus sign (useful in race distribution display) @@ -120,9 +149,16 @@ void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, fl final_num = "-"; else if(plus) final_num = "+"; - final_num = strcat(final_num, str); - drawstring(pos, final_num, vsize, rgb, alpha, dflags); + + vector pos, sz; + sz_x = sz_y = lettersize; + pos_x = (vid_conwidth / 2) * bound(0, 1 + position_x, 2); + pos_x -= stringwidth(final_num, FALSE, sz) * 0.5; + pos_y = (vid_conheight / 2) * bound(0, 1 - position_y, 2); + pos_y -= sz_y / 2; + + drawstring(pos, final_num, sz, rgb, alpha, dflags); } vector Sbar_NumColor (float x) @@ -1684,17 +1720,50 @@ void Sbar_Portrait() { // draws the portrait, using the values set in Ent_ReadPortrait - vector left; + // 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) + if(portrait_time + cvar("sbar_portrait_time") >= time) { - drawpic(left + '10 -80 0', portrait_image, '120 160 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawcolorcodedstring(left + '10 80 0', portrait_name, '12 12 0', sbar_alpha_fg, DRAWFLAG_NORMAL); + 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; + } } } @@ -1940,11 +2009,6 @@ void Sbar_Score() void Sbar_Status() { - vector bottom; - bottom_x = vid_conwidth/2; - bottom_y = vid_conheight; - bottom_z = 0; - float armor, health, x, a; armor = getstati(STAT_ARMOR); health = getstati(STAT_HEALTH); @@ -1952,50 +2016,35 @@ void Sbar_Status() float stat_items; stat_items = getstati(STAT_ITEMS); - vector health_pos, armor_pos, pos; - health_pos = bottom - '43 58 0'; - armor_pos = bottom - '43 68 0'; - - if (cvar("viewsize") <= 100) { - if (teamplay) - drawpic(bottom - '96 96 0', "gfx/hud/bg_status", '192 96 0', GetTeamRGB(myteam) * sbar_color_bg_team, sbar_alpha_bg, DRAWFLAG_NORMAL); // hud color = myteam color - else { - // allow for custom HUD colors in non-teamgames - color = stov(cvar_string("sbar_color_bg")); - - drawpic(bottom - '96 96 0', "gfx/hud/bg_status", '192 96 0', color, sbar_alpha_bg, DRAWFLAG_NORMAL); - } - } + if (cvar("viewsize") <= 100 && sbar_hudselector) + Sbar_DrawPic("gfx/hud/bg_status", stov(cvar_string("hud_panel_status_background_position")), stov(cvar_string("hud_panel_status_background_scale")), TRUE); // armor x = armor; if (x > 0) { - drawpic(armor_pos + '-8 -13.5 0', "gfx/hud/sb_armor", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - armor_pos -= '1 0 0' * stringwidth(ftos(x), FALSE, '12 12 0') * 0.5; - Sbar_DrawXNum(armor_pos, x, 3, 0, 12, Sbar_NumColor(x), sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawPic("gfx/hud/sb_armor", stov(cvar_string("hud_item_armor_icon_position")), stov(cvar_string("hud_item_armor_icon_scale")), FALSE); + Sbar_DrawXNum(stov(cvar_string("hud_item_armor_text_position")), x, 3, 0, cvar("hud_item_armor_text_scale"), Sbar_NumColor(x), sbar_alpha_fg, DRAWFLAG_NORMAL); } // health x = health; - drawpic(health_pos + '-11 16 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - 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); + Sbar_DrawPic("gfx/hud/sb_health", stov(cvar_string("hud_item_health_icon_position")), stov(cvar_string("hud_item_health_icon_scale")), FALSE); + Sbar_DrawXNum(stov(cvar_string("hud_item_health_text_position")), x, 3, 0, cvar("hud_item_health_text_scale"), Sbar_NumColor(x), sbar_alpha_fg, DRAWFLAG_NORMAL); - // ammo - pos_x = bottom_x + 140; - pos_y = bottom_y - 20; + // if we are dead, we can skip the HUD from here + if(health <= 0) + return; + // ammo float weapon_clipload, weapon_clipsize; - vector ammo_pos_offset; // if we are using the jetpack, show fuel ammo. Otherwise show the ammo of our weapon if(stat_items & IT_JETPACK && button_jetpack) { a = getstati(GetAmmoStat(0)); // how much fuel do we have? - drawpic(pos - '98 18 0', GetAmmoPicture(0), '20 20 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - ammo_pos_offset = '1 0 0' * stringwidth(ftos(a), FALSE, '16 16 0') * 0.5; - Sbar_DrawXNum(pos - '118 16 0' - ammo_pos_offset, a, 3, 0, 16, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawPic(GetAmmoPicture(0), stov(cvar_string("hud_item_ammo_icon_position")), stov(cvar_string("hud_item_ammo_noload_icon_scale")), FALSE); + Sbar_DrawXNum(stov(cvar_string("hud_item_ammo_noload_text_position")), a, 3, 0, cvar("hud_item_ammo_noload_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } else { @@ -2007,7 +2056,7 @@ void Sbar_Status() // if (stat_items & GetAmmoItemCode(i)) { a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i? - drawpic(pos - '98 18 0', GetAmmoPicture(i), '20 20 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawPic(GetAmmoPicture(i), stov(cvar_string("hud_item_ammo_icon_position")), stov(cvar_string("hud_item_ammo_icon_scale")), FALSE); weapon_clipsize = getstati(STAT_WEAPON_CLIPSIZE); // if the weapon we're holding is reloadable, show both its ammo and load @@ -2015,22 +2064,14 @@ void Sbar_Status() { weapon_clipload = getstati(STAT_WEAPON_CLIPLOAD); if(weapon_clipload < 0) // we're reloading - { - ammo_pos_offset = '1 0 0' * stringwidth("- -", FALSE, '16 16 0') * 0.5; - drawstring(pos - '118 23 0' - ammo_pos_offset, "- -", '16 16 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - } + Sbar_DrawString("- -", stov(cvar_string("hud_item_clip_load_text_position")), cvar("hud_item_clip_load_text_scale")); else - { - ammo_pos_offset = '1 0 0' * stringwidth(ftos(weapon_clipload), FALSE, '16 16 0') * 0.5; - Sbar_DrawXNum(pos - '118 23 0' - ammo_pos_offset, weapon_clipload, 2, 0, 16, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - } - ammo_pos_offset = '1 0 0' * stringwidth(ftos(a), FALSE, '12 12 0') * 0.5; - Sbar_DrawXNum(pos - '118 7 0' - ammo_pos_offset, a, 3, 0, 12, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawXNum(stov(cvar_string("hud_item_clip_load_text_position")), weapon_clipload, 2, 0, cvar("hud_item_clip_load_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawXNum(stov(cvar_string("hud_item_ammo_load_text_position")), a, 3, 0, cvar("hud_item_ammo_load_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } else { - ammo_pos_offset = '1 0 0' * stringwidth(ftos(a), FALSE, '16 16 0') * 0.5; - Sbar_DrawXNum(pos - '118 16 0' - ammo_pos_offset, a, 3, 0, 16, '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawXNum(stov(cvar_string("hud_item_ammo_noload_text_position")), a, 3, 0, cvar("hud_item_ammo_noload_text_scale"), '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } } } @@ -2040,7 +2081,7 @@ void Sbar_Status() entity e; e = get_weaponinfo(activeweapon); if (e && e.netname != "" && e.netname != "N/A") - drawpic(bottom - '96 96 0', strcat("gfx/hud/bg_status_activeweapon_", e.netname), '192 96 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + Sbar_DrawPic(strcat("gfx/hud/bg_status_activeweapon_", e.netname), stov(cvar_string("hud_item_weapon_position")), stov(cvar_string("hud_item_weapon_scale")), FALSE); } void Sbar_Timer() @@ -2105,7 +2146,7 @@ void Sbar_Timer() bgpos_z = 0; } - if (cvar("viewsize") <= 100) { // draw timer background when viewsize <= 100 + if (cvar("viewsize") <= 100 && sbar_hudselector) { // draw timer background when viewsize <= 100 if (teamplay) drawpic(bgpos, "gfx/hud/bg_timer", '120 30 0' * scale, GetTeamRGB(myteam) * sbar_color_bg_team, sbar_alpha_bg, DRAWFLAG_NORMAL); // timer bg color = myteam color else { @@ -3085,6 +3126,7 @@ void Sbar_Draw (void) Sbar_DrawScoreboard(); Sbar_Score(); Sbar_Timer(); + Sbar_Portrait(); if(getstati(STAT_VORE_EATEN)) Sbar_Status(); @@ -3114,6 +3156,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) @@ -3121,6 +3164,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 } } @@ -3128,7 +3172,7 @@ void Sbar_Draw (void) if(g_vore) // only when the vore system is active { // draw the stomach board - if (cvar("viewsize") <= 100) { + if (cvar("viewsize") <= 100 && sbar_hudselector) { if (teamplay) drawpic(bottomleft- '0 256 0', "gfx/hud/bg_stomach", '256 256 0', GetTeamRGB(myteam) * sbar_color_bg_team, sbar_alpha_bg, DRAWFLAG_NORMAL); // hud color = myteam color else { @@ -3171,7 +3215,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'; @@ -3192,6 +3236,7 @@ void Sbar_Draw (void) float f, l; pos = bottomleft; + hud_total_prey = 0; for(pl = players.sort_next; pl; pl = pl.sort_next) { if(pl.team == COLOR_SPECTATOR) @@ -3207,11 +3252,15 @@ void Sbar_Draw (void) f = pl.plpredator == player_localentnum; } - if(f && l <= 8) // limit the stomach board to 9 entries due to the HUD design + if(f) { - Sbar_PrintStomachboardItem(pos - '-16 124 0', pl); - pos_y += 1.1 * sbar_fontsize_y; - l += 1; + if(l <= 8) // limit the stomach board to 9 entries due to the HUD design + { + Sbar_PrintStomachboardItem(pos - '-16 124 0', pl); + pos_y += 1.1 * sbar_fontsize_y; + l += 1; + } + ++hud_total_prey; } // set the predator's name @@ -3584,12 +3633,11 @@ void Ent_ReadPortrait() pl_skin = ReadByte(); pl_name = ReadString(); - // updating an existent portrait - if(portrait_time) - { + // update existing portraits + if(portrait_name) strunzone(portrait_name); + if(portrait_image) strunzone(portrait_image); - } portrait_time = time; portrait_name = strzone(pl_name);