From 45ab94f2f9c5e19d9cab5b337c89e5e4d7cda56f Mon Sep 17 00:00:00 2001 From: Des Date: Thu, 15 May 2025 08:19:18 -0300 Subject: [PATCH] Add hud_panel_timer_warning_relative, hud_panel_timer_warning_red and hud_panel_timer_warning_yellow to customize when timer changes colors as a warning. --- _hud_common.cfg | 3 +++ qcsrc/client/hud/panel/timer.qc | 29 ++++++++++++++++++++++++----- qcsrc/client/hud/panel/timer.qh | 5 ++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index d574fcb0ce..bfde50f354 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -99,6 +99,9 @@ seta hud_panel_healtharmor_hide_ondeath 0 "hide this panel when dead" seta hud_panel_timer_increment "0" "show elapsed time instead of remaining time" seta hud_panel_timer_secondary "1" "secondary timer; \"0\" = hide, \"1\" = show, \"2\" = show swapped" seta hud_panel_timer_unbound "0" "show seconds leading up to the start of the match" +seta hud_panel_timer_warning_relative "0" "Make hud_panel_timer_warning_red and hud_panel_timer_warning_yellow factors relative to a reference, \"1\" = timelimit, \"2\" = server record for current map (only works in CTS)" +seta hud_panel_timer_warning_red "60" "How many seconds before match end to turn timer red, or factor to multiply reference if hud_panel_timer_warning_relative is set" +seta hud_panel_timer_warning_yellow "300" "How many seconds before match end to turn timer yellow, or factor to multiply reference if hud_panel_timer_warning_relative is set" seta hud_panel_engineinfo_framecounter_exponentialmovingaverage 1 "use an averaging method for calculating fps instead of counting frametime like engine does" seta hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight 0.1 "weight of latest data point" diff --git a/qcsrc/client/hud/panel/timer.qc b/qcsrc/client/hud/panel/timer.qc index ae796fbdd3..7d2aea5037 100644 --- a/qcsrc/client/hud/panel/timer.qc +++ b/qcsrc/client/hud/panel/timer.qc @@ -11,11 +11,30 @@ void HUD_Timer_Export(int fh) // allow saving cvars that aesthetically change the panel into hud skin files } -vector HUD_Timer_Color(float timeleft) +vector HUD_Timer_Color(float timeleft, float timelimit) { - if(timeleft <= 60) + int limitred,limityellow; + if(autocvar_hud_panel_timer_warning_relative) { + if(autocvar_hud_panel_timer_warning_relative == 1 && timelimit) + { + limitred = 100 * timelimit * autocvar_hud_panel_timer_warning_red; + limityellow = 100 * timelimit * autocvar_hud_panel_timer_warning_yellow; + } else if(autocvar_hud_panel_timer_warning_relative == 2 && ISGAMETYPE(CTS) && race_server_record) + { + limitred = race_server_record * autocvar_hud_panel_timer_warning_red; + limityellow = race_server_record * autocvar_hud_panel_timer_warning_yellow; + } else { + limitred = 100 * 60; + limityellow = 100 *300; + } + } else { // relative 0, means fixed values in seconds + limitred = 100 * autocvar_hud_panel_timer_warning_red; + limityellow = 100 * autocvar_hud_panel_timer_warning_yellow; + } + + if(100 * timeleft <= limitred) return '1 0 0'; // red - else if(timeleft <= 300) + else if(100 * timeleft <= limityellow) return '1 1 0'; // yellow else return '1 1 1'; // white @@ -80,7 +99,7 @@ void HUD_Timer() // Timer color if(!intermission_time && !warmup_stage && timelimit > 0) - timer_color = HUD_Timer_Color(timeleft); + timer_color = HUD_Timer_Color(timeleft, timelimit); // Timer text if (autocvar_hud_panel_timer_increment || timelimit <= 0) @@ -107,7 +126,7 @@ void HUD_Timer() // Subtimer color if(!intermission_time && round_timelimit > 0) - subtimer_color = HUD_Timer_Color(round_timeleft); + subtimer_color = HUD_Timer_Color(round_timeleft, round_timelimit); // Subtimer text if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) diff --git a/qcsrc/client/hud/panel/timer.qh b/qcsrc/client/hud/panel/timer.qh index 3790f47770..a7df923819 100644 --- a/qcsrc/client/hud/panel/timer.qh +++ b/qcsrc/client/hud/panel/timer.qh @@ -6,7 +6,10 @@ bool autocvar_hud_panel_timer_dynamichud = true; bool autocvar_hud_panel_timer_increment; int autocvar_hud_panel_timer_secondary = 1; bool autocvar_hud_panel_timer_unbound; +int autocvar_hud_panel_timer_warning_relative = 0; +float autocvar_hud_panel_timer_warning_red = 60; +float autocvar_hud_panel_timer_warning_yellow = 300; -vector HUD_Timer_Color(float timeleft); +vector HUD_Timer_Color(float timeleft, float timelimit); float HUD_Timer_TimeElapsed(float curtime, float starttime); float HUD_Timer_TimeLeft(float curtime, float starttime, float timelimit); -- 2.39.5