OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
50 #include "table/strings.h"
56 bool _ignore_restrictions;
103 if (
GB(callback, 0, 8) == 0xFF)
return;
104 if (callback < 0x400) {
115 if (callback == 0x400)
return;
116 if (callback == 0x401) {
120 if (callback < 0x400) {
127 if (callback >= 0x800 && callback < 0xC00) {
140 enum CargoSuffixInOut {
155 template <
typename TC,
typename TS>
158 static_assert(std::tuple_size_v<std::remove_reference_t<decltype(cargoes)>> <=
lengthof(suffixes));
162 for (uint j = 0; j <
lengthof(suffixes); j++) {
165 uint cargotype = local_id << 16 | use_input;
166 GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
168 suffixes[j].text.clear();
174 for (uint j = 0; j <
lengthof(suffixes); j++) {
175 suffixes[j].text.clear();
179 case CARGOSUFFIX_OUT:
214 uint cargotype = local_id << 16 | use_input;
216 }
else if (use_input == CARGOSUFFIX_IN) {
218 }
else if (use_input == CARGOSUFFIX_OUT) {
231 return (r != 0) ? r < 0 : (a < b);
267 static constexpr
NWidgetPart _nested_build_industry_widgets[] = {
278 SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
280 SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
284 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),
291 SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
299 WDP_AUTO,
"build_industry", 170, 212,
302 _nested_build_industry_widgets
308 std::vector<IndustryType>
list;
316 void UpdateAvailability()
341 this->list.push_back(ind);
346 if (this->selected_type ==
INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
348 this->UpdateAvailability();
350 this->vscroll->
SetCount(this->list.size());
372 std::string
MakeCargoListString(
const std::span<const CargoID> cargolist,
const std::span<const CargoSuffix> cargo_suffix,
StringID prefixstr)
const
374 assert(cargolist.size() == cargo_suffix.size());
376 std::string cargostring;
378 size_t firstcargo = 0;
380 for (
size_t j = 0; j < cargolist.size(); j++) {
389 cargostring +=
GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
395 cargostring =
GetString(prefixstr) + cargostring;
413 if (_game_mode != GM_EDITOR) {
425 this->legend.width = this->legend.height * 9 / 6;
437 for (
const auto &indtype : this->list) {
440 resize.height = std::max<uint>({this->legend.height, d.height, count.height}) + padding.height;
442 d.height = 5 *
resize.height;
449 int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
450 uint extra_lines_req = 0;
451 uint extra_lines_prd = 0;
452 uint extra_lines_newgrf = 0;
455 for (
const auto &indtype : this->list) {
463 if (strdim.width > max_minwidth) {
464 extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
465 strdim.width = max_minwidth;
471 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
473 if (strdim.width > max_minwidth) {
474 extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
475 strdim.width = max_minwidth;
481 extra_lines_newgrf = 4;
486 height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
488 size.width = d.width + padding.width;
496 d.width += padding.width;
497 d.height += padding.height;
504 void SetStringParameters(
WidgetID widget)
const override
510 if (_game_mode == GM_EDITOR) {
512 SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
518 SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
525 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
535 icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
536 icon.bottom = icon.top + this->legend.height - 1;
539 for (
auto it = first; it != last; ++it) {
540 IndustryType type = *it;
541 bool selected = this->selected_type == type;
551 text = text.
Translate(0, this->resize.step_height);
552 icon = icon.
Translate(0, this->resize.step_height);
567 if (_game_mode != GM_EDITOR) {
569 DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
582 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
589 if (callback_res > 0x400) {
593 if (str != STR_UNDEFINED) {
606 static void AskManyRandomIndustriesCallback(
Window *,
bool confirmed)
608 if (!confirmed)
return;
617 old_generating_world.Restore();
621 static void AskRemoveAllIndustriesCallback(
Window *,
bool confirmed)
623 if (!confirmed)
return;
637 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
641 assert(_game_mode == GM_EDITOR);
643 ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY,
nullptr, AskManyRandomIndustriesCallback);
648 assert(_game_mode == GM_EDITOR);
650 ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY,
nullptr, AskRemoveAllIndustriesCallback);
656 if (it != this->list.end()) {
657 this->selected_type = *it;
658 this->UpdateAvailability();
701 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
706 uint32_t seed = InteractiveRandom();
707 uint32_t layout_index = InteractiveRandomRange((uint32_t)indsp->
layouts.size());
709 if (_game_mode == GM_EDITOR) {
719 _ignore_restrictions =
true;
723 cur_company.Restore();
724 old_generating_world.Restore();
725 _ignore_restrictions =
false;
735 if (_game_mode == GM_EDITOR)
return;
739 this->UpdateAvailability();
740 if (
enabled != this->enabled) {
761 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
763 if (!gui_scope)
return;
770 void ShowBuildIndustryWindow()
777 static void UpdateIndustryProduction(
Industry *i);
779 static inline bool IsProductionAlterable(
const Industry *i)
782 bool has_prod = std::any_of(std::begin(is->production_rate), std::end(is->production_rate), [](
auto rate) { return rate != 0; });
820 this->clicked_button = 0;
843 const Rect r = this->GetWidget<NWidgetBase>(
WID_IV_INFO)->GetCurrentRect();
845 if (expected != r.bottom) {
846 this->info_height = expected - r.top + 1;
852 void DrawCargoIcon(
const Rect &r,
CargoID cid)
const
873 bool has_accept =
false;
876 DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
892 DrawCargoIcon(ir, a.cargo);
907 str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
914 str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
934 if (this->editable ==
EA_RATE) this->production_offset_y = ir.top;
938 DrawCargoIcon(ir, p.cargo);
944 SetDParam(1, p.history[LAST_MONTH].production);
949 if (this->editable ==
EA_RATE) {
951 p.rate > 0, p.rate < 255);
953 ir.top += line_height;
962 this->production_offset_y = ir.top;
967 ir.top += line_height;
974 if (callback_res > 0x400) {
978 if (message != STR_NULL && message != STR_UNDEFINED) {
992 if (!i->
text.empty()) {
995 ir.top =
DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
1002 void SetStringParameters(
WidgetID widget)
const override
1012 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1019 switch (this->editable) {
1027 if (pt.y >= this->production_offset_y) {
1029 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1048 switch (this->editable) {
1071 default: NOT_REACHED();
1074 UpdateIndustryProduction(i);
1077 this->clicked_line = line;
1078 this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1081 this->editbox_line = line;
1082 switch (this->editable) {
1093 default: NOT_REACHED();
1120 this->clicked_button = 0;
1134 void OnMouseWheel(
int wheel)
override
1141 void OnQueryTextFinished(std::optional<std::string> str)
override
1143 if (!str.has_value() || str->empty())
return;
1146 uint value = atoi(str->c_str());
1147 switch (this->editbox_line) {
1158 UpdateIndustryProduction(i);
1167 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1169 if (!gui_scope)
return;
1171 if (IsProductionAlterable(i)) {
1190 static void UpdateIndustryProduction(
Industry *i)
1228 WDP_AUTO,
"view_industry", 260, 120,
1234 void ShowIndustryViewWindow(
int industry)
1282 auto accepted_cargo = cargoes.first;
1283 auto produced_cargo = cargoes.second;
1285 bool accepted_cargo_matches;
1287 switch (accepted_cargo) {
1289 accepted_cargo_matches =
true;
1293 accepted_cargo_matches = !(*industry)->IsCargoAccepted();
1297 accepted_cargo_matches = (*industry)->IsCargoAccepted(accepted_cargo);
1301 bool produced_cargo_matches;
1303 switch (produced_cargo) {
1305 produced_cargo_matches =
true;
1309 produced_cargo_matches = !(*industry)->IsCargoProduced();
1313 produced_cargo_matches = (*industry)->IsCargoProduced(produced_cargo);
1317 return accepted_cargo_matches && produced_cargo_matches;
1335 static inline const StringID sorter_names[] = {
1338 STR_SORT_BY_PRODUCTION,
1339 STR_SORT_BY_TRANSPORTED,
1341 static const std::initializer_list<GUIIndustryList::SortFunction * const> sorter_funcs;
1343 GUIIndustryList industries{IndustryDirectoryWindow::produced_cargo_filter};
1349 static CargoID produced_cargo_filter;
1368 if (this->produced_cargo_filter_criteria != cid) {
1369 this->produced_cargo_filter_criteria = cid;
1385 if (this->accepted_cargo_filter_criteria != cid) {
1386 this->accepted_cargo_filter_criteria = cid;
1427 for (
const Industry *i : this->industries) {
1437 this->industries.clear();
1441 if (this->string_filter.
IsEmpty()) {
1442 this->industries.push_back(i);
1446 this->string_filter.
AddLine(i->GetCachedName());
1447 if (this->string_filter.
GetState()) this->industries.push_back(i);
1452 auto filter = std::make_pair(this->accepted_cargo_filter_criteria, this->produced_cargo_filter_criteria);
1454 this->industries.
Filter(filter);
1457 this->vscroll->
SetCount(this->industries.size());
1461 this->industries.
Sort();
1488 CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1491 int percentage = 0, produced_cargo_count = 0;
1492 for (
const auto &p : i->
produced) {
1495 if (transported != -1) {
1496 produced_cargo_count++;
1497 percentage += transported;
1499 if (produced_cargo_count == 0 && &p == &i->
produced.back() && percentage == 0) {
1502 }
else if (filter == p.cargo) {
1507 if (produced_cargo_count == 0)
return percentage;
1508 return percentage / produced_cargo_count;
1526 int r = it_a - it_b;
1535 uint prod_a = 0, prod_b = 0;
1537 for (
const auto &pa : a->
produced) {
1538 if (
IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
1540 for (
const auto &pb : b->
produced) {
1541 if (
IsValidCargoID(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
1544 if (
auto ita = a->
GetCargoProduced(filter); ita != std::end(a->
produced)) prod_a = ita->history[LAST_MONTH].production;
1545 if (
auto itb = b->
GetCargoProduced(filter); itb != std::end(b->
produced)) prod_b = itb->history[LAST_MONTH].production;
1547 int r = prod_a - prod_b;
1575 uint16_t production;
1579 CargoInfo(
CargoID cargo_id, uint16_t production, uint transported, std::string &&suffix) : cargo_id(cargo_id), production(production), transported(transported), suffix(std::move(suffix)) {}
1581 std::vector<CargoInfo> cargos;
1583 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1587 cargos.emplace_back(itp->cargo, itp->history[LAST_MONTH].production,
ToPercent8(itp->history[LAST_MONTH].PctTransported()), std::move(cargo_suffix.
text));
1595 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1596 if (a.production != b.production) return a.production > b.production;
1597 return a.transported > b.transported;
1603 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1604 if (a.transported != b.transported) return a.transported > b.transported;
1605 return a.production > b.production;
1614 auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](
const CargoInfo &ci) ->
bool {
1615 return ci.cargo_id == cid;
1617 if (filtered_ci != cargos.end()) {
1618 std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1623 for (
size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1624 CargoInfo &ci = cargos[j];
1625 SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1636 switch (cargos.size()) {
1637 case 0:
return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1638 case 1:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1639 case 2:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1640 case 3:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1641 default:
return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1652 this->industries.
SetListing(this->last_sorting);
1653 this->industries.
SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1666 this->last_sorting = this->industries.
GetListing();
1674 void SetStringParameters(
WidgetID widget)
const override
1683 SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.
SortType()]);
1687 SetDParam(0, this->GetCargoFilterLabel(this->accepted_cargo_filter_criteria));
1691 SetDParam(0, this->GetCargoFilterLabel(this->produced_cargo_filter_criteria));
1696 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1710 tmp_dpi.left += ir.left;
1711 tmp_dpi.top += ir.top;
1718 if (this->industries.empty()) {
1724 for (
auto it = first; it != last; ++it) {
1734 ir.top += this->resize.step_height;
1747 d.height += padding.height;
1754 d.width += padding.width;
1755 d.height += padding.height;
1762 resize.height = d.height;
1764 d.width += padding.width;
1765 d.height += padding.height;
1784 list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1790 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1803 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
1807 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
1812 if (it != this->industries.end()) {
1824 void OnDropdownSelect(
WidgetID widget,
int index)
override
1828 if (this->industries.
SortType() != index) {
1855 void OnEditboxChanged(
WidgetID wid)
override
1880 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1883 case IDIWD_FORCE_REBUILD:
1888 case IDIWD_PRODUCTION_CHANGE:
1911 static inline HotkeyList hotkeys {
"industrydirectory", {
1916 Listing IndustryDirectoryWindow::last_sorting = {
false, 0};
1919 const std::initializer_list<GUIIndustryList::SortFunction * const> IndustryDirectoryWindow::sorter_funcs = {
1920 &IndustryNameSorter,
1921 &IndustryTypeSorter,
1922 &IndustryProductionSorter,
1923 &IndustryTransportedCargoSorter
1931 WDP_AUTO,
"list_industries", 428, 190,
1935 &IndustryDirectoryWindow::hotkeys
1938 void ShowIndustryDirectory()
1958 SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1961 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1963 SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1970 WDP_AUTO,
"industry_cargoes", 300, 210,
2007 using Cargoes = uint16_t;
2049 this->u.industry.ind_type =
ind_type;
2050 std::fill(std::begin(this->u.industry.other_accepted), std::end(this->u.industry.other_accepted), INVALID_CARGO);
2051 std::fill(std::begin(this->u.industry.other_produced), std::end(this->u.industry.other_produced), INVALID_CARGO);
2067 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2068 if (
cargo == this->u.cargo.vertical_cargoes[i]) {
2073 if (column < 0)
return -1;
2076 assert(!
HasBit(this->u.cargo.supp_cargoes, column));
2077 SetBit(this->u.cargo.supp_cargoes, column);
2079 assert(!
HasBit(this->u.cargo.cust_cargoes, column));
2080 SetBit(this->u.cargo.cust_cargoes, column);
2093 return this->u.cargo.supp_cargoes != 0 || this->u.cargo.cust_cargoes != 0;
2104 assert(std::size(
cargoes) <= std::size(this->u.cargo.vertical_cargoes));
2106 this->u.cargo.num_cargoes =
static_cast<uint8_t
>(std::distance(std::begin(this->u.cargo.vertical_cargoes), insert));
2108 std::sort(std::begin(this->u.cargo.vertical_cargoes), insert, comparator);
2109 std::fill(insert, std::end(this->u.cargo.vertical_cargoes), INVALID_CARGO);
2110 this->u.cargo.top_end =
false;
2111 this->u.cargo.bottom_end =
false;
2112 this->u.cargo.supp_cargoes = 0;
2113 this->u.cargo.cust_cargoes = 0;
2124 assert(std::size(
cargoes) <= std::size(this->u.cargo_label.cargoes));
2125 auto insert = std::copy(std::begin(
cargoes), std::end(
cargoes), std::begin(this->u.cargo_label.cargoes));
2126 std::fill(insert, std::end(this->u.cargo_label.cargoes), INVALID_CARGO);
2137 this->u.header = textid;
2148 int n = this->u.cargo.num_cargoes;
2158 void Draw(
int xpos,
int ypos)
const
2160 switch (this->type) {
2181 int blob_left, blob_right;
2196 std::span<const CargoID> other_right, other_left;
2198 other_right = this->u.industry.other_accepted;
2199 other_left = this->u.industry.other_produced;
2201 other_right = this->u.industry.other_produced;
2202 other_left = this->u.industry.other_accepted;
2227 int colpos = cargo_base;
2228 for (
int i = 0; i < this->u.cargo.num_cargoes; i++) {
2240 Cargoes hor_left, hor_right;
2242 hor_left = this->u.cargo.cust_cargoes;
2243 hor_right = this->u.cargo.supp_cargoes;
2245 hor_left = this->u.cargo.supp_cargoes;
2246 hor_right = this->u.cargo.cust_cargoes;
2250 if (
HasBit(hor_left, i)) {
2254 for (; col > 0; col--) {
2261 if (
HasBit(hor_right, i)) {
2265 for (; col < this->u.cargo.num_cargoes - 1; col++) {
2308 for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2309 if (pt.x < cpos)
break;
2318 if (pt.y < vpos)
return INVALID_CARGO;
2326 if (
HasBit(this->u.cargo.supp_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2327 if (left !=
nullptr) {
2331 return INVALID_CARGO;
2333 if (col == this->u.cargo.num_cargoes) {
2334 if (
HasBit(this->u.cargo.cust_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2335 if (right !=
nullptr) {
2339 return INVALID_CARGO;
2346 if (
HasBit(this->u.cargo.supp_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2347 return INVALID_CARGO;
2350 if (
HasBit(this->u.cargo.cust_cargoes, row))
return this->u.cargo.vertical_cargoes[row];
2351 return INVALID_CARGO;
2366 if (pt.y < vpos)
return INVALID_CARGO;
2371 return this->u.cargo_label.cargoes[row];
2390 static_assert(
MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::produced_cargo)>);
2425 std::fill(std::begin(ind_fld->u.
industry.other_produced), std::end(ind_fld->u.
industry.other_produced), INVALID_CARGO);
2429 int other_count = 0;
2434 int col = cargo_fld->
ConnectCargo(indsp->produced_cargo[i],
true);
2435 if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2439 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2440 if (
HasBit(cargo_fld->u.
cargo.supp_cargoes, i)) ind_fld->u.
industry.other_produced[i] = others[--other_count];
2444 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2460 std::fill(std::begin(cargoes), std::end(cargoes), INVALID_CARGO);
2463 CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2466 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2467 int col = cargo_fld->
ConnectCargo(cargo_fld->u.
cargo.vertical_cargoes[i], !accepting);
2468 if (col >= 0) cargoes[col] = cargo_fld->u.
cargo.vertical_cargoes[i];
2484 std::fill(std::begin(ind_fld->u.
industry.other_accepted), std::end(ind_fld->u.
industry.other_accepted), INVALID_CARGO);
2488 int other_count = 0;
2494 if (col < 0) others[other_count++] = indsp->
accepts_cargo[i];
2498 for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2499 if (!
HasBit(cargo_fld->u.
cargo.cust_cargoes, i)) ind_fld->u.
industry.other_accepted[i] = others[--other_count];
2503 for (uint i = 0; i < cargo_fld->u.
cargo.num_cargoes; i++) {
2505 if (!hs.enabled)
continue;
2507 for (uint j = 0; j <
lengthof(hs.accepts_cargo); j++) {
2508 if (hs.cargo_acceptance[j] > 0 && cargo_fld->u.
cargo.vertical_cargoes[i] == hs.accepts_cargo[j]) {
2549 typedef std::vector<CargoesRow> Fields;
2599 this->ind_textsize.width = 0;
2600 this->ind_textsize.height = 0;
2604 if (!indsp->
enabled)
continue;
2609 d.width = std::max(d.width, this->ind_textsize.width);
2610 d.height = this->ind_textsize.height;
2614 this->cargo_textsize.width = 0;
2615 this->cargo_textsize.height = 0;
2617 if (!csp->IsValid())
continue;
2620 d =
maxdim(d, this->cargo_textsize);
2645 size.width = std::max(size.width, this->ind_textsize.width + padding.width);
2649 size.width = std::max(size.width, this->cargo_textsize.width + padding.width);
2654 void SetStringParameters(
WidgetID widget)
const override
2673 static bool HasCommonValidCargo(
const std::span<const CargoID> cargoes1,
const std::span<const CargoID> cargoes2)
2675 for (
const CargoID cid1 : cargoes1) {
2677 for (
const CargoID cid2 : cargoes2) {
2678 if (cid1 == cid2)
return true;
2691 for (
const CargoID cid : cargoes) {
2708 case LT_TEMPERATE: climate_mask =
HZ_TEMP;
break;
2711 case LT_TOYLAND: climate_mask =
HZ_TOYLND;
break;
2712 default: NOT_REACHED();
2714 for (
const CargoID cid : cargoes) {
2718 if (!hs.enabled || !(hs.building_availability & climate_mask))
continue;
2720 for (uint j = 0; j <
lengthof(hs.accepts_cargo); j++) {
2721 if (hs.cargo_acceptance[j] > 0 && cid == hs.accepts_cargo[j])
return true;
2738 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;
2791 assert(this->fields[row].columns[col].type ==
CFT_EMPTY);
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();
2908 auto cargoes = std::span(&cid, 1);
2913 int num_indrows = std::max(num_supp, num_cust);
2914 for (
int i = 0; i < num_indrows; i++) {
2915 CargoesRow &row = this->fields.emplace_back();
2923 this->fields[num_indrows].MakeCargoLabel(0,
false);
2930 if (!indsp->
enabled)
continue;
2933 this->
PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2938 this->
PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2943 if (houses_supply) {
2947 if (houses_accept) {
2953 this->vscroll->
SetCount(num_indrows);
2965 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
2967 if (!gui_scope)
return;
2977 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2993 for (
const auto &field : this->fields) {
2994 if (vpos + row_height >= 0) {
2995 int xpos = left_pos;
3004 while (col >= 0 && col <= last_column) {
3005 field.columns[col].Draw(xpos, vpos);
3011 if (vpos >=
height)
break;
3030 if (pt.y < vpos)
return false;
3033 if (row + 1 >= (
int)this->fields.size())
return false;
3038 if (pt.x < xpos)
return false;
3040 for (column = 0; column <= 5; column++) {
3042 if (pt.x < xpos +
width)
break;
3046 if (column > num_columns)
return false;
3053 fieldxy->x = num_columns - column;
3056 fieldxy->x = column;
3062 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
3069 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3070 switch (fld->
type) {
3076 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3077 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3110 lst.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
3123 if (!indsp->
enabled)
continue;
3124 lst.push_back(MakeDropDownListStringItem(indsp->
name, ind));
3135 void OnDropdownSelect(
WidgetID widget,
int index)
override
3137 if (index < 0)
return;
3150 bool OnTooltip([[maybe_unused]]
Point pt,
WidgetID widget, TooltipCloseCondition close_cond)
override
3157 const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3159 switch (fld->
type) {
3161 CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 :
nullptr;
3162 CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 :
nullptr;
3174 GuiShowTooltips(
this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond);
3184 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.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
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.
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
void MakeCargoLabel(const std::span< const CargoID > cargoes, bool left_align)
Make a field displaying cargo type names.
@ 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...
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static WindowDesc _build_industry_desc(WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, _nested_build_industry_widgets)
Window definition of the dynamic place industries gui.
@ 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.
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
uint8_t clicked_button
The button that has been clicked (to raise)
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 SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
static bool HousesCanSupply(const std::span< const CargoID > cargoes)
Can houses be used to supply one of the cargoes?
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.
@ ZOOM_OUT
Zoom out (get helicopter view).
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.
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
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.
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.
std::array< ProducedHistory, 2 > history
History of cargo produced and transported.
void OnResize() override
Called after the window got resized.
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 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.
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.
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
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...
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
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.
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.
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
Cargoes cust_cargoes
Cargoes in vertical_cargoes leaving to the right.
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.
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
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.
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Defines the internal data of a functional industry.
static bool HousesCanAccept(const std::span< const CargoID > cargoes)
Can houses be used as customers of the produced cargoes?
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.
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
@ TPE_MAIL
Cargo behaves mail-like for production.
uint8_t landscape
the landscape we're currently in
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.
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
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.
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.
uint8_t map_colour
colour used for the small map
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.
static bool HasCommonValidCargo(const std::span< const CargoID > cargoes1, const std::span< const CargoID > cargoes2)
Do the two sets of cargoes have a valid cargo in common?
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
High level window description.
AcceptedCargoes accepted
accepted cargo slots
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.
uint8_t prod_level
general production level
@ HZ_TOYLND
15 8000 can appear in toyland climate
@ ZOOM_IN
Zoom in (get more detailed view).
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.
static int CountMatchingProducingIndustries(const std::span< const CargoID > cargoes)
Count how many industries have produced cargoes in common with one of the supplied set.
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).
ProducedCargoes produced
produced cargo slots
ResizeInfo resize
Resize information.
Common return value for all commands.
TileArea location
Location of the industry.
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Editability editable
Mode for changing production.
SoundSettings sound
sound effect settings
int32_t WindowNumber
Number to differentiate different windows of the same class.
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.
@ OWNER_NONE
The tile has no ownership.
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)
std::string MakeCargoListString(const std::span< const CargoID > cargolist, const std::span< const CargoSuffix > cargo_suffix, StringID prefixstr) const
Build a string of cargo names with suffixes attached.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void OnResize() override
Called after the window got resized.
@ 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.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
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.
static int CountMatchingAcceptingIndustries(const std::span< const CargoID > cargoes)
Count how many industries have accepted cargoes in common with one of the supplied set.
@ 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.
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
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.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
@ 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.
bool(const const Industry * *, const std::pair< CargoID, CargoID > &) FilterFunction
Signature of filter function.
#define lengthof(array)
Return the length of an fixed size array.
@ 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?
ProducedCargoes::iterator GetCargoProduced(CargoID cargo)
Get produced cargo slot for a specific cargo type.
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).
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
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).
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
static int GetCargoTransportedPercentsIfValid(const Industry::ProducedCargo &p)
Returns percents of cargo transported if industry produces this cargo, else -1.
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.
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.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
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.
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.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
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.
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
@ IL_MULTIPLIER
Production multiplier.
bool left_align
Align all cargo texts to the left (else align to the right).
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
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.
Cargoes supp_cargoes
Cargoes in vertical_cargoes entering from the left.
uint8_t raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
static const uint8_t PC_YELLOW
Yellow palette colour.
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.
Dimension cargo_icon_size
Largest cargo icon dimension.
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.
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.
bool IsShaded() const
Is window shaded currently?
static WindowDesc _industry_directory_desc(WDP_AUTO, "list_industries", 428, 190, WC_INDUSTRY_DIRECTORY, WC_NONE, 0, _nested_industry_directory_widgets, &IndustryDirectoryWindow::hotkeys)
Window definition of the industry directory gui.
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
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
@ 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.
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
TileIndex tile
The base tile of the area.
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.
void ResetState()
Reset the matching state to process a new item.
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
void ShowDropDownMenu(Window *w, std::span< 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.
@ 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.
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
TownProductionEffect
Town effect when producing cargo.
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.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
static WindowDesc _industry_view_desc(WDP_AUTO, "view_industry", 260, 120, WC_INDUSTRY_VIEW, WC_NONE, 0, _nested_industry_view_widgets)
Window definition of the view industry gui.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
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.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
void MakeCargo(const std::span< const CargoID > cargoes)
Make a piece of cargo column.
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.
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
uint8_t SortType() const
Get the sorttype of the list.
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.
int width
width of the window (number of pixels to the right in x direction)
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 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.
Transfer storage of cargo suffix information.
uint8_t bottom_end
Stop at the bottom of the vertical cargoes.
@ HZ_TEMP
12 1000 can appear in temperate climate
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.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
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.
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.
std::array< CargoID, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
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.
static WindowDesc _industry_cargoes_desc(WDP_AUTO, "industry_cargoes", 300, 210, WC_INDUSTRY_CARGOES, WC_NONE, 0, _nested_industry_cargoes_widgets)
Window description for the industry cargoes window.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
StringID name
Displayed name of the industry.
@ SWS_OFF
Scroll wheel has no effect.
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.
void DrawWidgets() const
Paint all widgets of a window.
const struct GRFFile * grffile
grf file that introduced this entity
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).
Specification of a rectangle with absolute coordinates of all edges.
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
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.
@ IL_RATE2
Production rate of cargo 2.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
static bool CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
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 SETTING_BUTTON_HEIGHT
Height of setting buttons.
@ 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,.
GUISettings gui
settings related to the GUI
static Dimension cargo_line
Dimensions of cargo lines.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
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 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.