|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
49 #include "table/strings.h"
55 bool _ignore_restrictions;
102 if (
GB(callback, 0, 8) == 0xFF)
return;
103 if (callback < 0x400) {
114 if (callback == 0x400)
return;
115 if (callback == 0x401) {
119 if (callback < 0x400) {
126 if (callback >= 0x800 && callback < 0xC00) {
139 enum CargoSuffixInOut {
154 template <
typename TC,
typename TS>
161 for (uint j = 0; j <
lengthof(suffixes); j++) {
164 uint cargotype = local_id << 16 | use_input;
165 GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
167 suffixes[j].text[0] =
'\0';
173 for (uint j = 0; j <
lengthof(suffixes); j++) {
174 suffixes[j].text[0] =
'\0';
178 case CARGOSUFFIX_OUT:
206 suffix.
text[0] =
'\0';
211 uint cargotype = local_id << 16 | use_input;
213 }
else if (use_input == CARGOSUFFIX_IN) {
214 if (slot < 3)
GetCargoSuffix(slot, cst, ind, ind_type, indspec, suffix);
215 }
else if (use_input == CARGOSUFFIX_OUT) {
216 if (slot < 2)
GetCargoSuffix(slot + 3, cst, ind, ind_type, indspec, suffix);
228 return (r != 0) ? r < 0 : (a < b);
264 static constexpr
NWidgetPart _nested_build_industry_widgets[] = {
275 SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
277 SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
281 NWidget(
WWT_MATRIX, COLOUR_DARK_GREEN,
WID_DPI_MATRIX_WIDGET),
SetMatrixDataTip(1, 0, STR_FUND_INDUSTRY_SELECTION_TOOLTIP),
SetFill(1, 0),
SetResize(1, 1),
SetScrollbar(
WID_DPI_SCROLLBAR),
288 SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
296 WDP_AUTO,
"build_industry", 170, 212,
299 std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets)
305 std::vector<IndustryType>
list;
313 void UpdateAvailability()
338 this->list.push_back(ind);
343 if (this->selected_type ==
INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
345 this->UpdateAvailability();
347 this->vscroll->
SetCount(this->list.size());
371 std::string cargostring;
375 for (
int j = 0; j < cargolistlen; j++) {
378 if (firstcargo < 0) {
384 cargostring +=
GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
390 cargostring =
GetString(prefixstr) + cargostring;
408 if (_game_mode != GM_EDITOR) {
420 this->legend.width = this->legend.height * 9 / 6;
430 for (
const auto &indtype : this->list) {
435 d.height = 5 *
resize->height;
442 int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
443 uint extra_lines_req = 0;
444 uint extra_lines_prd = 0;
445 uint extra_lines_newgrf = 0;
448 for (
const auto &indtype : this->list) {
456 if (strdim.width > max_minwidth) {
457 extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
458 strdim.width = max_minwidth;
464 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
466 if (strdim.width > max_minwidth) {
467 extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
468 strdim.width = max_minwidth;
474 extra_lines_newgrf = 4;
479 height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
481 size->width = d.width + padding.width;
489 d.width += padding.width;
490 d.height += padding.height;
497 void SetStringParameters(
WidgetID widget)
const override
503 if (_game_mode == GM_EDITOR) {
505 SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
511 SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
518 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
528 icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
529 icon.bottom = icon.top + this->legend.height - 1;
532 IndustryType type = this->list[i];
533 bool selected = this->selected_type == type;
543 text = text.
Translate(0, this->resize.step_height);
544 icon = icon.
Translate(0, this->resize.step_height);
559 if (_game_mode != GM_EDITOR) {
561 DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
574 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix,
lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
581 if (callback_res > 0x400) {
585 if (str != STR_UNDEFINED) {
598 static void AskManyRandomIndustriesCallback(
Window *,
bool confirmed)
600 if (!confirmed)
return;
609 old_generating_world.Restore();
613 static void AskRemoveAllIndustriesCallback(
Window *,
bool confirmed)
615 if (!confirmed)
return;
629 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
633 assert(_game_mode == GM_EDITOR);
635 ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY,
nullptr, AskManyRandomIndustriesCallback);
640 assert(_game_mode == GM_EDITOR);
642 ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY,
nullptr, AskRemoveAllIndustriesCallback);
648 if (it != this->list.end()) {
649 this->selected_type = *it;
650 this->UpdateAvailability();
693 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
698 uint32_t seed = InteractiveRandom();
699 uint32_t layout_index = InteractiveRandomRange((uint32_t)indsp->
layouts.size());
701 if (_game_mode == GM_EDITOR) {
711 _ignore_restrictions =
true;
715 cur_company.Restore();
716 old_generating_world.Restore();
717 _ignore_restrictions =
false;
727 if (_game_mode == GM_EDITOR)
return;
731 this->UpdateAvailability();
732 if (
enabled != this->enabled) {
753 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
755 if (!gui_scope)
return;
762 void ShowBuildIndustryWindow()
769 static void UpdateIndustryProduction(
Industry *i);
771 static inline bool IsProductionAlterable(
const Industry *i)
774 bool has_prod =
false;
775 for (
size_t j = 0; j <
lengthof(is->production_rate); j++) {
776 if (is->production_rate[j] != 0) {
817 this->clicked_button = 0;
839 const Rect r = this->GetWidget<NWidgetBase>(
WID_IV_INFO)->GetCurrentRect();
841 if (expected != r.bottom) {
842 this->info_height = expected - r.top + 1;
860 bool has_accept =
false;
863 DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
891 str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
898 str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
918 if (this->editable ==
EA_RATE) this->production_offset_y = ir.top;
926 SetDParam(1, p.history[LAST_MONTH].production);
931 if (this->editable ==
EA_RATE) {
933 p.rate > 0, p.rate < 255);
935 ir.top += line_height;
944 this->production_offset_y = ir.top;
949 ir.top += line_height;
956 if (callback_res > 0x400) {
960 if (message != STR_NULL && message != STR_UNDEFINED) {
974 if (!i->
text.empty()) {
977 ir.top =
DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
984 void SetStringParameters(
WidgetID widget)
const override
994 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1001 switch (this->editable) {
1009 if (pt.y >= this->production_offset_y) {
1011 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1030 switch (this->editable) {
1053 default: NOT_REACHED();
1056 UpdateIndustryProduction(i);
1059 this->clicked_line = line;
1060 this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1063 this->editbox_line = line;
1064 switch (this->editable) {
1075 default: NOT_REACHED();
1102 this->clicked_button = 0;
1116 void OnQueryTextFinished(
char *str)
override
1121 uint value = atoi(str);
1122 switch (this->editbox_line) {
1133 UpdateIndustryProduction(i);
1142 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1144 if (!gui_scope)
return;
1146 if (IsProductionAlterable(i)) {
1165 static void UpdateIndustryProduction(
Industry *i)
1203 WDP_AUTO,
"view_industry", 260, 120,
1209 void ShowIndustryViewWindow(
int industry)
1257 auto accepted_cargo = cargoes.first;
1258 auto produced_cargo = cargoes.second;
1260 bool accepted_cargo_matches;
1262 switch (accepted_cargo) {
1264 accepted_cargo_matches =
true;
1268 accepted_cargo_matches = !(*industry)->IsCargoAccepted();
1272 accepted_cargo_matches = (*industry)->IsCargoAccepted(accepted_cargo);
1276 bool produced_cargo_matches;
1278 switch (produced_cargo) {
1280 produced_cargo_matches =
true;
1284 produced_cargo_matches = !(*industry)->IsCargoProduced();
1288 produced_cargo_matches = (*industry)->IsCargoProduced(produced_cargo);
1292 return accepted_cargo_matches && produced_cargo_matches;
1310 static const StringID sorter_names[];
1313 GUIIndustryList industries{IndustryDirectoryWindow::produced_cargo_filter};
1319 static CargoID produced_cargo_filter;
1338 if (this->produced_cargo_filter_criteria != cid) {
1339 this->produced_cargo_filter_criteria = cid;
1355 if (this->accepted_cargo_filter_criteria != cid) {
1356 this->accepted_cargo_filter_criteria = cid;
1397 for (
const Industry *i : this->industries) {
1407 this->industries.clear();
1410 if (this->string_filter.
IsEmpty()) {
1411 this->industries.push_back(i);
1415 this->string_filter.
AddLine(i->GetCachedName());
1416 if (this->string_filter.
GetState()) this->industries.push_back(i);
1419 this->industries.shrink_to_fit();
1422 auto filter = std::make_pair(this->accepted_cargo_filter_criteria, this->produced_cargo_filter_criteria);
1424 this->industries.
Filter(filter);
1427 this->vscroll->
SetCount(this->industries.size());
1431 this->industries.
Sort();
1458 CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1461 int percentage = 0, produced_cargo_count = 0;
1462 for (
const auto &p : i->
produced) {
1465 if (transported != -1) {
1466 produced_cargo_count++;
1467 percentage += transported;
1469 if (produced_cargo_count == 0 && &p == &i->
produced.back() && percentage == 0) {
1472 }
else if (filter == p.cargo) {
1477 if (produced_cargo_count == 0)
return percentage;
1478 return percentage / produced_cargo_count;
1496 int r = it_a - it_b;
1505 uint prod_a = 0, prod_b = 0;
1507 for (
const auto &pa : a->
produced) {
1508 if (
IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
1510 for (
const auto &pb : b->
produced) {
1511 if (
IsValidCargoID(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
1514 if (
auto ita = a->
GetCargoProduced(filter); ita != std::end(a->
produced)) prod_a = ita->history[LAST_MONTH].production;
1515 if (
auto itb = b->
GetCargoProduced(filter); itb != std::end(b->
produced)) prod_b = itb->history[LAST_MONTH].production;
1517 int r = prod_a - prod_b;
1547 uint16_t production;
1551 std::vector<CargoInfo> cargos;
1553 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1556 cargos.push_back({ itp->cargo, itp->history[LAST_MONTH].production, cargo_suffix[itp - std::begin(i->
produced)].
text.c_str(),
ToPercent8(itp->history[LAST_MONTH].PctTransported()) });
1564 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1565 if (a.production != b.production) return a.production > b.production;
1566 return a.transported > b.transported;
1572 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1573 if (a.transported != b.transported) return a.transported > b.transported;
1574 return a.production > b.production;
1583 auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](
const CargoInfo &ci) ->
bool {
1584 return ci.cargo_id == cid;
1586 if (filtered_ci != cargos.end()) {
1587 std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1592 for (
size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1593 CargoInfo ci = cargos[j];
1594 SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1605 switch (cargos.size()) {
1606 case 0:
return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1607 case 1:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1608 case 2:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1609 case 3:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1610 default:
return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1621 this->industries.
SetListing(this->last_sorting);
1622 this->industries.
SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1635 this->last_sorting = this->industries.
GetListing();
1643 void SetStringParameters(
WidgetID widget)
const override
1647 SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.
SortType()]);
1651 SetDParam(0, this->GetCargoFilterLabel(this->accepted_cargo_filter_criteria));
1655 SetDParam(0, this->GetCargoFilterLabel(this->produced_cargo_filter_criteria));
1660 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1674 tmp_dpi.left += ir.left;
1675 tmp_dpi.top += ir.top;
1682 if (this->industries.empty()) {
1688 for (uint i = this->vscroll->
GetPosition(); i < this->industries.size(); i++) {
1698 ir.top += this->resize.step_height;
1712 d.height += padding.height;
1713 *size =
maxdim(*size, d);
1719 for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] !=
INVALID_STRING_ID; i++) {
1722 d.width += padding.width;
1723 d.height += padding.height;
1724 *size =
maxdim(*size, d);
1730 resize->height = d.height;
1732 d.width += padding.width;
1733 d.height += padding.height;
1734 *size =
maxdim(*size, d);
1752 list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false));
1758 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1771 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
1775 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
1780 if (it != this->industries.end()) {
1792 void OnDropdownSelect(
WidgetID widget,
int index)
override
1796 if (this->industries.
SortType() != index) {
1823 void OnEditboxChanged(
WidgetID wid)
override
1848 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1851 case IDIWD_FORCE_REBUILD:
1856 case IDIWD_PRODUCTION_CHANGE:
1879 static inline HotkeyList hotkeys {
"industrydirectory", {
1884 Listing IndustryDirectoryWindow::last_sorting = {
false, 0};
1888 &IndustryNameSorter,
1889 &IndustryTypeSorter,
1890 &IndustryProductionSorter,
1891 &IndustryTransportedCargoSorter
1895 const StringID IndustryDirectoryWindow::sorter_names[] = {
1898 STR_SORT_BY_PRODUCTION,
1899 STR_SORT_BY_TRANSPORTED,
1908 WDP_AUTO,
"list_industries", 428, 190,
1912 &IndustryDirectoryWindow::hotkeys
1915 void ShowIndustryDirectory()
1935 SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1938 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1940 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1947 WDP_AUTO,
"industry_cargoes", 300, 210,
2023 this->u.industry.ind_type =
ind_type;
2024 std::fill(std::begin(this->u.industry.other_accepted), std::end(this->u.industry.other_accepted), INVALID_CARGO);
2025 std::fill(std::begin(this->u.industry.other_produced), std::end(this->u.industry.other_produced), INVALID_CARGO);
2041 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2042 if (
cargo == this->u.cargo.vertical_cargoes[i]) {
2047 if (column < 0)
return -1;
2051 this->u.cargo.supp_cargoes[column] = column;
2054 this->u.cargo.cust_cargoes[column] = column;
2086 auto insert = std::begin(this->u.cargo.vertical_cargoes);
2087 for (uint i = 0; insert != std::end(this->u.cargo.vertical_cargoes) && i < length; i++) {
2093 this->u.cargo.num_cargoes = (count < 0) ? static_cast<uint8_t>(insert - std::begin(this->u.cargo.vertical_cargoes)) : count;
2095 std::sort(std::begin(this->u.cargo.vertical_cargoes), insert, comparator);
2096 std::fill(insert, std::end(this->u.cargo.vertical_cargoes), INVALID_CARGO);
2097 this->u.cargo.top_end =
top_end;
2099 std::fill(std::begin(this->u.cargo.supp_cargoes), std::end(this->u.cargo.supp_cargoes), INVALID_CARGO);
2100 std::fill(std::begin(this->u.cargo.cust_cargoes), std::end(this->u.cargo.cust_cargoes), INVALID_CARGO);
2113 for (i = 0; i <
MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] =
cargoes[i];
2114 for (; i <
MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
2125 this->u.header = textid;
2136 int n = this->u.cargo.num_cargoes;
2146 void Draw(
int xpos,
int ypos)
const
2148 switch (this->type) {
2169 int blob_left, blob_right;
2184 const CargoID *other_right, *other_left;
2186 other_right = this->u.industry.other_accepted;
2187 other_left = this->u.industry.other_produced;
2189 other_right = this->u.industry.other_produced;
2190 other_left = this->u.industry.other_accepted;
2215 int colpos = cargo_base;
2216 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2228 const CargoID *hor_left, *hor_right;
2230 hor_left = this->u.cargo.cust_cargoes;
2231 hor_right = this->u.cargo.supp_cargoes;
2233 hor_left = this->u.cargo.supp_cargoes;
2234 hor_right = this->u.cargo.cust_cargoes;
2239 int col = hor_left[i];
2242 for (; col > 0; col--) {
2250 int col = hor_right[i];
2253 for (; col < this->u.cargo.num_cargoes - 1; col++) {
2296 for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2297 if (pt.x < cpos)
break;
2306 if (pt.y < vpos)
return INVALID_CARGO;
2314 if (
IsValidCargoID(this->u.cargo.supp_cargoes[row]))
return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2315 if (left !=
nullptr) {
2319 return INVALID_CARGO;
2321 if (col == this->u.cargo.num_cargoes) {
2322 if (
IsValidCargoID(this->u.cargo.cust_cargoes[row]))
return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2323 if (right !=
nullptr) {
2327 return INVALID_CARGO;
2334 if (
IsValidCargoID(this->u.cargo.supp_cargoes[row]))
return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2335 return INVALID_CARGO;
2338 if (
IsValidCargoID(this->u.cargo.cust_cargoes[row]))
return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2339 return INVALID_CARGO;
2354 if (pt.y < vpos)
return INVALID_CARGO;
2359 return this->u.cargo_label.cargoes[row];
2413 std::fill(std::begin(ind_fld->u.
industry.other_produced), std::end(ind_fld->u.
industry.other_produced), INVALID_CARGO);
2417 int other_count = 0;
2422 int col = cargo_fld->
ConnectCargo(indsp->produced_cargo[i],
true);
2423 if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2427 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2432 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2448 std::fill(std::begin(cargoes), std::end(cargoes), INVALID_CARGO);
2451 CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2454 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2455 int col = cargo_fld->
ConnectCargo(cargo_fld->u.
cargo.vertical_cargoes[i], !accepting);
2456 if (col >= 0) cargoes[col] = cargo_fld->u.
cargo.vertical_cargoes[i];
2472 std::fill(std::begin(ind_fld->u.
industry.other_accepted), std::end(ind_fld->u.
industry.other_accepted), INVALID_CARGO);
2476 int other_count = 0;
2482 if (col < 0) others[other_count++] = indsp->
accepts_cargo[i];
2486 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2491 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2538 typedef std::vector<CargoesRow> Fields;
2588 this->ind_textsize.width = 0;
2589 this->ind_textsize.height = 0;
2593 if (!indsp->
enabled)
continue;
2598 d.width = std::max(d.width, this->ind_textsize.width);
2599 d.height = this->ind_textsize.height;
2603 this->cargo_textsize.width = 0;
2604 this->cargo_textsize.height = 0;
2606 if (!csp->IsValid())
continue;
2609 d =
maxdim(d, this->cargo_textsize);
2634 size->width = std::max(size->width, this->ind_textsize.width + padding.width);
2638 size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
2645 void SetStringParameters (
WidgetID widget)
const override
2668 while (length1 > 0) {
2670 for (uint i = 0; i < length2; i++)
if (*cargoes1 == cargoes2[i])
return true;
2686 for (uint i = 0; i < length; i++) {
2705 case LT_TEMPERATE: climate_mask =
HZ_TEMP;
break;
2708 case LT_TOYLAND: climate_mask =
HZ_TOYLND;
break;
2709 default: NOT_REACHED();
2711 for (uint i = 0; i < length; i++) {
2737 if (!indsp->
enabled)
continue;
2755 if (!indsp->
enabled)
continue;
2770 while (top < bottom && !this->
fields[
top].columns[column].HasConnection()) {
2771 this->fields[
top].columns[column].MakeEmpty(
CFT_EMPTY);
2774 this->fields[
top].columns[column].u.cargo.top_end =
true;
2776 while (bottom >
top && !this->fields[bottom].columns[column].HasConnection()) {
2777 this->fields[bottom].columns[column].MakeEmpty(
CFT_EMPTY);
2780 this->fields[bottom].columns[column].u.cargo.bottom_end =
true;
2792 this->fields[row].columns[col].MakeIndustry(it);
2794 this->fields[row].ConnectIndustryProduced(col);
2796 this->fields[row].ConnectIndustryAccepted(col);
2818 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2819 this->ind_cargo = displayed_it;
2823 this->fields.clear();
2824 CargoesRow &first_row = this->fields.emplace_back();
2837 int num_indrows = std::max(3, std::max(num_supp, num_cust));
2838 for (
int i = 0; i < num_indrows; i++) {
2839 CargoesRow &row = this->fields.emplace_back();
2847 int central_row = 1 + num_indrows / 2;
2848 this->fields[central_row].columns[2].MakeIndustry(displayed_it);
2849 this->fields[central_row].ConnectIndustryProduced(2);
2850 this->fields[central_row].ConnectIndustryAccepted(2);
2853 this->fields[central_row - 1].MakeCargoLabel(2,
true);
2854 this->fields[central_row + 1].MakeCargoLabel(2,
false);
2861 if (!indsp->
enabled)
continue;
2864 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2869 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2874 if (houses_supply) {
2878 if (houses_accept) {
2885 this->vscroll->
SetCount(num_indrows);
2896 this->GetWidget<NWidgetCore>(
WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2900 this->fields.clear();
2901 CargoesRow &first_row = this->fields.emplace_back();
2912 int num_indrows = std::max(num_supp, num_cust);
2913 for (
int i = 0; i < num_indrows; i++) {
2914 CargoesRow &row = this->fields.emplace_back();
2922 this->fields[num_indrows].MakeCargoLabel(0,
false);
2929 if (!indsp->
enabled)
continue;
2932 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2937 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2942 if (houses_supply) {
2946 if (houses_accept) {
2952 this->vscroll->
SetCount(num_indrows);
2964 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2966 if (!gui_scope)
return;
2976 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2992 for (
const auto &field : this->fields) {
2993 if (vpos + row_height >= 0) {
2994 int xpos = left_pos;
3003 while (col >= 0 && col <= last_column) {
3004 field.columns[col].Draw(xpos, vpos);
3010 if (vpos >=
height)
break;
3029 if (pt.y < vpos)
return false;
3032 if (row + 1 >= (
int)this->fields.size())
return false;
3037 if (pt.x < xpos)
return false;
3039 for (column = 0; column <= 5; column++) {
3041 if (pt.x < xpos +
width)
break;
3045 if (column > num_columns)
return false;
3052 fieldxy->x = num_columns - column;
3055 fieldxy->x = column;
3061 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
3068 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3069 switch (fld->
type) {
3075 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3076 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3109 lst.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false));
3122 if (!indsp->
enabled)
continue;
3123 lst.push_back(std::make_unique<DropDownListStringItem>(indsp->
name, ind,
false));
3134 void OnDropdownSelect(
WidgetID widget,
int index)
override
3136 if (index < 0)
return;
3149 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
3156 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3158 switch (fld->
type) {
3160 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3161 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3173 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond);
3183 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, 1);
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
@ ES_HANDLED
The passed event is handled.
static constexpr NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ TC_FORCED
Ignore colour changes from strings.
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
Count how many industries have produced cargoes in common with one of the supplied set.
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
static bool HousesCanAccept(const CargoID *cargoes, uint length)
Can houses be used as customers of the produced cargoes?
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
byte map_colour
colour used for the small map
@ TPE_MAIL
Cargo behaves mail-like for production.
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
@ CBM_IND_CARGO_SUFFIX
cargo sub-type display
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
uint8_t num_cargoes
Number of cargoes.
void MakeCargo(const CargoID *cargoes, uint length, int count=-1, bool top_end=false, bool bottom_end=false)
Make a piece of cargo column.
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
static bool HousesCanSupply(const CargoID *cargoes, uint length)
Can houses be used to supply one of the cargoes?
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
void OnInit() override
Notification that the nested widget tree gets initialized.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
List of hotkeys for a window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
void ComputeIndustryDisplay(IndustryType displayed_it)
Compute what and where to display for industry type it.
CargoID other_produced[MAX_CARGOES]
Cargoes produced but not used in this figure.
Dimensions (a width and height) of a rectangle in 2D.
@ ByType
Sorter type to sort by type.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
uint8_t top_end
Stop at the top of the vertical cargoes.
void SetFilterState(bool state)
Enable or disable the filter.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int production_offset_y
The offset of the production texts/buttons.
bool IsEmpty() const
Check whether any filter words were entered.
byte landscape
the landscape we're currently in
Class to backup a specific variable and restore it later.
void BuildSortIndustriesList()
(Re)Build industries list
void SetFilterTerm(const char *str)
Set the term to filter on.
Dimension ind_textsize
Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
void OnResize() override
Called after the window got resized.
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
std::array< ProducedHistory, 2 > history
History of cargo produced and transported.
void OnResize() override
Called after the window got resized.
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
@ PRODLEVEL_CLOSURE
signal set to actually close the industry
Money GetConstructionCost() const
Get the cost for constructing this industry.
@ CSD_CARGO
Display the cargo without sub-type (cb37 result 401).
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ EA_MULTIPLIER
Allow changing the production multiplier.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
List template of 'things' T to sort in a GUI.
static const uint8_t PC_WHITE
White palette colour.
ViewportData * viewport
Pointer to viewport data, if present.
A single row of CargoesField.
void SetAcceptedCargoFilter(CargoID cid)
Set accepted cargo filter for the industry list.
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ ByName
Sorter type to sort by name.
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static Dimension cargo_stub
Dimensions of cargo stub (unconnected cargo line.)
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
IntervalTimer< TimerWindow > rebuild_interval
Rebuild the industry list on a regular interval.
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
void PlaceIndustry(int row, int col, IndustryType it)
Place an industry in the fields.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
void SortIndustryTypes()
Initialize the list of sorted industry types.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
void ShortenCargoColumn(int column, int top, int bottom)
Shorten the cargo column to just the part between industries.
@ CST_DIR
Industry-directory window.
static Dimension legend
Dimension of the legend blob.
Cheat setup_prod
setup raw-material production in game
bool enabled
Availability state of the selected industry.
bool _ctrl_pressed
Is Ctrl pressed?
@ SND_15_BEEP
19 == 0x13 GUI button click
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
static const uint TILE_SIZE
Tile size in world coordinates.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
ProducedCargoArray produced
INDUSTRY_NUM_OUTPUTS production cargo slots.
void RecomputeProductionMultipliers()
Recompute #production_rate for current prod_level.
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
ClientSettings _settings_client
The current settings for this game.
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
ProducedCargoArray::iterator GetCargoProduced(CargoID cargo)
Get produced cargo slot for a specific cargo type.
Specification of a cargo type.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
@ SA_RIGHT
Right align the text (must be a single bit).
static void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
Gets all strings to display after the cargoes of industries (using callback 37)
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
static WindowDesc _industry_view_desc(__FILE__, __LINE__, WDP_AUTO, "view_industry", 260, 120, WC_INDUSTRY_VIEW, WC_NONE, 0, std::begin(_nested_industry_view_widgets), std::end(_nested_industry_view_widgets))
Window definition of the view industry gui.
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Defines the internal data of a functional industry.
uint GetIndustryListWidth() const
Get the width needed to draw the longest industry line.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
@ CFT_INDUSTRY
Display industry.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
StringID GetErrorMessage() const
Returns the error message of a command.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by transported cargo and name.
static bool CDECL CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
bool NeedRebuild() const
Check if a rebuild is needed.
@ CBM_IND_FUND_MORE_TEXT
additional text in fund window
Data stored about a string that can be modified in the GUI.
@ ByProduction
Sorter type to sort by production amount.
CargoesFieldType type
Type of field.
void OnTimeout() override
Called when this window's timeout has been reached.
bool Succeeded() const
Did this command succeed?
int GetCargoBase(int xpos) const
For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.
char *const buf
buffer in which text is saved
@ CBID_INDUSTRY_FUND_MORE_TEXT
Called to determine more text in the fund industry window.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
void CcBuildIndustry(Commands, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32_t, bool, uint32_t)
Command callback.
void OnInit() override
Notification that the nested widget tree gets initialized.
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
High level window description.
std::vector< IndustryType > list
List of industries.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
@ CFT_CARGO
Display cargo connections.
const int MAX_FILTER_LENGTH
The max length of the filter, in chars.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
void OnResize() override
Called after the window got resized.
CargoID CargoLabelClickedAt(Point pt) const
Decide what cargo the user clicked in the cargo label field.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
CargoSuffixDisplay
Ways of displaying the cargo.
Window displaying the cargo connections around an industry (or cargo).
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
@ WDP_AUTO
Find a place automatically.
Data structure describing how to show the list (what sort direction and criteria).
ResizeInfo resize
Resize information.
Common return value for all commands.
TileArea location
Location of the industry.
static WindowDesc _build_industry_desc(__FILE__, __LINE__, WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets))
Window definition of the dynamic place industries gui.
Editability editable
Mode for changing production.
SoundSettings sound
sound effect settings
int32_t WindowNumber
Number to differentiate different windows of the same class.
static const HouseID NUM_HOUSES
Total number of houses.
void OnInit() override
Notification that the nested widget tree gets initialized.
@ FS_NORMAL
Index of the normal font in the font tables.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
struct CargoesField::@5::@8 cargo_label
Label data (for CFT_CARGO_LABEL).
void MakeCargoLabel(int column, bool accepting)
Construct a CFT_CARGO_LABEL field.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
static int vert_inter_industry_space
Amount of space between two industries in a column.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
IndustryType type
type of industry.
int height
Height of the window (number of pixels down in y direction)
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void OnResize() override
Called after the window got resized.
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
void OnPaint() override
The window must be repainted.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
@ FS_SMALL
Index of the small font in the font tables.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
static int industry_width
Width of an industry field.
Cheats _cheats
All the cheats.
@ HZ_TEMP
12 1000 can appear in temperate climate
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
void OnTimeout() override
Called when this window's timeout has been reached.
ClearGround GetRawClearGround(Tile t)
Get the type of clear tile but never return CLEAR_SNOW.
Data about a single field in the IndustryCargoesWindow panel.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
CargoID cargoes[MAX_CARGOES]
Cargoes to display (or #INVALID_CARGO).
CargoSuffixDisplay display
How to display the cargo and text.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
void OnPaint() override
The window must be repainted.
struct CargoesField::@5::@6 industry
Industry data (for CFT_INDUSTRY).
StringID GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
AcceptedCargoArray accepted
INDUSTRY_NUM_INPUTS input cargo slots.
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
static uint max_cargoes
Largest number of cargoes actually on any industry.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
bool IsDescSortOrder() const
Check if the sort order is descending.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ PRODLEVEL_MAXIMUM
the industry is running at full speed
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
@ CST_VIEW
View-industry window.
WindowFlags flags
Window flags.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Dimension legend
Dimension of the legend 'blob'.
static constexpr NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
void SetProducedCargoFilter(CargoID cid)
Set produced cargo filter for the industry list.
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
bool _networking
are we in networking mode?
StringID header
Header text (for CFT_HEADER).
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
CargoID accepted_cargo_filter_criteria
Selected accepted cargo filter index.
@ ByTransported
Sorter type to sort by transported percentage.
@ CBID_INDUSTRY_CARGO_SUFFIX
Called to determine text to display after cargo name.
bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
Calculate in which field was clicked, and within the field, at what position.
Coordinates of a point in 2D.
@ CFT_SMALL_EMPTY
Empty small field (for the header).
static int GetCargoTransportedPercentsIfValid(const Industry::ProducedCargo &p)
Returns percents of cargo transported if industry produces this cargo, else -1.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
void Draw(int xpos, int ypos) const
Draw the field.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Editability
Modes for changing production.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
WindowNumber window_number
Window number within the window class.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
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.
static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
Gets the string to display after the cargo name (using callback 37)
Defines the data structure for constructing industry.
bool value
tells if the bool cheat is active or not
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ CFT_CARGO_LABEL
Display cargo labels.
static int normal_height
Height of the non-header rows.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
std::string text
General text with additional information.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
static int small_height
Height of the header row.
@ IACT_USERCREATION
from the Fund/build window
@ SA_HOR_CENTER
Horizontally center the text.
TileIndex GetCenterTile() const
Get the center tile.
byte cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
static Dimension cargo_space
Dimensions of space between cargo lines.
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
@ EA_RATE
Allow changing the production rates.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
bool _generating_world
Whether we are generating the map or not.
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b, const CargoID &)
Sort industries by name.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
CargoID produced_cargo_filter_criteria
Selected produced cargo filter index.
void ForceRebuild()
Force that a rebuild is needed.
@ IL_MULTIPLIER
Production multiplier.
bool left_align
Align all cargo texts to the left (else align to the right).
std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
Build a string of cargo names with suffixes attached.
bool enabled
entity still available (by default true).newgrf can disable it, though
int cheat_line_height
Height of each line for the WID_IV_INFO panel.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint8_t raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
static const uint8_t PC_YELLOW
Yellow palette colour.
CargoID cust_cargoes[MAX_CARGOES]
Cargoes leaving to the right (index in vertical_cargoes, or #INVALID_CARGO).
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
@ SBS_DOWN
Sort ascending.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
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.
CompanyID _current_company
Company currently doing an action.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
TownProductionEffect town_production_effect
The effect on town cargo production.
@ IL_RATE1
Production rate of cargo 1.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
CargoesField columns[5]
One row of fields.
@ CSD_CARGO_AMOUNT_TEXT
Display then cargo, amount, and string (cb37 result 000-3FF).
void MakeHeader(StringID textid)
Make a header above an industry column.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
bool IsShaded() const
Is window shaded currently?
Listing GetListing() const
Export current sort conditions.
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
static size_t GetNumItems()
Returns number of valid items in the pool.
InfoLine editbox_line
The line clicked to open the edit box.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
@ CST_FUND
Fund-industry window.
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
static debug_inline uint Size()
Get the size of the map.
CargoesFieldType
Available types of field.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
IndustryType selected_type
industry corresponding to the above index
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
TileIndex tile
The base tile of the area.
#define endof(x)
Get the end element of an fixed size array.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
void ResetState()
Reset the matching state to process a new item.
@ OWNER_NONE
The tile has no ownership.
static int cargo_field_width
Width of a cargo field.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
void ShowSmallMap()
Show the smallmap window.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
GRFFileProps grf_prop
properties related to the grf file
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
EventState
State of handling an event.
@ HT_RECT
rectangle (stations, depots, ...)
InfoLine clicked_line
The line of the button that has been clicked.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by type and name.
bool GetState() const
Get the matching state of the current item.
InfoLine
Specific lines in the info panel.
HouseZones building_availability
where can it be built (climates, zones)
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
StringID name
Name of this type of cargo.
@ CBM_IND_WINDOW_MORE_TEXT
additional text in industry window
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const uint8_t PC_BLACK
Black palette colour.
static const int ACTION_CLEAR
Clear editbox.
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
int top
y position of top edge of the window
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
@ SA_LEFT
Left align the text.
TownProductionEffect
Town effect when producing cargo.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
uint8_t SortType() const
Get the sorttype of the list.
static bool HasCommonValidCargo(const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
Do the two sets of cargoes have a valid cargo in common?
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
bool click_beep
Beep on a random selection of buttons.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
@ HZ_TOYLND
15 8000 can appear in toyland climate
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Comparator to sort CargoID by according to desired order.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
bool CDECL FilterFunction(const const Industry * *, const std::pair< CargoID, CargoID > &)
Signature of filter function.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Transfer storage of cargo suffix information.
uint8_t bottom_end
Stop at the bottom of the vertical cargoes.
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.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
static int blob_distance
Distance of the industry legend colour from the edge of the industry box.
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
static void SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode=false)
Clear temporary changes made since the last call to SwitchMode, and set whether subsequent changes sh...
@ CBID_INDUSTRY_WINDOW_MORE_TEXT
Called to determine more text in the industry window.
void OnInit() override
Notification that the nested widget tree gets initialized.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
static WindowDesc _industry_directory_desc(__FILE__, __LINE__, WDP_AUTO, "list_industries", 428, 190, WC_INDUSTRY_DIRECTORY, WC_NONE, 0, std::begin(_nested_industry_directory_widgets), std::end(_nested_industry_directory_widgets), &IndustryDirectoryWindow::hotkeys)
Window definition of the industry directory gui.
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by production and name.
void SetButtons()
Update status of the fund and display-chain widgets.
StringFilter string_filter
Filter for industries.
ConstructionSettings construction
construction of things in-game
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
CargoSuffixType
Cargo suffix type (for which window is it requested)
Data structure for an opened window.
Commands
List of commands.
byte clicked_button
The button that has been clicked (to raise)
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
StringID name
Displayed name of the industry.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
int DrawInfo(const Rect &r)
Draw the text in the WID_IV_INFO panel.
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
void DrawWidgets() const
Paint all widgets of a window.
const struct GRFFile * grffile
grf file that introduced this entity
byte prod_level
general production level
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
CargoesFieldType type
Type of field.
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
void RaiseWidgetWhenLowered(byte widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Specification of a rectangle with absolute coordinates of all edges.
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
CargoID supp_cargoes[MAX_CARGOES]
Cargoes entering from the left (index in vertical_cargoes, or #INVALID_CARGO).
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
Decide which cargo was clicked at in a CFT_CARGO field.
bool Sort(Comp compare)
Sort the list.
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
@ IL_RATE2
Production rate of cargo 2.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
std::string text
Cargo suffix text.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
static const int MAX_MINWIDTH_LINEHEIGHTS
The largest allowed minimum-width of the window, given in line heights.
@ WC_SMALLMAP
Small map; Window numbers:
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
Count how many industries have accepted cargoes in common with one of the supplied set.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
Fields fields
Fields to display in the WID_IC_PANEL.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
@ CSD_CARGO_AMOUNT
Display the cargo and amount (if useful), but no sub-type (cb37 result 400 or fail).
int info_height
Height needed for the WID_IV_INFO panel.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ IDHK_FOCUS_FILTER_BOX
Focus the filter box.
struct CargoesField::@5::@7 cargo
Cargo data (for CFT_CARGO).
void GenerateIndustries()
This function will create random industries during game creation.
QueryString industry_editbox
Filter editbox.
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
Build (fund or prospect) a new industry,.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
static Dimension cargo_line
Dimensions of cargo lines.
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Data about how and where to blit pixels.
bool persistent_buildingtools
keep the building tools active after usage
void SetListing(Listing l)
Import sort conditions.
All data for a single hotkey.
IndustryDirectoryHotkeys
Enum referring to the Hotkeys in the industry directory window.
static WindowDesc _industry_cargoes_desc(__FILE__, __LINE__, WDP_AUTO, "industry_cargoes", 300, 210, WC_INDUSTRY_CARGOES, WC_NONE, 0, std::begin(_nested_industry_cargoes_widgets), std::end(_nested_industry_cargoes_widgets))
Window description for the industry cargoes window.
static constexpr NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.