31 #include "table/strings.h"
37 static CompanyMask _legend_excluded_companies;
38 static CargoTypes _legend_excluded_cargo_payment_rates;
39 static CargoTypes _legend_excluded_cargo_production_history;
43 static const uint INVALID_DATAPOINT_POS = UINT_MAX;
64 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
84 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
103 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
105 if (!gui_scope)
return;
108 SetBit(_legend_excluded_companies, data);
119 auto vert = std::make_unique<NWidgetVertical>(
NC_EQUALSIZE);
120 vert->SetPadding(2, 2, 2, 2);
124 auto panel = std::make_unique<NWidgetBackground>(
WWT_PANEL, COLOUR_BROWN, widnum);
127 panel->SetFill(1, 1);
128 panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
129 vert->Add(std::move(panel));
134 static constexpr
NWidgetPart _nested_graph_legend_widgets[] = {
150 _nested_graph_legend_widgets
153 static void ShowGraphLegend()
155 AllocateWindowDescFront<GraphLegendWindow>(_graph_legend_desc, 0);
170 static const int GRAPH_MAX_DATASETS = 64;
171 static const int GRAPH_BASE_COLOUR =
GREY_SCALE(2);
172 static const int GRAPH_GRID_COLOUR =
GREY_SCALE(3);
173 static const int GRAPH_AXIS_LINE_COLOUR =
GREY_SCALE(1);
174 static const int GRAPH_ZERO_LINE_COLOUR =
GREY_SCALE(8);
175 static const int GRAPH_YEAR_LINE_COLOUR =
GREY_SCALE(5);
189 uint8_t num_on_x_axis;
190 uint8_t num_vert_lines;
201 uint16_t x_values_start;
202 uint16_t x_values_increment;
205 uint8_t colours[GRAPH_MAX_DATASETS];
216 assert(num_hori_lines > 0);
219 current_interval.
highest = INT64_MIN;
220 current_interval.
lowest = INT64_MAX;
222 for (
int i = 0; i < this->num_dataset; i++) {
223 if (
HasBit(this->excluded_data, i))
continue;
224 for (
int j = 0; j < this->num_on_x_axis; j++) {
227 if (datapoint != INVALID_DATAPOINT) {
228 current_interval.
highest = std::max(current_interval.
highest, datapoint);
229 current_interval.
lowest = std::min(current_interval.
lowest, datapoint);
235 double abs_lower = (current_interval.
lowest > 0) ? 0 : (
double)
abs(current_interval.
lowest);
236 double abs_higher = (current_interval.
highest < 0) ? 0 : (
double)current_interval.
highest;
239 abs_higher = (11.0 * abs_higher) / 10.0;
240 abs_lower = (11.0 * abs_lower) / 10.0;
245 if (abs_lower != 0 || abs_higher != 0) {
247 num_pos_grids = (int)floor(0.5 + num_hori_lines * abs_higher / (abs_higher + abs_lower));
250 if (num_pos_grids == 0 && abs_higher != 0) num_pos_grids++;
251 if (num_pos_grids == num_hori_lines && abs_lower != 0) num_pos_grids--;
256 if (abs_higher > 0) {
257 grid_size_higher = abs_higher >
INT64_MAX_IN_DOUBLE ? INT64_MAX :
static_cast<int64_t
>(abs_higher);
258 grid_size_higher = (grid_size_higher + num_pos_grids - 1) / num_pos_grids;
263 grid_size_lower = abs_lower >
INT64_MAX_IN_DOUBLE ? INT64_MAX :
static_cast<int64_t
>(abs_lower);
264 grid_size_lower = (grid_size_lower + num_hori_lines - num_pos_grids - 1) / (num_hori_lines - num_pos_grids);
267 grid_size = std::max(grid_size_higher, grid_size_lower);
270 num_pos_grids = num_hori_lines / 2;
274 current_interval.
highest = num_pos_grids * grid_size;
275 current_interval.
lowest = -(num_hori_lines - num_pos_grids) * grid_size;
276 return current_interval;
287 int64_t y_label = current_interval.
highest;
288 int64_t y_label_separation = (current_interval.
highest - current_interval.
lowest) / num_hori_lines;
292 for (
int i = 0; i < (num_hori_lines + 1); i++) {
296 if (d.width > max_width) max_width = d.width;
298 y_label -= y_label_separation;
317 assert(this->num_vert_lines > 0);
336 r.left += label_width;
338 int x_sep = (r.right - r.left) / this->num_vert_lines;
339 int y_sep = (r.bottom - r.top) / num_hori_lines;
343 r.right = r.left + x_sep * this->num_vert_lines;
344 r.bottom = r.top + y_sep * num_hori_lines;
348 x_axis_offset = (int)((r.bottom - r.top) * (double)interval.
highest / (
double)interval_size);
351 GfxFillRect(r.left, r.top, r.right, r.bottom, GRAPH_BASE_COLOUR);
358 int grid_colour = GRAPH_GRID_COLOUR;
359 for (
int i = 1; i < this->num_vert_lines + 1; i++) {
362 grid_colour = (i % 4 == 0) ? GRAPH_YEAR_LINE_COLOUR : GRAPH_GRID_COLOUR;
371 for (
int i = 0; i < (num_hori_lines + 1); i++) {
373 GfxFillRect(r.left, y, r.right, y, GRAPH_GRID_COLOUR);
378 GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR);
381 y = x_axis_offset + r.top;
382 GfxFillRect(r.left, y, r.right, y, GRAPH_ZERO_LINE_COLOUR);
385 if (this->num_on_x_axis == 0)
return;
387 assert(this->num_on_x_axis > 0);
390 int64_t y_label = interval.
highest;
391 int64_t y_label_separation =
abs(interval.
highest - interval.
lowest) / num_hori_lines;
395 for (
int i = 0; i < (num_hori_lines + 1); i++) {
400 y_label -= y_label_separation;
405 if (this->draw_dates) {
410 for (
int i = 0; i < this->num_on_x_axis; i++) {
411 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
421 GfxFillRect(x + x_sep, r.top + 1, x + x_sep, r.bottom - 1, GRAPH_YEAR_LINE_COLOUR);
429 uint16_t label = this->x_values_start;
431 for (
int i = 0; i < this->num_on_x_axis; i++) {
435 label += this->x_values_increment;
442 uint pointoffs1 = (linewidth + 1) / 2;
443 uint pointoffs2 = linewidth + 1 - pointoffs1;
444 for (
int i = 0; i < this->num_dataset; i++) {
445 if (!
HasBit(this->excluded_data, i)) {
447 x = r.left + (x_sep / 2);
449 uint8_t colour = this->colours[i];
450 uint prev_x = INVALID_DATAPOINT_POS;
451 uint prev_y = INVALID_DATAPOINT_POS;
453 for (
int j = 0; j < this->num_on_x_axis; j++) {
456 if (datapoint != INVALID_DATAPOINT) {
468 int mult_range = FindLastBit<uint32_t>(x_axis_offset) + FindLastBit<uint64_t>(
abs(datapoint));
469 int reduce_range = std::max(mult_range - 31, 0);
473 datapoint = -(
abs(datapoint) >> reduce_range);
475 datapoint >>= reduce_range;
477 y = r.top + x_axis_offset - ((r.bottom - r.top) * datapoint) / (interval_size >> reduce_range);
480 GfxFillRect(x - pointoffs1, y - pointoffs1, x + pointoffs2, y + pointoffs2, colour);
483 if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, colour, linewidth);
488 prev_x = INVALID_DATAPOINT_POS;
489 prev_y = INVALID_DATAPOINT_POS;
501 format_str_y_axis(format_str_y_axis)
505 this->month_increment = 3;
517 wid->SetDataTip(STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, STR_NULL);
528 uint x_label_width = 0;
531 if (this->draw_dates) {
533 TimerGameEconomy::Year year = this->year;
534 for (
int i = 0; i < this->num_on_x_axis; i++) {
535 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
537 x_label_width = std::max(x_label_width,
GetStringBoundingBox(month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH).
width);
557 size.height = std::max<uint>(size.height, size.width / 3);
560 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
569 return INVALID_DATAPOINT;
572 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
588 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
590 if (!gui_scope)
return;
600 CompanyMask excluded_companies = _legend_excluded_companies;
609 nums = std::min(this->num_vert_lines, std::max(nums, c->num_valid_stat_ent));
619 if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
620 this->year == yr && this->month == mo) {
625 this->excluded_data = excluded_companies;
626 this->num_on_x_axis = nums;
635 for (
int j = this->num_on_x_axis, i = 0; --j >= 0;) {
637 this->cost[numd][i] = INVALID_DATAPOINT;
641 this->cost[numd][i] = std::min(GetGraphData(c, j), INVALID_DATAPOINT - 1);
649 this->num_dataset = numd;
677 static constexpr
NWidgetPart _nested_operating_profit_widgets[] = {
691 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_EMPTY, STR_NULL),
700 WDP_AUTO,
"graph_operating_profit", 0, 0,
703 _nested_operating_profit_widgets
707 void ShowOperatingProfitGraph()
709 AllocateWindowDescFront<OperatingProfitGraphWindow>(_operating_profit_desc, 0);
736 static constexpr
NWidgetPart _nested_income_graph_widgets[] = {
750 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_EMPTY, STR_NULL),
762 _nested_income_graph_widgets
765 void ShowIncomeGraph()
767 AllocateWindowDescFront<IncomeGraphWindow>(_income_graph_desc, 0);
793 static constexpr
NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
807 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_EMPTY, STR_NULL),
815 static WindowDesc _delivered_cargo_graph_desc(
816 WDP_AUTO,
"graph_delivered_cargo", 0, 0,
819 _nested_delivered_cargo_graph_widgets
822 void ShowDeliveredCargoGraph()
824 AllocateWindowDescFront<DeliveredCargoGraphWindow>(_delivered_cargo_graph_desc, 0);
849 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
852 this->BaseGraphWindow::OnClick(pt, widget, click_count);
856 static constexpr
NWidgetPart _nested_performance_history_widgets[] = {
871 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_EMPTY, STR_NULL),
880 WDP_AUTO,
"graph_performance", 0, 0,
883 _nested_performance_history_widgets
886 void ShowPerformanceHistoryGraph()
888 AllocateWindowDescFront<PerformanceHistoryGraphWindow>(_performance_history_desc, 0);
914 static constexpr
NWidgetPart _nested_company_value_graph_widgets[] = {
928 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_EMPTY, STR_NULL),
937 WDP_AUTO,
"graph_company_value", 0, 0,
940 _nested_company_value_graph_widgets
943 void ShowCompanyValueGraph()
945 AllocateWindowDescFront<CompanyValueGraphWindow>(_company_value_graph_desc, 0);
960 this->num_on_x_axis = 20;
961 this->num_vert_lines = 20;
962 this->draw_dates =
false;
986 void UpdateExcludedData()
988 this->excluded_data = 0;
992 if (
HasBit(_legend_excluded_cargo_payment_rates, cs->Index()))
SetBit(this->excluded_data, i);
1000 BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill,
resize);
1015 this->line_height = size.height;
1016 size.height = this->line_height * 11;
1021 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1024 BaseGraphWindow::DrawWidget(r, widget);
1033 for (
auto it = first; it != last; ++it) {
1036 bool lowered = !
HasBit(_legend_excluded_cargo_payment_rates, cs->
Index());
1052 line = line.
Translate(0, this->line_height);
1056 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1061 _legend_excluded_cargo_payment_rates = 0;
1062 this->excluded_data = 0;
1070 SetBit(_legend_excluded_cargo_payment_rates, cs->
Index());
1071 SetBit(this->excluded_data, i);
1081 ToggleBit(_legend_excluded_cargo_payment_rates, (*it)->Index());
1082 this->UpdateExcludedData();
1105 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1107 if (!gui_scope)
return;
1121 this->UpdateExcludedData();
1125 this->colours[i] = cs->legend_colour;
1126 for (uint j = 0; j != this->num_on_x_axis; j++) {
1127 this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->
Index());
1131 this->num_dataset = i;
1135 static constexpr
NWidgetPart _nested_cargo_payment_rates_widgets[] = {
1146 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_HEADER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
1157 NWidget(
WWT_MATRIX, COLOUR_BROWN,
WID_GRAPH_MATRIX),
SetFill(1, 0),
SetResize(0, 2),
SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
SetScrollbar(
WID_GRAPH_MATRIX_SCROLLBAR),
1166 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_NULL, STR_NULL),
1174 WDP_AUTO,
"graph_cargo_payment_rates", 0, 0,
1177 _nested_cargo_payment_rates_widgets
1181 void ShowCargoPaymentRates()
1183 AllocateWindowDescFront<PaymentRatesGraphWindow>(_cargo_payment_rates_desc, 0);
1196 this->UpdateCompanyStats();
1202 void UpdateCompanyStats()
1213 uint score_info_left;
1214 uint score_info_right;
1219 uint score_detail_left;
1220 uint score_detail_right;
1229 uint score_info_width = 0;
1230 for (uint i = SCORE_BEGIN; i <
SCORE_END; i++) {
1245 int max = -(999999999 - 500);
1268 this->score_info_left = rtl ? right - score_info_width :
left;
1269 this->score_info_right = rtl ? right :
left + score_info_width;
1271 this->score_detail_left = rtl ?
left : right - score_detail_width;
1272 this->score_detail_right = rtl ?
left + score_detail_width : right;
1275 this->bar_right = this->bar_left + this->bar_width - 1;
1280 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1302 int64_t val = _score_part[company][score_type];
1312 uint bar_top =
CenterBounds(r.top, r.bottom, this->bar_height);
1315 DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
1319 DrawString(this->score_info_left, this->score_info_right, text_top, STR_JUST_COMMA, TC_BLACK,
SA_RIGHT);
1322 uint x = Clamp<int64_t>(val, 0, needed) * this->bar_width / needed;
1325 x = this->bar_right - x;
1327 x = this->bar_left + x;
1331 if (x != this->bar_left)
GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height - 1, rtl ? colour_notdone : colour_done);
1332 if (x != this->bar_right)
GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height - 1, rtl ? colour_done : colour_notdone);
1335 SetDParam(0, Clamp<int64_t>(val, 0, needed) * 100 / needed);
1336 DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING,
SA_HOR_CENTER);
1339 if (score_type == SCORE_LOAN) val = needed - val;
1345 switch (score_type) {
1346 case SCORE_MIN_PROFIT:
1347 case SCORE_MIN_INCOME:
1348 case SCORE_MAX_INCOME:
1351 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
1354 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
1358 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1375 if (--this->timeout == 0) {
1376 this->UpdateCompanyStats();
1386 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1388 if (!gui_scope)
return;
1403 this->company = c->index;
1431 this->month_increment = 1;
1441 for (
const auto &p : i->
produced) {
1462 void UpdateExcludedData()
1464 this->excluded_data = 0;
1468 for (
const auto &p : i->
produced) {
1470 if (
HasBit(_legend_excluded_cargo_production_history, p.cargo))
SetBit(this->excluded_data, index);
1478 BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill,
resize);
1484 for (
const auto &p : i->
produced) {
1496 this->line_height = size.height;
1497 size.height = this->line_height * 11;
1502 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1505 BaseGraphWindow::DrawWidget(r, widget);
1518 for (
const auto &p : i->
produced) {
1521 if (pos-- > 0)
continue;
1522 if (--max < 0)
break;
1526 bool lowered = !
HasBit(_legend_excluded_cargo_production_history, p.cargo);
1542 line = line.
Translate(0, this->line_height);
1546 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1551 _legend_excluded_cargo_production_history = 0;
1552 this->excluded_data = 0;
1560 for (
const auto &p : i->
produced) {
1563 SetBit(_legend_excluded_cargo_production_history, p.cargo);
1564 SetBit(this->excluded_data, index);
1573 if (row >= this->vscroll->
GetCount())
return;
1576 for (
const auto &p : i->
produced) {
1578 if (row-- > 0)
continue;
1580 ToggleBit(_legend_excluded_cargo_production_history, p.cargo);
1581 this->UpdateExcludedData();
1590 void SetStringParameters(
WidgetID widget)
const override
1603 this->UpdateExcludedData();
1612 if (!initialize && this->excluded_data == excluded_cargo && this->num_on_x_axis == this->num_vert_lines && this->year == yr && this->month == mo) {
1622 for (
const auto &p : i->
produced) {
1627 this->colours[index] = cs->legend_colour;
1634 this->num_dataset = index;
1641 static constexpr
NWidgetPart _nested_industry_production_widgets[] = {
1658 NWidget(
WWT_MATRIX, COLOUR_BROWN,
WID_GRAPH_MATRIX),
SetFill(1, 0),
SetResize(0, 2),
SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
SetScrollbar(
WID_GRAPH_MATRIX_SCROLLBAR),
1667 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_GRAPH_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_EMPTY, STR_NULL),
1675 WDP_AUTO,
"graph_industry_production", 0, 0,
1678 _nested_industry_production_widgets
1681 void ShowIndustryProductionGraph(
WindowNumber window_number)
1683 AllocateWindowDescFront<IndustryProductionGraphWindow>(_industry_production_desc, window_number);
1693 const StringID performance_tips[] = {
1694 realtime ? STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP_PERIODS : STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP_YEARS,
1695 STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
1696 realtime ? STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP_PERIODS : STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP_YEARS,
1697 STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
1698 STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
1699 STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
1700 STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
1701 STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
1702 STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
1703 STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
1708 auto vert = std::make_unique<NWidgetVertical>(
NC_EQUALSIZE);
1710 auto panel = std::make_unique<NWidgetBackground>(
WWT_PANEL, COLOUR_BROWN, widnum);
1711 panel->SetFill(1, 1);
1713 vert->Add(std::move(panel));
1724 static constexpr
NWidgetPart _nested_performance_rating_detail_widgets[] = {
1737 static WindowDesc _performance_rating_detail_desc(
1741 _nested_performance_rating_detail_widgets
1744 void ShowPerformanceRatingDetail()
1746 AllocateWindowDescFront<PerformanceRatingDetailWindow>(_performance_rating_detail_desc, 0);
1749 void InitializeGraphGui()
1751 _legend_excluded_companies = 0;
1752 _legend_excluded_cargo_payment_rates = 0;
1753 _legend_excluded_cargo_production_history = 0;
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Types/functions related to cargoes.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static Year year
Current year, starting at 0.
static Month month
Current month (0..11).
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
uint8_t Month
Type for the month, note: 0 based, i.e.
Definition of stuff that is very close to a company, like the company struct itself.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
GUI Functions related to companies.
Owner
Enum for all companies/owners.
@ INVALID_COMPANY
An invalid company.
@ COMPANY_FIRST
First company, same as owner.
@ MAX_COMPANIES
Maximum number of companies.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated,...
const ScoreInfo _score_info[]
Score info, values used for computing the detailed performance rating.
Functions related to the economy.
ScoreID
Score categories in the detailed performance rating.
@ SCORE_END
How many scores are there..
@ SCORE_MAX
The max score that can be in the performance history.
@ SCORE_TOTAL
This must always be the last entry.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Functions related to the gfx engine.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
@ SA_LEFT
Left align the text.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_HOR_CENTER
Horizontally center the text.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static std::unique_ptr< NWidgetBase > MakeNWidgetCompanyLines()
Construct a vertical list of buttons, one for each company.
constexpr double INT64_MAX_IN_DOUBLE
The biggest double that when cast to int64_t still fits in a int64_t.
static std::unique_ptr< NWidgetBase > MakePerformanceDetailPanels()
Make a vertical list of panels for outputting score details.
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsGraphGUI()
Make a number of rows with buttons for each company for the performance rating detail window.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
static const uint8_t PC_BLACK
Black palette colour.
#define GREY_SCALE(level)
Return the colour for a particular greyscale level.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
Get width for Y labels.
void OnGameTick() override
Called once per (game) tick.
static const int MIN_GRID_PIXEL_SIZE
Minimum distance between graph lines.
static const int GRAPH_NUM_MONTHS
Number of months displayed in the graph.
static const int ECONOMY_QUARTER_MINUTES
Minutes per economic quarter.
static const int ECONOMY_MONTH_MINUTES
Minutes per economic month.
uint64_t excluded_data
bitmask of the datasets that shouldn't be displayed.
bool draw_dates
Should we draw months and years on the time axis?
static const int MIN_GRAPH_NUM_LINES_Y
Minimal number of horizontal lines to draw.
uint8_t month_increment
month increment between vertical lines. must be divisor of 12.
static const int PAYMENT_GRAPH_X_STEP_DAYS
X-axis step label for cargo payment rates "Days in transit".
ValuesInterval GetValuesInterval(int num_hori_lines) const
Get the interval that contains the graph's data.
OverflowSafeInt64 cost[GRAPH_MAX_DATASETS][GRAPH_NUM_MONTHS]
Stored costs for the last GRAPH_NUM_MONTHS months.
virtual void UpdateStatistics(bool initialize)
Update the statistics.
static const TextColour GRAPH_AXIS_LABEL_COLOUR
colour of the graph axis label.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void DrawGraph(Rect r) const
Actually draw the graph.
static const int PAYMENT_GRAPH_X_STEP_SECONDS
X-axis step label for cargo payment rates "Seconds in transit".
const T GetSum() const
Get the sum of all cargo amounts.
Specification of a cargo type.
CargoID Index() const
Determines index of this cargospec.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
StringID name
Name of this type of cargo.
GUISettings gui
settings related to the GUI
Money income
The amount of income.
Money expenses
The amount of expenses.
Money company_value
The value of the company.
CargoArray delivered_cargo
The amount of delivered cargo.
int32_t performance_history
Company score (scale 0-1000)
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Colours colour
Company colour.
uint8_t num_valid_stat_ent
Number of valid statistical entries in old_economy.
uint16_t rate
The conversion rate compared to the base currency.
Dimensions (a width and height) of a rectangle in 2D.
uint8_t graph_line_thickness
the thickness of the lines in the various graph guis
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateStatistics(bool initialize) override
Update the statistics.
void OnResize() override
Called after the window got resized.
uint line_height
Pixel height of each cargo type row.
uint legend_width
Width of legend 'blob'.
void OnInit() override
Notification that the nested widget tree gets initialized.
Scrollbar * vscroll
Cargo list scrollbar.
Defines the internal data of a functional industry.
ProducedCargoes produced
produced cargo slots
uint line_height
Pixel height of each cargo type row.
void OnResize() override
Called after the window got resized.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnGameTick() override
Called once per (game) tick.
void UpdatePaymentRates()
Update the payment rates according to the latest information.
IntervalTimer< TimerWindow > update_payment_interval
Update the payment rates on a regular interval.
uint legend_width
Width of legend 'blob'.
Scrollbar * vscroll
Cargo list scrollbar.
Coordinates of a point in 2D.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
int needed
How much you need to get the perfect score.
int score
How much score it will give.
Templated helper to make a type-safe 'typedef' representing a single POD value.
Contains the interval of a graph's data.
OverflowSafeInt64 lowest
Lowest value of this interval. Must be zero or less.
OverflowSafeInt64 highest
Highest value of this interval. Must be zero or greater.
High level window description.
Data structure for an opened window.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
int left
x position of left edge of the window
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction)
int width
width of the window (number of pixels to the right in x direction)
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
WindowNumber window_number
Window number within the window class.
Definition of Interval and OneShot timers.
Definition of the game-economy-timer.
Definition of the tick-based game-timer.
Definition of the Window system.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ WC_PERFORMANCE_HISTORY
Performance history graph; Window numbers:
@ WC_PERFORMANCE_DETAIL
Performance detail window; Window numbers:
@ WC_PAYMENT_RATES
Payment rates graph; Window numbers:
@ WC_GRAPH_LEGEND
Legend for graphs; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_OPERATING_PROFIT
Operating profit graph; Window numbers:
@ WC_INDUSTRY_PRODUCTION
Industry production history graph; Window numbers:
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
@ WC_INCOME_GRAPH
Income graph; Window numbers:
@ WC_DELIVERED_CARGO
Delivered cargo graph; Window numbers:
@ WC_COMPANY_VALUE
Company value graph; Window numbers:
Functions related to zooming.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
@ ZOOM_LVL_NORMAL
The normal zoom level.