From ccc87d35fdced597623a7de44589f77920da8487 Mon Sep 17 00:00:00 2001 From: z411 Date: Sun, 19 Mar 2023 11:07:04 +0000 Subject: [PATCH] Make the speed unit a global, consistent setting --- _hud_common.cfg | 4 ++-- qcsrc/client/hud/hud.qh | 2 ++ qcsrc/client/hud/panel/physics.qc | 4 ++-- qcsrc/client/hud/panel/physics.qh | 1 - qcsrc/client/hud/panel/scoreboard.qc | 7 ++++--- qcsrc/client/hud/panel/strafehud.qc | 10 +++++----- qcsrc/client/hud/panel/strafehud.qh | 1 - qcsrc/client/main.qc | 4 ++-- qcsrc/menu/xonotic/dialog_hudpanel_physics.qc | 12 ++---------- qcsrc/menu/xonotic/dialog_settings_game_hud.qc | 9 +++++++++ 10 files changed, 28 insertions(+), 26 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 766f89819..6339895ea 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -19,6 +19,8 @@ seta hud_colorset_kill_2 "3" "similar to above, but less important... OR, a high seta hud_colorset_kill_3 "4" "'good' or 'beneficial' text (you fragging someone, etc)" seta hud_colorset_background "7" "neutral/unimportant text" +seta hud_speed_unit "1" "speed unit (1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots)" + // general hud panel cvars (i.e. shouldn't be adjusted by a skin config) seta hud_panel_weapons 1 "enable this panel" seta hud_panel_ammo 1 "enable this panel" @@ -106,7 +108,6 @@ seta hud_panel_engineinfo_framecounter_time "0.1" "time between framerate displa seta hud_panel_physics_acceleration_movingaverage 1 "use an averaging method for calculating acceleration instead of the real value" seta hud_panel_physics_update_interval 0.016 "how often (in seconds) numeric values get updated on screen" -seta hud_panel_physics_speed_unit "1" "speed unit (1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots)" seta hud_panel_itemstime_progressbar_maxtime "30" "when left time is at least this amount, the status bar is full" seta hud_panel_itemstime_hidespawned "1" "if 1 hide an item from the panel when all the occurrences of it are available again; if 2 hide it when at least one occurrence is available again" @@ -157,7 +158,6 @@ seta _hud_panel_strafehud_demo "0" "strafehud changes angle during configure" seta hud_panel_strafehud_mode "0" "strafehud mode which controls whether the strafehud is centered at \"0\" = view angle, \"1\" = velocity angle" seta hud_panel_strafehud_range "0" "the angle range up to 360 degrees displayed on the strafehud, \"0\" = dynamic (chooses the minimum range required to still see the whole area needed for accelerating at once)" seta hud_panel_strafehud_style "1" "\"0\" = no styling, \"1\" = progress bar style for the strafe bar, \"2\" = gradient for the strafe bar" -seta hud_panel_strafehud_unit "1" "speed unit (1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots), length unit (1 = qu, 2 = m, 3 = km, 4 = mi, 5 = nmi)" seta hud_panel_strafehud_unit_show "1" "show units" seta hud_panel_strafehud_bar_neutral_color "1 1 1" "color of the strafe meter neutral zone" seta hud_panel_strafehud_bar_neutral_alpha "0.3" "opacity of the strafe meter neutral zone" diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index 0eb81916c..312aaea99 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -203,6 +203,8 @@ string autocvar_hud_skin; float autocvar_hud_progressbar_alpha; float autocvar_hud_panel_update_interval; +int autocvar_hud_speed_unit; + float autocvar_hud_dynamic_follow; float autocvar_hud_dynamic_follow_scale; vector autocvar_hud_dynamic_follow_scale_xyz; diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index 53d778a4b..efbf045cd 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -63,7 +63,7 @@ void HUD_Physics() text_scale = min(autocvar_hud_panel_physics_text_scale, 1); //compute speed - float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); + float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit); vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel); float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 ); @@ -177,7 +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); + string unit = GetSpeedUnit(autocvar_hud_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/physics.qh b/qcsrc/client/hud/panel/physics.qh index e0f93b0f5..353a970cd 100644 --- a/qcsrc/client/hud/panel/physics.qh +++ b/qcsrc/client/hud/panel/physics.qh @@ -14,7 +14,6 @@ int autocvar_hud_panel_physics_baralign; bool autocvar_hud_panel_physics_flip; bool autocvar_hud_panel_physics_dynamichud = true; float autocvar_hud_panel_physics_speed_max; -int autocvar_hud_panel_physics_speed_unit; bool autocvar_hud_panel_physics_speed_unit_show; bool autocvar_hud_panel_physics_speed_vertical; int autocvar_hud_panel_physics_text; diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 9256d162b..cd176345f 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -2455,7 +2455,8 @@ void Scoreboard_Draw() if(MUTATOR_CALLHOOK(ShowRankings)) { string ranktitle = M_ARGV(0, string); - string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit); + string unit = GetSpeedUnit(autocvar_hud_speed_unit); + float conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit); if(race_speedaward_alltimebest) { string name; @@ -2464,11 +2465,11 @@ void Scoreboard_Draw() if(race_speedaward) { name = textShortenToWidth(ColorTranslateRGB(race_speedaward_holder), namesize, hud_fontsize, stringwidth_colors); - str = sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward, unit, name); + str = sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward * conversion_factor, unit, name); str = strcat(str, " / "); } name = textShortenToWidth(ColorTranslateRGB(race_speedaward_alltimebest_holder), namesize, hud_fontsize, stringwidth_colors); - str = strcat(str, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest, unit, name)); + str = strcat(str, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest * conversion_factor, unit, name)); drawcolorcodedstring(pos, str, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL); pos.y += 1.25 * hud_fontsize.y; // line height + line spacing } diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index e4e339c44..46e8b7631 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -116,9 +116,9 @@ void HUD_StrafeHUD() // HUD 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); - 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 speed_conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit); + float length_conversion_factor = GetLengthUnitFactor(autocvar_hud_speed_unit); + int length_decimals = autocvar_hud_speed_unit >= 3 && autocvar_hud_speed_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); float minspeed; @@ -639,7 +639,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); + string speed_unit = GetSpeedUnit(autocvar_hud_speed_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); } } @@ -674,7 +674,7 @@ void HUD_StrafeHUD() float text_alpha = cos(((time - jumptime) / autocvar_hud_panel_strafehud_jumpheight_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does 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); + string length_unit = GetLengthUnit(autocvar_hud_speed_unit); drawstring_aspect(panel_pos - eY * jumpheight_size.y, strcat(ftos_decimals(jumpheight, 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/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index 2fbd9b275..64a78c981 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -7,7 +7,6 @@ bool autocvar_hud_panel_strafehud_dynamichud = true; int autocvar_hud_panel_strafehud_mode = 0; float autocvar_hud_panel_strafehud_range = 0; int autocvar_hud_panel_strafehud_style = 1; -int autocvar_hud_panel_strafehud_unit = 1; bool autocvar_hud_panel_strafehud_unit_show = true; vector autocvar_hud_panel_strafehud_bar_neutral_color = '1 1 1'; float autocvar_hud_panel_strafehud_bar_neutral_alpha = 0.3; diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 4e05e681d..8f10bd757 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1254,11 +1254,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) race_server_record = ReadInt24_t(); break; case RACE_NET_SPEED_AWARD: - race_speedaward = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); + race_speedaward = ReadInt24_t(); strcpy(race_speedaward_holder, ReadString()); break; case RACE_NET_SPEED_AWARD_BEST: - race_speedaward_alltimebest = ReadInt24_t() * GetSpeedUnitFactor(autocvar_hud_panel_physics_speed_unit); + race_speedaward_alltimebest = ReadInt24_t(); strcpy(race_speedaward_alltimebest_holder, ReadString()); break; case RACE_NET_RANKINGS_CNT: diff --git a/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc b/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc index 3a1e0bee1..db966263f 100644 --- a/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc +++ b/qcsrc/menu/xonotic/dialog_hudpanel_physics.qc @@ -45,16 +45,8 @@ void XonoticHUDPhysicsDialog_fill(entity me) // me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("qu/s"))); // setDependent(e, "hud_panel_physics_progressbar", 1, 1); me.TR(me); - me.TDempty(me, 0.2); - me.TD(me, 1, 1.2, e = makeXonoticTextLabel(0, _("Speed unit:"))); - me.TD(me, 1, 2.6/3*2, e = makeXonoticTextSlider("hud_panel_physics_speed_unit")); - e.addValue(e, _("qu/s") , "1"); - e.addValue(e, _("m/s") , "2"); - e.addValue(e, _("km/h") , "3"); - e.addValue(e, _("mph") , "4"); - e.addValue(e, _("knots"), "5"); - e.configureXonoticTextSliderValues(e); - me.TD(me, 1, 2.6/3, e = makeXonoticCheckBox(0, "hud_panel_physics_speed_unit_show", _("Show"))); + me.TDempty(me, 1); + me.TD(me, 1, 3, e = makeXonoticCheckBox(0, "hud_panel_physics_speed_unit_show", _("Show speed unit"))); me.TR(me); me.TDempty(me, 0.2); me.TD(me, 1, 3.8/2, e = makeXonoticCheckBox(0, "hud_panel_physics_topspeed", _("Top speed"))); diff --git a/qcsrc/menu/xonotic/dialog_settings_game_hud.qc b/qcsrc/menu/xonotic/dialog_settings_game_hud.qc index 76ee74c59..dadef0647 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game_hud.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game_hud.qc @@ -159,6 +159,15 @@ void XonoticGameHUDSettingsTab_fill(entity me) setDependent(e, "hud_shownames", 1, 1); me.TR(me); + me.TR(me); + me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Speed unit:"))); + me.TD(me, 1, 2, e = makeXonoticTextSlider("hud_speed_unit")); + e.addValue(e, _("qu/s") , "1"); + e.addValue(e, _("m/s") , "2"); + e.addValue(e, _("km/h") , "3"); + e.addValue(e, _("mph") , "4"); + e.addValue(e, _("knots"), "5"); + e.configureXonoticTextSliderValues(e); me.TR(me); me.TD(me, 1, 1, e = makeXonoticTextLabel(0, _("Damage overlay:"))); me.TD(me, 1, 2, e = makeXonoticSlider(0, 1, 0.05, "hud_damage")); -- 2.39.2