diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 05430dddad..45d47a7f72 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -22,6 +22,7 @@ #include "core/geometry_func.hpp" #include "currency.h" #include "zoom_func.h" +#include "unit_conversion.h" #include "widgets/graph_widget.h" @@ -887,8 +888,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { this->num_on_x_axis = 20; this->num_vert_lines = 20; this->month = 0xFF; - this->x_values_start = 10; - this->x_values_increment = 10; + this->SetXAxis(); this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); @@ -900,6 +900,23 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { this->FinishInitNested(window_number); } + void SetXAxis() + { + uint16 x_scale; + switch (_settings_game.locale.units_velocity) { + case 2: + x_scale = 5; + break; + case 3: + x_scale = 1; + break; + default: + x_scale = 10; + } + this->x_values_start = x_scale; + this->x_values_increment = x_scale; + } + void OnInit() override { /* Width of the legend blob. */ @@ -1039,6 +1056,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { void OnInvalidateData(int data = 0, bool gui_scope = true) override { if (!gui_scope) return; + this->SetXAxis(); this->OnHundredthTick(); } @@ -1048,18 +1066,27 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { int i = 0; const CargoSpec *cs; - const float factor = 200.0f * 28.57f * 0.4f; + const float factor = 200.0f * 28.57f * 0.4f * ConvertSpeedToUnitDisplaySpeed(1 << 16) / (1.6f * static_cast(1 << 16)); FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { this->colours[i] = cs->legend_colour; for (int j = 0; j != 20; j++) { - const byte ctt = static_cast(factor / ((static_cast(j) + 1) * 10.0f)); - this->cost[i][j] = GetTransportedGoodsIncome(1, 200, ctt, cs->Index()); + const byte ctt = static_cast(factor / static_cast((j + 1) * this->x_values_increment)); + this->cost[i][j] = GetTransportedGoodsIncome(10, 20, ctt, cs->Index()); } i++; } this->num_dataset = i; } + + void SetStringParameters(int widget) const override + { + switch (widget) { + case WID_CPR_FOOTER: + SetDParam(0, STR_UNIT_NAME_VELOCITY_IMPERIAL + _settings_game.locale.units_velocity); + break; + } + } }; static const NWidgetPart _nested_cargo_payment_rates_widgets[] = { @@ -1093,7 +1120,7 @@ static const NWidgetPart _nested_cargo_payment_rates_widgets[] = { EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(NWID_SPACER), SetMinimalSize(WD_RESIZEBOX_WIDTH, 0), SetFill(1, 0), SetResize(1, 0), - NWidget(WWT_TEXT, COLOUR_BROWN, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL), + NWidget(WWT_TEXT, COLOUR_BROWN, WID_CPR_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL_SPEED, STR_NULL), NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0), NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CPR_RESIZE), EndContainer(), diff --git a/src/lang/english.txt b/src/lang/english.txt index c0539669cd..d02489a3b5 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -603,7 +603,8 @@ STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION :{WHITE}Company STR_GRAPH_COMPANY_VALUES_CAPTION :{WHITE}Company values STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION :{WHITE}Cargo Payment Rates -STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL :{TINY_FONT}{BLACK}Average transit speed (km/h) +STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL :{TINY_FONT}{BLACK}Days in transit +STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL_SPEED :{TINY_FONT}{BLACK}Average transit speed ({STRING}) STR_GRAPH_CARGO_PAYMENT_RATES_TITLE :{TINY_FONT}{BLACK}Payment for delivering 10 units (or 10,000 litres) of cargo a distance of 20 squares STR_GRAPH_CARGO_ENABLE_ALL :{TINY_FONT}{BLACK}Enable all STR_GRAPH_CARGO_DISABLE_ALL :{TINY_FONT}{BLACK}Disable all diff --git a/src/settings.cpp b/src/settings.cpp index 4884c5b3f5..e9c9bae17e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1520,6 +1520,12 @@ static bool ClimateThresholdModeChanged(int32 p1) return true; } +static bool VelocityUnitsChanged(int32 p1) { + InvalidateWindowClassesData(WC_PAYMENT_RATES); + MarkWholeScreenDirty(); + return true; +} + /** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */ static void ValidateSettings() { diff --git a/src/table/settings.ini b/src/table/settings.ini index b1000f307f..d0c91524bc 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -61,6 +61,7 @@ static bool ViewportMapShowTunnelModeChanged(int32 p1); static bool ViewportMapLandscapeModeChanged(int32 p1); static bool UpdateLinkgraphColours(int32 p1); static bool ClimateThresholdModeChanged(int32 p1); +static bool VelocityUnitsChanged(int32 p1); static bool UpdateClientName(int32 p1); static bool UpdateServerPassword(int32 p1); @@ -4103,7 +4104,7 @@ guiflags = SGF_MULTISTRING def = 1 max = 3 full = _locale_units -proc = RedrawScreen +proc = VelocityUnitsChanged cat = SC_BASIC str = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY strhelp = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_HELPTEXT