1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-09-02 19:39:12 +00:00

Feature: Use real-time "wallclock" timekeeping units (#11341)

This commit is contained in:
Tyler Trahan
2024-01-23 11:36:09 -05:00
committed by GitHub
parent bbdbf9a589
commit fd9e72a7e7
30 changed files with 546 additions and 140 deletions

View File

@@ -170,6 +170,9 @@ protected:
static const int GRAPH_ZERO_LINE_COLOUR = GREY_SCALE(8);
static const int GRAPH_YEAR_LINE_COLOUR = GREY_SCALE(5);
static const int GRAPH_NUM_MONTHS = 24; ///< Number of months displayed in the graph.
static const int PAYMENT_GRAPH_X_STEP_DAYS = 20; ///< X-axis step label for cargo payment rates "Days in transit".
static const int PAYMENT_GRAPH_X_STEP_SECONDS = 10; ///< X-axis step label for cargo payment rates "Seconds in transit".
static const int ECONOMY_QUARTER_MINUTES = 3; ///< Minutes per economic quarter.
static const TextColour GRAPH_AXIS_LABEL_COLOUR = TC_BLACK; ///< colour of the graph axis label.
@@ -336,8 +339,13 @@ protected:
/* Don't draw the first line, as that's where the axis will be. */
x = r.left + x_sep;
for (int i = 0; i < this->num_vert_lines; i++) {
GfxFillRect(x, r.top, x, r.bottom, GRAPH_GRID_COLOUR);
int grid_colour = GRAPH_GRID_COLOUR;
for (int i = 1; i < this->num_vert_lines + 1; i++) {
/* If using wallclock units, we separate periods with a lighter line. */
if (TimerGameEconomy::UsingWallclockUnits()) {
grid_colour = (i % 4 == 0) ? GRAPH_YEAR_LINE_COLOUR : GRAPH_GRID_COLOUR;
}
GfxFillRect(x, r.top, x, r.bottom, grid_colour);
x += x_sep;
}
@@ -399,7 +407,7 @@ protected:
x += x_sep;
}
} else {
/* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates). */
/* Draw x-axis labels for graphs not based on quarterly performance (cargo payment rates, and all graphs when using wallclock units). */
x = r.left;
y = r.bottom + ScaleGUITrad(2);
uint16_t label = this->x_values_start;
@@ -622,6 +630,12 @@ struct OperatingProfitGraphWindow : BaseGraphWindow {
OperatingProfitGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
{
this->num_on_x_axis = GRAPH_NUM_MONTHS;
this->num_vert_lines = GRAPH_NUM_MONTHS;
this->x_values_start = ECONOMY_QUARTER_MINUTES;
this->x_values_increment = ECONOMY_QUARTER_MINUTES;
this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
this->InitializeWindow(window_number);
}
@@ -641,10 +655,12 @@ static constexpr NWidgetPart _nested_operating_profit_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 160), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_CV_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -673,6 +689,12 @@ struct IncomeGraphWindow : BaseGraphWindow {
IncomeGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
{
this->num_on_x_axis = GRAPH_NUM_MONTHS;
this->num_vert_lines = GRAPH_NUM_MONTHS;
this->x_values_start = ECONOMY_QUARTER_MINUTES;
this->x_values_increment = ECONOMY_QUARTER_MINUTES;
this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
this->InitializeWindow(window_number);
}
@@ -692,10 +714,12 @@ static constexpr NWidgetPart _nested_income_graph_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_CV_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -722,6 +746,12 @@ struct DeliveredCargoGraphWindow : BaseGraphWindow {
DeliveredCargoGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_COMMA)
{
this->num_on_x_axis = GRAPH_NUM_MONTHS;
this->num_vert_lines = GRAPH_NUM_MONTHS;
this->x_values_start = ECONOMY_QUARTER_MINUTES;
this->x_values_increment = ECONOMY_QUARTER_MINUTES;
this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
this->InitializeWindow(window_number);
}
@@ -741,10 +771,12 @@ static constexpr NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_CV_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -771,6 +803,12 @@ struct PerformanceHistoryGraphWindow : BaseGraphWindow {
PerformanceHistoryGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_PHG_GRAPH, STR_JUST_COMMA)
{
this->num_on_x_axis = GRAPH_NUM_MONTHS;
this->num_vert_lines = GRAPH_NUM_MONTHS;
this->x_values_start = ECONOMY_QUARTER_MINUTES;
this->x_values_increment = ECONOMY_QUARTER_MINUTES;
this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
this->InitializeWindow(window_number);
}
@@ -797,10 +835,12 @@ static constexpr NWidgetPart _nested_performance_history_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_PHG_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_PHG_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_PHG_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_PHG_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -827,6 +867,12 @@ struct CompanyValueGraphWindow : BaseGraphWindow {
CompanyValueGraphWindow(WindowDesc *desc, WindowNumber window_number) :
BaseGraphWindow(desc, WID_CV_GRAPH, STR_JUST_CURRENCY_SHORT)
{
this->num_on_x_axis = GRAPH_NUM_MONTHS;
this->num_vert_lines = GRAPH_NUM_MONTHS;
this->x_values_start = ECONOMY_QUARTER_MINUTES;
this->x_values_increment = ECONOMY_QUARTER_MINUTES;
this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
this->InitializeWindow(window_number);
}
@@ -846,10 +892,12 @@ static constexpr NWidgetPart _nested_company_value_graph_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_CV_BACKGROUND),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_EMPTY, COLOUR_BROWN, WID_CV_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1),
NWidget(NWID_VERTICAL),
NWidget(NWID_SPACER), SetFill(0, 1), SetResize(0, 1),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 0), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_TEXT, COLOUR_BROWN, WID_CV_FOOTER), SetMinimalSize(0, 6), SetPadding(2, 0, 2, 0), SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CV_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),
EndContainer(),
@@ -883,8 +931,9 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
this->num_on_x_axis = 20;
this->num_vert_lines = 20;
this->draw_dates = false;
this->x_values_start = 10;
this->x_values_increment = 10;
/* The x-axis is labeled in either seconds or days. A day is two seconds, so we adjust the label if needed. */
this->x_values_start = (TimerGameEconomy::UsingWallclockUnits() ? PAYMENT_GRAPH_X_STEP_SECONDS : PAYMENT_GRAPH_X_STEP_DAYS);
this->x_values_increment = (TimerGameEconomy::UsingWallclockUnits() ? PAYMENT_GRAPH_X_STEP_SECONDS : PAYMENT_GRAPH_X_STEP_DAYS);
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
@@ -1085,7 +1134,7 @@ static constexpr NWidgetPart _nested_cargo_payment_rates_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetMinimalSize(12, 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_TIME_LABEL, STR_NULL),
NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN, WID_CPR_RESIZE), SetDataTip(RWV_HIDE_BEVEL, STR_TOOLTIP_RESIZE),
EndContainer(),