From 6d37aaae5f251f096d9cc7686f1cbfb38b165cac Mon Sep 17 00:00:00 2001 From: cypress Date: Sun, 27 Aug 2023 10:15:16 -0400 Subject: [PATCH] CLIENT/FTE: Add stopwatch to HUD --- source/client/defs/custom.qc | 5 +++++ source/client/hud.qc | 23 +++++++++++++++++++++++ source/client/main.qc | 16 ++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/source/client/defs/custom.qc b/source/client/defs/custom.qc index b12b567..26111a1 100644 --- a/source/client/defs/custom.qc +++ b/source/client/defs/custom.qc @@ -212,6 +212,11 @@ int platform_is_web; #define OPTION_WEB_ONLY 1 #define OPTION_WEB_AND_EXE 2 +// Stopwatch server time counter +float stopwatch_sec; +int stopwatch_min; +int stopwatch_hr; + //controller buttons /* diff --git a/source/client/hud.qc b/source/client/hud.qc index 513d4e5..5332b11 100644 --- a/source/client/hud.qc +++ b/source/client/hud.qc @@ -1522,6 +1522,25 @@ void(float width, float height) HUD_ReviveIcons = } } +void(float width, float height) HUD_StopWatch = +{ + string sec, min, hr; + string stopwatch; + + if (stopwatch_sec < 10) { + sec = strcat("0", substring(ftos(stopwatch_sec), 0, 3)); + } else { + sec = substring(ftos(stopwatch_sec), 0, 4); + } + + if (stopwatch_min < 10) min = strcat("0", ftos(stopwatch_min)); else min = ftos(stopwatch_min); + if (stopwatch_hr < 10) hr = strcat("0", ftos(stopwatch_hr)); else hr = ftos(stopwatch_hr); + + stopwatch = strcat(hr, ":", min, ":", sec); + + drawstring([width - (strlen(stopwatch) * 12) - 2, 2], stopwatch, [12, 12], TEXT_ORANGE, 1, 0); +} + /******************* * HUD Draw * *******************/ @@ -1576,6 +1595,10 @@ void(float width, float height) HUD_Draw = HUD_PlayerNames(width, height); HUD_ReviveIcons(width, height); + + if (cvar("scr_serverstopwatch")) { + HUD_StopWatch(width, height); + } } else { HUD_Waypoint(width, height); } diff --git a/source/client/main.qc b/source/client/main.qc index 8c98ca2..b83b923 100644 --- a/source/client/main.qc +++ b/source/client/main.qc @@ -177,6 +177,10 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init = // force build date text in menu cvar_set("cl_showbuildtime", "1"); + // in-game stopwatch + registercvar("scr_serverstopwatch", "0"); + stopwatch_sec = stopwatch_min = stopwatch_hr = 0; + // retrieve custom maps Customs_Get(); @@ -548,6 +552,18 @@ noref void(float width, float height, float menushown) CSQC_UpdateView = cvar_set("r_viewmodel_fov", ftos(cvar("r_viewmodel_default_fov")*getstatf(STAT_VIEWZOOM))); + // Increment the stopwatch + // FIXME: I don't really liket his being in UpdateView.. this has nothing to do with rendering. + stopwatch_sec = time - (stopwatch_min * 60 + (stopwatch_hr * 360)); + + if (stopwatch_sec >= 60) { + stopwatch_min += stopwatch_sec/60; + } + + if (stopwatch_min >= 60) { + stopwatch_hr += stopwatch_min/60; + stopwatch_min = 0; + } //autoadd entities received from servers for drawing addentities(MASK_ENGINE);