From 9e814be01b75fd862cd3b0a7f413798253bba623 Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 8 Jul 2021 23:38:23 +0200 Subject: [PATCH] Rankings panel: allow immediate update of speed unit when changing hud_panel_physics_speed_unit. Also optimize other GetSpeedUnit calls --- qcsrc/client/hud/panel/physics.qc | 2 +- qcsrc/client/hud/panel/racetimer.qh | 2 -- qcsrc/client/hud/panel/scoreboard.qc | 5 +++-- qcsrc/client/hud/panel/strafehud.qc | 4 ++-- qcsrc/client/main.qc | 2 -- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index 6a0baed31..53d778a4b 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -64,7 +64,6 @@ void HUD_Physics() //compute speed float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); - string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit); vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel); float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 ); @@ -178,6 +177,7 @@ void HUD_Physics() tmp_size.x = panel_size.x * (1 - 0.75); tmp_size.y = panel_size.y * 0.4 * text_scale; tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2; + string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit); drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); } } diff --git a/qcsrc/client/hud/panel/racetimer.qh b/qcsrc/client/hud/panel/racetimer.qh index ba7bd3229..8f4c09c10 100644 --- a/qcsrc/client/hud/panel/racetimer.qh +++ b/qcsrc/client/hud/panel/racetimer.qh @@ -23,10 +23,8 @@ string race_penaltyreason; // reason for penalty float race_server_record; // server record float race_speedaward; string race_speedaward_holder; -string race_speedaward_unit; float race_speedaward_alltimebest; string race_speedaward_alltimebest_holder; -string race_speedaward_alltimebest_unit; // RACE float race_mycheckpoint; diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 6133b18de..5cd42e545 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -2070,12 +2070,13 @@ void Scoreboard_Draw() if(MUTATOR_CALLHOOK(ShowRankings)) { string ranktitle = M_ARGV(0, string); + string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit); if(race_speedaward) { - drawcolorcodedstring(pos, sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward, race_speedaward_unit, ColorTranslateRGB(race_speedaward_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); + drawcolorcodedstring(pos, sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward, unit, ColorTranslateRGB(race_speedaward_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); pos.y += 1.25 * hud_fontsize.y; } if(race_speedaward_alltimebest) { - drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest, race_speedaward_alltimebest_unit, ColorTranslateRGB(race_speedaward_alltimebest_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); + drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest, unit, ColorTranslateRGB(race_speedaward_alltimebest_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); pos.y += 1.25 * hud_fontsize.y; } if (race_speedaward || race_speedaward_alltimebest) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index dd9594b7b..2f0df0821 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -124,8 +124,6 @@ void HUD_StrafeHUD() int mode = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0; float speed_conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_strafehud_unit); float length_conversion_factor = GetLengthUnitFactor(autocvar_hud_panel_strafehud_unit); - string speed_unit = GetSpeedUnit(autocvar_hud_panel_strafehud_unit); - string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit); int length_decimals = autocvar_hud_panel_strafehud_unit >= 3 && autocvar_hud_panel_strafehud_unit <= 5 ? 6 : 2; // use more decimals when displaying km or miles float antiflicker_angle = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180); float antiflicker_speed = max(0, autocvar_hud_panel_strafehud_antiflicker_speed); @@ -647,6 +645,7 @@ void HUD_StrafeHUD() { vector startspeed_size = panel_size; startspeed_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_startspeed_size, 5); + string speed_unit = GetSpeedUnit(autocvar_hud_panel_strafehud_unit); drawstring_aspect(panel_pos + eY * panel_size.y, strcat(ftos_decimals(startspeed * speed_conversion_factor, 2), autocvar_hud_panel_strafehud_unit_show ? speed_unit : ""), startspeed_size, autocvar_hud_panel_strafehud_startspeed_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } } @@ -699,6 +698,7 @@ void HUD_StrafeHUD() { vector jumpheight_size = panel_size; jumpheight_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_jumpheight_size, 5); + string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit); drawstring_aspect(panel_pos - eY * jumpheight_size.y, strcat(ftos_decimals(jumpheight_persistent * length_conversion_factor, length_decimals), autocvar_hud_panel_strafehud_unit_show ? length_unit : ""), jumpheight_size, autocvar_hud_panel_strafehud_jumpheight_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } } diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 757effd99..ca49edd03 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1183,12 +1183,10 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) case RACE_NET_SPEED_AWARD: race_speedaward = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); strcpy(race_speedaward_holder, ReadString()); - strcpy(race_speedaward_unit, GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; case RACE_NET_SPEED_AWARD_BEST: race_speedaward_alltimebest = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); strcpy(race_speedaward_alltimebest_holder, ReadString()); - strcpy(race_speedaward_alltimebest_unit, GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; case RACE_NET_RANKINGS_CNT: RANKINGS_DISPLAY_CNT = ReadByte(); -- 2.39.2