From 5d7c87f5e4c3cb22347a4f43fd19c3b326a47d16 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 26 Feb 2024 20:50:20 +0000 Subject: [PATCH] Add setting for whether to show vehicle running costs per calendar year See #660 --- src/build_vehicle_gui.cpp | 2 +- src/engine.cpp | 4 +++- src/engine_gui.cpp | 2 +- src/lang/extra/english.txt | 3 +++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings/gui_settings.ini | 8 ++++++++ src/vehicle.cpp | 11 +++++++++++ src/vehicle_base.h | 6 +----- src/vehicle_gui.cpp | 2 +- 10 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index df8d2e26e3..7fd43d8c27 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -790,7 +790,7 @@ static StringID GetRunningCostString() { if (EconTime::UsingWallclockUnits()) { return STR_PURCHASE_INFO_RUNNINGCOST_PERIOD; - } else if (DayLengthFactor() > 1) { + } else if (DayLengthFactor() > 1 && !_settings_client.gui.show_running_costs_calendar_year) { return STR_PURCHASE_INFO_RUNNINGCOST_ORIG_YEAR; } else { return STR_PURCHASE_INFO_RUNNINGCOST_YEAR; diff --git a/src/engine.cpp b/src/engine.cpp index c4184ee36e..b4d5b9e5a1 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -319,7 +319,9 @@ uint Engine::DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity) const */ Money Engine::GetDisplayRunningCost() const { - return this->GetRunningCost() * DayLengthFactor(); + Money cost = this->GetRunningCost(); + if (_settings_client.gui.show_running_costs_calendar_year) cost *= DayLengthFactor(); + return cost; } /** diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp index 7f36ca89aa..2b5c706516 100644 --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -206,7 +206,7 @@ static StringID GetRunningCostString() { if (EconTime::UsingWallclockUnits()) { return STR_ENGINE_PREVIEW_RUNCOST_PERIOD; - } else if (DayLengthFactor() > 1) { + } else if (DayLengthFactor() > 1 && !_settings_client.gui.show_running_costs_calendar_year) { return STR_ENGINE_PREVIEW_RUNCOST_ORIG_YEAR; } else { return STR_ENGINE_PREVIEW_RUNCOST_YEAR; diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index a7f50f822a..761cae810a 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -323,6 +323,9 @@ STR_CONFIG_SETTING_HIDE_DEFAULT_STOP_LOCATION_HELPTEXT :When enabled, h STR_CONFIG_SHOW_RAIL_POLYLINE_TOOL :Show rail polyline tool: {STRING2} STR_CONFIG_SHOW_RAIL_POLYLINE_TOOL_HELPTEXT :When enabled, the rail construction toolbar includes a button to build using the polyline mode. +STR_CONFIG_SHOW_VEHICLE_RUNNING_COSTS_CALENDAR_YEAR :Show vehicle running costs per calendar year: {STRING2} +STR_CONFIG_SHOW_VEHICLE_RUNNING_COSTS_CALENDAR_YEAR_HELPTEXT :When using a day length factor greater than one, show vehicle running costs per calendar year instead of per original year. + STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES :Enable signals on bridges/tunnels advanced modes: {STRING2} STR_CONFIG_SETTING_ADV_SIG_BRIDGE_TUN_MODES_HELPTEXT :Enables use of advanced modes of signal simulation on bridges and tunnels. When disabled, bridges/tunnels which are not already in an advanced mode cannot be changed to an advanced mode, however other players may choose to enable this setting and use an advanced mode. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 978be74978..f86dffcdd7 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2282,6 +2282,7 @@ static SettingsContainer &GetSettingsTree() vehicle_windows->Add(new SettingEntry("gui.enable_single_veh_shared_order_gui")); vehicle_windows->Add(new SettingEntry("gui.show_order_number_vehicle_view")); vehicle_windows->Add(new SettingEntry("gui.hide_default_stop_location")); + vehicle_windows->Add(new ConditionallyHiddenSettingEntry("gui.show_running_costs_calendar_year", []() -> bool { return GetGameSettings().economy.timekeeping_units != TKU_CALENDAR; })); } SettingsPage *departureboards = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_DEPARTUREBOARDS)); diff --git a/src/settings_type.h b/src/settings_type.h index 2ab0e33f33..8c7a010294 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -316,6 +316,7 @@ struct GUISettings : public TimeSettings { bool show_order_number_vehicle_view; ///< Show order number in vehicle view window bool hide_default_stop_location; ///< Hide default stop location for orders bool show_rail_polyline_tool; ///< Show rail polyline tool + bool show_running_costs_calendar_year; ///< Show vehicle running costs in calendar years uint16_t console_backlog_timeout; ///< the minimum amount of time items should be in the console backlog before they will be removed in ~3 seconds granularity. uint16_t console_backlog_length; ///< the minimum amount of items in the console backlog before items will be removed. diff --git a/src/table/settings/gui_settings.ini b/src/table/settings/gui_settings.ini index 654ab051fa..1e795d73e9 100644 --- a/src/table/settings/gui_settings.ini +++ b/src/table/settings/gui_settings.ini @@ -1619,6 +1619,14 @@ str = STR_CONFIG_SHOW_RAIL_POLYLINE_TOOL strhelp = STR_CONFIG_SHOW_RAIL_POLYLINE_TOOL_HELPTEXT post_cb = [](auto) { InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_RAIL); } +[SDTC_BOOL] +var = gui.show_running_costs_calendar_year +flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_PATCH +def = false +str = STR_CONFIG_SHOW_VEHICLE_RUNNING_COSTS_CALENDAR_YEAR +strhelp = STR_CONFIG_SHOW_VEHICLE_RUNNING_COSTS_CALENDAR_YEAR_HELPTEXT +post_cb = [](auto) { MarkWholeScreenDirty(); } + ; For the dedicated build we'll enable dates in logs by default. [SDTC_BOOL] ifdef = DEDICATED diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 3671a9331b..9c7da23f46 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -4353,6 +4353,17 @@ void Vehicle::SetNext(Vehicle *next) } } +/** + * Gets the running cost of a vehicle that can be sent into SetDParam for string processing. + * @return the vehicle's running cost + */ +Money Vehicle::GetDisplayRunningCost() const +{ + Money cost = this->GetRunningCost() >> 8; + if (_settings_client.gui.show_running_costs_calendar_year) cost *= DayLengthFactor(); + return cost; +} + /** * Adds this vehicle to a shared vehicle chain. * @param shared_chain a vehicle of the chain with shared vehicles. diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 5889d5a081..0ccb4aa6c2 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -727,11 +727,7 @@ public: */ virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; } - /** - * Gets the running cost of a vehicle that can be sent into SetDParam for string processing. - * @return the vehicle's running cost - */ - Money GetDisplayRunningCost() const { return this->GetRunningCost() >> 8; } + Money GetDisplayRunningCost() const; /** * Gets the profit vehicle had this year. It can be sent into SetDParam for string processing. diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 49d3be3247..ba956ee271 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3106,7 +3106,7 @@ struct VehicleDetailsWindow : Window { { if (EconTime::UsingWallclockUnits()) { return STR_VEHICLE_INFO_AGE_RUNNING_COST_PERIOD; - } else if (DayLengthFactor() > 1) { + } else if (DayLengthFactor() > 1 && !_settings_client.gui.show_running_costs_calendar_year) { return STR_VEHICLE_INFO_AGE_RUNNING_COST_ORIG_YR; } else { return STR_VEHICLE_INFO_AGE_RUNNING_COST_YR;