OpenTTD Source  20240917-master-g9ab0a47812
industry_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "error.h"
12 #include "gui.h"
13 #include "settings_gui.h"
14 #include "sound_func.h"
15 #include "window_func.h"
16 #include "textbuf_gui.h"
17 #include "command_func.h"
18 #include "viewport_func.h"
19 #include "industry.h"
20 #include "town.h"
21 #include "cheat_type.h"
22 #include "newgrf_industries.h"
23 #include "newgrf_text.h"
24 #include "newgrf_debug.h"
25 #include "network/network.h"
26 #include "strings_func.h"
27 #include "company_func.h"
28 #include "tilehighlight_func.h"
29 #include "string_func.h"
30 #include "sortlist_type.h"
31 #include "dropdown_func.h"
32 #include "company_base.h"
33 #include "core/geometry_func.hpp"
34 #include "core/random_func.hpp"
35 #include "core/backup_type.hpp"
36 #include "genworld.h"
37 #include "smallmap_gui.h"
38 #include "dropdown_type.h"
39 #include "clear_map.h"
40 #include "zoom_func.h"
41 #include "industry_cmd.h"
42 #include "querystring_gui.h"
43 #include "stringfilter_type.h"
44 #include "timer/timer.h"
45 #include "timer/timer_window.h"
46 #include "hotkeys.h"
47 
49 
50 #include "table/strings.h"
51 
52 #include <bitset>
53 
54 #include "safeguards.h"
55 
56 bool _ignore_restrictions;
57 std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
58 
64 };
65 
72 };
73 
75 struct CargoSuffix {
77  std::string text;
78 };
79 
80 extern void GenerateIndustries();
81 static void ShowIndustryCargoesWindow(IndustryType id);
82 
92 static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
93 {
94  suffix.text.clear();
95  suffix.display = CSD_CARGO_AMOUNT;
96 
97  if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
98  TileIndex t = (cst != CST_FUND) ? ind->location.tile : INVALID_TILE;
99  uint16_t callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, t);
100  if (callback == CALLBACK_FAILED) return;
101 
102  if (indspec->grf_prop.grffile->grf_version < 8) {
103  if (GB(callback, 0, 8) == 0xFF) return;
104  if (callback < 0x400) {
106  suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback));
109  return;
110  }
112  return;
113 
114  } else { // GRF version 8 or higher.
115  if (callback == 0x400) return;
116  if (callback == 0x401) {
117  suffix.display = CSD_CARGO;
118  return;
119  }
120  if (callback < 0x400) {
122  suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback));
125  return;
126  }
127  if (callback >= 0x800 && callback < 0xC00) {
129  suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 - 0x800 + callback));
131  suffix.display = CSD_CARGO_TEXT;
132  return;
133  }
135  return;
136  }
137  }
138 }
139 
140 enum CargoSuffixInOut {
141  CARGOSUFFIX_OUT = 0,
142  CARGOSUFFIX_IN = 1,
143 };
144 
155 template <typename TC, typename TS>
156 static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
157 {
158  static_assert(std::tuple_size_v<std::remove_reference_t<decltype(cargoes)>> <= lengthof(suffixes));
159 
161  /* Reworked behaviour with new many-in-many-out scheme */
162  for (uint j = 0; j < lengthof(suffixes); j++) {
163  if (IsValidCargoID(cargoes[j])) {
164  uint8_t local_id = indspec->grf_prop.grffile->cargo_map[cargoes[j]]; // should we check the value for valid?
165  uint cargotype = local_id << 16 | use_input;
166  GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
167  } else {
168  suffixes[j].text.clear();
169  suffixes[j].display = CSD_CARGO;
170  }
171  }
172  } else {
173  /* Compatible behaviour with old 3-in-2-out scheme */
174  for (uint j = 0; j < lengthof(suffixes); j++) {
175  suffixes[j].text.clear();
176  suffixes[j].display = CSD_CARGO;
177  }
178  switch (use_input) {
179  case CARGOSUFFIX_OUT:
180  // Handle INDUSTRY_ORIGINAL_NUM_OUTPUTS cargoes
181  if (IsValidCargoID(cargoes[0])) GetCargoSuffix(3, cst, ind, ind_type, indspec, suffixes[0]);
182  if (IsValidCargoID(cargoes[1])) GetCargoSuffix(4, cst, ind, ind_type, indspec, suffixes[1]);
183  break;
184  case CARGOSUFFIX_IN:
185  // Handle INDUSTRY_ORIGINAL_NUM_INPUTS cargoes
186  if (IsValidCargoID(cargoes[0])) GetCargoSuffix(0, cst, ind, ind_type, indspec, suffixes[0]);
187  if (IsValidCargoID(cargoes[1])) GetCargoSuffix(1, cst, ind, ind_type, indspec, suffixes[1]);
188  if (IsValidCargoID(cargoes[2])) GetCargoSuffix(2, cst, ind, ind_type, indspec, suffixes[2]);
189  break;
190  default:
191  NOT_REACHED();
192  }
193  }
194 }
195 
207 void GetCargoSuffix(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoID cargo, uint8_t slot, CargoSuffix &suffix)
208 {
209  suffix.text.clear();
210  suffix.display = CSD_CARGO;
211  if (!IsValidCargoID(cargo)) return;
213  uint8_t local_id = indspec->grf_prop.grffile->cargo_map[cargo]; // should we check the value for valid?
214  uint cargotype = local_id << 16 | use_input;
215  GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffix);
216  } else if (use_input == CARGOSUFFIX_IN) {
217  if (slot < INDUSTRY_ORIGINAL_NUM_INPUTS) GetCargoSuffix(slot, cst, ind, ind_type, indspec, suffix);
218  } else if (use_input == CARGOSUFFIX_OUT) {
219  if (slot < INDUSTRY_ORIGINAL_NUM_OUTPUTS) GetCargoSuffix(slot + INDUSTRY_ORIGINAL_NUM_INPUTS, cst, ind, ind_type, indspec, suffix);
220  }
221 }
222 
223 std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
224 
226 static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
227 {
228  int r = StrNaturalCompare(GetString(GetIndustrySpec(a)->name), GetString(GetIndustrySpec(b)->name)); // Sort by name (natural sorting).
229 
230  /* If the names are equal, sort by industry type. */
231  return (r != 0) ? r < 0 : (a < b);
232 }
233 
238 {
239  /* Add each industry type to the list. */
240  for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
241  _sorted_industry_types[i] = i;
242  }
243 
244  /* Sort industry types by name. */
246 }
247 
254 void CcBuildIndustry(Commands, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32_t, bool, uint32_t)
255 {
256  if (result.Succeeded()) return;
257 
258  if (indtype < NUM_INDUSTRYTYPES) {
259  const IndustrySpec *indsp = GetIndustrySpec(indtype);
260  if (indsp->enabled) {
261  SetDParam(0, indsp->name);
262  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, result.GetErrorMessage(), WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE);
263  }
264  }
265 }
266 
267 static constexpr NWidgetPart _nested_build_industry_widgets[] = {
269  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
270  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FUND_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
271  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
272  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
273  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
274  EndContainer(),
278  SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
279  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET), SetMinimalSize(0, 12), SetFill(1, 0), SetResize(1, 0),
280  SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
281  EndContainer(),
282  EndContainer(),
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),
285  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_DPI_SCROLLBAR),
286  EndContainer(),
287  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_DPI_INFOPANEL), SetResize(1, 0),
288  EndContainer(),
290  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_DISPLAY_WIDGET), SetFill(1, 0), SetResize(1, 0),
291  SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
292  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_FUND_WIDGET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
293  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
294  EndContainer(),
295 };
296 
299  WDP_AUTO, "build_industry", 170, 212,
302  _nested_build_industry_widgets
303 );
304 
306 class BuildIndustryWindow : public Window {
307  IndustryType selected_type;
308  std::vector<IndustryType> list;
309  bool enabled;
310  Scrollbar *vscroll;
312 
314  static const int MAX_MINWIDTH_LINEHEIGHTS = 20;
315 
316  void UpdateAvailability()
317  {
318  this->enabled = this->selected_type != INVALID_INDUSTRYTYPE && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0);
319  }
320 
321  void SetupArrays()
322  {
323  this->list.clear();
324 
325  /* Fill the arrays with industries.
326  * The tests performed after the enabled allow to load the industries
327  * In the same way they are inserted by grf (if any)
328  */
329  for (IndustryType ind : _sorted_industry_types) {
330  const IndustrySpec *indsp = GetIndustrySpec(ind);
331  if (indsp->enabled) {
332  /* Rule is that editor mode loads all industries.
333  * In game mode, all non raw industries are loaded too
334  * and raw ones are loaded only when setting allows it */
335  if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
336  /* Unselect if the industry is no longer in the list */
337  if (this->selected_type == ind) this->selected_type = INVALID_INDUSTRYTYPE;
338  continue;
339  }
340 
341  this->list.push_back(ind);
342  }
343  }
344 
345  /* First industry type is selected if the current selection is invalid. */
346  if (this->selected_type == INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
347 
348  this->UpdateAvailability();
349 
350  this->vscroll->SetCount(this->list.size());
351  }
352 
354  void SetButtons()
355  {
356  this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled);
357  this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled);
358  }
359 
372  std::string MakeCargoListString(const std::span<const CargoID> cargolist, const std::span<const CargoSuffix> cargo_suffix, StringID prefixstr) const
373  {
374  assert(cargolist.size() == cargo_suffix.size());
375 
376  std::string cargostring;
377  size_t numcargo = 0;
378  size_t firstcargo = 0;
379 
380  for (size_t j = 0; j < cargolist.size(); j++) {
381  if (!IsValidCargoID(cargolist[j])) continue;
382  numcargo++;
383  if (numcargo == 1) {
384  firstcargo = j;
385  continue;
386  }
387  SetDParam(0, CargoSpec::Get(cargolist[j])->name);
388  SetDParamStr(1, cargo_suffix[j].text);
389  cargostring += GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
390  }
391 
392  if (numcargo > 0) {
393  SetDParam(0, CargoSpec::Get(cargolist[firstcargo])->name);
394  SetDParamStr(1, cargo_suffix[firstcargo].text);
395  cargostring = GetString(prefixstr) + cargostring;
396  } else {
397  SetDParam(0, STR_JUST_NOTHING);
398  SetDParamStr(1, "");
399  cargostring = GetString(prefixstr);
400  }
401 
402  return cargostring;
403  }
404 
405 public:
407  {
408  this->selected_type = INVALID_INDUSTRYTYPE;
409 
410  this->CreateNestedTree();
411  this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
412  /* Show scenario editor tools in editor. */
413  if (_game_mode != GM_EDITOR) {
414  this->GetWidget<NWidgetStacked>(WID_DPI_SCENARIO_EDITOR_PANE)->SetDisplayedPlane(SZSP_HORIZONTAL);
415  }
416  this->FinishInitNested(0);
417 
418  this->SetButtons();
419  }
420 
421  void OnInit() override
422  {
423  /* Width of the legend blob -- slightly larger than the smallmap legend blob. */
424  this->legend.height = GetCharacterHeight(FS_SMALL);
425  this->legend.width = this->legend.height * 9 / 6;
426 
427  this->SetupArrays();
428  }
429 
430  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
431  {
432  switch (widget) {
433  case WID_DPI_MATRIX_WIDGET: {
434  SetDParamMaxDigits(0, 4);
435  Dimension count = GetStringBoundingBox(STR_JUST_COMMA, FS_SMALL);
436  Dimension d{};
437  for (const auto &indtype : this->list) {
438  d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name));
439  }
440  resize.height = std::max<uint>({this->legend.height, d.height, count.height}) + padding.height;
441  d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + WidgetDimensions::scaled.hsep_normal + count.width + padding.width;
442  d.height = 5 * resize.height;
443  size = maxdim(size, d);
444  break;
445  }
446 
447  case WID_DPI_INFOPANEL: {
448  /* Extra line for cost outside of editor. */
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;
454  Dimension d = {0, 0};
455  for (const auto &indtype : this->list) {
456  const IndustrySpec *indsp = GetIndustrySpec(indtype);
457  CargoSuffix cargo_suffix[std::tuple_size_v<decltype(indsp->accepts_cargo)>];
458 
459  /* Measure the accepted cargoes, if any. */
460  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix);
461  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
462  Dimension strdim = GetStringBoundingBox(cargostring);
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;
466  }
467  d = maxdim(d, strdim);
468 
469  /* Measure the produced cargoes, if any. */
470  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix);
471  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
472  strdim = GetStringBoundingBox(cargostring);
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;
476  }
477  d = maxdim(d, strdim);
478 
479  if (indsp->grf_prop.grffile != nullptr) {
480  /* Reserve a few extra lines for text from an industry NewGRF. */
481  extra_lines_newgrf = 4;
482  }
483  }
484 
485  /* Set it to something more sane :) */
486  height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
487  size.height = height * GetCharacterHeight(FS_NORMAL) + padding.height;
488  size.width = d.width + padding.width;
489  break;
490  }
491 
492  case WID_DPI_FUND_WIDGET: {
493  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
494  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY));
495  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY));
496  d.width += padding.width;
497  d.height += padding.height;
498  size = maxdim(size, d);
499  break;
500  }
501  }
502  }
503 
504  void SetStringParameters(WidgetID widget) const override
505  {
506  switch (widget) {
507  case WID_DPI_FUND_WIDGET:
508  /* Raw industries might be prospected. Show this fact by changing the string
509  * In Editor, you just build, while ingame, or you fund or you prospect */
510  if (_game_mode == GM_EDITOR) {
511  /* We've chosen many random industries but no industries have been specified */
512  SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
513  } else {
514  if (this->selected_type != INVALID_INDUSTRYTYPE) {
515  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
516  SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
517  } else {
518  SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
519  }
520  }
521  break;
522  }
523  }
524 
525  void DrawWidget(const Rect &r, WidgetID widget) const override
526  {
527  switch (widget) {
528  case WID_DPI_MATRIX_WIDGET: {
529  bool rtl = _current_text_dir == TD_RTL;
530  Rect text = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
531  Rect icon = text.WithWidth(this->legend.width, rtl);
532  text = text.Indent(this->legend.width + WidgetDimensions::scaled.hsep_wide, rtl);
533 
534  /* Vertical offset for legend icon. */
535  icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
536  icon.bottom = icon.top + this->legend.height - 1;
537 
538  auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->list);
539  for (auto it = first; it != last; ++it) {
540  IndustryType type = *it;
541  bool selected = this->selected_type == type;
542  const IndustrySpec *indsp = GetIndustrySpec(type);
543 
544  /* Draw the name of the industry in white is selected, otherwise, in orange */
545  DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE);
546  GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
549  DrawString(text, STR_JUST_COMMA, TC_BLACK, SA_RIGHT, false, FS_SMALL);
550 
551  text = text.Translate(0, this->resize.step_height);
552  icon = icon.Translate(0, this->resize.step_height);
553  }
554  break;
555  }
556 
557  case WID_DPI_INFOPANEL: {
558  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
559 
560  if (this->selected_type == INVALID_INDUSTRYTYPE) {
561  DrawStringMultiLine(ir, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
562  break;
563  }
564 
565  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
566 
567  if (_game_mode != GM_EDITOR) {
568  SetDParam(0, indsp->GetConstructionCost());
569  DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
570  ir.top += GetCharacterHeight(FS_NORMAL);
571  }
572 
573  CargoSuffix cargo_suffix[std::tuple_size_v<decltype(indsp->accepts_cargo)>];
574 
575  /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
576  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
577  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
578  ir.top = DrawStringMultiLine(ir, cargostring);
579 
580  /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
581  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
582  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
583  ir.top = DrawStringMultiLine(ir, cargostring);
584 
585  /* Get the additional purchase info text, if it has not already been queried. */
587  uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, nullptr, this->selected_type, INVALID_TILE);
588  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
589  if (callback_res > 0x400) {
591  } else {
592  StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
593  if (str != STR_UNDEFINED) {
595  DrawStringMultiLine(ir, str, TC_YELLOW);
597  }
598  }
599  }
600  }
601  break;
602  }
603  }
604  }
605 
606  static void AskManyRandomIndustriesCallback(Window *, bool confirmed)
607  {
608  if (!confirmed) return;
609 
610  if (Town::GetNumItems() == 0) {
611  ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO);
612  } else {
613  Backup<bool> old_generating_world(_generating_world, true);
617  old_generating_world.Restore();
618  }
619  }
620 
621  static void AskRemoveAllIndustriesCallback(Window *, bool confirmed)
622  {
623  if (!confirmed) return;
624 
625  for (Industry *industry : Industry::Iterate()) delete industry;
626 
627  /* Clear farmland. */
628  for (TileIndex tile = 0; tile < Map::Size(); tile++) {
629  if (IsTileType(tile, MP_CLEAR) && GetRawClearGround(tile) == CLEAR_FIELDS) {
630  MakeClear(tile, CLEAR_GRASS, 3);
631  }
632  }
633 
635  }
636 
637  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
638  {
639  switch (widget) {
641  assert(_game_mode == GM_EDITOR);
643  ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY, nullptr, AskManyRandomIndustriesCallback);
644  break;
645  }
646 
648  assert(_game_mode == GM_EDITOR);
650  ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY, nullptr, AskRemoveAllIndustriesCallback);
651  break;
652  }
653 
654  case WID_DPI_MATRIX_WIDGET: {
655  auto it = this->vscroll->GetScrolledItemFromWidget(this->list, pt.y, this, WID_DPI_MATRIX_WIDGET);
656  if (it != this->list.end()) { // Is it within the boundaries of available data?
657  this->selected_type = *it;
658  this->UpdateAvailability();
659 
660  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
661 
662  this->SetDirty();
663 
664  if (_thd.GetCallbackWnd() == this &&
665  ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) || !this->enabled)) {
666  /* Reset the button state if going to prospecting or "build many industries" */
667  this->RaiseButtons();
669  }
670 
671  this->SetButtons();
672  if (this->enabled && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
673  }
674  break;
675  }
676 
678  if (this->selected_type != INVALID_INDUSTRYTYPE) ShowIndustryCargoesWindow(this->selected_type);
679  break;
680 
681  case WID_DPI_FUND_WIDGET: {
682  if (this->selected_type != INVALID_INDUSTRYTYPE) {
683  if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
684  Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, 0, this->selected_type, 0, false, InteractiveRandom());
686  } else {
687  HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);
688  }
689  }
690  break;
691  }
692  }
693  }
694 
695  void OnResize() override
696  {
697  /* Adjust the number of items in the matrix depending of the resize */
698  this->vscroll->SetCapacityFromWidget(this, WID_DPI_MATRIX_WIDGET);
699  }
700 
701  void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
702  {
703  bool success = true;
704  /* We do not need to protect ourselves against "Random Many Industries" in this mode */
705  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
706  uint32_t seed = InteractiveRandom();
707  uint32_t layout_index = InteractiveRandomRange((uint32_t)indsp->layouts.size());
708 
709  if (_game_mode == GM_EDITOR) {
710  /* Show error if no town exists at all */
711  if (Town::GetNumItems() == 0) {
712  SetDParam(0, indsp->name);
713  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO, pt.x, pt.y);
714  return;
715  }
716 
718  Backup<bool> old_generating_world(_generating_world, true);
719  _ignore_restrictions = true;
720 
721  Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, &CcBuildIndustry, tile, this->selected_type, layout_index, false, seed);
722 
723  cur_company.Restore();
724  old_generating_world.Restore();
725  _ignore_restrictions = false;
726  } else {
727  success = Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, this->selected_type, layout_index, false, seed);
728  }
729 
730  /* If an industry has been built, just reset the cursor and the system */
732  }
733 
734  IntervalTimer<TimerWindow> update_interval = {std::chrono::seconds(3), [this](auto) {
735  if (_game_mode == GM_EDITOR) return;
736  if (this->selected_type == INVALID_INDUSTRYTYPE) return;
737 
738  bool enabled = this->enabled;
739  this->UpdateAvailability();
740  if (enabled != this->enabled) {
741  this->SetButtons();
742  this->SetDirty();
743  }
744  }};
745 
746  void OnTimeout() override
747  {
748  this->RaiseButtons();
749  }
750 
751  void OnPlaceObjectAbort() override
752  {
753  this->RaiseButtons();
754  }
755 
761  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
762  {
763  if (!gui_scope) return;
764  this->SetupArrays();
765  this->SetButtons();
766  this->SetDirty();
767  }
768 };
769 
770 void ShowBuildIndustryWindow()
771 {
772  if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
774  new BuildIndustryWindow();
775 }
776 
777 static void UpdateIndustryProduction(Industry *i);
778 
779 static inline bool IsProductionAlterable(const Industry *i)
780 {
781  const IndustrySpec *is = GetIndustrySpec(i->type);
782  bool has_prod = std::any_of(std::begin(is->production_rate), std::end(is->production_rate), [](auto rate) { return rate != 0; });
783  return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
784  (has_prod || is->IsRawIndustry()) &&
785  !_networking);
786 }
787 
789 {
791  enum Editability {
795  };
796 
798  enum InfoLine {
803  };
804 
809  uint8_t clicked_button;
813 
814 public:
816  {
817  this->flags |= WF_DISABLE_VP_SCROLL;
818  this->editbox_line = IL_NONE;
819  this->clicked_line = IL_NONE;
820  this->clicked_button = 0;
821  this->info_height = WidgetDimensions::scaled.framerect.Vertical() + 2 * GetCharacterHeight(FS_NORMAL); // Info panel has at least two lines text.
822 
823  this->InitNested(window_number);
824  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
825  nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_INDUSTRY));
826 
827  this->InvalidateData();
828  }
829 
830  void OnInit() override
831  {
832  /* This only used when the cheat to alter industry production is enabled */
833  this->cheat_line_height = std::max(SETTING_BUTTON_HEIGHT + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL));
834  this->cargo_icon_size = GetLargestCargoIconSize();
835  }
836 
837  void OnPaint() override
838  {
839  this->DrawWidgets();
840 
841  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
842 
843  const Rect r = this->GetWidget<NWidgetBase>(WID_IV_INFO)->GetCurrentRect();
844  int expected = this->DrawInfo(r);
845  if (expected != r.bottom) {
846  this->info_height = expected - r.top + 1;
847  this->ReInit();
848  return;
849  }
850  }
851 
852  void DrawCargoIcon(const Rect &r, CargoID cid) const
853  {
854  bool rtl = _current_text_dir == TD_RTL;
855  SpriteID icon = CargoSpec::Get(cid)->GetCargoIcon();
856  Dimension d = GetSpriteSize(icon);
857  Rect ir = r.WithWidth(this->cargo_icon_size.width, rtl).WithHeight(GetCharacterHeight(FS_NORMAL));
858  DrawSprite(icon, PAL_NONE, CenterBounds(ir.left, ir.right, d.width), CenterBounds(ir.top, ir.bottom, this->cargo_icon_size.height));
859  }
860 
866  int DrawInfo(const Rect &r)
867  {
868  bool rtl = _current_text_dir == TD_RTL;
870  const IndustrySpec *ind = GetIndustrySpec(i->type);
871  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
872  bool first = true;
873  bool has_accept = false;
874 
875  if (i->prod_level == PRODLEVEL_CLOSURE) {
876  DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
878  }
879 
880  const int label_indent = WidgetDimensions::scaled.hsep_normal + this->cargo_icon_size.width;
882 
883  for (const auto &a : i->accepted) {
884  if (!IsValidCargoID(a.cargo)) continue;
885  has_accept = true;
886  if (first) {
887  DrawString(ir, STR_INDUSTRY_VIEW_REQUIRES);
888  ir.top += GetCharacterHeight(FS_NORMAL);
889  first = false;
890  }
891 
892  DrawCargoIcon(ir, a.cargo);
893 
894  CargoSuffix suffix;
895  GetCargoSuffix(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, a.cargo, &a - i->accepted.data(), suffix);
896 
897  SetDParam(0, CargoSpec::Get(a.cargo)->name);
898  SetDParam(1, a.cargo);
899  SetDParam(2, a.waiting);
900  SetDParamStr(3, "");
901  StringID str = STR_NULL;
902  switch (suffix.display) {
904  SetDParamStr(3, suffix.text);
905  [[fallthrough]];
906  case CSD_CARGO_AMOUNT:
907  str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
908  break;
909 
910  case CSD_CARGO_TEXT:
911  SetDParamStr(3, suffix.text);
912  [[fallthrough]];
913  case CSD_CARGO:
914  str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
915  break;
916 
917  default:
918  NOT_REACHED();
919  }
920  DrawString(ir.Indent(label_indent, rtl), str);
921  ir.top += GetCharacterHeight(FS_NORMAL);
922  }
923 
924  int line_height = this->editable == EA_RATE ? this->cheat_line_height : GetCharacterHeight(FS_NORMAL);
925  int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
926  int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
927  first = true;
928  for (const auto &p : i->produced) {
929  if (!IsValidCargoID(p.cargo)) continue;
930  if (first) {
931  if (has_accept) ir.top += WidgetDimensions::scaled.vsep_wide;
932  DrawString(ir, TimerGameEconomy::UsingWallclockUnits() ? STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE : STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
933  ir.top += GetCharacterHeight(FS_NORMAL);
934  if (this->editable == EA_RATE) this->production_offset_y = ir.top;
935  first = false;
936  }
937 
938  DrawCargoIcon(ir, p.cargo);
939 
940  CargoSuffix suffix;
941  GetCargoSuffix(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, p.cargo, &p - i->produced.data(), suffix);
942 
943  SetDParam(0, p.cargo);
944  SetDParam(1, p.history[LAST_MONTH].production);
945  SetDParamStr(2, suffix.text);
946  SetDParam(3, ToPercent8(p.history[LAST_MONTH].PctTransported()));
947  DrawString(ir.Indent(label_indent + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal : 0), rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_TRANSPORTED);
948  /* Let's put out those buttons.. */
949  if (this->editable == EA_RATE) {
950  DrawArrowButtons(ir.Indent(label_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + (&p - i->produced.data())) ? this->clicked_button : 0,
951  p.rate > 0, p.rate < 255);
952  }
953  ir.top += line_height;
954  }
955 
956  /* Display production multiplier if editable */
957  if (this->editable == EA_MULTIPLIER) {
958  line_height = this->cheat_line_height;
959  text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
960  button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
962  this->production_offset_y = ir.top;
964  DrawString(ir.Indent(label_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
965  DrawArrowButtons(ir.Indent(label_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
967  ir.top += line_height;
968  }
969 
970  /* Get the extra message for the GUI */
972  uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
973  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
974  if (callback_res > 0x400) {
976  } else {
977  StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
978  if (message != STR_NULL && message != STR_UNDEFINED) {
980 
982  /* Use all the available space left from where we stand up to the
983  * end of the window. We ALSO enlarge the window if needed, so we
984  * can 'go' wild with the bottom of the window. */
985  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, message, TC_BLACK);
987  }
988  }
989  }
990  }
991 
992  if (!i->text.empty()) {
993  SetDParamStr(0, i->text);
995  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
996  }
997 
998  /* Return required bottom position, the last pixel row plus some padding. */
999  return ir.top - 1 + WidgetDimensions::scaled.framerect.bottom;
1000  }
1001 
1002  void SetStringParameters(WidgetID widget) const override
1003  {
1004  if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
1005  }
1006 
1007  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1008  {
1009  if (widget == WID_IV_INFO) size.height = this->info_height;
1010  }
1011 
1012  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1013  {
1014  switch (widget) {
1015  case WID_IV_INFO: {
1016  Industry *i = Industry::Get(this->window_number);
1017  InfoLine line = IL_NONE;
1018 
1019  switch (this->editable) {
1020  case EA_NONE: break;
1021 
1022  case EA_MULTIPLIER:
1023  if (IsInsideBS(pt.y, this->production_offset_y, this->cheat_line_height)) line = IL_MULTIPLIER;
1024  break;
1025 
1026  case EA_RATE:
1027  if (pt.y >= this->production_offset_y) {
1028  int row = (pt.y - this->production_offset_y) / this->cheat_line_height;
1029  for (auto itp = std::begin(i->produced); itp != std::end(i->produced); ++itp) {
1030  if (!IsValidCargoID(itp->cargo)) continue;
1031  row--;
1032  if (row < 0) {
1033  line = (InfoLine)(IL_RATE1 + (itp - std::begin(i->produced)));
1034  break;
1035  }
1036  }
1037  }
1038  break;
1039  }
1040  if (line == IL_NONE) return;
1041 
1042  bool rtl = _current_text_dir == TD_RTL;
1043  Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(this->cargo_icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
1044 
1045  if (r.WithWidth(SETTING_BUTTON_WIDTH, rtl).Contains(pt)) {
1046  /* Clicked buttons, decrease or increase production */
1047  bool decrease = r.WithWidth(SETTING_BUTTON_WIDTH / 2, rtl).Contains(pt);
1048  switch (this->editable) {
1049  case EA_MULTIPLIER:
1050  if (decrease) {
1051  if (i->prod_level <= PRODLEVEL_MINIMUM) return;
1052  i->prod_level = static_cast<uint8_t>(std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM));
1053  } else {
1054  if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
1055  i->prod_level = static_cast<uint8_t>(std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM));
1056  }
1057  break;
1058 
1059  case EA_RATE:
1060  if (decrease) {
1061  if (i->produced[line - IL_RATE1].rate <= 0) return;
1062  i->produced[line - IL_RATE1].rate = std::max(i->produced[line - IL_RATE1].rate / 2, 0);
1063  } else {
1064  if (i->produced[line - IL_RATE1].rate >= 255) return;
1065  /* a zero production industry is unlikely to give anything but zero, so push it a little bit */
1066  int new_prod = i->produced[line - IL_RATE1].rate == 0 ? 1 : i->produced[line - IL_RATE1].rate * 2;
1067  i->produced[line - IL_RATE1].rate = ClampTo<uint8_t>(new_prod);
1068  }
1069  break;
1070 
1071  default: NOT_REACHED();
1072  }
1073 
1074  UpdateIndustryProduction(i);
1075  this->SetDirty();
1076  this->SetTimeout();
1077  this->clicked_line = line;
1078  this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1080  /* clicked the text */
1081  this->editbox_line = line;
1082  switch (this->editable) {
1083  case EA_MULTIPLIER:
1085  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1086  break;
1087 
1088  case EA_RATE:
1089  SetDParam(0, i->produced[line - IL_RATE1].rate * 8);
1090  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1091  break;
1092 
1093  default: NOT_REACHED();
1094  }
1095  }
1096  break;
1097  }
1098 
1099  case WID_IV_GOTO: {
1100  Industry *i = Industry::Get(this->window_number);
1101  if (_ctrl_pressed) {
1103  } else {
1105  }
1106  break;
1107  }
1108 
1109  case WID_IV_DISPLAY: {
1110  Industry *i = Industry::Get(this->window_number);
1112  break;
1113  }
1114  }
1115  }
1116 
1117  void OnTimeout() override
1118  {
1119  this->clicked_line = IL_NONE;
1120  this->clicked_button = 0;
1121  this->SetDirty();
1122  }
1123 
1124  void OnResize() override
1125  {
1126  if (this->viewport != nullptr) {
1127  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
1128  nvp->UpdateViewportCoordinates(this);
1129 
1130  ScrollWindowToTile(Industry::Get(this->window_number)->location.GetCenterTile(), this, true); // Re-center viewport.
1131  }
1132  }
1133 
1134  void OnMouseWheel(int wheel) override
1135  {
1137  DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
1138  }
1139  }
1140 
1141  void OnQueryTextFinished(std::optional<std::string> str) override
1142  {
1143  if (!str.has_value() || str->empty()) return;
1144 
1145  Industry *i = Industry::Get(this->window_number);
1146  uint value = atoi(str->c_str());
1147  switch (this->editbox_line) {
1148  case IL_NONE: NOT_REACHED();
1149 
1150  case IL_MULTIPLIER:
1152  break;
1153 
1154  default:
1155  i->produced[this->editbox_line - IL_RATE1].rate = ClampU(RoundDivSU(value, 8), 0, 255);
1156  break;
1157  }
1158  UpdateIndustryProduction(i);
1159  this->SetDirty();
1160  }
1161 
1167  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1168  {
1169  if (!gui_scope) return;
1170  const Industry *i = Industry::Get(this->window_number);
1171  if (IsProductionAlterable(i)) {
1172  const IndustrySpec *ind = GetIndustrySpec(i->type);
1173  this->editable = ind->UsesOriginalEconomy() ? EA_MULTIPLIER : EA_RATE;
1174  } else {
1175  this->editable = EA_NONE;
1176  }
1177  }
1178 
1179  bool IsNewGRFInspectable() const override
1180  {
1181  return ::IsNewGRFInspectable(GSF_INDUSTRIES, this->window_number);
1182  }
1183 
1184  void ShowNewGRFInspectWindow() const override
1185  {
1186  ::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->window_number);
1187  }
1188 };
1189 
1190 static void UpdateIndustryProduction(Industry *i)
1191 {
1192  const IndustrySpec *indspec = GetIndustrySpec(i->type);
1194 
1195  for (auto &p : i->produced) {
1196  if (IsValidCargoID(p.cargo)) {
1197  p.history[LAST_MONTH].production = ScaleByCargoScale(8 * p.rate, false);
1198  }
1199  }
1200 }
1201 
1205  NWidget(WWT_CLOSEBOX, COLOUR_CREAM),
1206  NWidget(WWT_CAPTION, COLOUR_CREAM, WID_IV_CAPTION), SetDataTip(STR_INDUSTRY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1207  NWidget(WWT_PUSHIMGBTN, COLOUR_CREAM, WID_IV_GOTO), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetDataTip(SPR_GOTO_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
1208  NWidget(WWT_DEBUGBOX, COLOUR_CREAM),
1209  NWidget(WWT_SHADEBOX, COLOUR_CREAM),
1210  NWidget(WWT_DEFSIZEBOX, COLOUR_CREAM),
1211  NWidget(WWT_STICKYBOX, COLOUR_CREAM),
1212  EndContainer(),
1213  NWidget(WWT_PANEL, COLOUR_CREAM),
1214  NWidget(WWT_INSET, COLOUR_CREAM), SetPadding(2, 2, 2, 2),
1215  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_IV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
1216  EndContainer(),
1217  EndContainer(),
1218  NWidget(WWT_PANEL, COLOUR_CREAM, WID_IV_INFO), SetMinimalSize(260, 0), SetMinimalTextLines(2, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
1219  EndContainer(),
1221  NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
1222  NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
1223  EndContainer(),
1224 };
1225 
1228  WDP_AUTO, "view_industry", 260, 120,
1230  0,
1232 );
1233 
1234 void ShowIndustryViewWindow(int industry)
1235 {
1236  AllocateWindowDescFront<IndustryViewWindow>(_industry_view_desc, industry);
1237 }
1238 
1242  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1243  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_ID_CAPTION), SetDataTip(STR_INDUSTRY_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1244  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1245  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1246  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1247  EndContainer(),
1251  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
1252  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
1253  NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_ID_FILTER), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1254  EndContainer(),
1256  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_FILTER_BY_ACC_CARGO), SetMinimalSize(225, 12), SetFill(0, 1), SetDataTip(STR_INDUSTRY_DIRECTORY_ACCEPTED_CARGO_FILTER, STR_TOOLTIP_FILTER_CRITERIA),
1257  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_FILTER_BY_PROD_CARGO), SetMinimalSize(225, 12), SetFill(0, 1), SetDataTip(STR_INDUSTRY_DIRECTORY_PRODUCED_CARGO_FILTER, STR_TOOLTIP_FILTER_CRITERIA),
1258  NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(),
1259  EndContainer(),
1260  NWidget(WWT_PANEL, COLOUR_BROWN, WID_ID_INDUSTRY_LIST), SetDataTip(0x0, STR_INDUSTRY_DIRECTORY_LIST_CAPTION), SetResize(1, 1), SetScrollbar(WID_ID_VSCROLLBAR),
1261  EndContainer(),
1262  EndContainer(),
1263  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_ID_VSCROLLBAR),
1264  EndContainer(),
1266  NWidget(NWID_HSCROLLBAR, COLOUR_BROWN, WID_ID_HSCROLLBAR),
1267  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1268  EndContainer(),
1269 };
1270 
1272 
1280 static bool CargoFilter(const Industry * const *industry, const std::pair<CargoID, CargoID> &cargoes)
1281 {
1282  auto accepted_cargo = cargoes.first;
1283  auto produced_cargo = cargoes.second;
1284 
1285  bool accepted_cargo_matches;
1286 
1287  switch (accepted_cargo) {
1289  accepted_cargo_matches = true;
1290  break;
1291 
1293  accepted_cargo_matches = !(*industry)->IsCargoAccepted();
1294  break;
1295 
1296  default:
1297  accepted_cargo_matches = (*industry)->IsCargoAccepted(accepted_cargo);
1298  break;
1299  }
1300 
1301  bool produced_cargo_matches;
1302 
1303  switch (produced_cargo) {
1305  produced_cargo_matches = true;
1306  break;
1307 
1309  produced_cargo_matches = !(*industry)->IsCargoProduced();
1310  break;
1311 
1312  default:
1313  produced_cargo_matches = (*industry)->IsCargoProduced(produced_cargo);
1314  break;
1315  }
1316 
1317  return accepted_cargo_matches && produced_cargo_matches;
1318 }
1319 
1320 static GUIIndustryList::FilterFunction * const _industry_filter_funcs[] = { &CargoFilter };
1321 
1325 };
1330 protected:
1331  /* Runtime saved values */
1332  static Listing last_sorting;
1333 
1334  /* Constants for sorting industries */
1335  static inline const StringID sorter_names[] = {
1336  STR_SORT_BY_NAME,
1337  STR_SORT_BY_TYPE,
1338  STR_SORT_BY_PRODUCTION,
1339  STR_SORT_BY_TRANSPORTED,
1340  };
1341  static const std::initializer_list<GUIIndustryList::SortFunction * const> sorter_funcs;
1342 
1343  GUIIndustryList industries{IndustryDirectoryWindow::produced_cargo_filter};
1344  Scrollbar *vscroll;
1345  Scrollbar *hscroll;
1346 
1349  static CargoID produced_cargo_filter;
1350 
1351  const int MAX_FILTER_LENGTH = 16;
1354 
1355  enum class SorterType : uint8_t {
1356  ByName,
1357  ByType,
1358  ByProduction,
1359  ByTransported,
1360  };
1361 
1367  {
1368  if (this->produced_cargo_filter_criteria != cid) {
1369  this->produced_cargo_filter_criteria = cid;
1370  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1371  bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
1372 
1373  this->industries.SetFilterState(is_filtering_necessary);
1374  this->industries.SetFilterType(0);
1375  this->industries.ForceRebuild();
1376  }
1377  }
1378 
1384  {
1385  if (this->accepted_cargo_filter_criteria != cid) {
1386  this->accepted_cargo_filter_criteria = cid;
1387  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1388  bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
1389 
1390  this->industries.SetFilterState(is_filtering_necessary);
1391  this->industries.SetFilterType(0);
1392  this->industries.ForceRebuild();
1393  }
1394  }
1395 
1396  StringID GetCargoFilterLabel(CargoID cid) const
1397  {
1398  switch (cid) {
1399  case CargoFilterCriteria::CF_ANY: return STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
1400  case CargoFilterCriteria::CF_NONE: return STR_INDUSTRY_DIRECTORY_FILTER_NONE;
1401  default: return CargoSpec::Get(cid)->name;
1402  }
1403  }
1404 
1409  {
1410  this->produced_cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
1411  this->accepted_cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
1412 
1413  this->industries.SetFilterFuncs(_industry_filter_funcs);
1414 
1415  bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
1416 
1417  this->industries.SetFilterState(is_filtering_necessary);
1418  }
1419 
1425  {
1426  uint width = 0;
1427  for (const Industry *i : this->industries) {
1428  width = std::max(width, GetStringBoundingBox(this->GetIndustryString(i)).width);
1429  }
1431  }
1432 
1435  {
1436  if (this->industries.NeedRebuild()) {
1437  this->industries.clear();
1438  this->industries.reserve(Industry::GetNumItems());
1439 
1440  for (const Industry *i : Industry::Iterate()) {
1441  if (this->string_filter.IsEmpty()) {
1442  this->industries.push_back(i);
1443  continue;
1444  }
1445  this->string_filter.ResetState();
1446  this->string_filter.AddLine(i->GetCachedName());
1447  if (this->string_filter.GetState()) this->industries.push_back(i);
1448  }
1449 
1450  this->industries.RebuildDone();
1451 
1452  auto filter = std::make_pair(this->accepted_cargo_filter_criteria, this->produced_cargo_filter_criteria);
1453 
1454  this->industries.Filter(filter);
1455 
1456  this->hscroll->SetCount(this->GetIndustryListWidth());
1457  this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well.
1458  }
1459 
1460  IndustryDirectoryWindow::produced_cargo_filter = this->produced_cargo_filter_criteria;
1461  this->industries.Sort();
1462 
1463  this->SetDirty();
1464  }
1465 
1474  {
1475  if (!IsValidCargoID(p.cargo)) return -1;
1476  return ToPercent8(p.history[LAST_MONTH].PctTransported());
1477  }
1478 
1487  {
1488  CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1489  if (filter == CargoFilterCriteria::CF_NONE) return 0;
1490 
1491  int percentage = 0, produced_cargo_count = 0;
1492  for (const auto &p : i->produced) {
1493  if (filter == CargoFilterCriteria::CF_ANY) {
1494  int transported = GetCargoTransportedPercentsIfValid(p);
1495  if (transported != -1) {
1496  produced_cargo_count++;
1497  percentage += transported;
1498  }
1499  if (produced_cargo_count == 0 && &p == &i->produced.back() && percentage == 0) {
1500  return transported;
1501  }
1502  } else if (filter == p.cargo) {
1504  }
1505  }
1506 
1507  if (produced_cargo_count == 0) return percentage;
1508  return percentage / produced_cargo_count;
1509  }
1510 
1512  static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b, const CargoID &)
1513  {
1514  int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
1515  if (r == 0) return a->index < b->index;
1516  return r < 0;
1517  }
1518 
1520  static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
1521  {
1522  int it_a = 0;
1523  while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
1524  int it_b = 0;
1525  while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
1526  int r = it_a - it_b;
1527  return (r == 0) ? IndustryNameSorter(a, b, filter) : r < 0;
1528  }
1529 
1531  static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
1532  {
1533  if (filter == CargoFilterCriteria::CF_NONE) return IndustryTypeSorter(a, b, filter);
1534 
1535  uint prod_a = 0, prod_b = 0;
1536  if (filter == CargoFilterCriteria::CF_ANY) {
1537  for (const auto &pa : a->produced) {
1538  if (IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
1539  }
1540  for (const auto &pb : b->produced) {
1541  if (IsValidCargoID(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
1542  }
1543  } else {
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;
1546  }
1547  int r = prod_a - prod_b;
1548 
1549  return (r == 0) ? IndustryTypeSorter(a, b, filter) : r < 0;
1550  }
1551 
1553  static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
1554  {
1556  return (r == 0) ? IndustryNameSorter(a, b, filter) : r < 0;
1557  }
1558 
1565  {
1566  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1567  uint8_t p = 0;
1568 
1569  /* Industry name */
1570  SetDParam(p++, i->index);
1571 
1572  /* Get industry productions (CargoID, production, suffix, transported) */
1573  struct CargoInfo {
1574  CargoID cargo_id;
1575  uint16_t production;
1576  uint transported;
1577  std::string suffix;
1578 
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)) {}
1580  };
1581  std::vector<CargoInfo> cargos;
1582 
1583  for (auto itp = std::begin(i->produced); itp != std::end(i->produced); ++itp) {
1584  if (!IsValidCargoID(itp->cargo)) continue;
1585  CargoSuffix cargo_suffix;
1586  GetCargoSuffix(CARGOSUFFIX_OUT, CST_DIR, i, i->type, indsp, itp->cargo, itp - std::begin(i->produced), cargo_suffix);
1587  cargos.emplace_back(itp->cargo, itp->history[LAST_MONTH].production, ToPercent8(itp->history[LAST_MONTH].PctTransported()), std::move(cargo_suffix.text));
1588  }
1589 
1590  switch (static_cast<IndustryDirectoryWindow::SorterType>(this->industries.SortType())) {
1594  /* Sort by descending production, then descending transported */
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;
1598  });
1599  break;
1600 
1602  /* Sort by descending transported, then descending production */
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;
1606  });
1607  break;
1608  }
1609 
1610  /* If the produced cargo filter is active then move the filtered cargo to the beginning of the list,
1611  * because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */
1612  const CargoID cid = this->produced_cargo_filter_criteria;
1614  auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo &ci) -> bool {
1615  return ci.cargo_id == cid;
1616  });
1617  if (filtered_ci != cargos.end()) {
1618  std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1619  }
1620  }
1621 
1622  /* Display first 3 cargos */
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);
1626  SetDParam(p++, ci.cargo_id);
1627  SetDParam(p++, ci.production);
1628  SetDParamStr(p++, std::move(ci.suffix));
1629  SetDParam(p++, ci.transported);
1630  }
1631 
1632  /* Undisplayed cargos if any */
1633  SetDParam(p++, cargos.size() - 3);
1634 
1635  /* Drawing the right string */
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;
1642  }
1643  }
1644 
1645 public:
1647  {
1648  this->CreateNestedTree();
1649  this->vscroll = this->GetScrollbar(WID_ID_VSCROLLBAR);
1650  this->hscroll = this->GetScrollbar(WID_ID_HSCROLLBAR);
1651 
1652  this->industries.SetListing(this->last_sorting);
1653  this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1654  this->industries.ForceRebuild();
1655 
1656  this->FinishInitNested(0);
1657 
1658  this->BuildSortIndustriesList();
1659 
1661  this->industry_editbox.cancel_button = QueryString::ACTION_CLEAR;
1662  }
1663 
1665  {
1666  this->last_sorting = this->industries.GetListing();
1667  }
1668 
1669  void OnInit() override
1670  {
1671  this->SetCargoFilterArray();
1672  }
1673 
1674  void SetStringParameters(WidgetID widget) const override
1675  {
1676  switch (widget) {
1677  case WID_ID_CAPTION:
1678  SetDParam(0, this->vscroll->GetCount());
1680  break;
1681 
1683  SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]);
1684  break;
1685 
1687  SetDParam(0, this->GetCargoFilterLabel(this->accepted_cargo_filter_criteria));
1688  break;
1689 
1691  SetDParam(0, this->GetCargoFilterLabel(this->produced_cargo_filter_criteria));
1692  break;
1693  }
1694  }
1695 
1696  void DrawWidget(const Rect &r, WidgetID widget) const override
1697  {
1698  switch (widget) {
1699  case WID_ID_DROPDOWN_ORDER:
1700  this->DrawSortButtonState(widget, this->industries.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
1701  break;
1702 
1703  case WID_ID_INDUSTRY_LIST: {
1704  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
1705 
1706  /* Setup a clipping rectangle... */
1707  DrawPixelInfo tmp_dpi;
1708  if (!FillDrawPixelInfo(&tmp_dpi, ir)) return;
1709  /* ...but keep coordinates relative to the window. */
1710  tmp_dpi.left += ir.left;
1711  tmp_dpi.top += ir.top;
1712 
1713  AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1714 
1715  ir.left -= this->hscroll->GetPosition();
1716  ir.right += this->hscroll->GetCapacity() - this->hscroll->GetPosition();
1717 
1718  if (this->industries.empty()) {
1719  DrawString(ir, STR_INDUSTRY_DIRECTORY_NONE);
1720  break;
1721  }
1722  const CargoID acf_cid = this->accepted_cargo_filter_criteria;
1723  auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->industries);
1724  for (auto it = first; it != last; ++it) {
1725  TextColour tc = TC_FROMSTRING;
1726  if (acf_cid != CargoFilterCriteria::CF_ANY && acf_cid != CargoFilterCriteria::CF_NONE) {
1727  Industry *ind = const_cast<Industry *>(*it);
1728  if (IndustryTemporarilyRefusesCargo(ind, acf_cid)) {
1729  tc = TC_GREY | TC_FORCED;
1730  }
1731  }
1732  DrawString(ir, this->GetIndustryString(*it), tc);
1733 
1734  ir.top += this->resize.step_height;
1735  }
1736  break;
1737  }
1738  }
1739  }
1740 
1741  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1742  {
1743  switch (widget) {
1744  case WID_ID_DROPDOWN_ORDER: {
1745  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1746  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1747  d.height += padding.height;
1748  size = maxdim(size, d);
1749  break;
1750  }
1751 
1752  case WID_ID_DROPDOWN_CRITERIA: {
1753  Dimension d = GetStringListBoundingBox(IndustryDirectoryWindow::sorter_names);
1754  d.width += padding.width;
1755  d.height += padding.height;
1756  size = maxdim(size, d);
1757  break;
1758  }
1759 
1760  case WID_ID_INDUSTRY_LIST: {
1761  Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
1762  resize.height = d.height;
1763  d.height *= 5;
1764  d.width += padding.width;
1765  d.height += padding.height;
1766  size = maxdim(size, d);
1767  break;
1768  }
1769  }
1770  }
1771 
1772  DropDownList BuildCargoDropDownList() const
1773  {
1774  DropDownList list;
1775 
1776  /* Add item for disabling filtering. */
1777  list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY));
1778  /* Add item for industries not producing anything, e.g. power plants */
1779  list.push_back(MakeDropDownListStringItem(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE));
1780 
1781  /* Add cargos */
1783  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1784  list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1785  }
1786 
1787  return list;
1788  }
1789 
1790  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1791  {
1792  switch (widget) {
1793  case WID_ID_DROPDOWN_ORDER:
1794  this->industries.ToggleSortOrder();
1795  this->SetDirty();
1796  break;
1797 
1799  ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0);
1800  break;
1801 
1802  case WID_ID_FILTER_BY_ACC_CARGO: // Cargo filter dropdown
1803  ShowDropDownList(this, this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
1804  break;
1805 
1806  case WID_ID_FILTER_BY_PROD_CARGO: // Cargo filter dropdown
1807  ShowDropDownList(this, this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
1808  break;
1809 
1810  case WID_ID_INDUSTRY_LIST: {
1811  auto it = this->vscroll->GetScrolledItemFromWidget(this->industries, pt.y, this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.top);
1812  if (it != this->industries.end()) {
1813  if (_ctrl_pressed) {
1814  ShowExtraViewportWindow((*it)->location.tile);
1815  } else {
1816  ScrollMainWindowToTile((*it)->location.tile);
1817  }
1818  }
1819  break;
1820  }
1821  }
1822  }
1823 
1824  void OnDropdownSelect(WidgetID widget, int index) override
1825  {
1826  switch (widget) {
1827  case WID_ID_DROPDOWN_CRITERIA: {
1828  if (this->industries.SortType() != index) {
1829  this->industries.SetSortType(index);
1830  this->BuildSortIndustriesList();
1831  }
1832  break;
1833  }
1834 
1836  this->SetAcceptedCargoFilter(index);
1837  this->BuildSortIndustriesList();
1838  break;
1839  }
1840 
1842  this->SetProducedCargoFilter(index);
1843  this->BuildSortIndustriesList();
1844  break;
1845  }
1846  }
1847  }
1848 
1849  void OnResize() override
1850  {
1851  this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.Vertical());
1852  this->hscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.Horizontal());
1853  }
1854 
1855  void OnEditboxChanged(WidgetID wid) override
1856  {
1857  if (wid == WID_ID_FILTER) {
1858  this->string_filter.SetFilterTerm(this->industry_editbox.text.buf);
1859  this->InvalidateData(IDIWD_FORCE_REBUILD);
1860  }
1861  }
1862 
1863  void OnPaint() override
1864  {
1865  if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
1866  this->DrawWidgets();
1867  }
1868 
1870  IntervalTimer<TimerWindow> rebuild_interval = {std::chrono::seconds(3), [this](auto) {
1871  this->industries.ForceResort();
1872  this->BuildSortIndustriesList();
1873  }};
1874 
1880  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1881  {
1882  switch (data) {
1883  case IDIWD_FORCE_REBUILD:
1884  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1885  this->industries.ForceRebuild();
1886  break;
1887 
1888  case IDIWD_PRODUCTION_CHANGE:
1889  if (this->industries.SortType() == 2) this->industries.ForceResort();
1890  break;
1891 
1892  default:
1893  this->industries.ForceResort();
1894  break;
1895  }
1896  }
1897 
1898  EventState OnHotkey(int hotkey) override
1899  {
1900  switch (hotkey) {
1901  case IDHK_FOCUS_FILTER_BOX:
1903  SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
1904  break;
1905  default:
1906  return ES_NOT_HANDLED;
1907  }
1908  return ES_HANDLED;
1909  }
1910 
1911  static inline HotkeyList hotkeys {"industrydirectory", {
1912  Hotkey('F', "focus_filter_box", IDHK_FOCUS_FILTER_BOX),
1913  }};
1914 };
1915 
1916 Listing IndustryDirectoryWindow::last_sorting = {false, 0};
1917 
1918 /* Available station sorting functions. */
1919 const std::initializer_list<GUIIndustryList::SortFunction * const> IndustryDirectoryWindow::sorter_funcs = {
1920  &IndustryNameSorter,
1921  &IndustryTypeSorter,
1922  &IndustryProductionSorter,
1923  &IndustryTransportedCargoSorter
1924 };
1925 
1926 CargoID IndustryDirectoryWindow::produced_cargo_filter = CargoFilterCriteria::CF_ANY;
1927 
1928 
1931  WDP_AUTO, "list_industries", 428, 190,
1933  0,
1935  &IndustryDirectoryWindow::hotkeys
1936 );
1937 
1938 void ShowIndustryDirectory()
1939 {
1940  AllocateWindowDescFront<IndustryDirectoryWindow>(_industry_directory_desc, 0);
1941 }
1942 
1946  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1947  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_IC_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1948  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1949  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1950  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1951  EndContainer(),
1954  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_IC_SCROLLBAR),
1955  EndContainer(),
1957  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_NOTIFY),
1958  SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1959  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(0, 0), EndContainer(),
1960  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_IND_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1961  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1962  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_CARGO_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1963  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1964  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1965  EndContainer(),
1966 };
1967 
1970  WDP_AUTO, "industry_cargoes", 300, 210,
1972  0,
1974 );
1975 
1984 };
1985 
1986 static const uint MAX_CARGOES = 16;
1987 
1991  static int blob_distance;
1992 
1998 
1999  static const int INDUSTRY_LINE_COLOUR;
2000  static const int CARGO_LINE_COLOUR;
2001 
2003  static int cargo_field_width;
2004  static int industry_width;
2005  static uint max_cargoes;
2006 
2007  using Cargoes = uint16_t;
2008  static_assert(std::numeric_limits<Cargoes>::digits >= MAX_CARGOES);
2009 
2011  union {
2012  struct {
2013  IndustryType ind_type;
2016  } industry;
2017  struct {
2019  Cargoes supp_cargoes;
2020  Cargoes cust_cargoes;
2021  uint8_t num_cargoes;
2022  uint8_t top_end;
2023  uint8_t bottom_end;
2024  } cargo;
2025  struct {
2027  bool left_align;
2028  } cargo_label;
2030  } u; // Data for each type.
2031 
2037  {
2038  this->type = type;
2039  }
2040 
2046  void MakeIndustry(IndustryType ind_type)
2047  {
2048  this->type = CFT_INDUSTRY;
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);
2052  }
2053 
2060  int ConnectCargo(CargoID cargo, bool producer)
2061  {
2062  assert(this->type == CFT_CARGO);
2063  if (!IsValidCargoID(cargo)) return -1;
2064 
2065  /* Find the vertical cargo column carrying the cargo. */
2066  int column = -1;
2067  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
2068  if (cargo == this->u.cargo.vertical_cargoes[i]) {
2069  column = i;
2070  break;
2071  }
2072  }
2073  if (column < 0) return -1;
2074 
2075  if (producer) {
2076  assert(!HasBit(this->u.cargo.supp_cargoes, column));
2077  SetBit(this->u.cargo.supp_cargoes, column);
2078  } else {
2079  assert(!HasBit(this->u.cargo.cust_cargoes, column));
2080  SetBit(this->u.cargo.cust_cargoes, column);
2081  }
2082  return column;
2083  }
2084 
2090  {
2091  assert(this->type == CFT_CARGO);
2092 
2093  return this->u.cargo.supp_cargoes != 0 || this->u.cargo.cust_cargoes != 0;
2094  }
2095 
2101  void MakeCargo(const std::span<const CargoID> cargoes)
2102  {
2103  this->type = CFT_CARGO;
2104  assert(std::size(cargoes) <= std::size(this->u.cargo.vertical_cargoes));
2105  auto insert = std::copy_if(std::begin(cargoes), std::end(cargoes), std::begin(this->u.cargo.vertical_cargoes), IsValidCargoID);
2106  this->u.cargo.num_cargoes = static_cast<uint8_t>(std::distance(std::begin(this->u.cargo.vertical_cargoes), insert));
2107  CargoIDComparator comparator;
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;
2114  }
2115 
2121  void MakeCargoLabel(const std::span<const CargoID> cargoes, bool left_align)
2122  {
2123  this->type = CFT_CARGO_LABEL;
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);
2127  this->u.cargo_label.left_align = left_align;
2128  }
2129 
2134  void MakeHeader(StringID textid)
2135  {
2136  this->type = CFT_HEADER;
2137  this->u.header = textid;
2138  }
2139 
2145  int GetCargoBase(int xpos) const
2146  {
2147  assert(this->type == CFT_CARGO);
2148  int n = this->u.cargo.num_cargoes;
2149 
2150  return xpos + cargo_field_width / 2 - (CargoesField::cargo_line.width * n + CargoesField::cargo_space.width * (n - 1)) / 2;
2151  }
2152 
2158  void Draw(int xpos, int ypos) const
2159  {
2160  switch (this->type) {
2161  case CFT_EMPTY:
2162  case CFT_SMALL_EMPTY:
2163  break;
2164 
2165  case CFT_HEADER:
2166  ypos += (small_height - GetCharacterHeight(FS_NORMAL)) / 2;
2167  DrawString(xpos, xpos + industry_width, ypos, this->u.header, TC_WHITE, SA_HOR_CENTER);
2168  break;
2169 
2170  case CFT_INDUSTRY: {
2171  int ypos1 = ypos + vert_inter_industry_space / 2;
2172  int ypos2 = ypos + normal_height - 1 - vert_inter_industry_space / 2;
2173  int xpos2 = xpos + industry_width - 1;
2174  DrawRectOutline({xpos, ypos1, xpos2, ypos2}, INDUSTRY_LINE_COLOUR);
2175  ypos += (normal_height - GetCharacterHeight(FS_NORMAL)) / 2;
2176  if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2177  const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type);
2178  DrawString(xpos, xpos2, ypos, indsp->name, TC_WHITE, SA_HOR_CENTER);
2179 
2180  /* Draw the industry legend. */
2181  int blob_left, blob_right;
2182  if (_current_text_dir == TD_RTL) {
2183  blob_right = xpos2 - blob_distance;
2184  blob_left = blob_right - CargoesField::legend.width;
2185  } else {
2186  blob_left = xpos + blob_distance;
2187  blob_right = blob_left + CargoesField::legend.width;
2188  }
2189  GfxFillRect(blob_left, ypos2 - blob_distance - CargoesField::legend.height, blob_right, ypos2 - blob_distance, PC_BLACK); // Border
2190  GfxFillRect(blob_left + 1, ypos2 - blob_distance - CargoesField::legend.height + 1, blob_right - 1, ypos2 - blob_distance - 1, indsp->map_colour);
2191  } else {
2192  DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TC_FROMSTRING, SA_HOR_CENTER);
2193  }
2194 
2195  /* Draw the other_produced/other_accepted cargoes. */
2196  std::span<const CargoID> other_right, other_left;
2197  if (_current_text_dir == TD_RTL) {
2198  other_right = this->u.industry.other_accepted;
2199  other_left = this->u.industry.other_produced;
2200  } else {
2201  other_right = this->u.industry.other_produced;
2202  other_left = this->u.industry.other_accepted;
2203  }
2205  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2206  if (IsValidCargoID(other_right[i])) {
2207  const CargoSpec *csp = CargoSpec::Get(other_right[i]);
2208  int xp = xpos + industry_width + CargoesField::cargo_stub.width;
2209  DrawHorConnection(xpos + industry_width, xp - 1, ypos1, csp);
2210  GfxDrawLine(xp, ypos1, xp, ypos1 + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2211  }
2212  if (IsValidCargoID(other_left[i])) {
2213  const CargoSpec *csp = CargoSpec::Get(other_left[i]);
2214  int xp = xpos - CargoesField::cargo_stub.width;
2215  DrawHorConnection(xp + 1, xpos - 1, ypos1, csp);
2216  GfxDrawLine(xp, ypos1, xp, ypos1 + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2217  }
2219  }
2220  break;
2221  }
2222 
2223  case CFT_CARGO: {
2224  int cargo_base = this->GetCargoBase(xpos);
2225  int top = ypos + (this->u.cargo.top_end ? vert_inter_industry_space / 2 + 1 : 0);
2226  int bot = ypos - (this->u.cargo.bottom_end ? vert_inter_industry_space / 2 + 1 : 0) + normal_height - 1;
2227  int colpos = cargo_base;
2228  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
2229  if (this->u.cargo.top_end) GfxDrawLine(colpos, top - 1, colpos + CargoesField::cargo_line.width - 1, top - 1, CARGO_LINE_COLOUR);
2230  if (this->u.cargo.bottom_end) GfxDrawLine(colpos, bot + 1, colpos + CargoesField::cargo_line.width - 1, bot + 1, CARGO_LINE_COLOUR);
2231  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2232  colpos++;
2233  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[i]);
2234  GfxFillRect(colpos, top, colpos + CargoesField::cargo_line.width - 2, bot, csp->legend_colour, FILLRECT_OPAQUE);
2235  colpos += CargoesField::cargo_line.width - 2;
2236  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2237  colpos += 1 + CargoesField::cargo_space.width;
2238  }
2239 
2240  Cargoes hor_left, hor_right;
2241  if (_current_text_dir == TD_RTL) {
2242  hor_left = this->u.cargo.cust_cargoes;
2243  hor_right = this->u.cargo.supp_cargoes;
2244  } else {
2245  hor_left = this->u.cargo.supp_cargoes;
2246  hor_right = this->u.cargo.cust_cargoes;
2247  }
2249  for (uint i = 0; i < MAX_CARGOES; i++) {
2250  if (HasBit(hor_left, i)) {
2251  int col = i;
2252  int dx = 0;
2253  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2254  for (; col > 0; col--) {
2255  int lf = cargo_base + col * CargoesField::cargo_line.width + (col - 1) * CargoesField::cargo_space.width;
2256  DrawHorConnection(lf, lf + CargoesField::cargo_space.width - dx, ypos, csp);
2257  dx = 1;
2258  }
2259  DrawHorConnection(xpos, cargo_base - dx, ypos, csp);
2260  }
2261  if (HasBit(hor_right, i)) {
2262  int col = i;
2263  int dx = 0;
2264  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2265  for (; col < this->u.cargo.num_cargoes - 1; col++) {
2266  int lf = cargo_base + (col + 1) * CargoesField::cargo_line.width + col * CargoesField::cargo_space.width;
2267  DrawHorConnection(lf + dx - 1, lf + CargoesField::cargo_space.width - 1, ypos, csp);
2268  dx = 1;
2269  }
2270  DrawHorConnection(cargo_base + col * CargoesField::cargo_space.width + (col + 1) * CargoesField::cargo_line.width - 1 + dx, xpos + CargoesField::cargo_field_width - 1, ypos, csp);
2271  }
2273  }
2274  break;
2275  }
2276 
2277  case CFT_CARGO_LABEL:
2279  for (uint i = 0; i < MAX_CARGOES; i++) {
2280  if (IsValidCargoID(this->u.cargo_label.cargoes[i])) {
2281  const CargoSpec *csp = CargoSpec::Get(this->u.cargo_label.cargoes[i]);
2282  DrawString(xpos + WidgetDimensions::scaled.framerect.left, xpos + industry_width - 1 - WidgetDimensions::scaled.framerect.right, ypos, csp->name, TC_WHITE,
2283  (this->u.cargo_label.left_align) ? SA_LEFT : SA_RIGHT);
2284  }
2286  }
2287  break;
2288 
2289  default:
2290  NOT_REACHED();
2291  }
2292  }
2293 
2301  CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
2302  {
2303  assert(this->type == CFT_CARGO);
2304 
2305  /* Vertical matching. */
2306  int cpos = this->GetCargoBase(0);
2307  uint col;
2308  for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2309  if (pt.x < cpos) break;
2310  if (pt.x < cpos + (int)CargoesField::cargo_line.width) return this->u.cargo.vertical_cargoes[col];
2312  }
2313  /* col = 0 -> left of first col, 1 -> left of 2nd col, ... this->u.cargo.num_cargoes right of last-col. */
2314 
2316  uint row;
2317  for (row = 0; row < MAX_CARGOES; row++) {
2318  if (pt.y < vpos) return INVALID_CARGO;
2319  if (pt.y < vpos + GetCharacterHeight(FS_NORMAL)) break;
2321  }
2322  if (row == MAX_CARGOES) return INVALID_CARGO;
2323 
2324  /* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
2325  if (col == 0) {
2326  if (HasBit(this->u.cargo.supp_cargoes, row)) return this->u.cargo.vertical_cargoes[row];
2327  if (left != nullptr) {
2328  if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row];
2329  if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
2330  }
2331  return INVALID_CARGO;
2332  }
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) {
2336  if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row];
2337  if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row];
2338  }
2339  return INVALID_CARGO;
2340  }
2341  if (row >= col) {
2342  /* Clicked somewhere in-between vertical cargo connection.
2343  * Since the horizontal connection is made in the same order as the vertical list, the above condition
2344  * ensures we are left-below the main diagonal, thus at the supplying side.
2345  */
2346  if (HasBit(this->u.cargo.supp_cargoes, row)) return this->u.cargo.vertical_cargoes[row];
2347  return INVALID_CARGO;
2348  }
2349  /* Clicked at a customer connection. */
2350  if (HasBit(this->u.cargo.cust_cargoes, row)) return this->u.cargo.vertical_cargoes[row];
2351  return INVALID_CARGO;
2352  }
2353 
2360  {
2361  assert(this->type == CFT_CARGO_LABEL);
2362 
2363  int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height;
2364  uint row;
2365  for (row = 0; row < MAX_CARGOES; row++) {
2366  if (pt.y < vpos) return INVALID_CARGO;
2367  if (pt.y < vpos + GetCharacterHeight(FS_NORMAL)) break;
2369  }
2370  if (row == MAX_CARGOES) return INVALID_CARGO;
2371  return this->u.cargo_label.cargoes[row];
2372  }
2373 
2374 private:
2382  static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
2383  {
2384  GfxDrawLine(left, top, right, top, CARGO_LINE_COLOUR);
2385  GfxFillRect(left, top + 1, right, top + CargoesField::cargo_line.height - 2, csp->legend_colour, FILLRECT_OPAQUE);
2386  GfxDrawLine(left, top + CargoesField::cargo_line.height - 1, right, top + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2387  }
2388 };
2389 
2390 static_assert(MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::produced_cargo)>);
2391 static_assert(MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::accepts_cargo)>);
2392 
2398 
2405 
2407 
2410 
2412 struct CargoesRow {
2414 
2419  void ConnectIndustryProduced(int column)
2420  {
2421  CargoesField *ind_fld = this->columns + column;
2422  CargoesField *cargo_fld = this->columns + column + 1;
2423  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2424 
2425  std::fill(std::begin(ind_fld->u.industry.other_produced), std::end(ind_fld->u.industry.other_produced), INVALID_CARGO);
2426 
2427  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2428  CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
2429  int other_count = 0;
2430 
2431  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2432  assert(CargoesField::max_cargoes <= std::size(indsp->produced_cargo));
2433  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2434  int col = cargo_fld->ConnectCargo(indsp->produced_cargo[i], true);
2435  if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2436  }
2437 
2438  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
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];
2441  }
2442  } else {
2443  /* Houses only display cargo that towns produce. */
2444  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2445  CargoID cid = cargo_fld->u.cargo.vertical_cargoes[i];
2447  if (tpe == TPE_PASSENGERS || tpe == TPE_MAIL) cargo_fld->ConnectCargo(cid, true);
2448  }
2449  }
2450  }
2451 
2457  void MakeCargoLabel(int column, bool accepting)
2458  {
2459  CargoID cargoes[MAX_CARGOES];
2460  std::fill(std::begin(cargoes), std::end(cargoes), INVALID_CARGO);
2461 
2462  CargoesField *label_fld = this->columns + column;
2463  CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2464 
2465  assert(cargo_fld->type == CFT_CARGO && label_fld->type == CFT_EMPTY);
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];
2469  }
2470  label_fld->MakeCargoLabel(cargoes, accepting);
2471  }
2472 
2473 
2478  void ConnectIndustryAccepted(int column)
2479  {
2480  CargoesField *ind_fld = this->columns + column;
2481  CargoesField *cargo_fld = this->columns + column - 1;
2482  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2483 
2484  std::fill(std::begin(ind_fld->u.industry.other_accepted), std::end(ind_fld->u.industry.other_accepted), INVALID_CARGO);
2485 
2486  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2487  CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
2488  int other_count = 0;
2489 
2490  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2491  assert(CargoesField::max_cargoes <= std::size(indsp->accepts_cargo));
2492  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2493  int col = cargo_fld->ConnectCargo(indsp->accepts_cargo[i], false);
2494  if (col < 0) others[other_count++] = indsp->accepts_cargo[i];
2495  }
2496 
2497  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
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];
2500  }
2501  } else {
2502  /* Houses only display what is demanded. */
2503  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2504  for (const auto &hs : HouseSpec::Specs()) {
2505  if (!hs.enabled) continue;
2506 
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]) {
2509  cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], false);
2510  goto next_cargo;
2511  }
2512  }
2513  }
2514 next_cargo: ;
2515  }
2516  }
2517  }
2518 };
2519 
2520 
2549  typedef std::vector<CargoesRow> Fields;
2550 
2551  Fields fields;
2552  uint ind_cargo;
2555  Scrollbar *vscroll;
2556 
2558  {
2559  this->OnInit();
2560  this->CreateNestedTree();
2561  this->vscroll = this->GetScrollbar(WID_IC_SCROLLBAR);
2562  this->FinishInitNested(0);
2563  this->OnInvalidateData(id);
2564  }
2565 
2566  void OnInit() override
2567  {
2568  /* Initialize static CargoesField size variables. */
2569  Dimension d = GetStringBoundingBox(STR_INDUSTRY_CARGOES_PRODUCERS);
2570  d = maxdim(d, GetStringBoundingBox(STR_INDUSTRY_CARGOES_CUSTOMERS));
2573  CargoesField::small_height = d.height;
2574 
2575  /* Size of the legend blob -- slightly larger than the smallmap legend blob. */
2577  CargoesField::legend.width = CargoesField::legend.height * 9 / 6;
2578 
2579  /* Size of cargo lines. */
2582 
2583  /* Size of border between cargo lines and industry boxes. */
2586 
2587  /* Size of space between cargo lines. */
2590 
2591  /* Size of cargo stub (unconnected cargo line.) */
2593  CargoesField::cargo_stub.height = CargoesField::cargo_line.height; /* Unused */
2594 
2597 
2598  /* Decide about the size of the box holding the text of an industry type. */
2599  this->ind_textsize.width = 0;
2600  this->ind_textsize.height = 0;
2602  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2603  const IndustrySpec *indsp = GetIndustrySpec(it);
2604  if (!indsp->enabled) continue;
2605  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
2606  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(std::begin(indsp->accepts_cargo), std::end(indsp->accepts_cargo), IsValidCargoID));
2607  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(std::begin(indsp->produced_cargo), std::end(indsp->produced_cargo), IsValidCargoID));
2608  }
2609  d.width = std::max(d.width, this->ind_textsize.width);
2610  d.height = this->ind_textsize.height;
2611  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY));
2612 
2613  /* Compute max size of the cargo texts. */
2614  this->cargo_textsize.width = 0;
2615  this->cargo_textsize.height = 0;
2616  for (const CargoSpec *csp : CargoSpec::Iterate()) {
2617  if (!csp->IsValid()) continue;
2618  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name));
2619  }
2620  d = maxdim(d, this->cargo_textsize); // Box must also be wide enough to hold any cargo label.
2621  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_CARGO));
2622 
2624  /* Ensure the height is enough for the industry type text, for the horizontal connections, and for the cargo labels. */
2626  d.height = std::max(d.height + WidgetDimensions::scaled.frametext.Vertical(), min_ind_height);
2627 
2628  CargoesField::industry_width = d.width;
2630 
2631  /* Width of a #CFT_CARGO field. */
2633  }
2634 
2635  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2636  {
2637  switch (widget) {
2638  case WID_IC_PANEL:
2642  break;
2643 
2644  case WID_IC_IND_DROPDOWN:
2645  size.width = std::max(size.width, this->ind_textsize.width + padding.width);
2646  break;
2647 
2648  case WID_IC_CARGO_DROPDOWN:
2649  size.width = std::max(size.width, this->cargo_textsize.width + padding.width);
2650  break;
2651  }
2652  }
2653 
2654  void SetStringParameters(WidgetID widget) const override
2655  {
2656  if (widget != WID_IC_CAPTION) return;
2657 
2658  if (this->ind_cargo < NUM_INDUSTRYTYPES) {
2659  const IndustrySpec *indsp = GetIndustrySpec(this->ind_cargo);
2660  SetDParam(0, indsp->name);
2661  } else {
2662  const CargoSpec *csp = CargoSpec::Get(this->ind_cargo - NUM_INDUSTRYTYPES);
2663  SetDParam(0, csp->name);
2664  }
2665  }
2666 
2673  static bool HasCommonValidCargo(const std::span<const CargoID> cargoes1, const std::span<const CargoID> cargoes2)
2674  {
2675  for (const CargoID cid1 : cargoes1) {
2676  if (!IsValidCargoID(cid1)) continue;
2677  for (const CargoID cid2 : cargoes2) {
2678  if (cid1 == cid2) return true;
2679  }
2680  }
2681  return false;
2682  }
2683 
2689  static bool HousesCanSupply(const std::span<const CargoID> cargoes)
2690  {
2691  for (const CargoID cid : cargoes) {
2692  if (!IsValidCargoID(cid)) continue;
2694  if (tpe == TPE_PASSENGERS || tpe == TPE_MAIL) return true;
2695  }
2696  return false;
2697  }
2698 
2704  static bool HousesCanAccept(const std::span<const CargoID> cargoes)
2705  {
2706  HouseZones climate_mask;
2708  case LT_TEMPERATE: climate_mask = HZ_TEMP; break;
2709  case LT_ARCTIC: climate_mask = HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW; break;
2710  case LT_TROPIC: climate_mask = HZ_SUBTROPIC; break;
2711  case LT_TOYLAND: climate_mask = HZ_TOYLND; break;
2712  default: NOT_REACHED();
2713  }
2714  for (const CargoID cid : cargoes) {
2715  if (!IsValidCargoID(cid)) continue;
2716 
2717  for (const auto &hs : HouseSpec::Specs()) {
2718  if (!hs.enabled || !(hs.building_availability & climate_mask)) continue;
2719 
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;
2722  }
2723  }
2724  }
2725  return false;
2726  }
2727 
2733  static int CountMatchingAcceptingIndustries(const std::span<const CargoID> cargoes)
2734  {
2735  int count = 0;
2736  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2737  const IndustrySpec *indsp = GetIndustrySpec(it);
2738  if (!indsp->enabled) continue;
2739 
2740  if (HasCommonValidCargo(cargoes, indsp->accepts_cargo)) count++;
2741  }
2742  return count;
2743  }
2744 
2750  static int CountMatchingProducingIndustries(const std::span<const CargoID> cargoes)
2751  {
2752  int count = 0;
2753  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2754  const IndustrySpec *indsp = GetIndustrySpec(it);
2755  if (!indsp->enabled) continue;
2756 
2757  if (HasCommonValidCargo(cargoes, indsp->produced_cargo)) count++;
2758  }
2759  return count;
2760  }
2761 
2768  void ShortenCargoColumn(int column, int top, int bottom)
2769  {
2770  while (top < bottom && !this->fields[top].columns[column].HasConnection()) {
2771  this->fields[top].columns[column].MakeEmpty(CFT_EMPTY);
2772  top++;
2773  }
2774  this->fields[top].columns[column].u.cargo.top_end = true;
2775 
2776  while (bottom > top && !this->fields[bottom].columns[column].HasConnection()) {
2777  this->fields[bottom].columns[column].MakeEmpty(CFT_EMPTY);
2778  bottom--;
2779  }
2780  this->fields[bottom].columns[column].u.cargo.bottom_end = true;
2781  }
2782 
2789  void PlaceIndustry(int row, int col, IndustryType it)
2790  {
2791  assert(this->fields[row].columns[col].type == CFT_EMPTY);
2792  this->fields[row].columns[col].MakeIndustry(it);
2793  if (col == 0) {
2794  this->fields[row].ConnectIndustryProduced(col);
2795  } else {
2796  this->fields[row].ConnectIndustryAccepted(col);
2797  }
2798  }
2799 
2804  {
2805  if (!this->IsWidgetLowered(WID_IC_NOTIFY)) return;
2806 
2807  /* Only notify the smallmap window if it exists. In particular, do not
2808  * bring it to the front to prevent messing up any nice layout of the user. */
2810  }
2811 
2816  void ComputeIndustryDisplay(IndustryType displayed_it)
2817  {
2818  this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2819  this->ind_cargo = displayed_it;
2820  _displayed_industries.reset();
2821  _displayed_industries.set(displayed_it);
2822 
2823  this->fields.clear();
2824  CargoesRow &first_row = this->fields.emplace_back();
2825  first_row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
2826  first_row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
2827  first_row.columns[2].MakeEmpty(CFT_SMALL_EMPTY);
2828  first_row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
2829  first_row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
2830 
2831  const IndustrySpec *central_sp = GetIndustrySpec(displayed_it);
2832  bool houses_supply = HousesCanSupply(central_sp->accepts_cargo);
2833  bool houses_accept = HousesCanAccept(central_sp->produced_cargo);
2834  /* Make a field consisting of two cargo columns. */
2835  int num_supp = CountMatchingProducingIndustries(central_sp->accepts_cargo) + houses_supply;
2836  int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo) + houses_accept;
2837  int num_indrows = std::max(3, std::max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
2838  for (int i = 0; i < num_indrows; i++) {
2839  CargoesRow &row = this->fields.emplace_back();
2840  row.columns[0].MakeEmpty(CFT_EMPTY);
2841  row.columns[1].MakeCargo(central_sp->accepts_cargo);
2842  row.columns[2].MakeEmpty(CFT_EMPTY);
2843  row.columns[3].MakeCargo(central_sp->produced_cargo);
2844  row.columns[4].MakeEmpty(CFT_EMPTY);
2845  }
2846  /* Add central industry. */
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);
2851 
2852  /* Add cargo labels. */
2853  this->fields[central_row - 1].MakeCargoLabel(2, true);
2854  this->fields[central_row + 1].MakeCargoLabel(2, false);
2855 
2856  /* Add suppliers and customers of the 'it' industry. */
2857  int supp_count = 0;
2858  int cust_count = 0;
2859  for (IndustryType it : _sorted_industry_types) {
2860  const IndustrySpec *indsp = GetIndustrySpec(it);
2861  if (!indsp->enabled) continue;
2862 
2863  if (HasCommonValidCargo(central_sp->accepts_cargo, indsp->produced_cargo)) {
2864  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2865  _displayed_industries.set(it);
2866  supp_count++;
2867  }
2868  if (HasCommonValidCargo(central_sp->produced_cargo, indsp->accepts_cargo)) {
2869  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2870  _displayed_industries.set(it);
2871  cust_count++;
2872  }
2873  }
2874  if (houses_supply) {
2875  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2876  supp_count++;
2877  }
2878  if (houses_accept) {
2879  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, NUM_INDUSTRYTYPES);
2880  cust_count++;
2881  }
2882 
2883  this->ShortenCargoColumn(1, 1, num_indrows);
2884  this->ShortenCargoColumn(3, 1, num_indrows);
2885  this->vscroll->SetCount(num_indrows);
2886  this->SetDirty();
2887  this->NotifySmallmap();
2888  }
2889 
2895  {
2896  this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2897  this->ind_cargo = cid + NUM_INDUSTRYTYPES;
2898  _displayed_industries.reset();
2899 
2900  this->fields.clear();
2901  CargoesRow &first_row = this->fields.emplace_back();
2902  first_row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
2903  first_row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
2904  first_row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
2905  first_row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
2906  first_row.columns[4].MakeEmpty(CFT_SMALL_EMPTY);
2907 
2908  auto cargoes = std::span(&cid, 1);
2909  bool houses_supply = HousesCanSupply(cargoes);
2910  bool houses_accept = HousesCanAccept(cargoes);
2911  int num_supp = CountMatchingProducingIndustries(cargoes) + houses_supply + 1; // Ensure room for the cargo label.
2912  int num_cust = CountMatchingAcceptingIndustries(cargoes) + houses_accept;
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();
2916  row.columns[0].MakeEmpty(CFT_EMPTY);
2917  row.columns[1].MakeCargo(cargoes);
2918  row.columns[2].MakeEmpty(CFT_EMPTY);
2919  row.columns[3].MakeEmpty(CFT_EMPTY);
2920  row.columns[4].MakeEmpty(CFT_EMPTY);
2921  }
2922 
2923  this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
2924 
2925  /* Add suppliers and customers of the cargo. */
2926  int supp_count = 0;
2927  int cust_count = 0;
2928  for (IndustryType it : _sorted_industry_types) {
2929  const IndustrySpec *indsp = GetIndustrySpec(it);
2930  if (!indsp->enabled) continue;
2931 
2932  if (HasCommonValidCargo(cargoes, indsp->produced_cargo)) {
2933  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2934  _displayed_industries.set(it);
2935  supp_count++;
2936  }
2937  if (HasCommonValidCargo(cargoes, indsp->accepts_cargo)) {
2938  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2939  _displayed_industries.set(it);
2940  cust_count++;
2941  }
2942  }
2943  if (houses_supply) {
2944  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2945  supp_count++;
2946  }
2947  if (houses_accept) {
2948  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
2949  cust_count++;
2950  }
2951 
2952  this->ShortenCargoColumn(1, 1, num_indrows);
2953  this->vscroll->SetCount(num_indrows);
2954  this->SetDirty();
2955  this->NotifySmallmap();
2956  }
2957 
2965  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2966  {
2967  if (!gui_scope) return;
2968  if (data == NUM_INDUSTRYTYPES) {
2970  return;
2971  }
2972 
2973  assert(data >= 0 && data < NUM_INDUSTRYTYPES);
2974  this->ComputeIndustryDisplay(data);
2975  }
2976 
2977  void DrawWidget(const Rect &r, WidgetID widget) const override
2978  {
2979  if (widget != WID_IC_PANEL) return;
2980 
2981  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
2982  DrawPixelInfo tmp_dpi;
2983  if (!FillDrawPixelInfo(&tmp_dpi, ir)) return;
2984  AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
2985 
2987  if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2;
2988  int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
2989 
2990  const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2991  int vpos = WidgetDimensions::scaled.frametext.top - WidgetDimensions::scaled.bevel.top - this->vscroll->GetPosition() * nwp->resize_y;
2992  int row_height = CargoesField::small_height;
2993  for (const auto &field : this->fields) {
2994  if (vpos + row_height >= 0) {
2995  int xpos = left_pos;
2996  int col, dir;
2997  if (_current_text_dir == TD_RTL) {
2998  col = last_column;
2999  dir = -1;
3000  } else {
3001  col = 0;
3002  dir = 1;
3003  }
3004  while (col >= 0 && col <= last_column) {
3005  field.columns[col].Draw(xpos, vpos);
3007  col += dir;
3008  }
3009  }
3010  vpos += row_height;
3011  if (vpos >= height) break;
3012  row_height = CargoesField::normal_height;
3013  }
3014  }
3015 
3023  bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
3024  {
3025  const NWidgetBase *nw = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
3026  pt.x -= nw->pos_x;
3027  pt.y -= nw->pos_y;
3028 
3029  int vpos = WidgetDimensions::scaled.frametext.top + CargoesField::small_height - this->vscroll->GetPosition() * nw->resize_y;
3030  if (pt.y < vpos) return false;
3031 
3032  int row = (pt.y - vpos) / CargoesField::normal_height; // row is relative to row 1.
3033  if (row + 1 >= (int)this->fields.size()) return false;
3034  vpos = pt.y - vpos - row * CargoesField::normal_height; // Position in the row + 1 field
3035  row++; // rebase row to match index of this->fields.
3036 
3038  if (pt.x < xpos) return false;
3039  int column;
3040  for (column = 0; column <= 5; column++) {
3042  if (pt.x < xpos + width) break;
3043  xpos += width;
3044  }
3045  int num_columns = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
3046  if (column > num_columns) return false;
3047  xpos = pt.x - xpos;
3048 
3049  /* Return both positions, compensating for RTL languages (which works due to the equal symmetry in both displays). */
3050  fieldxy->y = row;
3051  xy->y = vpos;
3052  if (_current_text_dir == TD_RTL) {
3053  fieldxy->x = num_columns - column;
3054  xy->x = ((column & 1) ? CargoesField::cargo_field_width : CargoesField::industry_width) - xpos;
3055  } else {
3056  fieldxy->x = column;
3057  xy->x = xpos;
3058  }
3059  return true;
3060  }
3061 
3062  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
3063  {
3064  switch (widget) {
3065  case WID_IC_PANEL: {
3066  Point fieldxy, xy;
3067  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return;
3068 
3069  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3070  switch (fld->type) {
3071  case CFT_INDUSTRY:
3072  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES) this->ComputeIndustryDisplay(fld->u.industry.ind_type);
3073  break;
3074 
3075  case CFT_CARGO: {
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;
3078  CargoID cid = fld->CargoClickedAt(lft, rgt, xy);
3079  if (IsValidCargoID(cid)) this->ComputeCargoDisplay(cid);
3080  break;
3081  }
3082 
3083  case CFT_CARGO_LABEL: {
3084  CargoID cid = fld->CargoLabelClickedAt(xy);
3085  if (IsValidCargoID(cid)) this->ComputeCargoDisplay(cid);
3086  break;
3087  }
3088 
3089  default:
3090  break;
3091  }
3092  break;
3093  }
3094 
3095  case WID_IC_NOTIFY:
3098  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
3099 
3100  if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
3101  if (FindWindowByClass(WC_SMALLMAP) == nullptr) ShowSmallMap();
3102  this->NotifySmallmap();
3103  }
3104  break;
3105 
3106  case WID_IC_CARGO_DROPDOWN: {
3107  DropDownList lst;
3109  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
3110  lst.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
3111  }
3112  if (!lst.empty()) {
3113  int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
3114  ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN);
3115  }
3116  break;
3117  }
3118 
3119  case WID_IC_IND_DROPDOWN: {
3120  DropDownList lst;
3121  for (IndustryType ind : _sorted_industry_types) {
3122  const IndustrySpec *indsp = GetIndustrySpec(ind);
3123  if (!indsp->enabled) continue;
3124  lst.push_back(MakeDropDownListStringItem(indsp->name, ind));
3125  }
3126  if (!lst.empty()) {
3127  int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
3128  ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN);
3129  }
3130  break;
3131  }
3132  }
3133  }
3134 
3135  void OnDropdownSelect(WidgetID widget, int index) override
3136  {
3137  if (index < 0) return;
3138 
3139  switch (widget) {
3140  case WID_IC_CARGO_DROPDOWN:
3141  this->ComputeCargoDisplay(index);
3142  break;
3143 
3144  case WID_IC_IND_DROPDOWN:
3145  this->ComputeIndustryDisplay(index);
3146  break;
3147  }
3148  }
3149 
3150  bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
3151  {
3152  if (widget != WID_IC_PANEL) return false;
3153 
3154  Point fieldxy, xy;
3155  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
3156 
3157  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3158  CargoID cid = INVALID_CARGO;
3159  switch (fld->type) {
3160  case CFT_CARGO: {
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;
3163  cid = fld->CargoClickedAt(lft, rgt, xy);
3164  break;
3165  }
3166 
3167  case CFT_CARGO_LABEL: {
3168  cid = fld->CargoLabelClickedAt(xy);
3169  break;
3170  }
3171 
3172  case CFT_INDUSTRY:
3173  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
3174  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond);
3175  }
3176  return true;
3177 
3178  default:
3179  break;
3180  }
3181  if (IsValidCargoID(cid) && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) {
3182  const CargoSpec *csp = CargoSpec::Get(cid);
3183  SetDParam(0, csp->name);
3184  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, 1);
3185  return true;
3186  }
3187 
3188  return false;
3189  }
3190 
3191  void OnResize() override
3192  {
3193  this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL, WidgetDimensions::scaled.framerect.Vertical() + CargoesField::small_height);
3194  }
3195 };
3196 
3201 static void ShowIndustryCargoesWindow(IndustryType id)
3202 {
3203  if (id >= NUM_INDUSTRYTYPES) {
3204  for (IndustryType ind : _sorted_industry_types) {
3205  const IndustrySpec *indsp = GetIndustrySpec(ind);
3206  if (indsp->enabled) {
3207  id = ind;
3208  break;
3209  }
3210  }
3211  if (id >= NUM_INDUSTRYTYPES) return;
3212  }
3213 
3215  if (w != nullptr) {
3216  w->InvalidateData(id);
3217  return;
3218  }
3219  new IndustryCargoesWindow(id);
3220 }
3221 
3224 {
3226 }
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition: industry_gui.cpp:223
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:738
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2926
_nested_industry_view_widgets
static constexpr NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
Definition: industry_gui.cpp:1203
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:285
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1183
ToPercent8
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
Definition: math_func.hpp:295
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:364
PRODLEVEL_MINIMUM
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
Definition: industry.h:35
CargoesField::MakeCargoLabel
void MakeCargoLabel(const std::span< const CargoID > cargoes, bool left_align)
Make a field displaying cargo type names.
Definition: industry_gui.cpp:2121
sound_func.h
CBM_IND_PRODUCTION_CARGO_ARRIVAL
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
Definition: newgrf_callbacks.h:365
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
Definition: industry_type.h:26
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
_build_industry_desc
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
@ CBM_IND_CARGO_SUFFIX
cargo sub-type display
Definition: newgrf_callbacks.h:370
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2512
INDUSTRYBEH_CARGOTYPES_UNLIMITED
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
Definition: industrytype.h:76
IndustrySpec::UsesOriginalEconomy
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
Definition: industry_cmd.cpp:3167
CargoesField::num_cargoes
uint8_t num_cargoes
Number of cargoes.
Definition: industry_gui.cpp:2021
HouseZones
HouseZones
Definition: house.h:66
WC_INDUSTRY_CARGOES
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
Definition: window_type.h:515
IndustryTypeNameSorter
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
Definition: industry_gui.cpp:226
IndustryViewWindow::clicked_button
uint8_t clicked_button
The button that has been clicked (to raise)
Definition: industry_gui.cpp:809
IndustryDirectoryWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: industry_gui.cpp:1898
CargoesField::INDUSTRY_LINE_COLOUR
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
Definition: industry_gui.cpp:1999
querystring_gui.h
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
BuildIndustryWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:421
ShowQuery
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...
Definition: misc_gui.cpp:1223
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
SetDParamMaxDigits
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:143
IndustryCargoesWindow::HousesCanSupply
static bool HousesCanSupply(const std::span< const CargoID > cargoes)
Can houses be used to supply one of the cargoes?
Definition: industry_gui.cpp:2689
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:422
IndustryCargoesWindow::ComputeIndustryDisplay
void ComputeIndustryDisplay(IndustryType displayed_it)
Compute what and where to display for industry type it.
Definition: industry_gui.cpp:2816
CargoesField::other_produced
CargoID other_produced[MAX_CARGOES]
Cargoes produced but not used in this figure.
Definition: industry_gui.cpp:2014
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
IndustryDirectoryWindow::SorterType::ByType
@ ByType
Sorter type to sort by type.
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition: viewport_type.h:78
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:206
CargoesField::top_end
uint8_t top_end
Stop at the top of the vertical cargoes.
Definition: industry_gui.cpp:2022
HouseSpec::Specs
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Definition: newgrf_house.cpp:50
dropdown_func.h
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:330
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
IndustryViewWindow::production_offset_y
int production_offset_y
The offset of the production texts/buttons.
Definition: industry_gui.cpp:810
smallmap_gui.h
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
CFT_HEADER
@ CFT_HEADER
Header text.
Definition: industry_gui.cpp:1983
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
IndustryDirectoryWindow::BuildSortIndustriesList
void BuildSortIndustriesList()
(Re)Build industries list
Definition: industry_gui.cpp:1434
company_base.h
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
IndustryCargoesWindow::ind_textsize
Dimension ind_textsize
Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
Definition: industry_gui.cpp:2554
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:85
BuildIndustryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:695
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:682
Industry::ProducedCargo::history
std::array< ProducedHistory, 2 > history
History of cargo produced and transported.
Definition: industry.h:84
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
IndustryViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1124
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:551
PRODLEVEL_CLOSURE
@ PRODLEVEL_CLOSURE
signal set to actually close the industry
Definition: industry.h:34
IndustrySpec::GetConstructionCost
Money GetConstructionCost() const
Get the cost for constructing this industry.
Definition: industry_cmd.cpp:3145
CSD_CARGO
@ CSD_CARGO
Display the cargo without sub-type (cb37 result 401).
Definition: industry_gui.cpp:68
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
IndustryViewWindow::EA_MULTIPLIER
@ EA_MULTIPLIER
Allow changing the production multiplier.
Definition: industry_gui.cpp:793
WID_IC_IND_DROPDOWN
@ WID_IC_IND_DROPDOWN
Select industry dropdown.
Definition: industry_widget.h:54
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2288
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:238
GUIList
List template of 'things' T to sort in a GUI.
Definition: sortlist_type.h:47
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:70
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:321
WID_IC_NOTIFY
@ WID_IC_NOTIFY
Row of buttons at the bottom.
Definition: industry_widget.h:50
CargoesRow
A single row of CargoesField.
Definition: industry_gui.cpp:2412
IndustryDirectoryWindow::SetAcceptedCargoFilter
void SetAcceptedCargoFilter(CargoID cid)
Set accepted cargo filter for the industry list.
Definition: industry_gui.cpp:1383
Industry::ProducedCargo::cargo
CargoID cargo
Cargo type.
Definition: industry.h:81
IndustryViewWindow::IsNewGRFInspectable
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition: industry_gui.cpp:1179
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:50
IndustryDirectoryWindow::SorterType::ByName
@ ByName
Sorter type to sort by name.
WID_IV_DISPLAY
@ WID_IV_DISPLAY
Display chain button.
Definition: industry_widget.h:31
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition: window_type.h:363
IntervalTimer< TimerWindow >
GB
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.
Definition: bitmath_func.hpp:32
CargoesField::cargo_stub
static Dimension cargo_stub
Dimensions of cargo stub (unconnected cargo line.)
Definition: industry_gui.cpp:1997
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:134
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
IndustryDirectoryWindow::rebuild_interval
IntervalTimer< TimerWindow > rebuild_interval
Rebuild the industry list on a regular interval.
Definition: industry_gui.cpp:1870
IndustryCargoesWindow::PlaceIndustry
void PlaceIndustry(int row, int col, IndustryType it)
Place an industry in the fields.
Definition: industry_gui.cpp:2789
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
SortIndustryTypes
void SortIndustryTypes()
Initialize the list of sorted industry types.
Definition: industry_gui.cpp:237
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
IndustryCargoesWindow::ShortenCargoColumn
void ShortenCargoColumn(int column, int top, int bottom)
Shorten the cargo column to just the part between industries.
Definition: industry_gui.cpp:2768
CST_DIR
@ CST_DIR
Industry-directory window.
Definition: industry_gui.cpp:63
CargoesField::legend
static Dimension legend
Dimension of the legend blob.
Definition: industry_gui.cpp:1993
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1193
HZ_SUBARTC_BELOW
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition: house.h:76
Cheats::setup_prod
Cheat setup_prod
setup raw-material production in game
Definition: cheat_type.h:33
BuildIndustryWindow::enabled
bool enabled
Availability state of the selected industry.
Definition: industry_gui.cpp:309
WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET
@ WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET
Create random industries button.
Definition: industry_widget.h:17
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1216
WID_DPI_SCENARIO_EDITOR_PANE
@ WID_DPI_SCENARIO_EDITOR_PANE
Pane containing SE-only widgets.
Definition: industry_widget.h:15
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
HandlePlacePushButton
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:63
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:93
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:124
WC_BUILD_INDUSTRY
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
Definition: window_type.h:441
zoom_func.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2394
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:525
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:566
WID_IC_CARGO_DROPDOWN
@ WID_IC_CARGO_DROPDOWN
Select cargo dropdown.
Definition: industry_widget.h:53
Industry::RecomputeProductionMultipliers
void RecomputeProductionMultipliers()
Recompute #production_rate for current prod_level.
Definition: industry_cmd.cpp:2531
CargoSpec::Iterate
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
Definition: cargotype.h:190
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:56
CargoesField::ConnectCargo
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
Definition: industry_gui.cpp:2060
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:71
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:484
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
newgrf_debug.h
town.h
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
IndustryViewWindow::ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition: industry_gui.cpp:1184
CBM_IND_PRODUCTION_256_TICKS
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Definition: newgrf_callbacks.h:366
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
CargoesField::cust_cargoes
Cargoes cust_cargoes
Cargoes in vertical_cargoes leaving to the right.
Definition: industry_gui.cpp:2020
ClampU
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:150
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
WID_ID_FILTER
@ WID_ID_FILTER
Textbox to filter industry name.
Definition: industry_widget.h:41
CargoesField::CARGO_LINE_COLOUR
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
Definition: industry_gui.cpp:2000
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:815
CargoSpec::GetCargoIcon
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
Definition: cargotype.cpp:154
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:347
GetAllCargoSuffixes
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)
Definition: industry_gui.cpp:156
IndustryDirectoryWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:1880
clear_map.h
PRODLEVEL_DEFAULT
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Definition: industry.h:36
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
IndustryCargoesWindow::HousesCanAccept
static bool HousesCanAccept(const std::span< const CargoID > cargoes)
Can houses be used as customers of the produced cargoes?
Definition: industry_gui.cpp:2704
IndustryDirectoryWindow::GetIndustryListWidth
uint GetIndustryListWidth() const
Get the width needed to draw the longest industry line.
Definition: industry_gui.cpp:1424
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:696
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:314
CargoesField::DrawHorConnection
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
Definition: industry_gui.cpp:2382
WID_IV_GOTO
@ WID_IV_GOTO
Goto button.
Definition: industry_widget.h:30
CFT_INDUSTRY
@ CFT_INDUSTRY
Display industry.
Definition: industry_gui.cpp:1980
MAX_CARGOES
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
Definition: industry_gui.cpp:1986
TPE_MAIL
@ TPE_MAIL
Cargo behaves mail-like for production.
Definition: cargotype.h:37
GameCreationSettings::landscape
uint8_t landscape
the landscape we're currently in
Definition: settings_type.h:368
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:142
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
IndustryCargoesWindow::ind_cargo
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
Definition: industry_gui.cpp:2552
IndustryDirectoryWindow::IndustryTransportedCargoSorter
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by transported cargo and name.
Definition: industry_gui.cpp:1553
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1077
GUIList::SetFilterFuncs
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
Definition: sortlist_type.h:369
genworld.h
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:391
WID_IC_SCROLLBAR
@ WID_IC_SCROLLBAR
Scrollbar of the panel.
Definition: industry_widget.h:52
CBM_IND_FUND_MORE_TEXT
@ CBM_IND_FUND_MORE_TEXT
additional text in fund window
Definition: newgrf_callbacks.h:371
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
IndustryDirectoryWindow::SorterType::ByProduction
@ ByProduction
Sorter type to sort by production amount.
BuildIndustryWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:746
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
textbuf_gui.h
CargoesField::GetCargoBase
int GetCargoBase(int xpos) const
For a CFT_CARGO, compute the left position of the left-most vertical cargo connection.
Definition: industry_gui.cpp:2145
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
CBID_INDUSTRY_FUND_MORE_TEXT
@ CBID_INDUSTRY_FUND_MORE_TEXT
Called to determine more text in the fund industry window.
Definition: newgrf_callbacks.h:165
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:594
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
IndustrySpec::map_colour
uint8_t map_colour
colour used for the small map
Definition: industrytype.h:122
WID_DPI_SCROLLBAR
@ WID_DPI_SCROLLBAR
Scrollbar of the matrix.
Definition: industry_widget.h:19
CcBuildIndustry
void CcBuildIndustry(Commands, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32_t, bool, uint32_t)
Command callback.
Definition: industry_gui.cpp:254
IndustryDirectoryWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:1669
IndustryCargoesWindow::HasCommonValidCargo
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?
Definition: industry_gui.cpp:2673
MakeClear
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
Scrollbar::GetCount
size_type GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:724
WindowDesc
High level window description.
Definition: window_gui.h:162
Industry::accepted
AcceptedCargoes accepted
accepted cargo slots
Definition: industry.h:100
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
BuildIndustryWindow::list
std::vector< IndustryType > list
List of industries.
Definition: industry_gui.cpp:308
RoundDivSU
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:342
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
ScaleByCargoScale
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
Definition: economy_func.h:77
CFT_CARGO
@ CFT_CARGO
Display cargo connections.
Definition: industry_gui.cpp:1981
IndustryDirectoryWindow::MAX_FILTER_LENGTH
const int MAX_FILTER_LENGTH
The max length of the filter, in chars.
Definition: industry_gui.cpp:1351
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
IndustryCargoesWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:3191
WID_IV_VIEWPORT
@ WID_IV_VIEWPORT
Viewport of the industry.
Definition: industry_widget.h:28
CargoesField::CargoLabelClickedAt
CargoID CargoLabelClickedAt(Point pt) const
Decide what cargo the user clicked in the cargo label field.
Definition: industry_gui.cpp:2359
Industry::prod_level
uint8_t prod_level
general production level
Definition: industry.h:101
HZ_TOYLND
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition: house.h:78
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1230
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition: viewport_type.h:77
_sorted_standard_cargo_specs
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:169
IsInsideBS
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.
Definition: math_func.hpp:252
IndustryCargoesWindow::CountMatchingProducingIndustries
static int CountMatchingProducingIndustries(const std::span< const CargoID > cargoes)
Count how many industries have produced cargoes in common with one of the supplied set.
Definition: industry_gui.cpp:2750
CargoSuffixDisplay
CargoSuffixDisplay
Ways of displaying the cargo.
Definition: industry_gui.cpp:67
IndustryCargoesWindow
Window displaying the cargo connections around an industry (or cargo).
Definition: industry_gui.cpp:2548
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1128
IndustrySpec::IsRawIndustry
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
Definition: industry_cmd.cpp:3125
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:150
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
Industry::produced
ProducedCargoes produced
produced cargo slots
Definition: industry.h:99
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
CommandCost
Common return value for all commands.
Definition: command_type.h:23
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
HZ_SUBTROPIC
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition: house.h:77
IndustryViewWindow::editable
Editability editable
Mode for changing production.
Definition: industry_gui.cpp:806
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2297
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:614
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:731
IndustryCargoesWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:2566
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
CargoesField::cargo_label
struct CargoesField::@5::@8 cargo_label
Label data (for CFT_CARGO_LABEL).
CargoesRow::MakeCargoLabel
void MakeCargoLabel(int column, bool accepting)
Construct a CFT_CARGO_LABEL field.
Definition: industry_gui.cpp:2457
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1746
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:83
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1286
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:346
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
CargoesField::vert_inter_industry_space
static int vert_inter_industry_space
Amount of space between two industries in a column.
Definition: industry_gui.cpp:1990
Window::HandleButtonClick
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:590
Industry::type
IndustryType type
type of industry.
Definition: industry.h:104
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
IndustryViewWindow::IL_NONE
@ IL_NONE
No line.
Definition: industry_gui.cpp:799
BuildIndustryWindow::MakeCargoListString
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.
Definition: industry_gui.cpp:372
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:940
IndustryDirectoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1849
WC_INDUSTRY_DIRECTORY
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
Definition: window_type.h:266
IndustryViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:837
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:236
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:210
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2501
CargoesField::industry_width
static int industry_width
Width of an industry field.
Definition: industry_gui.cpp:2004
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
IndustryDirectoryWindow
The list of industries.
Definition: industry_gui.cpp:1329
IndustrySpec::layouts
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
Definition: industrytype.h:102
CargoesField::MakeIndustry
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
Definition: industry_gui.cpp:2046
IndustryViewWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:1117
GetRawClearGround
ClearGround GetRawClearGround(Tile t)
Get the type of clear tile but never return CLEAR_SNOW.
Definition: clear_map.h:47
CargoesField
Data about a single field in the IndustryCargoesWindow panel.
Definition: industry_gui.cpp:1989
IndustryCargoesWindow::CountMatchingAcceptingIndustries
static int CountMatchingAcceptingIndustries(const std::span< const CargoID > cargoes)
Count how many industries have accepted cargoes in common with one of the supplied set.
Definition: industry_gui.cpp:2733
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:739
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:114
CargoFilterCriteria::CF_NONE
static constexpr CargoID CF_NONE
Show only items which do not carry cargo (e.g. train engines)
Definition: cargo_type.h:95
CargoesField::cargoes
CargoID cargoes[MAX_CARGOES]
Cargoes to display (or #INVALID_CARGO).
Definition: industry_gui.cpp:2026
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:146
CargoSuffix::display
CargoSuffixDisplay display
How to display the cargo and text.
Definition: industry_gui.cpp:76
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:256
TPE_PASSENGERS
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
Definition: cargotype.h:36
WID_ID_FILTER_BY_ACC_CARGO
@ WID_ID_FILTER_BY_ACC_CARGO
Accepted cargo filter dropdown list.
Definition: industry_widget.h:39
WID_ID_VSCROLLBAR
@ WID_ID_VSCROLLBAR
Vertical scrollbar of the list.
Definition: industry_widget.h:44
IndustryDirectoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:1863
CargoesField::industry
struct CargoesField::@5::@6 industry
Industry data (for CFT_INDUSTRY).
dropdown_type.h
IndustryDirectoryWindow::GetIndustryString
StringID GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
Definition: industry_gui.cpp:1564
GetIndustryProbabilityCallback
uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
Definition: newgrf_industries.cpp:564
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:57
ShowIndustryCargoesWindow
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
Definition: industry_gui.cpp:3201
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:952
PSM_ENTER_GAMELOOP
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
Definition: newgrf_storage.h:21
CargoesField::max_cargoes
static uint max_cargoes
Largest number of cargoes actually on any industry.
Definition: industry_gui.cpp:2005
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1311
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:246
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:52
PRODLEVEL_MAXIMUM
@ PRODLEVEL_MAXIMUM
the industry is running at full speed
Definition: industry.h:37
industry.h
safeguards.h
sortlist_type.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1079
timer.h
GUIList< const Industry *, const CargoID &, const std::pair< CargoID, CargoID > & >::FilterFunction
bool(const const Industry * *, const std::pair< CargoID, CargoID > &) FilterFunction
Signature of filter function.
Definition: sortlist_type.h:50
WID_ID_INDUSTRY_LIST
@ WID_ID_INDUSTRY_LIST
Industry list.
Definition: industry_widget.h:42
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:280
CST_VIEW
@ CST_VIEW
View-industry window.
Definition: industry_gui.cpp:62
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:303
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
BuildIndustryWindow::legend
Dimension legend
Dimension of the legend 'blob'.
Definition: industry_gui.cpp:311
_nested_industry_directory_widgets
static constexpr NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
Definition: industry_gui.cpp:1240
CargoesRow::ConnectIndustryProduced
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
Definition: industry_gui.cpp:2419
IndustryDirectoryWindow::SetProducedCargoFilter
void SetProducedCargoFilter(CargoID cid)
Set produced cargo filter for the industry list.
Definition: industry_gui.cpp:1366
CargoesField::HasConnection
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
Definition: industry_gui.cpp:2089
Industry::GetCargoProduced
ProducedCargoes::iterator GetCargoProduced(CargoID cargo)
Get produced cargo slot for a specific cargo type.
Definition: industry.h:169
_displayed_industries
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
Definition: industry_gui.cpp:57
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:65
CargoesField::header
StringID header
Header text (for CFT_HEADER).
Definition: industry_gui.cpp:2029
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:988
CargoesField::vertical_cargoes
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
Definition: industry_gui.cpp:2018
IndustryDirectoryWindow::accepted_cargo_filter_criteria
CargoID accepted_cargo_filter_criteria
Selected accepted cargo filter index.
Definition: industry_gui.cpp:1348
newgrf_text.h
IndustryDirectoryWindow::SorterType::ByTransported
@ ByTransported
Sorter type to sort by transported percentage.
CBID_INDUSTRY_CARGO_SUFFIX
@ CBID_INDUSTRY_CARGO_SUFFIX
Called to determine text to display after cargo name.
Definition: newgrf_callbacks.h:162
IndustryCargoesWindow::CalculatePositionInWidget
bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
Calculate in which field was clicked, and within the field, at what position.
Definition: industry_gui.cpp:3023
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
CFT_SMALL_EMPTY
@ CFT_SMALL_EMPTY
Empty small field (for the header).
Definition: industry_gui.cpp:1979
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
IndustryDirectoryWindow::GetCargoTransportedPercentsIfValid
static int GetCargoTransportedPercentsIfValid(const Industry::ProducedCargo &p)
Returns percents of cargo transported if industry produces this cargo, else -1.
Definition: industry_gui.cpp:1473
Scrollbar::GetCapacity
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:733
GetGRFStringID
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:587
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
CargoesField::Draw
void Draw(int xpos, int ypos) const
Draw the field.
Definition: industry_gui.cpp:2158
IndustryCargoesWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:2965
IndustryViewWindow::Editability
Editability
Modes for changing production.
Definition: industry_gui.cpp:791
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:305
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:486
GfxFillRect
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.
Definition: gfx.cpp:114
GetCargoSuffix
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)
Definition: industry_gui.cpp:92
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:101
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3148
CFT_CARGO_LABEL
@ CFT_CARGO_LABEL
Display cargo labels.
Definition: industry_gui.cpp:1982
CargoesField::normal_height
static int normal_height
Height of the non-header rows.
Definition: industry_gui.cpp:2002
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:25
viewport_func.h
Industry::text
std::string text
General text with additional information.
Definition: industry.h:121
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
CargoesField::small_height
static int small_height
Height of the header row.
Definition: industry_gui.cpp:2002
IACT_USERCREATION
@ IACT_USERCREATION
from the Fund/build window
Definition: newgrf_industries.h:84
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:346
OrthogonalTileArea::GetCenterTile
TileIndex GetCenterTile() const
Get the center tile.
Definition: tilearea_type.h:59
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
CFT_EMPTY
@ CFT_EMPTY
Empty field.
Definition: industry_gui.cpp:1978
Industry::ProducedCargo
Definition: industry.h:80
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1548
FILLRECT_OPAQUE
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition: gfx_type.h:300
CargoesField::cargo_space
static Dimension cargo_space
Dimensions of space between cargo lines.
Definition: industry_gui.cpp:1996
IndustryViewWindow
Definition: industry_gui.cpp:788
IndustrySpec::callback_mask
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
Definition: industrytype.h:132
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
IndustryViewWindow::EA_RATE
@ EA_RATE
Allow changing the production rates.
Definition: industry_gui.cpp:794
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:390
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:922
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:67
CargoesField::cargo_border
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
Definition: industry_gui.cpp:1994
IndustryDirectoryWindow::IndustryNameSorter
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b, const CargoID &)
Sort industries by name.
Definition: industry_gui.cpp:1512
IndustryTemporarilyRefusesCargo
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Definition: newgrf_industries.cpp:677
IndustryDirectoryWindow::produced_cargo_filter_criteria
CargoID produced_cargo_filter_criteria
Selected produced cargo filter index.
Definition: industry_gui.cpp:1347
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:399
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:798
IndustryViewWindow::IL_MULTIPLIER
@ IL_MULTIPLIER
Production multiplier.
Definition: industry_gui.cpp:800
WID_DPI_INFOPANEL
@ WID_DPI_INFOPANEL
Info panel about the industry.
Definition: industry_widget.h:20
CargoesField::left_align
bool left_align
Align all cargo texts to the left (else align to the right).
Definition: industry_gui.cpp:2027
ZOOM_LVL_INDUSTRY
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
Definition: zoom_type.h:30
string_func.h
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:133
IndustryViewWindow::cheat_line_height
int cheat_line_height
Height of each line for the WID_IV_INFO panel.
Definition: industry_gui.cpp:812
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:500
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
CargoesField::supp_cargoes
Cargoes supp_cargoes
Cargoes in vertical_cargoes entering from the left.
Definition: industry_gui.cpp:2019
ConstructionSettings::raw_industry_construction
uint8_t raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
Definition: settings_type.h:393
PC_YELLOW
static const uint8_t PC_YELLOW
Yellow palette colour.
Definition: palette_func.h:80
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:115
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:223
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
DrawStringMultiLine
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.
Definition: gfx.cpp:774
WID_ID_DROPDOWN_CRITERIA
@ WID_ID_DROPDOWN_CRITERIA
Dropdown for the criteria of the sort.
Definition: industry_widget.h:38
WID_IC_CAPTION
@ WID_IC_CAPTION
Caption of the window.
Definition: industry_widget.h:49
IndustryViewWindow::cargo_icon_size
Dimension cargo_icon_size
Largest cargo icon dimension.
Definition: industry_gui.cpp:805
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:53
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
Definition: misc_gui.cpp:760
CargoSpec::town_production_effect
TownProductionEffect town_production_effect
The effect on town cargo production.
Definition: cargotype.h:84
IndustryViewWindow::IL_RATE1
@ IL_RATE1
Production rate of cargo 1.
Definition: industry_gui.cpp:801
Pool::PoolItem<&_industry_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
WID_DPI_DISPLAY_WIDGET
@ WID_DPI_DISPLAY_WIDGET
Display chain button.
Definition: industry_widget.h:21
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1723
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
CargoesRow::columns
CargoesField columns[5]
One row of fields.
Definition: industry_gui.cpp:2413
CSD_CARGO_AMOUNT_TEXT
@ CSD_CARGO_AMOUNT_TEXT
Display then cargo, amount, and string (cb37 result 000-3FF).
Definition: industry_gui.cpp:71
CargoesField::MakeHeader
void MakeHeader(StringID textid)
Make a header above an industry column.
Definition: industry_gui.cpp:2134
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:566
_industry_directory_desc
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.
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:250
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:138
IndustryDirectoryWindow::GetCargoTransportedSortValue
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
Definition: industry_gui.cpp:1486
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:369
industry_widget.h
IndustryViewWindow::editbox_line
InfoLine editbox_line
The line clicked to open the edit box.
Definition: industry_gui.cpp:807
INVALID_INDUSTRYTYPE
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
Definition: industry_type.h:27
HZ_SUBARTC_ABOVE
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition: house.h:74
CST_FUND
@ CST_FUND
Fund-industry window.
Definition: industry_gui.cpp:61
IndustryCargoesWindow::cargo_textsize
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
Definition: industry_gui.cpp:2553
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
CargoesFieldType
CargoesFieldType
Available types of field.
Definition: industry_gui.cpp:1977
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
BuildIndustryWindow::selected_type
IndustryType selected_type
industry corresponding to the above index
Definition: industry_gui.cpp:307
IndustryViewWindow::EA_NONE
@ EA_NONE
Not alterable.
Definition: industry_gui.cpp:792
WID_DPI_FUND_WIDGET
@ WID_DPI_FUND_WIDGET
Fund button.
Definition: industry_widget.h:22
IndustryCargoesWindow::ComputeCargoDisplay
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
Definition: industry_gui.cpp:2894
INDUSTRY_ORIGINAL_NUM_OUTPUTS
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
Definition: industry_type.h:41
geometry_func.hpp
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
InvalidateWindowClassesData
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...
Definition: window.cpp:3225
IndustryDirectoryWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: industry_gui.cpp:1408
cheat_type.h
industry_cmd.h
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
WID_IC_PANEL
@ WID_IC_PANEL
Panel that shows the chain.
Definition: industry_widget.h:51
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
CargoesField::cargo_field_width
static int cargo_field_width
Width of a cargo field.
Definition: industry_gui.cpp:2003
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:150
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:238
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:2067
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:782
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:319
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:134
ShowDropDownMenu
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.
Definition: dropdown.cpp:441
CSD_CARGO_TEXT
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
Definition: industry_gui.cpp:70
Industry::GetIndustryTypeCount
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:275
EventState
EventState
State of handling an event.
Definition: window_type.h:737
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
IndustryViewWindow::clicked_line
InfoLine clicked_line
The line of the button that has been clicked.
Definition: industry_gui.cpp:808
INDUSTRY_ORIGINAL_NUM_INPUTS
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
Definition: industry_type.h:40
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1113
TownProductionEffect
TownProductionEffect
Town effect when producing cargo.
Definition: cargotype.h:34
IndustryDirectoryWindow::IndustryTypeSorter
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by type and name.
Definition: industry_gui.cpp:1520
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
IndustryViewWindow::InfoLine
InfoLine
Specific lines in the info panel.
Definition: industry_gui.cpp:798
IndustryViewWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:1167
CargoID
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
_industry_view_desc
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.
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:344
GUISettings::scrollwheel_scrolling
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:177
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:88
CBM_IND_WINDOW_MORE_TEXT
@ CBM_IND_WINDOW_MORE_TEXT
additional text in industry window
Definition: newgrf_callbacks.h:372
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1733
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:67
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:404
CargoesField::MakeCargo
void MakeCargo(const std::span< const CargoID > cargoes)
Make a piece of cargo column.
Definition: industry_gui.cpp:2101
WID_ID_DROPDOWN_ORDER
@ WID_ID_DROPDOWN_ORDER
Dropdown for the order of the sort.
Definition: industry_widget.h:37
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:53
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
CargoesRow::ConnectIndustryAccepted
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
Definition: industry_gui.cpp:2478
BuildIndustryWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: industry_gui.cpp:751
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:313
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:505
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:345
network.h
Window::RaiseWidgetWhenLowered
void RaiseWidgetWhenLowered(WidgetID widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Definition: window_gui.h:487
CommandHelper
Definition: command_func.h:93
WID_ID_HSCROLLBAR
@ WID_ID_HSCROLLBAR
Horizontal scrollbar of the list.
Definition: industry_widget.h:43
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
window_func.h
IndustrySpec::behaviour
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:121
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:249
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:77
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
stringfilter_type.h
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1139
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1529
CargoIDComparator
Comparator to sort CargoID by according to desired order.
Definition: cargotype.h:241
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
random_func.hpp
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:409
DrawRectOutline
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
Definition: gfx.cpp:456
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:251
CargoSuffix
Transfer storage of cargo suffix information.
Definition: industry_gui.cpp:75
CargoesField::bottom_end
uint8_t bottom_end
Stop at the bottom of the vertical cargoes.
Definition: industry_gui.cpp:2023
HZ_TEMP
@ HZ_TEMP
12 1000 can appear in temperate climate
Definition: house.h:75
DrawString
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.
Definition: gfx.cpp:657
timer_window.h
Rect::Contains
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
Definition: geometry_type.hpp:223
CargoesField::blob_distance
static int blob_distance
Distance of the industry legend colour from the edge of the industry box.
Definition: industry_gui.cpp:1991
PSM_LEAVE_GAMELOOP
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
Definition: newgrf_storage.h:22
GetStringListBoundingBox
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition: gfx.cpp:889
BasePersistentStorageArray::SwitchMode
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...
Definition: newgrf_storage.cpp:54
CBID_INDUSTRY_WINDOW_MORE_TEXT
@ CBID_INDUSTRY_WINDOW_MORE_TEXT
Called to determine more text in the industry window.
Definition: newgrf_callbacks.h:171
IndustryViewWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:830
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:107
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:751
CargoesField::ind_type
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
Definition: industry_gui.cpp:2013
WID_ID_CAPTION
@ WID_ID_CAPTION
Caption of the window.
Definition: industry_widget.h:36
IndustryDirectoryWindow::IndustryProductionSorter
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b, const CargoID &filter)
Sort industries by production and name.
Definition: industry_gui.cpp:1531
IndustryDirectoryWindow::SorterType
SorterType
Definition: industry_gui.cpp:1355
BuildIndustryWindow::SetButtons
void SetButtons()
Update status of the fund and display-chain widgets.
Definition: industry_gui.cpp:354
IndustryDirectoryWindow::string_filter
StringFilter string_filter
Filter for industries.
Definition: industry_gui.cpp:1352
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:742
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
IndustrySpec::accepts_cargo
std::array< CargoID, INDUSTRY_NUM_INPUTS > accepts_cargo
16 accepted cargoes.
Definition: industrytype.h:116
gui.h
newgrf_industries.h
WID_IV_CAPTION
@ WID_IV_CAPTION
Caption of the window.
Definition: industry_widget.h:27
WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET
@ WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET
Remove all industries button.
Definition: industry_widget.h:16
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:595
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:123
CargoSuffixType
CargoSuffixType
Cargo suffix type (for which window is it requested)
Definition: industry_gui.cpp:60
Window
Data structure for an opened window.
Definition: window_gui.h:276
Commands
Commands
List of commands.
Definition: command_type.h:187
_industry_cargoes_desc
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.
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition: industrytype.h:123
SWS_OFF
@ SWS_OFF
Scroll wheel has no effect.
Definition: settings_type.h:133
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
IndustryViewWindow::DrawInfo
int DrawInfo(const Rect &r)
Draw the text in the WID_IV_INFO panel.
Definition: industry_gui.cpp:866
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
WID_ID_FILTER_BY_PROD_CARGO
@ WID_ID_FILTER_BY_PROD_CARGO
Produced cargo filter dropdown list.
Definition: industry_widget.h:40
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:312
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1204
settings_gui.h
CargoesField::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:2008
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:224
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1151
CargoesField::MakeEmpty
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
Definition: industry_gui.cpp:2036
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
WID_DPI_MATRIX_WIDGET
@ WID_DPI_MATRIX_WIDGET
Matrix of the industries.
Definition: industry_widget.h:18
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:65
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:459
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1223
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition: clear_map.h:23
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Widget part function for setting the aspect ratio.
Definition: widget_type.h:1297
CargoesField::CargoClickedAt
CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
Decide which cargo was clicked at in a CFT_CARGO field.
Definition: industry_gui.cpp:2301
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:270
IndustryViewWindow::IL_RATE2
@ IL_RATE2
Production rate of cargo 2.
Definition: industry_gui.cpp:802
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
GRFFile::cargo_map
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:131
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:881
CargoFilter
static bool CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
Definition: industry_gui.cpp:1280
GetIndustryCallback
uint16_t GetIndustryCallback(CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
Definition: newgrf_industries.cpp:516
CargoSuffix::text
std::string text
Cargo suffix text.
Definition: industry_gui.cpp:77
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3495
BuildIndustryWindow::MAX_MINWIDTH_LINEHEIGHTS
static const int MAX_MINWIDTH_LINEHEIGHTS
The largest allowed minimum-width of the window, given in line heights.
Definition: industry_gui.cpp:314
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:104
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition: widget_type.h:862
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
IndustryCargoesWindow::fields
Fields fields
Fields to display in the WID_IC_PANEL.
Definition: industry_gui.cpp:2551
GetLargestCargoIconSize
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
Definition: cargotype.cpp:124
IndustryCargoesWindow::NotifySmallmap
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
Definition: industry_gui.cpp:2803
GUIList::SetFilterType
void SetFilterType(uint8_t n_type)
Set the filtertype of the list.
Definition: sortlist_type.h:177
CSD_CARGO_AMOUNT
@ CSD_CARGO_AMOUNT
Display the cargo and amount (if useful), but no sub-type (cb37 result 400 or fail).
Definition: industry_gui.cpp:69
IndustryViewWindow::info_height
int info_height
Height needed for the WID_IV_INFO panel.
Definition: industry_gui.cpp:811
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:851
IDHK_FOCUS_FILTER_BOX
@ IDHK_FOCUS_FILTER_BOX
Focus the filter box.
Definition: industry_gui.cpp:1324
CargoesField::cargo
struct CargoesField::@5::@7 cargo
Cargo data (for CFT_CARGO).
StringFilter
String filter and state.
Definition: stringfilter_type.h:30
GenerateIndustries
void GenerateIndustries()
This function will create random industries during game creation.
Definition: industry_cmd.cpp:2462
IndustryDirectoryWindow::industry_editbox
QueryString industry_editbox
Filter editbox.
Definition: industry_gui.cpp:1353
WID_IV_INFO
@ WID_IV_INFO
Info of the industry.
Definition: industry_widget.h:29
CargoFilterCriteria::CF_ANY
static constexpr CargoID CF_ANY
Show all items independent of carried cargo (i.e. no filtering)
Definition: cargo_type.h:94
BuildIndustryWindow
Build (fund or prospect) a new industry,.
Definition: industry_gui.cpp:306
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:611
CargoesField::cargo_line
static Dimension cargo_line
Dimensions of cargo lines.
Definition: industry_gui.cpp:1995
GUIList::SetSortFuncs
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
Definition: sortlist_type.h:297
CargoesField::other_accepted
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
Definition: industry_gui.cpp:2015
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
TileHighlightData::GetCallbackWnd
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Definition: viewport.cpp:2585
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:157
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:198
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:152
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
IndustryDirectoryHotkeys
IndustryDirectoryHotkeys
Enum referring to the Hotkeys in the industry directory window.
Definition: industry_gui.cpp:1323
hotkeys.h
_nested_industry_cargoes_widgets
static constexpr NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
Definition: industry_gui.cpp:1944
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
backup_type.hpp
BuildIndustryWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:761
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103