From 1bf1fc199b6ae1dcc25a4ce024d6c94d8eb6aaa8 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 3 Feb 2016 11:24:49 +0200 Subject: [PATCH] Adjust latency position depending on time visibility Latency placement is no longer fixed: * If time is visible, it is placed on top of the screen and latency is placed below * If time is not visible, latency is placed on top of the screen Both are displayed on alternative HUD only --- src/g_shared/sbar.h | 3 +++ src/g_shared/shared_hud.cpp | 32 +++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/g_shared/sbar.h b/src/g_shared/sbar.h index b8416dd5d..764e427d3 100644 --- a/src/g_shared/sbar.h +++ b/src/g_shared/sbar.h @@ -57,6 +57,9 @@ class AWeapon; void ST_SetNeedRefresh(); +bool ST_IsTimeVisible(); +bool ST_IsLatencyVisible(); + // HUD Message base object -------------------------------------------------- class DHUDMessage : public DObject diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index 0fe8a4588..344f5b0ec 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -59,6 +59,7 @@ EXTERN_CVAR(Bool,am_follow) EXTERN_CVAR (Int, con_scaletext) EXTERN_CVAR (Bool, idmypos) +EXTERN_CVAR (Int, screenblocks) EXTERN_CVAR (Bool, am_showtime) EXTERN_CVAR (Bool, am_showtotaltime) @@ -868,7 +869,7 @@ static void DrawCoordinates(player_t * CPlayer) static void DrawTime() { - if (hud_showtime <= 0 || hud_showtime > 9) + if (!ST_IsTimeVisible()) { return; } @@ -935,6 +936,21 @@ static void DrawTime() DrawHudText(SmallFont, hud_timecolor, timeString, hudwidth - width, height, FRACUNIT); } +static bool IsAltHUDTextVisible() +{ + return hud_althud + && !automapactive + && (SCREENHEIGHT == viewheight) + && (11 == screenblocks); +} + +bool ST_IsTimeVisible() +{ + return IsAltHUDTextVisible() + && (hud_showtime > 0) + && (hud_showtime <= 9); +} + //--------------------------------------------------------------------------- // // Draw in-game latency @@ -943,9 +959,7 @@ static void DrawTime() static void DrawLatency() { - if (hud_showlag <= 0 || - (hud_showlag == 1 && !netgame) || - hud_showlag > 2) + if (!ST_IsLatencyVisible()) { return; } @@ -975,11 +989,19 @@ static void DrawLatency() const int characterCount = (int)strlen(tempstr); const int width = SmallFont->GetCharWidth('0') * characterCount + 2; // small offset from screen's border - const int height = SmallFont->GetHeight() * 2; + const int height = SmallFont->GetHeight() * (ST_IsTimeVisible() ? 2 : 1); DrawHudText(SmallFont, color, tempstr, hudwidth - width, height, FRACUNIT); } +bool ST_IsLatencyVisible() +{ + return IsAltHUDTextVisible() + && (hud_showlag > 0) + && (hud_showlag != 1 || netgame) + && (hud_showlag <= 2); +} + //--------------------------------------------------------------------------- //