Use localised units for payment graph X axis

Match quantities in graph title
This commit is contained in:
Jonathan G Rennison 2021-06-13 23:57:14 +01:00
parent f786b372c0
commit f438daa0bc
4 changed files with 43 additions and 8 deletions

View File

@ -22,6 +22,7 @@
#include "core/geometry_func.hpp" #include "core/geometry_func.hpp"
#include "currency.h" #include "currency.h"
#include "zoom_func.h" #include "zoom_func.h"
#include "unit_conversion.h"
#include "widgets/graph_widget.h" #include "widgets/graph_widget.h"
@ -887,8 +888,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
this->num_on_x_axis = 20; this->num_on_x_axis = 20;
this->num_vert_lines = 20; this->num_vert_lines = 20;
this->month = 0xFF; this->month = 0xFF;
this->x_values_start = 10; this->SetXAxis();
this->x_values_increment = 10;
this->CreateNestedTree(); this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
@ -900,6 +900,23 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
this->FinishInitNested(window_number); 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 void OnInit() override
{ {
/* Width of the legend blob. */ /* Width of the legend blob. */
@ -1039,6 +1056,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
void OnInvalidateData(int data = 0, bool gui_scope = true) override void OnInvalidateData(int data = 0, bool gui_scope = true) override
{ {
if (!gui_scope) return; if (!gui_scope) return;
this->SetXAxis();
this->OnHundredthTick(); this->OnHundredthTick();
} }
@ -1048,18 +1066,27 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
int i = 0; int i = 0;
const CargoSpec *cs; 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<float>(1 << 16));
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
this->colours[i] = cs->legend_colour; this->colours[i] = cs->legend_colour;
for (int j = 0; j != 20; j++) { for (int j = 0; j != 20; j++) {
const byte ctt = static_cast<byte>(factor / ((static_cast<float>(j) + 1) * 10.0f)); const byte ctt = static_cast<byte>(factor / static_cast<float>((j + 1) * this->x_values_increment));
this->cost[i][j] = GetTransportedGoodsIncome(1, 200, ctt, cs->Index()); this->cost[i][j] = GetTransportedGoodsIncome(10, 20, ctt, cs->Index());
} }
i++; i++;
} }
this->num_dataset = 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[] = { static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
@ -1093,7 +1120,7 @@ static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
EndContainer(), EndContainer(),
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(WD_RESIZEBOX_WIDTH, 0), SetFill(1, 0), SetResize(1, 0), 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(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CPR_RESIZE), NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CPR_RESIZE),
EndContainer(), EndContainer(),

View File

@ -603,7 +603,8 @@ STR_GRAPH_COMPANY_PERFORMANCE_RATINGS_CAPTION :{WHITE}Company
STR_GRAPH_COMPANY_VALUES_CAPTION :{WHITE}Company values STR_GRAPH_COMPANY_VALUES_CAPTION :{WHITE}Company values
STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION :{WHITE}Cargo Payment Rates 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_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_ENABLE_ALL :{TINY_FONT}{BLACK}Enable all
STR_GRAPH_CARGO_DISABLE_ALL :{TINY_FONT}{BLACK}Disable all STR_GRAPH_CARGO_DISABLE_ALL :{TINY_FONT}{BLACK}Disable all

View File

@ -1520,6 +1520,12 @@ static bool ClimateThresholdModeChanged(int32 p1)
return true; 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. */ /** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */
static void ValidateSettings() static void ValidateSettings()
{ {

View File

@ -61,6 +61,7 @@ static bool ViewportMapShowTunnelModeChanged(int32 p1);
static bool ViewportMapLandscapeModeChanged(int32 p1); static bool ViewportMapLandscapeModeChanged(int32 p1);
static bool UpdateLinkgraphColours(int32 p1); static bool UpdateLinkgraphColours(int32 p1);
static bool ClimateThresholdModeChanged(int32 p1); static bool ClimateThresholdModeChanged(int32 p1);
static bool VelocityUnitsChanged(int32 p1);
static bool UpdateClientName(int32 p1); static bool UpdateClientName(int32 p1);
static bool UpdateServerPassword(int32 p1); static bool UpdateServerPassword(int32 p1);
@ -4103,7 +4104,7 @@ guiflags = SGF_MULTISTRING
def = 1 def = 1
max = 3 max = 3
full = _locale_units full = _locale_units
proc = RedrawScreen proc = VelocityUnitsChanged
cat = SC_BASIC cat = SC_BASIC
str = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY str = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY
strhelp = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_HELPTEXT strhelp = STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_HELPTEXT