55#include "table/strings.h"
61bool _ignore_industry_restrictions;
104 std::array<int32_t, 16> regs100;
109 if (
GB(callback, 0, 8) == 0xFF)
return;
110 if (callback < 0x400) {
136 if (callback < 0x400) {
141 if (callback >= 0x800 && callback < 0xC00) {
168template <
typename TC,
typename TS>
171 static_assert(std::tuple_size_v<std::remove_reference_t<
decltype(cargoes)>> <=
lengthof(suffixes));
175 for (uint j = 0; j <
lengthof(suffixes); j++) {
179 GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
181 suffixes[j].text.clear();
187 for (uint j = 0; j <
lengthof(suffixes); j++) {
188 suffixes[j].text.clear();
244 return (r != 0) ? r < 0 : (a < b);
261static constexpr std::initializer_list<NWidgetPart> _nested_build_industry_widgets = {
272 SetStringTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
274 SetStringTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
278 NWidget(
WWT_MATRIX,
Colours::DarkGreen,
WID_DPI_MATRIX_WIDGET),
SetMatrixDataTip(1, 0, STR_FUND_INDUSTRY_SELECTION_TOOLTIP),
SetFill(1, 0),
SetResize(1, 1),
SetScrollbar(
WID_DPI_SCROLLBAR),
285 SetStringTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
294 WindowClass::BuildIndustry, WindowClass::None,
296 _nested_build_industry_widgets
300class BuildIndustryWindow :
public Window {
302 std::vector<IndustryType>
list{};
311 void UpdateAvailability()
332 if (this->selected_type == ind) this->selected_type = IT_INVALID;
336 this->
list.push_back(ind);
343 this->UpdateAvailability();
345 this->vscroll->SetCount(this->
list.size());
366 std::string
MakeCargoListString(
const std::span<const CargoType> cargolist,
const std::span<const CargoSuffix> cargo_suffix,
StringID prefixstr)
const
368 assert(cargolist.size() == cargo_suffix.size());
370 std::string cargostring;
373 for (
size_t j = 0; j < cargolist.size(); j++) {
376 if (!cargostring.empty()) cargostring += list_separator;
378 AppendStringWithArgsInPlace(cargostring, STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION, params);
382 return GetString(prefixstr, cargostring);
416 for (
const auto &indtype : this->list) {
429 uint extra_lines_req = 0;
430 uint extra_lines_prd = 0;
431 uint extra_lines_newgrf = 0;
434 for (
const auto &indtype : this->list) {
442 if (strdim.
width > max_minwidth) {
443 extra_lines_req = std::max(extra_lines_req, strdim.
width / max_minwidth + 1);
444 strdim.
width = max_minwidth;
450 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
452 if (strdim.
width > max_minwidth) {
453 extra_lines_prd = std::max(extra_lines_prd, strdim.
width / max_minwidth + 1);
454 strdim.
width = max_minwidth;
460 extra_lines_newgrf = 4;
465 height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
475 d.
width += padding.width;
476 d.
height += padding.height;
491 return GetString(STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
493 if (this->selected_type != IT_INVALID) {
495 return GetString((
_settings_game.construction.raw_industry_construction == 2 && indsp->
IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
497 return GetString(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
514 icon.top = r.top + (this->
resize.step_height - this->legend.
height + 1) / 2;
515 icon.bottom = icon.top + this->legend.
height - 1;
517 auto badge_column_widths = badge_classes.GetColumnWidths();
520 for (
auto it = first; it != last; ++it) {
521 IndustryType type = *it;
522 bool selected = this->selected_type == type;
526 if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) {
528 tr = tr.
Indent(badge_column_widths[0], rtl);
530 if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) {
532 tr = tr.
Indent(badge_column_widths[1], !rtl);
550 if (this->selected_type == IT_INVALID) {
571 cargostring = this->
MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
578 std::array<int32_t, 16> regs100;
582 if (callback_res == 0x40F) {
584 }
else if (callback_res > 0x400) {
599 static void AskManyRandomIndustriesCallback(
Window *,
bool confirmed)
601 if (!confirmed)
return;
606 Map::CountLandTiles();
614 static void AskRemoveAllIndustriesCallback(
Window *,
bool confirmed)
616 if (!confirmed)
return;
618 for (
Industry *industry : Industry::Iterate())
delete industry;
639 nullptr, AskManyRandomIndustriesCallback);
649 nullptr, AskRemoveAllIndustriesCallback);
655 if (it != this->list.end()) {
656 this->selected_type = *it;
657 this->UpdateAvailability();
663 if (_thd.GetCallbackWnd() ==
this &&
681 if (this->selected_type != IT_INVALID) {
683 Command<Commands::BuildIndustry>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY,
TileIndex{}, this->selected_type, 0,
false, InteractiveRandom());
705 uint32_t seed = InteractiveRandom();
706 uint32_t layout_index = InteractiveRandomRange((uint32_t)indsp->
layouts.size());
718 AutoRestoreBackup backup_ignore_industry_restritions(_ignore_industry_restrictions,
true);
720 Command<Commands::BuildIndustry>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, this->selected_type, layout_index,
false, seed);
722 success = Command<Commands::BuildIndustry>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, this->selected_type, layout_index,
false, seed);
731 if (this->selected_type == IT_INVALID)
return;
734 this->UpdateAvailability();
735 if (
enabled != this->enabled) {
756 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
758 if (!gui_scope)
return;
765void ShowBuildIndustryWindow()
772static void UpdateIndustryProduction(
Industry *i);
774static inline bool IsProductionAlterable(
const Industry *i)
777 bool has_prod = std::any_of(std::begin(is->production_rate), std::end(is->production_rate), [](
auto rate) { return rate != 0; });
845 if (expected != r.bottom) {
846 this->info_height = expected - r.top + 1;
852 void DrawCargoIcon(
const Rect &r,
CargoType cargo_type)
const
861 std::string GetAcceptedCargoString(
const Industry::AcceptedCargo &ac,
const CargoSuffix &suffix)
const
869 default: NOT_REACHED();
885 bool has_accept =
false;
891 DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
907 DrawCargoIcon(ir, a.cargo);
915 DrawString(ir.
Indent(label_indent, rtl), this->GetAcceptedCargoString(a, suffix));
933 DrawCargoIcon(ir, p.cargo);
939 GetString(STR_INDUSTRY_VIEW_TRANSPORTED, p.cargo, p.history[LAST_MONTH].production, suffix.
text,
ToPercent8(p.history[LAST_MONTH].PctTransported())));
943 p.rate > 0, p.rate < 255);
945 ir.top += line_height;
950 line_height = this->cheat_line_height;
954 this->production_offset_y = ir.top;
959 ir.top += line_height;
964 std::array<int32_t, 16> regs100;
968 if (callback_res == 0x40F) {
970 }
else if (callback_res > 0x400) {
982 if (!i->
text.empty()) {
1010 switch (this->editable) {
1018 if (pt.y >= this->production_offset_y) {
1019 int row = (pt.y - this->production_offset_y) / this->cheat_line_height;
1020 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1024 line = itp - std::begin(i->
produced);
1039 switch (this->editable) {
1052 if (i->
produced[line].rate <= 0)
return;
1055 if (i->
produced[line].rate >= 255)
return;
1057 int new_prod = i->
produced[line].rate == 0 ? 1 : i->
produced[line].rate * 2;
1062 default: NOT_REACHED();
1065 UpdateIndustryProduction(i);
1068 this->clicked_line = line;
1069 this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1072 this->editbox_line = line;
1073 switch (this->editable) {
1082 default: NOT_REACHED();
1113 this->clicked_button = 0;
1137 if (!str.has_value() || str->empty())
return;
1141 if (!value.has_value())
return;
1142 switch (this->editbox_line) {
1153 UpdateIndustryProduction(i);
1162 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1164 if (!gui_scope)
return;
1166 if (IsProductionAlterable(i)) {
1185static void UpdateIndustryProduction(
Industry *i)
1225 WindowClass::IndustryView, WindowClass::None,
1230void ShowIndustryViewWindow(IndustryID industry)
1278 auto accepted_cargo = cargoes.first;
1279 auto produced_cargo = cargoes.second;
1281 bool accepted_cargo_matches;
1283 switch (accepted_cargo) {
1285 accepted_cargo_matches =
true;
1289 accepted_cargo_matches = !(*industry)->IsCargoAccepted();
1293 accepted_cargo_matches = (*industry)->IsCargoAccepted(accepted_cargo);
1297 bool produced_cargo_matches;
1299 switch (produced_cargo) {
1301 produced_cargo_matches =
true;
1305 produced_cargo_matches = !(*industry)->IsCargoProduced();
1309 produced_cargo_matches = (*industry)->IsCargoProduced(produced_cargo);
1313 return accepted_cargo_matches && produced_cargo_matches;
1321class IndustryDirectoryWindow :
public Window {
1330 STR_SORT_BY_PRODUCTION,
1331 STR_SORT_BY_TRANSPORTED,
1333 static const std::initializer_list<GUIIndustryList::SortFunction * const>
sorter_funcs;
1335 GUIIndustryList industries{IndustryDirectoryWindow::produced_cargo_filter};
1336 Scrollbar *vscroll{};
1337 Scrollbar *hscroll{};
1361 if (this->produced_cargo_filter_criteria != cargo_type) {
1362 this->produced_cargo_filter_criteria = cargo_type;
1378 if (this->accepted_cargo_filter_criteria != cargo_type) {
1379 this->accepted_cargo_filter_criteria = cargo_type;
1391 switch (cargo_type) {
1421 for (
auto it = first; it != last; ++it) {
1431 this->industries.clear();
1435 if (this->string_filter.
IsEmpty()) {
1436 this->industries.push_back(i);
1440 this->string_filter.AddLine(i->GetCachedName());
1441 if (this->string_filter.
GetState()) this->industries.push_back(i);
1446 auto filter = std::make_pair(this->accepted_cargo_filter_criteria, this->produced_cargo_filter_criteria);
1448 this->industries.
Filter(filter);
1450 this->vscroll->
SetCount(this->industries.size());
1453 IndustryDirectoryWindow::produced_cargo_filter = this->produced_cargo_filter_criteria;
1454 this->industries.
Sort();
1480 CargoType filter = IndustryDirectoryWindow::produced_cargo_filter;
1483 int percentage = 0, produced_cargo_count = 0;
1484 for (
const auto &p : i->
produced) {
1487 if (transported != -1) {
1488 produced_cargo_count++;
1489 percentage += transported;
1491 if (produced_cargo_count == 0 && &p == &i->
produced.back() && percentage == 0) {
1494 }
else if (filter == p.cargo) {
1499 if (produced_cargo_count == 0)
return percentage;
1500 return percentage / produced_cargo_count;
1507 if (r == 0)
return a->index < b->index;
1518 int r = it_a - it_b;
1527 uint prod_a = 0, prod_b = 0;
1529 for (
const auto &pa : a->
produced) {
1530 if (
IsValidCargoType(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
1532 for (
const auto &pb : b->
produced) {
1533 if (
IsValidCargoType(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
1536 if (
auto ita = a->
GetCargoProduced(filter); ita != std::end(a->
produced)) prod_a = ita->history[LAST_MONTH].production;
1537 if (
auto itb = b->
GetCargoProduced(filter); itb != std::end(b->
produced)) prod_b = itb->history[LAST_MONTH].production;
1539 int r = prod_a - prod_b;
1551 StringID GetStringForNumCargo(
size_t count)
const
1554 case 0:
return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1555 case 1:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1556 case 2:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1557 case 3:
return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1558 default:
return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1574 uint16_t production;
1578 CargoInfo(
CargoType cargo_type, uint16_t production, uint transported, std::string &&suffix) : cargo_type(cargo_type), production(production), transported(transported), suffix(std::move(suffix)) {}
1580 std::vector<CargoInfo> cargos;
1582 for (
auto itp = std::begin(i->
produced); itp != std::end(i->
produced); ++itp) {
1586 cargos.emplace_back(itp->cargo, itp->history[LAST_MONTH].production,
ToPercent8(itp->history[LAST_MONTH].PctTransported()), std::move(cargo_suffix.
text));
1594 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1595 if (a.production != b.production) return a.production > b.production;
1596 return a.transported > b.transported;
1602 std::sort(cargos.begin(), cargos.end(), [](
const CargoInfo &a,
const CargoInfo &b) {
1603 if (a.transported != b.transported) return a.transported > b.transported;
1604 return a.production > b.production;
1611 const CargoType cargo_type = this->produced_cargo_filter_criteria;
1613 auto filtered_ci = std::ranges::find(cargos, cargo_type, &CargoInfo::cargo_type);
1614 if (filtered_ci != cargos.end()) {
1615 std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1619 static constexpr size_t MAX_DISPLAYED_CARGOES = 3;
1620 std::array<StringParameter, 2 + 5 * MAX_DISPLAYED_CARGOES> params{};
1621 auto it = params.begin();
1627 for (CargoInfo &ci : cargos | std::views::take(MAX_DISPLAYED_CARGOES)) {
1628 *it++ = STR_INDUSTRY_DIRECTORY_ITEM_INFO;
1629 *it++ = ci.cargo_type;
1630 *it++ = ci.production;
1631 *it++ = std::move(ci.suffix);
1632 *it++ = ci.transported;
1636 if (std::size(cargos) > MAX_DISPLAYED_CARGOES) *it++ = std::size(cargos) - MAX_DISPLAYED_CARGOES;
1638 return GetStringWithArgs(GetStringForNumCargo(std::size(cargos)), {params.begin(), it});
1648 this->industries.
SetListing(this->last_sorting);
1663 this->last_sorting = this->industries.
GetListing();
1683 return GetString(STR_INDUSTRY_DIRECTORY_ACCEPTED_CARGO_FILTER, this->GetCargoFilterLabel(this->accepted_cargo_filter_criteria));
1686 return GetString(STR_INDUSTRY_DIRECTORY_PRODUCED_CARGO_FILTER, this->GetCargoFilterLabel(this->produced_cargo_filter_criteria));
1707 tmp_dpi.left += ir.left;
1708 tmp_dpi.top += ir.top;
1714 if (this->industries.empty()) {
1718 const CargoType acf_cargo_type = this->accepted_cargo_filter_criteria;
1720 for (
auto it = first; it != last; ++it) {
1730 ir.top += this->
resize.step_height;
1743 d.
height += padding.height;
1750 d.
width += padding.width;
1751 d.
height += padding.height;
1760 d.
width += padding.width;
1761 d.
height += padding.height;
1799 static std::string acc_cargo_filter;
1805 static std::string prod_cargo_filter;
1812 if (it != this->industries.end()) {
1828 if (this->industries.
SortType() != index) {
1881 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1884 case IDIWD_FORCE_REBUILD:
1889 case IDIWD_PRODUCTION_CHANGE:
1899 static inline HotkeyList hotkeys {
"industrydirectory", {
1904Listing IndustryDirectoryWindow::last_sorting = {
false, 0};
1920 WindowClass::IndustryDirectory, WindowClass::None,
1923 &IndustryDirectoryWindow::hotkeys
1926void ShowIndustryDirectory()
1949 SetStringTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1952 SetStringTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1954 SetStringTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1962 WindowClass::IndustryCargoes, WindowClass::None,
1973 static_assert(std::numeric_limits<CargoSlotMask>::digits >=
MAX_CARGOES);
1977 static_assert(
MAX_CARGOES >= std::tuple_size_v<
decltype(IndustrySpec::produced_cargo)>);
2018 template <
typename T>
T *
Get() {
return dynamic_cast<T *
>(
this); }
2025 template <
typename T>
const T *
Get()
const {
return dynamic_cast<const T *
>(
this); }
2096 assert(cargo_types.
Count() <= std::size(this->vertical_cargoes));
2098 auto it = this->vertical_cargoes.begin();
2099 for (
CargoType cargo_type : cargo_types) *it++ = cargo_type;
2101 this->num_cargoes =
static_cast<uint8_t
>(std::distance(std::begin(this->vertical_cargoes), it));
2104 std::fill(it, std::end(this->vertical_cargoes),
INVALID_CARGO);
2124 hor_left = this->cust_cargoes;
2125 hor_right = this->supp_cargoes;
2127 hor_left = this->supp_cargoes;
2128 hor_right = this->cust_cargoes;
2132 for (
int i = 0; i < this->num_cargoes; ++i) {
2133 if (!
HasBit(this->skip_cargoes, i)) {
2134 Rect col = col_base;
2136 if (
HasBit(this->top_end, i)) {
2137 col.top = row_base.top;
2139 col_padding.top = 0;
2142 if (
HasBit(this->bottom_end, i)) {
2143 col.bottom = row_base.bottom;
2145 col_padding.bottom = 0;
2161 col_base = col_base.
Translate(col_step, 0);
2162 row_base = row_base.
Translate(0, row_step);
2178 hor_left = this->cust_cargoes;
2179 hor_right = this->supp_cargoes;
2181 hor_left = this->supp_cargoes;
2182 hor_right = this->cust_cargoes;
2185 col_base = col_base.
Translate(this->num_cargoes * col_step, 0);
2186 row_base = row_base.
Translate(0, this->num_cargoes * row_step);
2189 for (
int i =
static_cast<int>(this->num_cargoes) - 1; i >= 0; --i) {
2190 col_base = col_base.
Translate(-col_step, 0);
2191 row_base = row_base.
Translate(0, -row_step);
2193 if (
HasBit(this->skip_cargoes, i))
continue;
2195 Rect col = col_base;
2196 if (
HasBit(this->top_end, i)) {
2197 col.top = row_base.top;
2201 if (
HasBit(this->bottom_end, i)) {
2202 col.bottom = row_base.bottom;
2207 CargoType cargo_type = this->vertical_cargoes[i];
2209 if (col.
Contains(pt))
return cargo_type;
2210 if (
HasBit(hor_left, i) && row_base.
WithX(row_base.left, col_base.left).
Contains(pt))
return cargo_type;
2211 if (
HasBit(hor_right, i) && row_base.
WithX(col_base.right, row_base.right).
Contains(pt))
return cargo_type;
2228 auto it = std::ranges::find(this->vertical_cargoes, cargo);
2229 if (it == this->vertical_cargoes.end())
return -1;
2231 int column =
static_cast<int>(std::distance(this->vertical_cargoes.begin(), it));
2234 assert(!
HasBit(this->supp_cargoes, column));
2235 SetBit(this->supp_cargoes, column);
2237 assert(!
HasBit(this->cust_cargoes, column));
2238 SetBit(this->cust_cargoes, column);
2253 if (accepting) mask |= this->supp_cargoes;
2254 if (supplying) mask |= this->cust_cargoes;
2279 std::span<const CargoType> other_right, other_left;
2281 other_right = this->other_accepted;
2282 other_left = this->other_produced;
2284 other_right = this->other_produced;
2285 other_left = this->other_accepted;
2294 GfxFillRect(r_stub.
Shrink({0, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, WidgetDimensions::scaled.bevel.bottom}),
CargoSpec::Get(other_right[i])->legend_colour);
2300 GfxFillRect(r_stub.
Shrink({WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, 0, WidgetDimensions::scaled.bevel.bottom}),
CargoSpec::Get(other_left[i])->legend_colour);
2312 std::span<const CargoType> other_right, other_left;
2314 other_right = this->other_accepted;
2315 other_left = this->other_produced;
2317 other_right = this->other_produced;
2318 other_left = this->other_accepted;
2325 if (r_stub.
Contains(pt))
return other_right[i];
2330 if (r_stub.
Contains(pt))
return other_left[i];
2392 if (r.
Contains(pt))
return this->industry_type;
2450 assert(std::size(
cargo_types) <= std::size(this->cargo_types));
2452 auto r = std::ranges::copy(
cargo_types, std::begin(this->cargo_types));
2453 std::fill(r.out, std::end(this->cargo_types),
INVALID_CARGO);
2473 for (
CargoType cargo_type : this->cargo_types) {
2475 if (r.
Contains(pt))
return cargo_type;
2496 return column >= 0 && column < static_cast<int>(std::tuple_size_v<
decltype(
ChainRow::columns)>);
2506 for (
const std::unique_ptr<ChainField> &fld : this->columns) {
2507 if (fld ==
nullptr)
continue;
2508 height = std::max(height, fld->Height());
2522 if (this->columns[col] !=
nullptr) this->columns[col]->Draw(r.
WithWidth(width, rtl));
2523 r = r.
Indent(width, rtl);
2542 auto result = this->columns[col]->ClickedAt(r_col, pt);
2543 if (!std::holds_alternative<std::monostate>(result))
return result;
2546 r = r.
Indent(width, rtl);
2561 assert(ind_fld !=
nullptr);
2567 if (conn_fld !=
nullptr) {
2569 if (conn_fld->ConnectCargo(cargo_type,
true) >= 0) others.Reset(cargo_type);
2571 used_slots = conn_fld->supp_cargoes;
2575 auto it = others.
begin();
2576 auto last = others.
end();
2578 if (
HasBit(used_slots, i))
continue;
2592 assert(this->columns[column] ==
nullptr);
2594 std::array<CargoType, ChainField::ChainField::MAX_CARGOES> cargo_types;
2598 assert(conn_fld !=
nullptr);
2600 for (uint i = 0; i < conn_fld->
num_cargoes; ++i) {
2617 assert(ind_fld !=
nullptr);
2623 if (conn_fld !=
nullptr) {
2625 if (conn_fld->ConnectCargo(cargo_type,
false) >= 0) others.Reset(cargo_type);
2627 used_slots = conn_fld->cust_cargoes;
2631 auto it = others.
begin();
2632 auto last = others.
end();
2634 if (
HasBit(used_slots, i))
continue;
2689struct IndustryCargoesWindow :
public Window {
2690 std::vector<std::pair<ChainField::ClickedAtResult, int>>
history;
2725 if (!this->history.empty()) this->history.erase(this->history.begin() + this->history_pos + 1, this->history.end());
2727 if (this->history.size() >= 256) this->history.erase(this->history.begin());
2728 this->history.emplace_back(this->ind_cargo, 0);
2729 this->history_pos = this->history.size() - 1;
2747 if (delta == 0 || this->history.empty())
return;
2749 this->history_pos =
Clamp(
static_cast<int>(this->history_pos) + delta, 0,
static_cast<int>(this->history.size()) - 1);
2751 this->
ComputeDisplay(this->history[this->history_pos].first,
false);
2762 uint max_cargoes = 0;
2765 if (!indsp->
enabled)
continue;
2767 max_cargoes = std::max<uint>(max_cargoes, std::ranges::count_if(indsp->produced_cargo,
IsValidCargoType));
2786 if (!hs.enabled || !hs.building_availability.Any(climate_mask))
continue;
2867 size.
width = std::max(size.
width, this->ind_textsize.width + padding.width);
2871 size.
width = std::max(size.
width, this->cargo_textsize.width + padding.width);
2881 std::string operator()(std::monostate) {
return GetString(STR_NULL); }
2882 std::string operator()(IndustryType industry_type) {
return GetString(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION,
GetIndustrySpec(industry_type)->name); }
2884 std::string operator()(
HouseID) {
return GetString(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_INDUSTRY_CARGOES_HOUSES); }
2886 return std::visit(visitor{}, this->ind_cargo);
2919 if (!indsp->
enabled)
continue;
2921 if (cargoes.
Any({indsp->accepts_cargo})) ++count;
2936 if (!indsp->
enabled)
continue;
2938 if (cargoes.
Any({indsp->produced_cargo})) ++count;
2956 for (
int i =
top; i <= middle; ++i) {
2958 if (fld ==
nullptr)
continue;
2962 if (accepting && this->rows[i].columns[column + 1]->Get<CargoChainField>() !=
nullptr)
break;
2963 if (i == middle)
break;
2966 fld->
skip_cargoes = last_skip & ~fld->GetConnections(accepting, supplying);
2971 for (
int i = bottom; i >= middle; --i) {
2973 if (fld ==
nullptr)
continue;
2977 if (supplying && this->rows[i].columns[column - 1]->Get<CargoChainField>() !=
nullptr)
break;
2978 if (i == middle)
break;
2981 fld->
skip_cargoes = last_skip & ~fld->GetConnections(accepting, supplying);
2992 void PlaceAndConnect(std::unique_ptr<AcceptsProducesChainField> &&field,
int row,
int col)
2994 assert(this->rows[row].columns[col] ==
nullptr);
2995 this->rows[row].columns[col] = std::move(field);
2996 this->rows[row].ConnectProducedCargo(col);
2997 this->rows[row].ConnectAcceptedCargo(col);
3021 ChainRow &first_row = this->rows.emplace_back();
3022 first_row.
columns[0] = std::make_unique<HeaderChainField>(STR_INDUSTRY_CARGOES_SOURCES);
3023 first_row.
columns[4] = std::make_unique<HeaderChainField>(STR_INDUSTRY_CARGOES_DESTINATIONS);
3030 int num_indrows = std::max(3, std::max(num_supp, num_cust));
3033 for (
int i = 0; i < num_indrows; i++) {
3034 ChainRow &row = this->rows.emplace_back();
3035 row.
columns[1] = std::make_unique<ConnectionChainField>(accepts);
3036 row.
columns[3] = std::make_unique<ConnectionChainField>(produces);
3040 int central_row = 1 + num_indrows / 2;
3041 this->rows[central_row].columns[2] = std::move(field);
3042 this->rows[central_row].ConnectProducedCargo(2);
3043 this->rows[central_row].ConnectAcceptedCargo(2);
3046 this->rows[central_row - 1].MakeCargoLabel(2,
true);
3047 this->rows[central_row + 1].MakeCargoLabel(2,
false);
3050 int supp_pos = 1 + (num_indrows + 1 - num_supp) / 2;
3051 int cust_pos = 1 + (num_indrows - num_cust) / 2;
3056 if (!indsp->
enabled)
continue;
3058 if (accepts.
Any({indsp->produced_cargo})) {
3059 this->
PlaceAndConnect(std::make_unique<IndustryChainField>(it), supp_pos++, 0);
3062 if (produces.
Any({indsp->accepts_cargo})) {
3063 this->
PlaceAndConnect(std::make_unique<IndustryChainField>(it), cust_pos++, 4);
3068 if (houses_supply) this->
PlaceAndConnect(std::make_unique<HouseChainField>(), supp_pos++, 0);
3069 if (houses_accept) this->
PlaceAndConnect(std::make_unique<HouseChainField>(), cust_pos++, 4);
3073 this->vscroll->
SetCount(num_indrows);
3086 if (
const IndustryType *ptr = std::get_if<IndustryType>(&this->ind_cargo); ptr !=
nullptr && *ptr == industry_type)
return false;
3088 this->ind_cargo = industry_type;
3103 if (
const HouseID *ptr = std::get_if<HouseID>(&this->ind_cargo); ptr !=
nullptr && *ptr ==
HouseID{})
return false;
3121 if (
const CargoType *ptr = std::get_if<CargoType>(&this->ind_cargo); ptr !=
nullptr && *ptr == cargo_type)
return false;
3123 this->ind_cargo = cargo_type;
3127 ChainRow &first_row = this->rows.emplace_back();
3128 first_row.
columns[0] = std::make_unique<HeaderChainField>(STR_INDUSTRY_CARGOES_SOURCES);
3129 first_row.
columns[2] = std::make_unique<HeaderChainField>(STR_INDUSTRY_CARGOES_DESTINATIONS);
3136 int num_indrows = std::max(num_supp, num_cust);
3137 for (
int i = 0; i < num_indrows; i++) {
3138 ChainRow &row = this->rows.emplace_back();
3139 row.
columns[1] = std::make_unique<ConnectionChainField>(cargoes);
3143 int supp_pos = 1 + (num_indrows - num_supp) / 2;
3144 int cust_pos = 1 + (num_indrows - num_cust) / 2;
3147 if (!indsp->
enabled)
continue;
3149 if (cargoes.
Any({indsp->produced_cargo})) {
3150 this->
PlaceAndConnect(std::make_unique<IndustryChainField>(it), supp_pos++, 0);
3153 if (cargoes.
Any({indsp->accepts_cargo})) {
3154 this->
PlaceAndConnect(std::make_unique<IndustryChainField>(it), cust_pos++, 2);
3158 if (houses_supply) this->
PlaceAndConnect(std::make_unique<HouseChainField>(), supp_pos++, 0);
3159 if (houses_accept) this->
PlaceAndConnect(std::make_unique<HouseChainField>(), cust_pos++, 2);
3161 this->rows[supp_pos].MakeCargoLabel(0,
false);
3164 this->vscroll->
SetCount(num_indrows);
3177 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
3179 if (!gui_scope)
return;
3197 bool showing_cargo = std::holds_alternative<CargoType>(this->ind_cargo);
3215 tmp_dpi.left += ir.left;
3216 tmp_dpi.top += ir.top;
3220 for (
const ChainRow &row : this->rows) {
3221 int row_height = row.Height();
3237 for (
auto it = this->rows.begin(); it != this->rows.end(); ++it) {
3238 uint row_height = it->Height();
3240 auto result = it->ClickedAt(r.
WithHeight(row_height), pt);
3241 if (!std::holds_alternative<std::monostate>(result))
return result;
3259 IndustryCargoesWindow *w;
3260 bool operator()(std::monostate) {
return false; }
3265 if (std::visit(visitor{
this}, clicked_at) && update_history) {
3275 this->small = !this->small;
3309 static std::string cargo_filter;
3311 if (
CargoType *ptr = std::get_if<CargoType>(&this->ind_cargo); ptr !=
nullptr) selected =
to_underlying(*ptr);
3321 if (!indsp->
enabled)
continue;
3327 static std::string cargo_filter;
3329 if (IndustryType *ptr = std::get_if<IndustryType>(&this->ind_cargo); ptr !=
nullptr) {
3331 }
else if (std::holds_alternative<HouseID>(this->ind_cargo)) {
3359 if (index == INT_MAX) {
3361 }
else if (index >= 0) {
3373 IndustryCargoesWindow *w;
3375 bool operator()(std::monostate)
3384 bool operator()(IndustryType industry_type)
3398 return std::visit(visitor{
this, close_cond}, this->
ClickedAt(pt));
Class for backupping variables and making sure they are restored later.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Types related to cargoes...
static constexpr CargoType INVALID_CARGO
Invalid marker for cargoes.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
CargoType
Cargo slots to indicate a cargo type within a game.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
@ None
Town will not produce this cargo type.
Cheats _cheats
All the cheats.
Types related to cheating.
Field representing something that accepts and produces cargo.
ClickedAtResult ClickedAt(Rect r, Point pt) const override
Decide which industry/house or cargo was clicked at.
virtual CargoTypes GetProduced()=0
Connected the cargo types produced by this field.
virtual CargoTypes GetAccepted()=0
Connected the cargo types accepted by this field.
std::array< CargoType, ChainField::MAX_CARGOES > other_accepted
Cargoes accepted but not used in this figure.
void Draw(Rect r) const override
Draw the field.
AcceptsProducesChainField()
Construct a new Accepts/Produces chain field.
std::array< CargoType, ChainField::MAX_CARGOES > other_produced
Cargoes produced but not used in this figure.
uint Count() const
Count the number of set bits.
auto end() const
Returns an iterator to the end of the set bits.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
auto begin() const
Returns an iterator to begin of the set bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Build (fund or prospect) a new industry,.
IndustryType selected_type
industry corresponding to the above index
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Dimension legend
Dimension of the legend 'blob'.
void OnInit() override
Notification that the nested widget tree gets initialized.
void SetButtons()
Update status of the fund and display-chain widgets.
static const int MAX_MINWIDTH_LINEHEIGHTS
The largest allowed minimum-width of the window, given in line heights.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
std::string MakeCargoListString(const std::span< const CargoType > cargolist, const std::span< const CargoSuffix > cargo_suffix, StringID prefixstr) const
Build a string of cargo names with suffixes attached.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnResize() override
Called after the window got resized.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::vector< IndustryType > list
List of industries.
bool enabled
Availability state of the selected industry.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
ClickedAtResult ClickedAt(Rect r, Point pt) const override
Decide which industry/house or cargo was clicked at.
Alignment align
The text alignment.
void Draw(Rect r) const override
Draw the field.
std::array< CargoType, ChainField::MAX_CARGOES > cargo_types
Cargoes to display (or INVALID_CARGO).
CargoChainField(std::span< const CargoType > cargo_types, Alignment align)
Construct a new cargo label chain field.
const T * Get() const
Get this field as a specific type implemention.
static constexpr CargoSlotMask ALL_CARGO_SLOTS
Value representing all cargo slots.
static uint max_cargoes
Largest number of cargoes actually on any industry.
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
std::variant< std::monostate, HouseID, IndustryType, CargoType > ClickedAtResult
Result type of testing clicked position.
static int normal_height
Height of the non-header rows.
uint16_t CargoSlotMask
Type representing a mask of cargo slots.
static Dimension cargo_line
Dimensions of cargo lines.
static CargoTypes town_produces
Mask of cargo types produced by towns.
static constexpr PixelColour CARGO_LINE_COLOUR
Line colour around the cargo.
static int connection_field_width
Width of a cargo connection field.
static uint GetConnectionHeight()
Get the height of all cargo connections in a row.
virtual int Width() const
Get the width of this field.
static constexpr uint MAX_CARGOES
Maximum number of cargoes carried in a field.
static int industry_width
Width of an industry field.
T * Get()
Get this field as a specific type implemention.
virtual ClickedAtResult ClickedAt(Rect r, Point pt) const
Decide which industry/house or cargo was clicked at.
virtual int Height() const
Get the height of this field.
static int blob_distance
Distance of the industry legend colour from the edge of the industry box.
static Dimension legend
Dimension of the legend blob.
static int vert_inter_industry_space
Amount of space between two industries in a column.
static CargoTypes town_accepts
Mask of cargo types accepted by towns.
static FontSize fontsize
Font size of industry chain strings.
static Dimension cargo_stub
Dimensions of cargo stub (unconnected cargo line.).
static Dimension cargo_space
Dimensions of space between cargo lines.
virtual void Draw(Rect r) const =0
Draw the field.
static int small_height
Height of the header row.
A single row of ChainField.
void Draw(Rect r) const
Draw this row of fields.
void ConnectAcceptedCargo(int column)
Connect accepted cargoes to the connection column before it.
ChainField::ClickedAtResult ClickedAt(Rect r, Point pt) const
Get the ClickedAt result for a field in this row.
static const int MAX_COLUMNS
Maximum number of columns in a row.
std::array< std::unique_ptr< ChainField >, MAX_COLUMNS > columns
One row of fields.
void MakeCargoLabel(int column, bool accepting)
Construct a Cargo chain field.
static bool IsValidColumn(int column)
Test if a given column index is valid.
void ConnectProducedCargo(int column)
Connect produced cargoes to the connection column after it.
int Height() const
Get the height of this row of fields.
Field representing cargo connections.
CargoSlotMask skip_cargoes
Stop at the top of the vertical cargoes.
void Draw(Rect r) const override
Draw the field.
int ConnectCargo(CargoType cargo, bool producer)
Connect a cargo to the cargo column.
CargoSlotMask supp_cargoes
Bitmask of cargoes in vertical_cargoes entering from the left.
CargoSlotMask cust_cargoes
Bitmask of cargoes in vertical_cargoes leaving to the right.
CargoSlotMask GetConnections(bool accepting, bool supplying) const
Get the cargo connections.
uint8_t num_cargoes
Number of cargoes.
std::array< CargoType, ChainField::MAX_CARGOES > vertical_cargoes
Cargoes running from top to bottom (cargo type or INVALID_CARGO).
ConnectionChainField(CargoTypes cargo_types)
Construct a new cargo connection chain field.
CargoSlotMask bottom_end
Stop at the bottom of the vertical cargoes.
CargoSlotMask top_end
Stop at the top of the vertical cargoes.
int Width() const override
Get the width of this field.
ClickedAtResult ClickedAt(Rect r, Point pt) const override
Decide which industry/house or cargo was clicked at.
std::string GetDecodedString() const
Decode the encoded string.
uint GetTotalColumnsWidth() const
Get total width of all columns.
List template of 'things' T to sort in a GUI.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetListing(Listing l)
Import sort conditions.
void SetFilterState(bool state)
Enable or disable the filter.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
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.
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
bool(const const Industry **item, const std::pair< CargoType, CargoType > &filter) FilterFunction
Listing GetListing() const
Export current sort conditions.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Field representing a house.
CargoTypes GetProduced() override
Connected the cargo types produced by this field.
CargoTypes GetAccepted() override
Connected the cargo types accepted by this field.
void Draw(Rect r) const override
Draw the field.
ClickedAtResult ClickedAt(Rect r, Point pt) const override
Decide which industry/house or cargo was clicked at.
ClickedAtResult ClickedAt(Rect r, Point pt) const override
Decide which industry/house or cargo was clicked at.
IndustryChainField(IndustryType industry_type)
Construct a new Industry chain field.
CargoTypes GetAccepted() override
Connected the cargo types accepted by this field.
IndustryType industry_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
void Draw(Rect r) const override
Draw the field.
CargoTypes GetProduced() override
Connected the cargo types produced by this field.
Colours colour
Colour for this industry.
~IndustryDirectoryWindow() override
Save the last sorting state.
const IntervalTimer< TimerWindow > rebuild_interval
Rebuild the industry list on a regular interval.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b, const CargoType &filter)
Sort industries by type and name.
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
static const StringID sorter_names[]
Strings describing how industries are sorted.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
const int MAX_FILTER_LENGTH
The max length of the filter, in chars.
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
void OnResize() override
Called after the window got resized.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void SetProducedCargoFilter(CargoType cargo_type)
Set produced cargo filter for the industry list.
static int GetCargoTransportedPercentsIfValid(const Industry::ProducedCargo &p)
Returns percents of cargo transported if industry produces this cargo, else -1.
SorterType
Ways to sort industries.
@ ByName
Sorter type to sort by name.
@ ByTransported
Sorter type to sort by transported percentage.
@ ByProduction
Sorter type to sort by production amount.
@ ByType
Sorter type to sort by type.
std::string GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
uint GetIndustryListWidth() const
Get the width needed to draw the longest industry line.
static const std::initializer_list< GUIIndustryList::SortFunction *const > sorter_funcs
Functions to sort industries.
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b, const CargoType &filter)
Sort industries by transported cargo and name.
QueryString industry_editbox
Filter editbox.
StringFilter string_filter
Filter for industries.
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b, const CargoType &filter)
Sort industries by production and name.
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b, const CargoType &filter)
Sort industries by name.
void BuildSortIndustriesList()
(Re)Build industries list
CargoType accepted_cargo_filter_criteria
Selected accepted cargo filter index.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void SetAcceptedCargoFilter(CargoType cargo_type)
Set accepted cargo filter for the industry list.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
CargoType produced_cargo_filter_criteria
Selected produced cargo filter index.
void OnPaint() override
The window must be repainted.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnResize() override
Called after the window got resized.
int cheat_line_height
Height of each line for the WID_IV_INFO panel.
int production_offset_y
The offset of the production texts/buttons.
void OnPaint() override
The window must be repainted.
Editability editable
Mode for changing production.
ClickedCargoLine editbox_line
The line clicked to open the edit box.
void OnTimeout() override
Called when this window's timeout has been reached.
~IndustryViewWindow() override
Close the industry production window.
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
int info_height
Height needed for the WID_IV_INFO panel.
Dimension cargo_icon_size
Largest cargo icon dimension.
void OnMouseWheel(int wheel, WidgetID widget) override
The mouse wheel has been turned.
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
static constexpr ClickedCargoLine CCL_NONE
No cargo line has been clicked.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint8_t clicked_button
The button that has been clicked (to raise).
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
int8_t ClickedCargoLine
Clicked cargo line in the info panel.
int DrawInfo(const Rect &r)
Draw the text in the WID_IV_INFO panel.
ClickedCargoLine clicked_line
The line of the button that has been clicked.
static constexpr ClickedCargoLine CCL_MULTIPLIER
Product multiplier line is clicked.
Editability
Modes for changing production.
@ Rate
Allow changing the production rates.
@ Multiplier
Allow changing the production multiplier.
An interval timer will fire every interval, and will continue to fire until it is deleted.
TileIndex tile
The base tile of the area.
TileIndex GetCentreTile() const
Get the centre tile.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Map accessors for 'clear' tiles.
@ Grass
Plain grass with dirt transition (0-3).
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a dropdown menu window near a widget of the parent window.
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
Creates new DropDownListIconItem.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ Filterable
Set if the dropdown is filterable.
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
#define T
Climate temperate.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Functions related to errors.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
@ Start
Align to the start, LTR/RTL aware.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
@ Middle
Align to the middle.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
bool IsCtrlPressed()
Test if the ctrl key is pressed.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
FontSize
Available font sizes.
@ Small
Index of the small font in the font tables.
@ Normal
Index of the normal font in the font tables.
Colours
One of 16 base colours used for companies and windows/widgets.
@ Forced
Ignore colour changes from strings.
@ FromString
Marker for telling to use the colour from the string.
@ Industry
Destination is an industry.
static const CursorID SPR_CURSOR_INDUSTRY
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Hotkey related functions.
HouseZones GetClimateMaskForLandscape()
Get the HouseZones climate mask for the current landscape type.
EnumBitSet< HouseZone, uint16_t > HouseZones
Bitset of HouseZone elements.
uint16_t HouseID
OpenTTD ID of house types.
static constexpr uint8_t PRODLEVEL_MAXIMUM
the industry is running at full speed
static constexpr uint8_t PRODLEVEL_DEFAULT
default level set when the industry is created
static constexpr uint8_t PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
static constexpr uint8_t PRODLEVEL_CLOSURE
signal set to actually close the industry
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Command definitions related to industries.
static constexpr std::initializer_list< NWidgetPart > _nested_industry_directory_widgets
Widget definition of the industry directory gui.
void ShowIndustryCargoesWindow()
Open the industry and cargoes window with an industry.
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).
CargoSuffixType
Cargo suffix type (for which window is it requested).
@ View
View-industry window.
@ Fund
Fund-industry window.
@ Directory
Industry-directory window.
static WindowDesc _industry_directory_desc(WindowPosition::Automatic, "list_industries", 428, 190, WindowClass::IndustryDirectory, WindowClass::None, {}, _nested_industry_directory_widgets, &IndustryDirectoryWindow::hotkeys)
Window definition of the industry directory gui.
static bool CargoFilter(const Industry *const *industry, const std::pair< CargoType, CargoType > &cargoes)
Cargo filter functions.
CargoSuffixDirection
Cargo direction for cargo suffixes.
@ Out
Get cargo suffix for output cargoes.
@ In
Get cargo suffix for input cargoes.
void GenerateIndustries()
This function will create random industries during game creation.
static WindowDesc _build_industry_desc(WindowPosition::Automatic, "build_industry", 170, 212, WindowClass::BuildIndustry, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_industry_widgets)
Window definition of the dynamic place industries gui.
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
CargoSuffixDisplay
Ways of displaying the cargo.
@ AmountAndText
Display the cargo, amount, and string (cb37 result 000-3FF).
@ None
Display the cargo without sub-type (cb37 result 401).
@ Text
Display the cargo and supplied string (cb37 result 800-BFF).
@ Amount
Display the cargo and amount (if useful), but no sub-type (cb37 result 400 or fail).
static Dimension GetMaximalSizeIndustryString(FontSize fs=FontSize::Normal)
Get the maximal size for industry type names.
static WindowDesc _industry_view_desc(WindowPosition::Automatic, "view_industry", 260, 120, WindowClass::IndustryView, WindowClass::None, {}, _nested_industry_view_widgets)
Window definition of the view industry gui.
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
static WindowDesc _industry_cargoes_desc(WindowPosition::Automatic, "industry_cargoes", 300, 210, WindowClass::IndustryCargoes, WindowClass::None, {}, _nested_industry_cargoes_widgets)
Window description for the industry cargoes window.
static void GetAllCargoSuffixes(CargoSuffixDirection 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).
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
static constexpr std::initializer_list< NWidgetPart > _nested_industry_view_widgets
Widget definition of the view industry gui.
static Dimension GetMaximalSizeCargoString(FontSize fs=FontSize::Normal)
Get the maximal size for cargo names.
void SortIndustryTypes()
Initialize the list of sorted industry types.
static constexpr std::initializer_list< NWidgetPart > _nested_industry_cargoes_widgets
Widgets of the industry cargoes window.
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like IT_...
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
@ CargoTypesUnlimited
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
@ Processing
Like factories.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
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.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
void ShowQuery(EncodedString &&caption, EncodedString &&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...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static constexpr CargoType CF_NONE
Show only items which do not carry cargo (e.g. train engines).
static constexpr CargoType CF_ANY
Show all items independent of carried cargo (i.e. no filtering).
bool _networking
are we in networking mode?
Basic functions/variables used all over the place.
@ Industries
Industries feature.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &gui_classes, std::span< const BadgeID > badges, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Draw a badge column group.
GUI functions related to NewGRF badges.
@ CargoSuffix
Show suffix after cargo name.
@ WindowMoreText
additional text in industry window
@ FundMoreText
additional text in fund window
@ Production256Ticks
call production callback every 256 ticks
@ ProductionCargoArrival
call production callback when cargo arrives at the industry
@ CargoSuffix
cargo sub-type display
@ CBID_INDUSTRY_WINDOW_MORE_TEXT
Called to determine more text in the industry window.
@ CBID_INDUSTRY_CARGO_SUFFIX
Called to determine text to display after cargo name.
@ CBID_INDUSTRY_FUND_MORE_TEXT
Called to determine more text in the fund industry window.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(GrfID grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Functions/types related to NewGRF debugging.
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile, std::span< int32_t > regs100)
Perform an industry callback.
uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoType cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Functions for NewGRF industries.
@ UserCreation
from the Fund/build window
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
std::string GetGRFStringWithTextStack(const struct GRFFile *grffile, GRFStringID grfstringid, std::span< const int32_t > textstack)
Format a GRF string using the text ref stack for parameters.
Header of Action 04 "universal holder" structure and functions.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
@ Editor
In the scenario editor.
static constexpr PixelColour PC_BLACK
Black palette colour.
static constexpr PixelColour PC_WHITE
White palette colour.
Base for the GUIs that have an edit box in them.
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
@ Off
Scroll wheel has no effect.
void ShowSmallMap()
Show the smallmap window.
Base types for having sorted lists in GUIs.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Functions related to sound.
@ Count
by amount of cargo
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Searching and filtering using a stringterm.
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
std::string_view GetListSeparator()
Get the list separator string for the current language.
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Functions related to OTTD's strings.
auto MakeParameters(Args &&... args)
Helper to create the StringParameters with its own buffer with the given parameter values.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Horizontal and vertical alignment.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
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...
Specification of a cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
PixelColour legend_colour
Colour in legends and graphs.
StringID name
Name of this type of cargo.
Transfer storage of cargo suffix information.
std::string text
Cargo suffix text.
CargoSuffixDisplay display
How to display the cargo and text.
Comparator to sort CargoType by according to desired order.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Data about how and where to blit pixels.
Container for the text colour and some text colour related flags for drawing.
GrfID grfid
grfid that introduced this entity.
const struct GRFFile * grffile
grf file that introduced this entity
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoType -> local ID).
uint8_t grf_version
GRF version (See https://newgrf-specs.tt-wiki.net/wiki/Version_numbers#GRF_version).
List of hotkeys for a window.
All data for a single hotkey.
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Window displaying the cargo connections around an industry (or cargo).
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
static bool HousesCanAccept(CargoTypes cargoes)
Can houses be used as customers of the produced cargoes?
static bool small
Set if industry chain display should be smaller.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool ComputeCargoDisplay(CargoType cargo_type)
Compute what and where to display for cargo type cargo_type.
void OnX2Click(Point pt, WidgetID widget) override
A click with the X2 mouse button has been made on the window.
std::vector< ChainRow > rows
Fields to display in the WID_IC_PANEL.
void UpdateHistoryScrollpos()
Update the current navigation history scroll position.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
bool ComputeIndustryDisplay(IndustryType industry_type)
Compute the display for an industry type.
void OnInit() override
Notification that the nested widget tree gets initialized.
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Dimension ind_textsize
Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
ChainField::ClickedAtResult ind_cargo
The displayed house, industry or cargo type.
void OnResize() override
Called after the window got resized.
void AppendHistory()
Place current house/industry/cargo choice in the navigation history.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
uint CountHouseCargoTypes() const
Count the maximal number of cargo types handled by all houses.
size_t history_pos
Position in browsing history.
void NavigateHistory(int delta)
Move within navigation history.
Scrollbar * vscroll
Vertical scrollbar of window.
void ShortenConnectionsColumn(int column, int top, int middle, int bottom, bool accepting, bool supplying)
Shorten the cargo column to just the part between industries.
static int CountMatchingProducingIndustries(CargoTypes cargoes)
Count how many industries have produced cargoes in common with one of the supplied set.
void ComputeAcceptsProducesIndustryDisplay(std::unique_ptr< AcceptsProducesChainField > &&field, CargoTypes accepts, CargoTypes produces)
Compute what and where to display for an Accepts/Produces chain field.
bool ComputeHouseDisplay()
Compute the display for a house.
static bool HousesCanSupply(CargoTypes cargoes)
Can houses be used to supply one of the cargoes?
static int CountMatchingAcceptingIndustries(CargoTypes cargoes)
Count how many industries have accepted cargoes in common with one of the supplied set.
uint CountIndustryCargoTypes()
Count the maximal number of cargo types handled by all industry types.
ChainField::ClickedAtResult ClickedAt(Point pt) const
Calculate in which field was clicked.
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
void PlaceAndConnect(std::unique_ptr< AcceptsProducesChainField > &&field, int row, int col)
Place an industry/house in the fields.
void ComputeDisplay(ChainField::ClickedAtResult clicked_at, bool update_history=true)
Compute the cargo chain display.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Rect GetRowRect(const Rect &r) const
Get the area covered by the cargo chain display.
void UpdateNavigationButtons()
Update state of navigation buttons.
std::vector< std::pair< ChainField::ClickedAtResult, int > > history
Browsing history in this window.
void OnX1Click(Point pt, WidgetID widget) override
A click with the X1 mouse button has been made on the window.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Defines the data structure for constructing industry.
IndustryCallbackMasks callback_mask
Bitmask of industry callbacks that have to be called.
std::array< CargoType, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
SubstituteGRFFileProps grf_prop
properties related to the grf file
StringID name
Displayed name of the industry.
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
IndustryBehaviours behaviour
How this industry will behave, and how others entities can use it.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
bool enabled
entity still available (by default true).newgrf can disable it, though
Money GetConstructionCost() const
Get the cost for constructing this industry.
IndustryLifeTypes life_type
This is also known as Industry production flag, in newgrf specs.
PixelColour map_colour
colour used for the small map
CargoType cargo
Cargo type.
uint16_t waiting
Amount of cargo waiting to processed.
CargoType cargo
Cargo type.
HistoryData< ProducedHistory > history
History of cargo produced and transported for this month and 24 previous months.
Defines the internal data of a functional industry.
IndustryType type
type of industry.
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
uint8_t prod_level
general production level
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
EncodedString text
General text with additional information.
ProducedCargoes::iterator GetCargoProduced(CargoType cargo)
Get produced cargo slot for a specific cargo type.
ProducedCargoes produced
produced cargo slots
AcceptedCargoes accepted
accepted cargo slots
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
TileArea location
Location of the industry.
bool IsCargoProduced() const
Test if this industry produces any cargo.
Data structure describing how to show the list (what sort direction and criteria).
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Colour for pixel/line drawing.
static Pool::IterateWrapper< Industry > Iterate(size_t from=0)
static Industry * Get(auto index)
static size_t GetNumItems()
static bool IsValidID(auto index)
Data stored about a string that can be modified in the GUI.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
Padding dimensions to apply to each side of a Rect.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect CentreToHeight(int height) const
Centre a vertical dimension within this Rect.
Rect CentreToWidth(int width) const
Centre a horizontal dimension within this Rect.
Rect WithX(int new_left, int new_right) const
Create a new Rect, replacing the left and right coordinates.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
std::string_view GetText() const
Get the current text.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
ResizeInfo resize
Resize information.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void DrawSortButton(WidgetID widget, bool descending) const
Draw a sort button's up or down arrow symbol.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
bool IsShaded() const
Is window shaded currently?
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
int top
y position of top edge of the window
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
WindowFlags flags
Window flags.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int height
Height of the window (number of pixels down in y direction).
int width
width of the window (number of pixels to the right in x direction)
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ Clear
A tile without any structures, i.e. grass, rocks, farm fields etc.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the Window system.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_OUT
Zoom out (get helicopter view).
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
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...
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ DisableVpScroll
Window does not do autoscroll,.
@ Automatic
Find a place automatically.
Functions related to zooming.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
@ Industry
Default zoom level for the industry view.