From 0008e7d7697246a7ee24167673556a52af8e1a16 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 31 Mar 2024 17:48:58 +0100 Subject: [PATCH] Fix velocity unit names used in cargo payments graph window --- src/graph_gui.cpp | 2 +- src/strings.cpp | 25 +++++++++++++++++++++++++ src/strings_func.h | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 0f80fbc9b4..c881da9681 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1501,7 +1501,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { case WID_GRAPH_FOOTER_CUSTOM: if (_cargo_payment_x_mode) { SetDParam(0, STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL_SPEED); - SetDParam(1, STR_UNIT_NAME_VELOCITY_IMPERIAL + _settings_game.locale.units_velocity); + SetDParam(1, GetVelocityUnitName(VEH_TRAIN)); } else { if (_settings_time.time_in_minutes) { SetDParam(0, STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL_MINUTES); diff --git a/src/strings.cpp b/src/strings.cpp index 5de6ebcf61..02df664121 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -858,6 +858,31 @@ static const Units _units_time_years_or_minutes[] = { { { 12 }, STR_UNITS_MINUTES, 0 }, }; +StringID GetVelocityUnitName(VehicleType type) +{ + uint8_t setting = (type == VEH_SHIP || type == VEH_AIRCRAFT) ? _settings_game.locale.units_velocity_nautical : _settings_game.locale.units_velocity; + + assert(setting < lengthof(_units_velocity_calendar)); + assert(setting < lengthof(_units_velocity_realtime)); + static_assert(lengthof(_units_velocity_calendar) == 5 && lengthof(_units_velocity_realtime) == 5); + + switch (setting) { + case 0: + case 1: + case 2: + return STR_UNIT_NAME_VELOCITY_IMPERIAL + setting; + + case 3: + return EconTime::UsingWallclockUnits() ? STR_UNIT_NAME_VELOCITY_GAMEUNITS_WALLCLOCK : STR_UNIT_NAME_VELOCITY_GAMEUNITS; + + case 4: + return STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_KNOTS; + + default: + NOT_REACHED(); + } +} + /** * Get the correct velocity units depending on the vehicle type and whether we're using real-time units. * @param type VehicleType to convert velocity for. diff --git a/src/strings_func.h b/src/strings_func.h index 43828f098b..d2800ffe34 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -71,6 +71,8 @@ uint32_t GetStringGRFID(StringID string); uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type); uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type); +StringID GetVelocityUnitName(VehicleType type); + /** * Pack velocity and vehicle type for use with SCC_VELOCITY string parameter. * @param speed Display speed for parameter.