27 #include "table/strings.h" 34 static CompanyMask _legend_excluded_companies;
35 static CargoTypes _legend_excluded_cargo;
39 static const uint INVALID_DATAPOINT_POS = UINT_MAX;
68 DrawCompanyIcon(cid, rtl ? r.right - d.width - 2 : r.left + 2, r.top + (r.bottom - r.top - d.height) / 2);
96 if (!gui_scope)
return;
99 SetBit(_legend_excluded_companies, data);
119 panel->
SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP);
126 static const NWidgetPart _nested_graph_legend_widgets[] = {
147 _nested_graph_legend_widgets,
lengthof(_nested_graph_legend_widgets)
150 static void ShowGraphLegend()
152 AllocateWindowDescFront<GraphLegendWindow>(&_graph_legend_desc, 0);
167 static const int GRAPH_MAX_DATASETS = 64;
168 static const int GRAPH_AXIS_LINE_COLOUR =
PC_BLACK;
169 static const int GRAPH_NUM_MONTHS = 24;
171 static const int MIN_GRAPH_NUM_LINES_Y = 9;
172 static const int MIN_GRID_PIXEL_SIZE = 20;
187 uint16 x_values_start;
188 uint16 x_values_increment;
192 byte colours[GRAPH_MAX_DATASETS];
203 assert(num_hori_lines > 0);
206 current_interval.
highest = INT64_MIN;
207 current_interval.
lowest = INT64_MAX;
209 for (
int i = 0; i < this->num_dataset; i++) {
210 if (
HasBit(this->excluded_data, i))
continue;
211 for (
int j = 0; j < this->num_on_x_axis; j++) {
214 if (datapoint != INVALID_DATAPOINT) {
223 current_interval.
lowest = (11 * current_interval.
lowest) / 10;
226 double abs_lower = (current_interval.
lowest > 0) ? 0 : (
double)
abs(current_interval.
lowest);
227 double abs_higher = (current_interval.
highest < 0) ? 0 : (
double)current_interval.
highest;
232 if (abs_lower != 0 || abs_higher != 0) {
234 num_pos_grids = (int)floor(0.5 + num_hori_lines * abs_higher / (abs_higher + abs_lower));
237 if (num_pos_grids == 0 && abs_higher != 0) num_pos_grids++;
238 if (num_pos_grids == num_hori_lines && abs_lower != 0) num_pos_grids--;
241 int64 grid_size_higher = (abs_higher > 0) ? ((int64)abs_higher + num_pos_grids - 1) / num_pos_grids : 0;
242 int64 grid_size_lower = (abs_lower > 0) ? ((int64)abs_lower + num_hori_lines - num_pos_grids - 1) / (num_hori_lines - num_pos_grids) : 0;
243 grid_size =
max(grid_size_higher, grid_size_lower);
246 num_pos_grids = num_hori_lines / 2;
250 current_interval.
highest = num_pos_grids * grid_size;
251 current_interval.
lowest = -(num_hori_lines - num_pos_grids) * grid_size;
252 return current_interval;
263 int64 y_label = current_interval.
highest;
264 int64 y_label_separation = (current_interval.
highest - current_interval.
lowest) / num_hori_lines;
268 for (
int i = 0; i < (num_hori_lines + 1); i++) {
272 if (d.width > max_width) max_width = d.width;
274 y_label -= y_label_separation;
293 assert(this->num_vert_lines > 0);
305 int num_hori_lines = 160 / MIN_GRID_PIXEL_SIZE;
307 int resize = (r.bottom - r.top - 160) / (2 * MIN_GRID_PIXEL_SIZE);
308 if (resize > 0) num_hori_lines +=
resize;
310 interval = GetValuesInterval(num_hori_lines);
312 int label_width = GetYLabelWidth(interval, num_hori_lines);
314 r.left += label_width;
316 int x_sep = (r.right - r.left) / this->num_vert_lines;
317 int y_sep = (r.bottom - r.top) / num_hori_lines;
321 r.right = r.left + x_sep * this->num_vert_lines;
322 r.bottom = r.top + y_sep * num_hori_lines;
326 x_axis_offset = (int)((r.bottom - r.top) * (double)interval.
highest / (
double)interval_size);
333 for (
int i = 0; i < this->num_vert_lines; i++) {
341 for (
int i = 0; i < (num_hori_lines + 1); i++) {
342 GfxFillRect(r.left - 3, y, r.left - 1, y, GRAPH_AXIS_LINE_COLOUR);
348 GfxFillRect(r.left, r.top, r.left, r.bottom, GRAPH_AXIS_LINE_COLOUR);
351 y = x_axis_offset + r.top;
352 GfxFillRect(r.left, y, r.right, y, GRAPH_AXIS_LINE_COLOUR);
355 if (this->num_on_x_axis == 0)
return;
357 assert(this->num_on_x_axis > 0);
358 assert(this->num_dataset > 0);
361 int64 y_label = interval.
highest;
362 int64 y_label_separation =
abs(interval.
highest - interval.
lowest) / num_hori_lines;
366 for (
int i = 0; i < (num_hori_lines + 1); i++) {
369 DrawString(r.left - label_width - 4, r.left - 4, y, STR_GRAPH_Y_LABEL, graph_axis_label_colour,
SA_RIGHT);
371 y_label -= y_label_separation;
376 if (this->month != 0xFF) {
379 byte month = this->month;
380 Year year = this->year;
381 for (
int i = 0; i < this->num_on_x_axis; i++) {
382 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
383 SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2);
385 DrawStringMultiLine(x, x + x_sep, y, this->
height, month == 0 ? STR_GRAPH_X_LABEL_MONTH_YEAR : STR_GRAPH_X_LABEL_MONTH, graph_axis_label_colour);
398 uint16 label = this->x_values_start;
400 for (
int i = 0; i < this->num_on_x_axis; i++) {
404 label += this->x_values_increment;
411 uint pointoffs1 = (linewidth + 1) / 2;
412 uint pointoffs2 = linewidth + 1 - pointoffs1;
413 for (
int i = 0; i < this->num_dataset; i++) {
414 if (!
HasBit(this->excluded_data, i)) {
416 x = r.left + (x_sep / 2);
418 byte colour = this->colours[i];
419 uint prev_x = INVALID_DATAPOINT_POS;
420 uint prev_y = INVALID_DATAPOINT_POS;
422 for (
int j = 0; j < this->num_on_x_axis; j++) {
425 if (datapoint != INVALID_DATAPOINT) {
438 int reduce_range =
max(mult_range - 31, 0);
442 datapoint = -(
abs(datapoint) >> reduce_range);
444 datapoint >>= reduce_range;
446 y = r.top + x_axis_offset - ((r.bottom - r.top) * datapoint) / (interval_size >> reduce_range);
449 GfxFillRect(x - pointoffs1, y - pointoffs1, x + pointoffs2, y + pointoffs2, colour);
452 if (prev_x != INVALID_DATAPOINT_POS) GfxDrawLine(prev_x, prev_y, x, y, colour, linewidth);
457 prev_x = INVALID_DATAPOINT_POS;
458 prev_y = INVALID_DATAPOINT_POS;
470 format_str_y_axis(format_str_y_axis)
473 this->num_vert_lines = 24;
474 this->graph_widget = widget;
480 this->UpdateStatistics(
true);
488 if (widget != this->graph_widget)
return;
490 uint x_label_width = 0;
492 if (this->month != 0xFF) {
493 byte month = this->month;
494 Year year = this->year;
495 for (
int i = 0; i < this->num_on_x_axis; i++) {
496 SetDParam(0, month + STR_MONTH_ABBREV_JAN);
497 SetDParam(1, month + STR_MONTH_ABBREV_JAN + 2);
517 size->width = max<uint>(size->width, 5 + y_label_width + this->num_on_x_axis * (x_label_width + 5) + 9);
518 size->height = max<uint>(size->height, 5 + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->month != 0xFF ? 3 : 1)) *
FONT_HEIGHT_SMALL + 4);
519 size->height = max<uint>(size->height, size->width / 3);
524 if (widget != this->graph_widget)
return;
531 return INVALID_DATAPOINT;
542 this->UpdateStatistics(
false);
552 if (!gui_scope)
return;
553 this->UpdateStatistics(
true);
562 CompanyMask excluded_companies = _legend_excluded_companies;
581 if (!initialize && this->excluded_data == excluded_companies && this->num_on_x_axis == nums &&
582 this->year == yr && this->month == mo) {
587 this->excluded_data = excluded_companies;
588 this->num_on_x_axis = nums;
597 for (
int j = this->num_on_x_axis, i = 0; --j >= 0;) {
598 this->cost[numd][i] = (j >= c->
num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
605 this->num_dataset = numd;
618 this->InitializeWindow(window_number);
627 static const NWidgetPart _nested_operating_profit_widgets[] = {
648 WDP_AUTO,
"graph_operating_profit", 0, 0,
651 _nested_operating_profit_widgets,
lengthof(_nested_operating_profit_widgets)
655 void ShowOperatingProfitGraph()
657 AllocateWindowDescFront<OperatingProfitGraphWindow>(&_operating_profit_desc, 0);
669 this->InitializeWindow(window_number);
678 static const NWidgetPart _nested_income_graph_widgets[] = {
702 _nested_income_graph_widgets,
lengthof(_nested_income_graph_widgets)
705 void ShowIncomeGraph()
707 AllocateWindowDescFront<IncomeGraphWindow>(&_income_graph_desc, 0);
718 this->InitializeWindow(window_number);
727 static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
747 static WindowDesc _delivered_cargo_graph_desc(
748 WDP_AUTO,
"graph_delivered_cargo", 0, 0,
751 _nested_delivered_cargo_graph_widgets,
lengthof(_nested_delivered_cargo_graph_widgets)
754 void ShowDeliveredCargoGraph()
756 AllocateWindowDescFront<DeliveredCargoGraphWindow>(&_delivered_cargo_graph_desc, 0);
767 this->InitializeWindow(window_number);
782 static const NWidgetPart _nested_performance_history_widgets[] = {
804 WDP_AUTO,
"graph_performance", 0, 0,
807 _nested_performance_history_widgets,
lengthof(_nested_performance_history_widgets)
810 void ShowPerformanceHistoryGraph()
812 AllocateWindowDescFront<PerformanceHistoryGraphWindow>(&_performance_history_desc, 0);
823 this->InitializeWindow(window_number);
832 static const NWidgetPart _nested_company_value_graph_widgets[] = {
853 WDP_AUTO,
"graph_company_value", 0, 0,
856 _nested_company_value_graph_widgets,
lengthof(_nested_company_value_graph_widgets)
859 void ShowCompanyValueGraph()
861 AllocateWindowDescFront<CompanyValueGraphWindow>(&_company_value_graph_desc, 0);
875 this->num_on_x_axis = 20;
876 this->num_vert_lines = 20;
878 this->x_values_start = 10;
879 this->x_values_increment = 10;
891 void UpdateExcludedData()
893 this->excluded_data = 0;
920 this->line_height = size->height;
921 size->height = this->line_height * 11;
923 resize->height = this->line_height;
943 if (pos-- > 0)
continue;
944 if (--max < 0)
break;
946 bool lowered = !
HasBit(_legend_excluded_cargo, cs->
Index());
949 if (lowered)
DrawFrameRect(r.left, y, r.right, y + this->line_height - 1, COLOUR_ORANGE, lowered ?
FR_LOWERED : FR_NONE);
951 byte clk_dif = lowered ? 1 : 0;
955 GfxFillRect(rect_x + 1, y + 1 + clk_dif, rect_x + 7, y + 4 + clk_dif, cs->legend_colour);
957 DrawString(rtl ? r.left : x + 14 + clk_dif, (rtl ? r.right - 14 + clk_dif : r.right), y + clk_dif, STR_GRAPH_CARGO_PAYMENT_CARGO);
959 y += this->line_height;
968 _legend_excluded_cargo = 0;
969 this->excluded_data = 0;
979 SetBit(this->excluded_data, i);
988 if (row >= this->vscroll->
GetCount())
return;
992 if (row-- > 0)
continue;
995 this->UpdateExcludedData();
1021 if (!gui_scope)
return;
1027 this->UpdateExcludedData();
1032 this->colours[i] = cs->legend_colour;
1033 for (uint j = 0; j != 20; j++) {
1034 this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->
Index());
1038 this->num_dataset = i;
1042 static const NWidgetPart _nested_cargo_payment_rates_widgets[] = {
1053 NWidget(
WWT_TEXT, COLOUR_GREY,
WID_CPR_HEADER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_TITLE, STR_NULL),
1073 NWidget(
WWT_TEXT, COLOUR_GREY,
WID_CPR_FOOTER),
SetMinimalSize(0, 6),
SetPadding(2, 0, 2, 0),
SetDataTip(STR_GRAPH_CARGO_PAYMENT_RATES_X_LABEL, STR_NULL),
1081 WDP_AUTO,
"graph_cargo_payment_rates", 0, 0,
1084 _nested_cargo_payment_rates_widgets,
lengthof(_nested_cargo_payment_rates_widgets)
1088 void ShowCargoPaymentRates()
1090 AllocateWindowDescFront<PaymentRatesGraphWindow>(&_cargo_payment_rates_desc, 0);
1097 static const StringID _performance_titles[] = {
1098 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
1099 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ENGINEER,
1100 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
1101 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRAFFIC_MANAGER,
1102 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
1103 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TRANSPORT_COORDINATOR,
1104 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
1105 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_ROUTE_SUPERVISOR,
1106 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
1107 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_DIRECTOR,
1108 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
1109 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHIEF_EXECUTIVE,
1110 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
1111 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_CHAIRMAN,
1112 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_PRESIDENT,
1113 STR_COMPANY_LEAGUE_PERFORMANCE_TITLE_TYCOON,
1116 static inline StringID GetPerformanceTitleFromValue(uint value)
1118 return _performance_titles[
minu(value, 1000) >> 6];
1136 this->companies.clear();
1139 this->companies.push_back(c);
1142 this->companies.shrink_to_fit();
1162 this->BuildCompanyList();
1163 this->companies.
Sort(&PerformanceSorter);
1182 for (uint i = 0; i != this->companies.size(); i++) {
1183 const Company *c = this->companies[i];
1184 DrawString(ordinal_left, ordinal_right, y, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
1191 DrawString(text_left, text_right, y, STR_COMPANY_LEAGUE_COMPANY_NAME);
1192 y += this->line_height;
1200 this->ordinal_width = 0;
1204 this->ordinal_width += 5;
1206 uint widest_width = 0;
1207 uint widest_title = 0;
1208 for (uint i = 0; i <
lengthof(_performance_titles); i++) {
1210 if (width > widest_width) {
1212 widest_width =
width;
1217 this->icon_width = d.width + 2;
1223 SetDParam(2, _performance_titles[widest_title]);
1227 this->text_width = widest_width + 30;
1257 static const NWidgetPart _nested_company_league_widgets[] = {
1271 _nested_company_league_widgets,
lengthof(_nested_company_league_widgets)
1274 void ShowCompanyLeagueTable()
1276 AllocateWindowDescFront<CompanyLeagueWindow>(&_company_league_desc, 0);
1289 this->UpdateCompanyStats();
1295 void UpdateCompanyStats()
1306 uint score_info_left;
1307 uint score_info_right;
1312 uint score_detail_left;
1313 uint score_detail_right;
1322 uint score_info_width = 0;
1323 for (uint i = SCORE_BEGIN; i <
SCORE_END; i++) {
1338 int max = -(999999999 - 500);
1351 if (_currency->rate < 1000) max /= _currency->rate;
1356 size->width = 7 + score_info_width + 5 + this->bar_width + 5 + score_detail_width + 7;
1358 uint right = size->width - 7;
1361 this->score_info_left = rtl ? right - score_info_width :
left;
1362 this->score_info_right = rtl ? right : left + score_info_width;
1364 this->score_detail_left = rtl ?
left : right - score_detail_width;
1365 this->score_detail_right = rtl ? left + score_detail_width : right;
1367 this->bar_left = left + (rtl ? score_detail_width : score_info_width) + 5;
1368 this->bar_right = this->bar_left + this->bar_width;
1381 int offset = (cid == this->company) ? 1 : 0;
1383 DrawCompanyIcon(cid, (r.left + r.right - sprite_size.width) / 2 + offset, (r.top + r.bottom - sprite_size.height) / 2 + offset);
1396 int64 val = _score_part[company][score_type];
1407 uint text_top = bar_top + 2;
1409 DrawString(this->score_info_left, this->score_info_right, text_top, STR_PERFORMANCE_DETAIL_VEHICLES + score_type);
1413 DrawString(this->score_info_left, this->score_info_right, text_top, STR_BLACK_COMMA, TC_FROMSTRING,
SA_RIGHT);
1416 uint x = Clamp<int64>(val, 0, needed) * this->bar_width / needed;
1419 x = this->bar_right - x;
1421 x = this->bar_left + x;
1425 if (x != this->bar_left)
GfxFillRect(this->bar_left, bar_top, x, bar_top + this->bar_height, rtl ? colour_notdone : colour_done);
1426 if (x != this->bar_right)
GfxFillRect(x, bar_top, this->bar_right, bar_top + this->bar_height, rtl ? colour_done : colour_notdone);
1429 SetDParam(0, Clamp<int64>(val, 0, needed) * 100 / needed);
1430 DrawString(this->bar_left, this->bar_right, text_top, STR_PERFORMANCE_DETAIL_PERCENT, TC_FROMSTRING,
SA_HOR_CENTER);
1433 if (score_type == SCORE_LOAN) val = needed - val;
1439 switch (score_type) {
1440 case SCORE_MIN_PROFIT:
1441 case SCORE_MIN_INCOME:
1442 case SCORE_MAX_INCOME:
1445 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY);
1448 DrawString(this->score_detail_left, this->score_detail_right, text_top, STR_PERFORMANCE_DETAIL_AMOUNT_INT);
1469 if (--this->timeout == 0) {
1470 this->UpdateCompanyStats();
1482 if (!gui_scope)
return;
1497 this->company = c->index;
1517 const StringID performance_tips[] = {
1518 STR_PERFORMANCE_DETAIL_VEHICLES_TOOLTIP,
1519 STR_PERFORMANCE_DETAIL_STATIONS_TOOLTIP,
1520 STR_PERFORMANCE_DETAIL_MIN_PROFIT_TOOLTIP,
1521 STR_PERFORMANCE_DETAIL_MIN_INCOME_TOOLTIP,
1522 STR_PERFORMANCE_DETAIL_MAX_INCOME_TOOLTIP,
1523 STR_PERFORMANCE_DETAIL_DELIVERED_TOOLTIP,
1524 STR_PERFORMANCE_DETAIL_CARGO_TOOLTIP,
1525 STR_PERFORMANCE_DETAIL_MONEY_TOOLTIP,
1526 STR_PERFORMANCE_DETAIL_LOAN_TOOLTIP,
1527 STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
1549 static const NWidgetPart _nested_performance_rating_detail_widgets[] = {
1562 static WindowDesc _performance_rating_detail_desc(
1566 _nested_performance_rating_detail_widgets,
lengthof(_nested_performance_rating_detail_widgets)
1569 void ShowPerformanceRatingDetail()
1571 AllocateWindowDescFront<PerformanceRatingDetailWindow>(&_performance_rating_detail_desc, 0);
1574 void InitializeGraphGui()
1576 _legend_excluded_companies = 0;
1577 _legend_excluded_cargo = 0;
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
Base types for having sorted lists in GUIs.
List template of 'things' T to sort in a GUI.
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
const ScoreInfo _score_info[]
Score info, values used for computing the detailed performance rating.
static bool PerformanceSorter(const Company *const &c1, const Company *const &c2)
Sort the company league by performance history.
static uint minu(const uint a, const uint b)
Returns the minimum of two unsigned integers.
Horizontally center the text.
ResizeInfo resize
Resize information.
OverflowSafeInt64 lowest
Lowest value of this interval. Must be zero or less.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
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...
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
High level window description.
int left
x position of left edge of the window
void DrawWidgets() const
Paint all widgets of a window.
int32 performance_history
Company score (scale 0-1000)
Functions related to dates.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Functions to handle different currencies.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Offset at top to draw the frame rectangular area.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Maximal number of cargo types in a game.
NWidgetBase * MakeCompanyButtonRowsGraphGUI(int *biggest_index)
Make a number of rows with buttons for each company for the performance rating detail window...
Specification of a cargo type.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Tindex index
Index of this pool item.
This must always be the last entry.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
void OnPaint() override
The window must be repainted.
uint64 excluded_data
bitmask of the datasets that shouldn't be displayed.
Offset at top of a matrix cell.
Payment rates graph; Window numbers:
Company value graph; Window numbers:
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
void OnGameTick() override
Called once per (game) tick.
uint text_width
The width of the actual text.
uint8 graph_line_thickness
the thickness of the lines in the various graph guis
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
static T max(const T a, const T b)
Returns the maximum of two values.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Year _cur_year
Current year, starting at 0.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
static NWidgetBase * MakePerformanceDetailPanels(int *biggest_index)
Make a vertical list of panels for outputting score details.
StringID name
Name of this type of cargo.
bool NeedRebuild() const
Check if a rebuild is needed.
Functions, definitions and such used only by the GUI.
void ForceRebuild()
Force that a rebuild is needed.
Data structure for an opened window.
Income graph; Window numbers:
Money expenses
The amount of expenses.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
How many scores are there..
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void UpdateStatistics(bool initialize)
Update the statistics.
void OnResize() override
Called after the window got resized.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Functions related to the gfx engine.
ClientSettings _settings_client
The current settings for this game.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
ValuesInterval GetValuesInterval(int num_hori_lines) const
Get the interval that contains the graph's data.
int score
How much score it will give.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Operating profit graph; Window numbers:
Company league window; Window numbers:
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
GUI Functions related to companies.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
uint icon_width
The width of the company icon.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
OverflowSafeInt64 highest
Highest value of this interval. Must be zero or greater.
void OnHundredthTick() override
Called once every 100 (game) ticks.
Offset at bottom to draw the frame rectangular area.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
void DrawGraph(Rect r) const
Actually draw the graph.
#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var)
Loop header for iterating over 'real' cargoes, sorted by name.
bool Sort(SortFunction *compare)
Sort the list.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static const uint8 PC_BLACK
Black palette colour.
The max score that can be in the performance history.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
uint8 FindLastBit(uint64 x)
Search the last set bit in a 64 bit variable.
int line_height
Height of the text lines.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Performance detail window; Window numbers:
Month _cur_month
Current month (0..11)
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Contains the interval of a graph's data.
uint8 _sorted_standard_cargo_specs_size
Number of standard cargo specifications stored in the _sorted_cargo_specs array.
GUISettings gui
settings related to the GUI
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Scrollbar * vscroll
Cargo list scrollbar.
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
void OnGameTick() override
Called once per (game) tick.
uint ordinal_width
The width of the ordinal number.
First company, same as owner.
TextDirection _current_text_dir
Text direction of the currently selected language.
byte colour
Company colour.
Functions related to the economy.
CargoArray delivered_cargo
The amount of delivered cargo.
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated...
static T abs(const T a)
Returns the absolute value of (scalar) variable.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Maximum number of companies.
uint GetYLabelWidth(ValuesInterval current_interval, int num_hori_lines) const
Get width for Y labels.
Types/functions related to cargoes.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
CargoID Index() const
Determines index of this cargospec.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Index of the small font in the font tables.
static NWidgetBase * MakeNWidgetCompanyLines(int *biggest_index)
Construct a vertical list of buttons, one for each company.
Delivered cargo graph; Window numbers:
ScoreID
Score categories in the detailed performance rating.
Width of a resize box widget.
Offset at right to draw the frame rectangular area.
uint line_height
Pixel height of each cargo type row.
int width
width of the window (number of pixels to the right in x direction)
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
int needed
How much you need to get the perfect score.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
Money income
The amount of income.
Text is written right-to-left by default.
Right align the text (must be a single bit).
WindowNumber window_number
Window number within the window class.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Window functions not directly related to making/drawing windows.
Money company_value
The value of the company.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Find a place automatically.
void BuildCompanyList()
(Re)Build the company league list
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
Legend for graphs; Window numbers:
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
This file contains all sprite-related enums and defines.
const T GetSum() const
Get the sum of all cargo amounts.
Performance history graph; Window numbers:
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-...
int height
Height of the window (number of pixels down in y direction)
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
void OnGameTick() override
Called once per (game) tick.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.