OpenTTD Source  14.0-beta3
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 "widgets/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 "widgets/dropdown_type.h"
40 #include "clear_map.h"
41 #include "zoom_func.h"
42 #include "industry_cmd.h"
43 #include "querystring_gui.h"
44 #include "stringfilter_type.h"
45 #include "timer/timer.h"
46 #include "timer/timer_window.h"
47 #include "hotkeys.h"
48 
49 #include "table/strings.h"
50 
51 #include <bitset>
52 
53 #include "safeguards.h"
54 
55 bool _ignore_restrictions;
56 std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
57 
63 };
64 
71 };
72 
74 struct CargoSuffix {
76  std::string text;
77 };
78 
79 extern void GenerateIndustries();
80 static void ShowIndustryCargoesWindow(IndustryType id);
81 
91 static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
92 {
93  suffix.text.clear();
94  suffix.display = CSD_CARGO_AMOUNT;
95 
96  if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
97  TileIndex t = (cst != CST_FUND) ? ind->location.tile : INVALID_TILE;
98  uint16_t callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, t);
99  if (callback == CALLBACK_FAILED) return;
100 
101  if (indspec->grf_prop.grffile->grf_version < 8) {
102  if (GB(callback, 0, 8) == 0xFF) return;
103  if (callback < 0x400) {
105  suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback));
108  return;
109  }
111  return;
112 
113  } else { // GRF version 8 or higher.
114  if (callback == 0x400) return;
115  if (callback == 0x401) {
116  suffix.display = CSD_CARGO;
117  return;
118  }
119  if (callback < 0x400) {
121  suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback));
124  return;
125  }
126  if (callback >= 0x800 && callback < 0xC00) {
128  suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 - 0x800 + callback));
130  suffix.display = CSD_CARGO_TEXT;
131  return;
132  }
134  return;
135  }
136  }
137 }
138 
139 enum CargoSuffixInOut {
140  CARGOSUFFIX_OUT = 0,
141  CARGOSUFFIX_IN = 1,
142 };
143 
154 template <typename TC, typename TS>
155 static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
156 {
157  static_assert(lengthof(cargoes) <= lengthof(suffixes));
158 
160  /* Reworked behaviour with new many-in-many-out scheme */
161  for (uint j = 0; j < lengthof(suffixes); j++) {
162  if (IsValidCargoID(cargoes[j])) {
163  byte local_id = indspec->grf_prop.grffile->cargo_map[cargoes[j]]; // should we check the value for valid?
164  uint cargotype = local_id << 16 | use_input;
165  GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
166  } else {
167  suffixes[j].text[0] = '\0';
168  suffixes[j].display = CSD_CARGO;
169  }
170  }
171  } else {
172  /* Compatible behaviour with old 3-in-2-out scheme */
173  for (uint j = 0; j < lengthof(suffixes); j++) {
174  suffixes[j].text[0] = '\0';
175  suffixes[j].display = CSD_CARGO;
176  }
177  switch (use_input) {
178  case CARGOSUFFIX_OUT:
179  if (IsValidCargoID(cargoes[0])) GetCargoSuffix(3, cst, ind, ind_type, indspec, suffixes[0]);
180  if (IsValidCargoID(cargoes[1])) GetCargoSuffix(4, cst, ind, ind_type, indspec, suffixes[1]);
181  break;
182  case CARGOSUFFIX_IN:
183  if (IsValidCargoID(cargoes[0])) GetCargoSuffix(0, cst, ind, ind_type, indspec, suffixes[0]);
184  if (IsValidCargoID(cargoes[1])) GetCargoSuffix(1, cst, ind, ind_type, indspec, suffixes[1]);
185  if (IsValidCargoID(cargoes[2])) GetCargoSuffix(2, cst, ind, ind_type, indspec, suffixes[2]);
186  break;
187  default:
188  NOT_REACHED();
189  }
190  }
191 }
192 
204 void GetCargoSuffix(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoID cargo, uint8_t slot, CargoSuffix &suffix)
205 {
206  suffix.text[0] = '\0';
207  suffix.display = CSD_CARGO;
208  if (!IsValidCargoID(cargo)) return;
210  byte local_id = indspec->grf_prop.grffile->cargo_map[cargo]; // should we check the value for valid?
211  uint cargotype = local_id << 16 | use_input;
212  GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffix);
213  } else if (use_input == CARGOSUFFIX_IN) {
214  if (slot < 3) GetCargoSuffix(slot, cst, ind, ind_type, indspec, suffix);
215  } else if (use_input == CARGOSUFFIX_OUT) {
216  if (slot < 2) GetCargoSuffix(slot + 3, cst, ind, ind_type, indspec, suffix);
217  }
218 }
219 
220 std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
221 
223 static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
224 {
225  int r = StrNaturalCompare(GetString(GetIndustrySpec(a)->name), GetString(GetIndustrySpec(b)->name)); // Sort by name (natural sorting).
226 
227  /* If the names are equal, sort by industry type. */
228  return (r != 0) ? r < 0 : (a < b);
229 }
230 
235 {
236  /* Add each industry type to the list. */
237  for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
238  _sorted_industry_types[i] = i;
239  }
240 
241  /* Sort industry types by name. */
243 }
244 
251 void CcBuildIndustry(Commands, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32_t, bool, uint32_t)
252 {
253  if (result.Succeeded()) return;
254 
255  if (indtype < NUM_INDUSTRYTYPES) {
256  const IndustrySpec *indsp = GetIndustrySpec(indtype);
257  if (indsp->enabled) {
258  SetDParam(0, indsp->name);
259  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, result.GetErrorMessage(), WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE);
260  }
261  }
262 }
263 
264 static constexpr NWidgetPart _nested_build_industry_widgets[] = {
266  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
267  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FUND_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
268  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
269  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
270  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
271  EndContainer(),
275  SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
276  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET), SetMinimalSize(0, 12), SetFill(1, 0), SetResize(1, 0),
277  SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
278  EndContainer(),
279  EndContainer(),
281  NWidget(WWT_MATRIX, COLOUR_DARK_GREEN, WID_DPI_MATRIX_WIDGET), SetMatrixDataTip(1, 0, STR_FUND_INDUSTRY_SELECTION_TOOLTIP), SetFill(1, 0), SetResize(1, 1), SetScrollbar(WID_DPI_SCROLLBAR),
282  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_DPI_SCROLLBAR),
283  EndContainer(),
284  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_DPI_INFOPANEL), SetResize(1, 0),
285  EndContainer(),
287  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_DISPLAY_WIDGET), SetFill(1, 0), SetResize(1, 0),
288  SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
289  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_FUND_WIDGET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
290  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
291  EndContainer(),
292 };
293 
295 static WindowDesc _build_industry_desc(__FILE__, __LINE__,
296  WDP_AUTO, "build_industry", 170, 212,
299  std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets)
300 );
301 
303 class BuildIndustryWindow : public Window {
304  IndustryType selected_type;
305  std::vector<IndustryType> list;
306  bool enabled;
307  Scrollbar *vscroll;
309 
311  static const int MAX_MINWIDTH_LINEHEIGHTS = 20;
312 
313  void UpdateAvailability()
314  {
315  this->enabled = this->selected_type != INVALID_INDUSTRYTYPE && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0);
316  }
317 
318  void SetupArrays()
319  {
320  this->list.clear();
321 
322  /* Fill the arrays with industries.
323  * The tests performed after the enabled allow to load the industries
324  * In the same way they are inserted by grf (if any)
325  */
326  for (IndustryType ind : _sorted_industry_types) {
327  const IndustrySpec *indsp = GetIndustrySpec(ind);
328  if (indsp->enabled) {
329  /* Rule is that editor mode loads all industries.
330  * In game mode, all non raw industries are loaded too
331  * and raw ones are loaded only when setting allows it */
332  if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
333  /* Unselect if the industry is no longer in the list */
334  if (this->selected_type == ind) this->selected_type = INVALID_INDUSTRYTYPE;
335  continue;
336  }
337 
338  this->list.push_back(ind);
339  }
340  }
341 
342  /* First industry type is selected if the current selection is invalid. */
343  if (this->selected_type == INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
344 
345  this->UpdateAvailability();
346 
347  this->vscroll->SetCount(this->list.size());
348  }
349 
351  void SetButtons()
352  {
353  this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled);
354  this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled);
355  }
356 
369  std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
370  {
371  std::string cargostring;
372  int numcargo = 0;
373  int firstcargo = -1;
374 
375  for (int j = 0; j < cargolistlen; j++) {
376  if (!IsValidCargoID(cargolist[j])) continue;
377  numcargo++;
378  if (firstcargo < 0) {
379  firstcargo = j;
380  continue;
381  }
382  SetDParam(0, CargoSpec::Get(cargolist[j])->name);
383  SetDParamStr(1, cargo_suffix[j].text);
384  cargostring += GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
385  }
386 
387  if (numcargo > 0) {
388  SetDParam(0, CargoSpec::Get(cargolist[firstcargo])->name);
389  SetDParamStr(1, cargo_suffix[firstcargo].text);
390  cargostring = GetString(prefixstr) + cargostring;
391  } else {
392  SetDParam(0, STR_JUST_NOTHING);
393  SetDParamStr(1, "");
394  cargostring = GetString(prefixstr);
395  }
396 
397  return cargostring;
398  }
399 
400 public:
402  {
403  this->selected_type = INVALID_INDUSTRYTYPE;
404 
405  this->CreateNestedTree();
406  this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
407  /* Show scenario editor tools in editor. */
408  if (_game_mode != GM_EDITOR) {
409  this->GetWidget<NWidgetStacked>(WID_DPI_SCENARIO_EDITOR_PANE)->SetDisplayedPlane(SZSP_HORIZONTAL);
410  }
411  this->FinishInitNested(0);
412 
413  this->SetButtons();
414  }
415 
416  void OnInit() override
417  {
418  /* Width of the legend blob -- slightly larger than the smallmap legend blob. */
419  this->legend.height = GetCharacterHeight(FS_SMALL);
420  this->legend.width = this->legend.height * 9 / 6;
421 
422  this->SetupArrays();
423  }
424 
425  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
426  {
427  switch (widget) {
428  case WID_DPI_MATRIX_WIDGET: {
429  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
430  for (const auto &indtype : this->list) {
431  d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name));
432  }
433  resize->height = std::max<uint>(this->legend.height, GetCharacterHeight(FS_NORMAL)) + padding.height;
434  d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width;
435  d.height = 5 * resize->height;
436  *size = maxdim(*size, d);
437  break;
438  }
439 
440  case WID_DPI_INFOPANEL: {
441  /* Extra line for cost outside of editor. */
442  int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
443  uint extra_lines_req = 0;
444  uint extra_lines_prd = 0;
445  uint extra_lines_newgrf = 0;
447  Dimension d = {0, 0};
448  for (const auto &indtype : this->list) {
449  const IndustrySpec *indsp = GetIndustrySpec(indtype);
450  CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
451 
452  /* Measure the accepted cargoes, if any. */
453  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix);
454  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
455  Dimension strdim = GetStringBoundingBox(cargostring);
456  if (strdim.width > max_minwidth) {
457  extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
458  strdim.width = max_minwidth;
459  }
460  d = maxdim(d, strdim);
461 
462  /* Measure the produced cargoes, if any. */
463  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix);
464  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
465  strdim = GetStringBoundingBox(cargostring);
466  if (strdim.width > max_minwidth) {
467  extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
468  strdim.width = max_minwidth;
469  }
470  d = maxdim(d, strdim);
471 
472  if (indsp->grf_prop.grffile != nullptr) {
473  /* Reserve a few extra lines for text from an industry NewGRF. */
474  extra_lines_newgrf = 4;
475  }
476  }
477 
478  /* Set it to something more sane :) */
479  height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
480  size->height = height * GetCharacterHeight(FS_NORMAL) + padding.height;
481  size->width = d.width + padding.width;
482  break;
483  }
484 
485  case WID_DPI_FUND_WIDGET: {
486  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
487  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY));
488  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY));
489  d.width += padding.width;
490  d.height += padding.height;
491  *size = maxdim(*size, d);
492  break;
493  }
494  }
495  }
496 
497  void SetStringParameters(WidgetID widget) const override
498  {
499  switch (widget) {
500  case WID_DPI_FUND_WIDGET:
501  /* Raw industries might be prospected. Show this fact by changing the string
502  * In Editor, you just build, while ingame, or you fund or you prospect */
503  if (_game_mode == GM_EDITOR) {
504  /* We've chosen many random industries but no industries have been specified */
505  SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
506  } else {
507  if (this->selected_type != INVALID_INDUSTRYTYPE) {
508  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
509  SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
510  } else {
511  SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
512  }
513  }
514  break;
515  }
516  }
517 
518  void DrawWidget(const Rect &r, WidgetID widget) const override
519  {
520  switch (widget) {
521  case WID_DPI_MATRIX_WIDGET: {
522  bool rtl = _current_text_dir == TD_RTL;
523  Rect text = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
524  Rect icon = text.WithWidth(this->legend.width, rtl);
525  text = text.Indent(this->legend.width + WidgetDimensions::scaled.hsep_wide, rtl);
526 
527  /* Vertical offset for legend icon. */
528  icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
529  icon.bottom = icon.top + this->legend.height - 1;
530 
531  for (uint16_t i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
532  IndustryType type = this->list[i];
533  bool selected = this->selected_type == type;
534  const IndustrySpec *indsp = GetIndustrySpec(type);
535 
536  /* Draw the name of the industry in white is selected, otherwise, in orange */
537  DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE);
538  GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
541  DrawString(text, STR_JUST_COMMA, TC_BLACK, SA_RIGHT, false, FS_SMALL);
542 
543  text = text.Translate(0, this->resize.step_height);
544  icon = icon.Translate(0, this->resize.step_height);
545  }
546  break;
547  }
548 
549  case WID_DPI_INFOPANEL: {
550  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
551 
552  if (this->selected_type == INVALID_INDUSTRYTYPE) {
553  DrawStringMultiLine(ir, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
554  break;
555  }
556 
557  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
558 
559  if (_game_mode != GM_EDITOR) {
560  SetDParam(0, indsp->GetConstructionCost());
561  DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
562  ir.top += GetCharacterHeight(FS_NORMAL);
563  }
564 
565  CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
566 
567  /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
568  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
569  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
570  ir.top = DrawStringMultiLine(ir, cargostring);
571 
572  /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
573  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
574  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
575  ir.top = DrawStringMultiLine(ir, cargostring);
576 
577  /* Get the additional purchase info text, if it has not already been queried. */
579  uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, nullptr, this->selected_type, INVALID_TILE);
580  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
581  if (callback_res > 0x400) {
583  } else {
584  StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
585  if (str != STR_UNDEFINED) {
587  DrawStringMultiLine(ir, str, TC_YELLOW);
589  }
590  }
591  }
592  }
593  break;
594  }
595  }
596  }
597 
598  static void AskManyRandomIndustriesCallback(Window *, bool confirmed)
599  {
600  if (!confirmed) return;
601 
602  if (Town::GetNumItems() == 0) {
603  ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO);
604  } else {
605  Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
609  old_generating_world.Restore();
610  }
611  }
612 
613  static void AskRemoveAllIndustriesCallback(Window *, bool confirmed)
614  {
615  if (!confirmed) return;
616 
617  for (Industry *industry : Industry::Iterate()) delete industry;
618 
619  /* Clear farmland. */
620  for (TileIndex tile = 0; tile < Map::Size(); tile++) {
621  if (IsTileType(tile, MP_CLEAR) && GetRawClearGround(tile) == CLEAR_FIELDS) {
622  MakeClear(tile, CLEAR_GRASS, 3);
623  }
624  }
625 
627  }
628 
629  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
630  {
631  switch (widget) {
633  assert(_game_mode == GM_EDITOR);
635  ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY, nullptr, AskManyRandomIndustriesCallback);
636  break;
637  }
638 
640  assert(_game_mode == GM_EDITOR);
642  ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY, nullptr, AskRemoveAllIndustriesCallback);
643  break;
644  }
645 
646  case WID_DPI_MATRIX_WIDGET: {
647  auto it = this->vscroll->GetScrolledItemFromWidget(this->list, pt.y, this, WID_DPI_MATRIX_WIDGET);
648  if (it != this->list.end()) { // Is it within the boundaries of available data?
649  this->selected_type = *it;
650  this->UpdateAvailability();
651 
652  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
653 
654  this->SetDirty();
655 
656  if (_thd.GetCallbackWnd() == this &&
657  ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) || !this->enabled)) {
658  /* Reset the button state if going to prospecting or "build many industries" */
659  this->RaiseButtons();
661  }
662 
663  this->SetButtons();
664  if (this->enabled && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
665  }
666  break;
667  }
668 
670  if (this->selected_type != INVALID_INDUSTRYTYPE) ShowIndustryCargoesWindow(this->selected_type);
671  break;
672 
673  case WID_DPI_FUND_WIDGET: {
674  if (this->selected_type != INVALID_INDUSTRYTYPE) {
675  if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
676  Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, 0, this->selected_type, 0, false, InteractiveRandom());
678  } else {
679  HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);
680  }
681  }
682  break;
683  }
684  }
685  }
686 
687  void OnResize() override
688  {
689  /* Adjust the number of items in the matrix depending of the resize */
690  this->vscroll->SetCapacityFromWidget(this, WID_DPI_MATRIX_WIDGET);
691  }
692 
693  void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
694  {
695  bool success = true;
696  /* We do not need to protect ourselves against "Random Many Industries" in this mode */
697  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
698  uint32_t seed = InteractiveRandom();
699  uint32_t layout_index = InteractiveRandomRange((uint32_t)indsp->layouts.size());
700 
701  if (_game_mode == GM_EDITOR) {
702  /* Show error if no town exists at all */
703  if (Town::GetNumItems() == 0) {
704  SetDParam(0, indsp->name);
705  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO, pt.x, pt.y);
706  return;
707  }
708 
709  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
710  Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
711  _ignore_restrictions = true;
712 
713  Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, &CcBuildIndustry, tile, this->selected_type, layout_index, false, seed);
714 
715  cur_company.Restore();
716  old_generating_world.Restore();
717  _ignore_restrictions = false;
718  } else {
719  success = Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, this->selected_type, layout_index, false, seed);
720  }
721 
722  /* If an industry has been built, just reset the cursor and the system */
724  }
725 
726  IntervalTimer<TimerWindow> update_interval = {std::chrono::seconds(3), [this](auto) {
727  if (_game_mode == GM_EDITOR) return;
728  if (this->selected_type == INVALID_INDUSTRYTYPE) return;
729 
730  bool enabled = this->enabled;
731  this->UpdateAvailability();
732  if (enabled != this->enabled) {
733  this->SetButtons();
734  this->SetDirty();
735  }
736  }};
737 
738  void OnTimeout() override
739  {
740  this->RaiseButtons();
741  }
742 
743  void OnPlaceObjectAbort() override
744  {
745  this->RaiseButtons();
746  }
747 
753  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
754  {
755  if (!gui_scope) return;
756  this->SetupArrays();
757  this->SetButtons();
758  this->SetDirty();
759  }
760 };
761 
762 void ShowBuildIndustryWindow()
763 {
764  if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
766  new BuildIndustryWindow();
767 }
768 
769 static void UpdateIndustryProduction(Industry *i);
770 
771 static inline bool IsProductionAlterable(const Industry *i)
772 {
773  const IndustrySpec *is = GetIndustrySpec(i->type);
774  bool has_prod = false;
775  for (size_t j = 0; j < lengthof(is->production_rate); j++) {
776  if (is->production_rate[j] != 0) {
777  has_prod = true;
778  break;
779  }
780  }
781  return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
782  (has_prod || is->IsRawIndustry()) &&
783  !_networking);
784 }
785 
787 {
789  enum Editability {
793  };
794 
796  enum InfoLine {
801  };
802 
810 
811 public:
813  {
814  this->flags |= WF_DISABLE_VP_SCROLL;
815  this->editbox_line = IL_NONE;
816  this->clicked_line = IL_NONE;
817  this->clicked_button = 0;
818  this->info_height = WidgetDimensions::scaled.framerect.Vertical() + 2 * GetCharacterHeight(FS_NORMAL); // Info panel has at least two lines text.
819 
820  this->InitNested(window_number);
821  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
822  nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_INDUSTRY));
823 
824  this->InvalidateData();
825  }
826 
827  void OnInit() override
828  {
829  /* This only used when the cheat to alter industry production is enabled */
830  this->cheat_line_height = std::max(SETTING_BUTTON_HEIGHT + WidgetDimensions::scaled.vsep_normal, GetCharacterHeight(FS_NORMAL));
831  }
832 
833  void OnPaint() override
834  {
835  this->DrawWidgets();
836 
837  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
838 
839  const Rect r = this->GetWidget<NWidgetBase>(WID_IV_INFO)->GetCurrentRect();
840  int expected = this->DrawInfo(r);
841  if (expected != r.bottom) {
842  this->info_height = expected - r.top + 1;
843  this->ReInit();
844  return;
845  }
846  }
847 
853  int DrawInfo(const Rect &r)
854  {
855  bool rtl = _current_text_dir == TD_RTL;
857  const IndustrySpec *ind = GetIndustrySpec(i->type);
858  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
859  bool first = true;
860  bool has_accept = false;
861 
862  if (i->prod_level == PRODLEVEL_CLOSURE) {
863  DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
865  }
866 
868 
869  for (const auto &a : i->accepted) {
870  if (!IsValidCargoID(a.cargo)) continue;
871  has_accept = true;
872  if (first) {
873  DrawString(ir, STR_INDUSTRY_VIEW_REQUIRES);
874  ir.top += GetCharacterHeight(FS_NORMAL);
875  first = false;
876  }
877 
878  CargoSuffix suffix;
879  GetCargoSuffix(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, a.cargo, &a - i->accepted.data(), suffix);
880 
881  SetDParam(0, CargoSpec::Get(a.cargo)->name);
882  SetDParam(1, a.cargo);
883  SetDParam(2, a.waiting);
884  SetDParamStr(3, "");
885  StringID str = STR_NULL;
886  switch (suffix.display) {
888  SetDParamStr(3, suffix.text);
889  [[fallthrough]];
890  case CSD_CARGO_AMOUNT:
891  str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
892  break;
893 
894  case CSD_CARGO_TEXT:
895  SetDParamStr(3, suffix.text);
896  [[fallthrough]];
897  case CSD_CARGO:
898  str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
899  break;
900 
901  default:
902  NOT_REACHED();
903  }
905  ir.top += GetCharacterHeight(FS_NORMAL);
906  }
907 
908  int line_height = this->editable == EA_RATE ? this->cheat_line_height : GetCharacterHeight(FS_NORMAL);
909  int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
910  int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
911  first = true;
912  for (const auto &p : i->produced) {
913  if (!IsValidCargoID(p.cargo)) continue;
914  if (first) {
915  if (has_accept) ir.top += WidgetDimensions::scaled.vsep_wide;
916  DrawString(ir, TimerGameEconomy::UsingWallclockUnits() ? STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE : STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
917  ir.top += GetCharacterHeight(FS_NORMAL);
918  if (this->editable == EA_RATE) this->production_offset_y = ir.top;
919  first = false;
920  }
921 
922  CargoSuffix suffix;
923  GetCargoSuffix(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, p.cargo, &p - i->produced.data(), suffix);
924 
925  SetDParam(0, p.cargo);
926  SetDParam(1, p.history[LAST_MONTH].production);
927  SetDParamStr(2, suffix.text);
928  SetDParam(3, ToPercent8(p.history[LAST_MONTH].PctTransported()));
929  DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal : 0), rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_TRANSPORTED);
930  /* Let's put out those buttons.. */
931  if (this->editable == EA_RATE) {
932  DrawArrowButtons(ir.Indent(WidgetDimensions::scaled.hsep_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,
933  p.rate > 0, p.rate < 255);
934  }
935  ir.top += line_height;
936  }
937 
938  /* Display production multiplier if editable */
939  if (this->editable == EA_MULTIPLIER) {
940  line_height = this->cheat_line_height;
941  text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
942  button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
944  this->production_offset_y = ir.top;
946  DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
947  DrawArrowButtons(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
949  ir.top += line_height;
950  }
951 
952  /* Get the extra message for the GUI */
954  uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
955  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
956  if (callback_res > 0x400) {
958  } else {
959  StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
960  if (message != STR_NULL && message != STR_UNDEFINED) {
962 
964  /* Use all the available space left from where we stand up to the
965  * end of the window. We ALSO enlarge the window if needed, so we
966  * can 'go' wild with the bottom of the window. */
967  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, message, TC_BLACK);
969  }
970  }
971  }
972  }
973 
974  if (!i->text.empty()) {
975  SetDParamStr(0, i->text);
977  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
978  }
979 
980  /* Return required bottom position, the last pixel row plus some padding. */
981  return ir.top - 1 + WidgetDimensions::scaled.framerect.bottom;
982  }
983 
984  void SetStringParameters(WidgetID widget) const override
985  {
986  if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
987  }
988 
989  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
990  {
991  if (widget == WID_IV_INFO) size->height = this->info_height;
992  }
993 
994  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
995  {
996  switch (widget) {
997  case WID_IV_INFO: {
999  InfoLine line = IL_NONE;
1000 
1001  switch (this->editable) {
1002  case EA_NONE: break;
1003 
1004  case EA_MULTIPLIER:
1005  if (IsInsideBS(pt.y, this->production_offset_y, this->cheat_line_height)) line = IL_MULTIPLIER;
1006  break;
1007 
1008  case EA_RATE:
1009  if (pt.y >= this->production_offset_y) {
1010  int row = (pt.y - this->production_offset_y) / this->cheat_line_height;
1011  for (auto itp = std::begin(i->produced); itp != std::end(i->produced); ++itp) {
1012  if (!IsValidCargoID(itp->cargo)) continue;
1013  row--;
1014  if (row < 0) {
1015  line = (InfoLine)(IL_RATE1 + (itp - std::begin(i->produced)));
1016  break;
1017  }
1018  }
1019  }
1020  break;
1021  }
1022  if (line == IL_NONE) return;
1023 
1024  bool rtl = _current_text_dir == TD_RTL;
1025  Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(WidgetDimensions::scaled.hsep_indent, rtl);
1026 
1027  if (r.WithWidth(SETTING_BUTTON_WIDTH, rtl).Contains(pt)) {
1028  /* Clicked buttons, decrease or increase production */
1029  bool decrease = r.WithWidth(SETTING_BUTTON_WIDTH / 2, rtl).Contains(pt);
1030  switch (this->editable) {
1031  case EA_MULTIPLIER:
1032  if (decrease) {
1033  if (i->prod_level <= PRODLEVEL_MINIMUM) return;
1034  i->prod_level = static_cast<byte>(std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM));
1035  } else {
1036  if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
1037  i->prod_level = static_cast<byte>(std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM));
1038  }
1039  break;
1040 
1041  case EA_RATE:
1042  if (decrease) {
1043  if (i->produced[line - IL_RATE1].rate <= 0) return;
1044  i->produced[line - IL_RATE1].rate = std::max(i->produced[line - IL_RATE1].rate / 2, 0);
1045  } else {
1046  if (i->produced[line - IL_RATE1].rate >= 255) return;
1047  /* a zero production industry is unlikely to give anything but zero, so push it a little bit */
1048  int new_prod = i->produced[line - IL_RATE1].rate == 0 ? 1 : i->produced[line - IL_RATE1].rate * 2;
1049  i->produced[line - IL_RATE1].rate = ClampTo<byte>(new_prod);
1050  }
1051  break;
1052 
1053  default: NOT_REACHED();
1054  }
1055 
1056  UpdateIndustryProduction(i);
1057  this->SetDirty();
1058  this->SetTimeout();
1059  this->clicked_line = line;
1060  this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1062  /* clicked the text */
1063  this->editbox_line = line;
1064  switch (this->editable) {
1065  case EA_MULTIPLIER:
1067  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1068  break;
1069 
1070  case EA_RATE:
1071  SetDParam(0, i->produced[line - IL_RATE1].rate * 8);
1072  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1073  break;
1074 
1075  default: NOT_REACHED();
1076  }
1077  }
1078  break;
1079  }
1080 
1081  case WID_IV_GOTO: {
1082  Industry *i = Industry::Get(this->window_number);
1083  if (_ctrl_pressed) {
1085  } else {
1087  }
1088  break;
1089  }
1090 
1091  case WID_IV_DISPLAY: {
1092  Industry *i = Industry::Get(this->window_number);
1094  break;
1095  }
1096  }
1097  }
1098 
1099  void OnTimeout() override
1100  {
1101  this->clicked_line = IL_NONE;
1102  this->clicked_button = 0;
1103  this->SetDirty();
1104  }
1105 
1106  void OnResize() override
1107  {
1108  if (this->viewport != nullptr) {
1109  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
1110  nvp->UpdateViewportCoordinates(this);
1111 
1112  ScrollWindowToTile(Industry::Get(this->window_number)->location.GetCenterTile(), this, true); // Re-center viewport.
1113  }
1114  }
1115 
1116  void OnQueryTextFinished(char *str) override
1117  {
1118  if (StrEmpty(str)) return;
1119 
1120  Industry *i = Industry::Get(this->window_number);
1121  uint value = atoi(str);
1122  switch (this->editbox_line) {
1123  case IL_NONE: NOT_REACHED();
1124 
1125  case IL_MULTIPLIER:
1127  break;
1128 
1129  default:
1130  i->produced[this->editbox_line - IL_RATE1].rate = ClampU(RoundDivSU(value, 8), 0, 255);
1131  break;
1132  }
1133  UpdateIndustryProduction(i);
1134  this->SetDirty();
1135  }
1136 
1142  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1143  {
1144  if (!gui_scope) return;
1145  const Industry *i = Industry::Get(this->window_number);
1146  if (IsProductionAlterable(i)) {
1147  const IndustrySpec *ind = GetIndustrySpec(i->type);
1148  this->editable = ind->UsesOriginalEconomy() ? EA_MULTIPLIER : EA_RATE;
1149  } else {
1150  this->editable = EA_NONE;
1151  }
1152  }
1153 
1154  bool IsNewGRFInspectable() const override
1155  {
1156  return ::IsNewGRFInspectable(GSF_INDUSTRIES, this->window_number);
1157  }
1158 
1159  void ShowNewGRFInspectWindow() const override
1160  {
1161  ::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->window_number);
1162  }
1163 };
1164 
1165 static void UpdateIndustryProduction(Industry *i)
1166 {
1167  const IndustrySpec *indspec = GetIndustrySpec(i->type);
1169 
1170  for (auto &p : i->produced) {
1171  if (IsValidCargoID(p.cargo)) {
1172  p.history[LAST_MONTH].production = ScaleByCargoScale(8 * p.rate, false);
1173  }
1174  }
1175 }
1176 
1180  NWidget(WWT_CLOSEBOX, COLOUR_CREAM),
1181  NWidget(WWT_CAPTION, COLOUR_CREAM, WID_IV_CAPTION), SetDataTip(STR_INDUSTRY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1182  NWidget(WWT_PUSHIMGBTN, COLOUR_CREAM, WID_IV_GOTO), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
1183  NWidget(WWT_DEBUGBOX, COLOUR_CREAM),
1184  NWidget(WWT_SHADEBOX, COLOUR_CREAM),
1185  NWidget(WWT_DEFSIZEBOX, COLOUR_CREAM),
1186  NWidget(WWT_STICKYBOX, COLOUR_CREAM),
1187  EndContainer(),
1188  NWidget(WWT_PANEL, COLOUR_CREAM),
1189  NWidget(WWT_INSET, COLOUR_CREAM), SetPadding(2, 2, 2, 2),
1190  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_IV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
1191  EndContainer(),
1192  EndContainer(),
1193  NWidget(WWT_PANEL, COLOUR_CREAM, WID_IV_INFO), SetMinimalSize(260, 0), SetMinimalTextLines(2, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
1194  EndContainer(),
1196  NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
1197  NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
1198  EndContainer(),
1199 };
1200 
1202 static WindowDesc _industry_view_desc(__FILE__, __LINE__,
1203  WDP_AUTO, "view_industry", 260, 120,
1205  0,
1207 );
1208 
1209 void ShowIndustryViewWindow(int industry)
1210 {
1211  AllocateWindowDescFront<IndustryViewWindow>(&_industry_view_desc, industry);
1212 }
1213 
1217  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1218  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_INDUSTRY_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1219  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1220  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1221  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1222  EndContainer(),
1226  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
1227  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
1228  NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_ID_FILTER), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1229  EndContainer(),
1231  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),
1232  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),
1233  NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(),
1234  EndContainer(),
1235  NWidget(WWT_PANEL, COLOUR_BROWN, WID_ID_INDUSTRY_LIST), SetDataTip(0x0, STR_INDUSTRY_DIRECTORY_LIST_CAPTION), SetResize(1, 1), SetScrollbar(WID_ID_VSCROLLBAR),
1236  EndContainer(),
1237  EndContainer(),
1238  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_ID_VSCROLLBAR),
1239  EndContainer(),
1241  NWidget(NWID_HSCROLLBAR, COLOUR_BROWN, WID_ID_HSCROLLBAR),
1242  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1243  EndContainer(),
1244 };
1245 
1247 
1255 static bool CDECL CargoFilter(const Industry * const *industry, const std::pair<CargoID, CargoID> &cargoes)
1256 {
1257  auto accepted_cargo = cargoes.first;
1258  auto produced_cargo = cargoes.second;
1259 
1260  bool accepted_cargo_matches;
1261 
1262  switch (accepted_cargo) {
1264  accepted_cargo_matches = true;
1265  break;
1266 
1268  accepted_cargo_matches = !(*industry)->IsCargoAccepted();
1269  break;
1270 
1271  default:
1272  accepted_cargo_matches = (*industry)->IsCargoAccepted(accepted_cargo);
1273  break;
1274  }
1275 
1276  bool produced_cargo_matches;
1277 
1278  switch (produced_cargo) {
1280  produced_cargo_matches = true;
1281  break;
1282 
1284  produced_cargo_matches = !(*industry)->IsCargoProduced();
1285  break;
1286 
1287  default:
1288  produced_cargo_matches = (*industry)->IsCargoProduced(produced_cargo);
1289  break;
1290  }
1291 
1292  return accepted_cargo_matches && produced_cargo_matches;
1293 }
1294 
1295 static GUIIndustryList::FilterFunction * const _filter_funcs[] = { &CargoFilter };
1296 
1300 };
1305 protected:
1306  /* Runtime saved values */
1307  static Listing last_sorting;
1308 
1309  /* Constants for sorting industries */
1310  static const StringID sorter_names[];
1311  static GUIIndustryList::SortFunction * const sorter_funcs[];
1312 
1313  GUIIndustryList industries{IndustryDirectoryWindow::produced_cargo_filter};
1314  Scrollbar *vscroll;
1315  Scrollbar *hscroll;
1316 
1319  static CargoID produced_cargo_filter;
1320 
1321  const int MAX_FILTER_LENGTH = 16;
1324 
1325  enum class SorterType : uint8_t {
1326  ByName,
1327  ByType,
1328  ByProduction,
1329  ByTransported,
1330  };
1331 
1337  {
1338  if (this->produced_cargo_filter_criteria != cid) {
1339  this->produced_cargo_filter_criteria = cid;
1340  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1341  bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
1342 
1343  this->industries.SetFilterState(is_filtering_necessary);
1344  this->industries.SetFilterType(0);
1345  this->industries.ForceRebuild();
1346  }
1347  }
1348 
1354  {
1355  if (this->accepted_cargo_filter_criteria != cid) {
1356  this->accepted_cargo_filter_criteria = cid;
1357  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1358  bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
1359 
1360  this->industries.SetFilterState(is_filtering_necessary);
1361  this->industries.SetFilterType(0);
1362  this->industries.ForceRebuild();
1363  }
1364  }
1365 
1366  StringID GetCargoFilterLabel(CargoID cid) const
1367  {
1368  switch (cid) {
1369  case CargoFilterCriteria::CF_ANY: return STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
1370  case CargoFilterCriteria::CF_NONE: return STR_INDUSTRY_DIRECTORY_FILTER_NONE;
1371  default: return CargoSpec::Get(cid)->name;
1372  }
1373  }
1374 
1379  {
1380  this->produced_cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
1381  this->accepted_cargo_filter_criteria = CargoFilterCriteria::CF_ANY;
1382 
1383  this->industries.SetFilterFuncs(_filter_funcs);
1384 
1385  bool is_filtering_necessary = this->produced_cargo_filter_criteria != CargoFilterCriteria::CF_ANY || this->accepted_cargo_filter_criteria != CargoFilterCriteria::CF_ANY;
1386 
1387  this->industries.SetFilterState(is_filtering_necessary);
1388  }
1389 
1395  {
1396  uint width = 0;
1397  for (const Industry *i : this->industries) {
1398  width = std::max(width, GetStringBoundingBox(this->GetIndustryString(i)).width);
1399  }
1401  }
1402 
1405  {
1406  if (this->industries.NeedRebuild()) {
1407  this->industries.clear();
1408 
1409  for (const Industry *i : Industry::Iterate()) {
1410  if (this->string_filter.IsEmpty()) {
1411  this->industries.push_back(i);
1412  continue;
1413  }
1414  this->string_filter.ResetState();
1415  this->string_filter.AddLine(i->GetCachedName());
1416  if (this->string_filter.GetState()) this->industries.push_back(i);
1417  }
1418 
1419  this->industries.shrink_to_fit();
1420  this->industries.RebuildDone();
1421 
1422  auto filter = std::make_pair(this->accepted_cargo_filter_criteria, this->produced_cargo_filter_criteria);
1423 
1424  this->industries.Filter(filter);
1425 
1426  this->hscroll->SetCount(this->GetIndustryListWidth());
1427  this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well.
1428  }
1429 
1430  IndustryDirectoryWindow::produced_cargo_filter = this->produced_cargo_filter_criteria;
1431  this->industries.Sort();
1432 
1433  this->SetDirty();
1434  }
1435 
1444  {
1445  if (!IsValidCargoID(p.cargo)) return -1;
1446  return ToPercent8(p.history[LAST_MONTH].PctTransported());
1447  }
1448 
1457  {
1458  CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1459  if (filter == CargoFilterCriteria::CF_NONE) return 0;
1460 
1461  int percentage = 0, produced_cargo_count = 0;
1462  for (const auto &p : i->produced) {
1463  if (filter == CargoFilterCriteria::CF_ANY) {
1464  int transported = GetCargoTransportedPercentsIfValid(p);
1465  if (transported != -1) {
1466  produced_cargo_count++;
1467  percentage += transported;
1468  }
1469  if (produced_cargo_count == 0 && &p == &i->produced.back() && percentage == 0) {
1470  return transported;
1471  }
1472  } else if (filter == p.cargo) {
1474  }
1475  }
1476 
1477  if (produced_cargo_count == 0) return percentage;
1478  return percentage / produced_cargo_count;
1479  }
1480 
1482  static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b, const CargoID &)
1483  {
1484  int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
1485  if (r == 0) return a->index < b->index;
1486  return r < 0;
1487  }
1488 
1490  static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
1491  {
1492  int it_a = 0;
1493  while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
1494  int it_b = 0;
1495  while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
1496  int r = it_a - it_b;
1497  return (r == 0) ? IndustryNameSorter(a, b, filter) : r < 0;
1498  }
1499 
1501  static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
1502  {
1503  if (filter == CargoFilterCriteria::CF_NONE) return IndustryTypeSorter(a, b, filter);
1504 
1505  uint prod_a = 0, prod_b = 0;
1506  if (filter == CargoFilterCriteria::CF_ANY) {
1507  for (const auto &pa : a->produced) {
1508  if (IsValidCargoID(pa.cargo)) prod_a += pa.history[LAST_MONTH].production;
1509  }
1510  for (const auto &pb : b->produced) {
1511  if (IsValidCargoID(pb.cargo)) prod_b += pb.history[LAST_MONTH].production;
1512  }
1513  } else {
1514  if (auto ita = a->GetCargoProduced(filter); ita != std::end(a->produced)) prod_a = ita->history[LAST_MONTH].production;
1515  if (auto itb = b->GetCargoProduced(filter); itb != std::end(b->produced)) prod_b = itb->history[LAST_MONTH].production;
1516  }
1517  int r = prod_a - prod_b;
1518 
1519  return (r == 0) ? IndustryTypeSorter(a, b, filter) : r < 0;
1520  }
1521 
1523  static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b, const CargoID &filter)
1524  {
1526  return (r == 0) ? IndustryNameSorter(a, b, filter) : r < 0;
1527  }
1528 
1535  {
1536  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1537  byte p = 0;
1538 
1539  /* Industry name */
1540  SetDParam(p++, i->index);
1541 
1542  static CargoSuffix cargo_suffix[INDUSTRY_NUM_OUTPUTS];
1543 
1544  /* Get industry productions (CargoID, production, suffix, transported) */
1545  struct CargoInfo {
1546  CargoID cargo_id;
1547  uint16_t production;
1548  const char *suffix;
1549  uint transported;
1550  };
1551  std::vector<CargoInfo> cargos;
1552 
1553  for (auto itp = std::begin(i->produced); itp != std::end(i->produced); ++itp) {
1554  if (!IsValidCargoID(itp->cargo)) continue;
1555  GetCargoSuffix(CARGOSUFFIX_OUT, CST_DIR, i, i->type, indsp, itp->cargo, itp - std::begin(i->produced), cargo_suffix[itp - std::begin(i->produced)]);
1556  cargos.push_back({ itp->cargo, itp->history[LAST_MONTH].production, cargo_suffix[itp - std::begin(i->produced)].text.c_str(), ToPercent8(itp->history[LAST_MONTH].PctTransported()) });
1557  }
1558 
1559  switch (static_cast<IndustryDirectoryWindow::SorterType>(this->industries.SortType())) {
1563  /* Sort by descending production, then descending transported */
1564  std::sort(cargos.begin(), cargos.end(), [](const CargoInfo &a, const CargoInfo &b) {
1565  if (a.production != b.production) return a.production > b.production;
1566  return a.transported > b.transported;
1567  });
1568  break;
1569 
1571  /* Sort by descending transported, then descending production */
1572  std::sort(cargos.begin(), cargos.end(), [](const CargoInfo &a, const CargoInfo &b) {
1573  if (a.transported != b.transported) return a.transported > b.transported;
1574  return a.production > b.production;
1575  });
1576  break;
1577  }
1578 
1579  /* If the produced cargo filter is active then move the filtered cargo to the beginning of the list,
1580  * because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */
1581  const CargoID cid = this->produced_cargo_filter_criteria;
1583  auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo &ci) -> bool {
1584  return ci.cargo_id == cid;
1585  });
1586  if (filtered_ci != cargos.end()) {
1587  std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1588  }
1589  }
1590 
1591  /* Display first 3 cargos */
1592  for (size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1593  CargoInfo ci = cargos[j];
1594  SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1595  SetDParam(p++, ci.cargo_id);
1596  SetDParam(p++, ci.production);
1597  SetDParamStr(p++, ci.suffix);
1598  SetDParam(p++, ci.transported);
1599  }
1600 
1601  /* Undisplayed cargos if any */
1602  SetDParam(p++, cargos.size() - 3);
1603 
1604  /* Drawing the right string */
1605  switch (cargos.size()) {
1606  case 0: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1607  case 1: return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1608  case 2: return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1609  case 3: return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1610  default: return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1611  }
1612  }
1613 
1614 public:
1616  {
1617  this->CreateNestedTree();
1618  this->vscroll = this->GetScrollbar(WID_ID_VSCROLLBAR);
1619  this->hscroll = this->GetScrollbar(WID_ID_HSCROLLBAR);
1620 
1621  this->industries.SetListing(this->last_sorting);
1622  this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1623  this->industries.ForceRebuild();
1624 
1625  this->FinishInitNested(0);
1626 
1627  this->BuildSortIndustriesList();
1628 
1630  this->industry_editbox.cancel_button = QueryString::ACTION_CLEAR;
1631  }
1632 
1634  {
1635  this->last_sorting = this->industries.GetListing();
1636  }
1637 
1638  void OnInit() override
1639  {
1640  this->SetCargoFilterArray();
1641  }
1642 
1643  void SetStringParameters(WidgetID widget) const override
1644  {
1645  switch (widget) {
1647  SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]);
1648  break;
1649 
1651  SetDParam(0, this->GetCargoFilterLabel(this->accepted_cargo_filter_criteria));
1652  break;
1653 
1655  SetDParam(0, this->GetCargoFilterLabel(this->produced_cargo_filter_criteria));
1656  break;
1657  }
1658  }
1659 
1660  void DrawWidget(const Rect &r, WidgetID widget) const override
1661  {
1662  switch (widget) {
1663  case WID_ID_DROPDOWN_ORDER:
1664  this->DrawSortButtonState(widget, this->industries.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
1665  break;
1666 
1667  case WID_ID_INDUSTRY_LIST: {
1668  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
1669 
1670  /* Setup a clipping rectangle... */
1671  DrawPixelInfo tmp_dpi;
1672  if (!FillDrawPixelInfo(&tmp_dpi, ir)) return;
1673  /* ...but keep coordinates relative to the window. */
1674  tmp_dpi.left += ir.left;
1675  tmp_dpi.top += ir.top;
1676 
1677  AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1678 
1679  ir.left -= this->hscroll->GetPosition();
1680  ir.right += this->hscroll->GetCapacity() - this->hscroll->GetPosition();
1681 
1682  if (this->industries.empty()) {
1683  DrawString(ir, STR_INDUSTRY_DIRECTORY_NONE);
1684  break;
1685  }
1686  int n = 0;
1687  const CargoID acf_cid = this->accepted_cargo_filter_criteria;
1688  for (uint i = this->vscroll->GetPosition(); i < this->industries.size(); i++) {
1689  TextColour tc = TC_FROMSTRING;
1690  if (acf_cid != CargoFilterCriteria::CF_ANY && acf_cid != CargoFilterCriteria::CF_NONE) {
1691  Industry *ind = const_cast<Industry *>(this->industries[i]);
1692  if (IndustryTemporarilyRefusesCargo(ind, acf_cid)) {
1693  tc = TC_GREY | TC_FORCED;
1694  }
1695  }
1696  DrawString(ir, this->GetIndustryString(this->industries[i]), tc);
1697 
1698  ir.top += this->resize.step_height;
1699  if (++n == this->vscroll->GetCapacity()) break; // max number of industries in 1 window
1700  }
1701  break;
1702  }
1703  }
1704  }
1705 
1706  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1707  {
1708  switch (widget) {
1709  case WID_ID_DROPDOWN_ORDER: {
1710  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1711  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1712  d.height += padding.height;
1713  *size = maxdim(*size, d);
1714  break;
1715  }
1716 
1717  case WID_ID_DROPDOWN_CRITERIA: {
1718  Dimension d = {0, 0};
1719  for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
1720  d = maxdim(d, GetStringBoundingBox(IndustryDirectoryWindow::sorter_names[i]));
1721  }
1722  d.width += padding.width;
1723  d.height += padding.height;
1724  *size = maxdim(*size, d);
1725  break;
1726  }
1727 
1728  case WID_ID_INDUSTRY_LIST: {
1729  Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
1730  resize->height = d.height;
1731  d.height *= 5;
1732  d.width += padding.width;
1733  d.height += padding.height;
1734  *size = maxdim(*size, d);
1735  break;
1736  }
1737  }
1738  }
1739 
1740  DropDownList BuildCargoDropDownList() const
1741  {
1742  DropDownList list;
1743 
1744  /* Add item for disabling filtering. */
1745  list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_ANY), CargoFilterCriteria::CF_ANY, false));
1746  /* Add item for industries not producing anything, e.g. power plants */
1747  list.push_back(std::make_unique<DropDownListStringItem>(this->GetCargoFilterLabel(CargoFilterCriteria::CF_NONE), CargoFilterCriteria::CF_NONE, false));
1748 
1749  /* Add cargos */
1751  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1752  list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false));
1753  }
1754 
1755  return list;
1756  }
1757 
1758  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1759  {
1760  switch (widget) {
1761  case WID_ID_DROPDOWN_ORDER:
1762  this->industries.ToggleSortOrder();
1763  this->SetDirty();
1764  break;
1765 
1767  ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0);
1768  break;
1769 
1770  case WID_ID_FILTER_BY_ACC_CARGO: // Cargo filter dropdown
1771  ShowDropDownList(this, this->BuildCargoDropDownList(), this->accepted_cargo_filter_criteria, widget);
1772  break;
1773 
1774  case WID_ID_FILTER_BY_PROD_CARGO: // Cargo filter dropdown
1775  ShowDropDownList(this, this->BuildCargoDropDownList(), this->produced_cargo_filter_criteria, widget);
1776  break;
1777 
1778  case WID_ID_INDUSTRY_LIST: {
1779  auto it = this->vscroll->GetScrolledItemFromWidget(this->industries, pt.y, this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.top);
1780  if (it != this->industries.end()) {
1781  if (_ctrl_pressed) {
1782  ShowExtraViewportWindow((*it)->location.tile);
1783  } else {
1784  ScrollMainWindowToTile((*it)->location.tile);
1785  }
1786  }
1787  break;
1788  }
1789  }
1790  }
1791 
1792  void OnDropdownSelect(WidgetID widget, int index) override
1793  {
1794  switch (widget) {
1795  case WID_ID_DROPDOWN_CRITERIA: {
1796  if (this->industries.SortType() != index) {
1797  this->industries.SetSortType(index);
1798  this->BuildSortIndustriesList();
1799  }
1800  break;
1801  }
1802 
1804  this->SetAcceptedCargoFilter(index);
1805  this->BuildSortIndustriesList();
1806  break;
1807  }
1808 
1810  this->SetProducedCargoFilter(index);
1811  this->BuildSortIndustriesList();
1812  break;
1813  }
1814  }
1815  }
1816 
1817  void OnResize() override
1818  {
1819  this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
1820  this->hscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
1821  }
1822 
1823  void OnEditboxChanged(WidgetID wid) override
1824  {
1825  if (wid == WID_ID_FILTER) {
1826  this->string_filter.SetFilterTerm(this->industry_editbox.text.buf);
1827  this->InvalidateData(IDIWD_FORCE_REBUILD);
1828  }
1829  }
1830 
1831  void OnPaint() override
1832  {
1833  if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
1834  this->DrawWidgets();
1835  }
1836 
1838  IntervalTimer<TimerWindow> rebuild_interval = {std::chrono::seconds(3), [this](auto) {
1839  this->industries.ForceResort();
1840  this->BuildSortIndustriesList();
1841  }};
1842 
1848  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1849  {
1850  switch (data) {
1851  case IDIWD_FORCE_REBUILD:
1852  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1853  this->industries.ForceRebuild();
1854  break;
1855 
1856  case IDIWD_PRODUCTION_CHANGE:
1857  if (this->industries.SortType() == 2) this->industries.ForceResort();
1858  break;
1859 
1860  default:
1861  this->industries.ForceResort();
1862  break;
1863  }
1864  }
1865 
1866  EventState OnHotkey(int hotkey) override
1867  {
1868  switch (hotkey) {
1869  case IDHK_FOCUS_FILTER_BOX:
1871  SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
1872  break;
1873  default:
1874  return ES_NOT_HANDLED;
1875  }
1876  return ES_HANDLED;
1877  }
1878 
1879  static inline HotkeyList hotkeys {"industrydirectory", {
1880  Hotkey('F', "focus_filter_box", IDHK_FOCUS_FILTER_BOX),
1881  }};
1882 };
1883 
1884 Listing IndustryDirectoryWindow::last_sorting = {false, 0};
1885 
1886 /* Available station sorting functions. */
1887 GUIIndustryList::SortFunction * const IndustryDirectoryWindow::sorter_funcs[] = {
1888  &IndustryNameSorter,
1889  &IndustryTypeSorter,
1890  &IndustryProductionSorter,
1891  &IndustryTransportedCargoSorter
1892 };
1893 
1894 /* Names of the sorting functions */
1895 const StringID IndustryDirectoryWindow::sorter_names[] = {
1896  STR_SORT_BY_NAME,
1897  STR_SORT_BY_TYPE,
1898  STR_SORT_BY_PRODUCTION,
1899  STR_SORT_BY_TRANSPORTED,
1901 };
1902 
1903 CargoID IndustryDirectoryWindow::produced_cargo_filter = CargoFilterCriteria::CF_ANY;
1904 
1905 
1907 static WindowDesc _industry_directory_desc(__FILE__, __LINE__,
1908  WDP_AUTO, "list_industries", 428, 190,
1910  0,
1912  &IndustryDirectoryWindow::hotkeys
1913 );
1914 
1915 void ShowIndustryDirectory()
1916 {
1917  AllocateWindowDescFront<IndustryDirectoryWindow>(&_industry_directory_desc, 0);
1918 }
1919 
1923  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1924  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_IC_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1925  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1926  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1927  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1928  EndContainer(),
1931  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_IC_SCROLLBAR),
1932  EndContainer(),
1934  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_NOTIFY),
1935  SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1936  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(0, 0), EndContainer(),
1937  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_IND_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1938  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1939  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_CARGO_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1940  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1941  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1942  EndContainer(),
1943 };
1944 
1946 static WindowDesc _industry_cargoes_desc(__FILE__, __LINE__,
1947  WDP_AUTO, "industry_cargoes", 300, 210,
1949  0,
1951 );
1952 
1961 };
1962 
1963 static const uint MAX_CARGOES = 16;
1964 
1968  static int blob_distance;
1969 
1975 
1976  static const int INDUSTRY_LINE_COLOUR;
1977  static const int CARGO_LINE_COLOUR;
1978 
1980  static int cargo_field_width;
1981  static int industry_width;
1982  static uint max_cargoes;
1983 
1985  union {
1986  struct {
1987  IndustryType ind_type;
1990  } industry;
1991  struct {
1993  uint8_t num_cargoes;
1995  uint8_t top_end;
1997  uint8_t bottom_end;
1998  } cargo;
1999  struct {
2001  bool left_align;
2002  } cargo_label;
2004  } u; // Data for each type.
2005 
2011  {
2012  this->type = type;
2013  }
2014 
2020  void MakeIndustry(IndustryType ind_type)
2021  {
2022  this->type = CFT_INDUSTRY;
2023  this->u.industry.ind_type = ind_type;
2024  std::fill(std::begin(this->u.industry.other_accepted), std::end(this->u.industry.other_accepted), INVALID_CARGO);
2025  std::fill(std::begin(this->u.industry.other_produced), std::end(this->u.industry.other_produced), INVALID_CARGO);
2026  }
2027 
2034  int ConnectCargo(CargoID cargo, bool producer)
2035  {
2036  assert(this->type == CFT_CARGO);
2037  if (!IsValidCargoID(cargo)) return -1;
2038 
2039  /* Find the vertical cargo column carrying the cargo. */
2040  int column = -1;
2041  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
2042  if (cargo == this->u.cargo.vertical_cargoes[i]) {
2043  column = i;
2044  break;
2045  }
2046  }
2047  if (column < 0) return -1;
2048 
2049  if (producer) {
2050  assert(!IsValidCargoID(this->u.cargo.supp_cargoes[column]));
2051  this->u.cargo.supp_cargoes[column] = column;
2052  } else {
2053  assert(!IsValidCargoID(this->u.cargo.cust_cargoes[column]));
2054  this->u.cargo.cust_cargoes[column] = column;
2055  }
2056  return column;
2057  }
2058 
2064  {
2065  assert(this->type == CFT_CARGO);
2066 
2067  for (uint i = 0; i < MAX_CARGOES; i++) {
2068  if (IsValidCargoID(this->u.cargo.supp_cargoes[i])) return true;
2069  if (IsValidCargoID(this->u.cargo.cust_cargoes[i])) return true;
2070  }
2071  return false;
2072  }
2073 
2083  void MakeCargo(const CargoID *cargoes, uint length, int count = -1, bool top_end = false, bool bottom_end = false)
2084  {
2085  this->type = CFT_CARGO;
2086  auto insert = std::begin(this->u.cargo.vertical_cargoes);
2087  for (uint i = 0; insert != std::end(this->u.cargo.vertical_cargoes) && i < length; i++) {
2088  if (IsValidCargoID(cargoes[i])) {
2089  *insert = cargoes[i];
2090  ++insert;
2091  }
2092  }
2093  this->u.cargo.num_cargoes = (count < 0) ? static_cast<uint8_t>(insert - std::begin(this->u.cargo.vertical_cargoes)) : count;
2094  CargoIDComparator comparator;
2095  std::sort(std::begin(this->u.cargo.vertical_cargoes), insert, comparator);
2096  std::fill(insert, std::end(this->u.cargo.vertical_cargoes), INVALID_CARGO);
2097  this->u.cargo.top_end = top_end;
2098  this->u.cargo.bottom_end = bottom_end;
2099  std::fill(std::begin(this->u.cargo.supp_cargoes), std::end(this->u.cargo.supp_cargoes), INVALID_CARGO);
2100  std::fill(std::begin(this->u.cargo.cust_cargoes), std::end(this->u.cargo.cust_cargoes), INVALID_CARGO);
2101  }
2102 
2109  void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
2110  {
2111  this->type = CFT_CARGO_LABEL;
2112  uint i;
2113  for (i = 0; i < MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i];
2114  for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
2115  this->u.cargo_label.left_align = left_align;
2116  }
2117 
2122  void MakeHeader(StringID textid)
2123  {
2124  this->type = CFT_HEADER;
2125  this->u.header = textid;
2126  }
2127 
2133  int GetCargoBase(int xpos) const
2134  {
2135  assert(this->type == CFT_CARGO);
2136  int n = this->u.cargo.num_cargoes;
2137 
2138  return xpos + cargo_field_width / 2 - (CargoesField::cargo_line.width * n + CargoesField::cargo_space.width * (n - 1)) / 2;
2139  }
2140 
2146  void Draw(int xpos, int ypos) const
2147  {
2148  switch (this->type) {
2149  case CFT_EMPTY:
2150  case CFT_SMALL_EMPTY:
2151  break;
2152 
2153  case CFT_HEADER:
2154  ypos += (small_height - GetCharacterHeight(FS_NORMAL)) / 2;
2155  DrawString(xpos, xpos + industry_width, ypos, this->u.header, TC_WHITE, SA_HOR_CENTER);
2156  break;
2157 
2158  case CFT_INDUSTRY: {
2159  int ypos1 = ypos + vert_inter_industry_space / 2;
2160  int ypos2 = ypos + normal_height - 1 - vert_inter_industry_space / 2;
2161  int xpos2 = xpos + industry_width - 1;
2162  DrawRectOutline({xpos, ypos1, xpos2, ypos2}, INDUSTRY_LINE_COLOUR);
2163  ypos += (normal_height - GetCharacterHeight(FS_NORMAL)) / 2;
2164  if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2165  const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type);
2166  DrawString(xpos, xpos2, ypos, indsp->name, TC_WHITE, SA_HOR_CENTER);
2167 
2168  /* Draw the industry legend. */
2169  int blob_left, blob_right;
2170  if (_current_text_dir == TD_RTL) {
2171  blob_right = xpos2 - blob_distance;
2172  blob_left = blob_right - CargoesField::legend.width;
2173  } else {
2174  blob_left = xpos + blob_distance;
2175  blob_right = blob_left + CargoesField::legend.width;
2176  }
2177  GfxFillRect(blob_left, ypos2 - blob_distance - CargoesField::legend.height, blob_right, ypos2 - blob_distance, PC_BLACK); // Border
2178  GfxFillRect(blob_left + 1, ypos2 - blob_distance - CargoesField::legend.height + 1, blob_right - 1, ypos2 - blob_distance - 1, indsp->map_colour);
2179  } else {
2180  DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TC_FROMSTRING, SA_HOR_CENTER);
2181  }
2182 
2183  /* Draw the other_produced/other_accepted cargoes. */
2184  const CargoID *other_right, *other_left;
2185  if (_current_text_dir == TD_RTL) {
2186  other_right = this->u.industry.other_accepted;
2187  other_left = this->u.industry.other_produced;
2188  } else {
2189  other_right = this->u.industry.other_produced;
2190  other_left = this->u.industry.other_accepted;
2191  }
2193  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2194  if (IsValidCargoID(other_right[i])) {
2195  const CargoSpec *csp = CargoSpec::Get(other_right[i]);
2196  int xp = xpos + industry_width + CargoesField::cargo_stub.width;
2197  DrawHorConnection(xpos + industry_width, xp - 1, ypos1, csp);
2198  GfxDrawLine(xp, ypos1, xp, ypos1 + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2199  }
2200  if (IsValidCargoID(other_left[i])) {
2201  const CargoSpec *csp = CargoSpec::Get(other_left[i]);
2202  int xp = xpos - CargoesField::cargo_stub.width;
2203  DrawHorConnection(xp + 1, xpos - 1, ypos1, csp);
2204  GfxDrawLine(xp, ypos1, xp, ypos1 + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2205  }
2207  }
2208  break;
2209  }
2210 
2211  case CFT_CARGO: {
2212  int cargo_base = this->GetCargoBase(xpos);
2213  int top = ypos + (this->u.cargo.top_end ? vert_inter_industry_space / 2 + 1 : 0);
2214  int bot = ypos - (this->u.cargo.bottom_end ? vert_inter_industry_space / 2 + 1 : 0) + normal_height - 1;
2215  int colpos = cargo_base;
2216  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
2217  if (this->u.cargo.top_end) GfxDrawLine(colpos, top - 1, colpos + CargoesField::cargo_line.width - 1, top - 1, CARGO_LINE_COLOUR);
2218  if (this->u.cargo.bottom_end) GfxDrawLine(colpos, bot + 1, colpos + CargoesField::cargo_line.width - 1, bot + 1, CARGO_LINE_COLOUR);
2219  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2220  colpos++;
2221  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[i]);
2222  GfxFillRect(colpos, top, colpos + CargoesField::cargo_line.width - 2, bot, csp->legend_colour, FILLRECT_OPAQUE);
2223  colpos += CargoesField::cargo_line.width - 2;
2224  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2225  colpos += 1 + CargoesField::cargo_space.width;
2226  }
2227 
2228  const CargoID *hor_left, *hor_right;
2229  if (_current_text_dir == TD_RTL) {
2230  hor_left = this->u.cargo.cust_cargoes;
2231  hor_right = this->u.cargo.supp_cargoes;
2232  } else {
2233  hor_left = this->u.cargo.supp_cargoes;
2234  hor_right = this->u.cargo.cust_cargoes;
2235  }
2237  for (uint i = 0; i < MAX_CARGOES; i++) {
2238  if (IsValidCargoID(hor_left[i])) {
2239  int col = hor_left[i];
2240  int dx = 0;
2241  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2242  for (; col > 0; col--) {
2243  int lf = cargo_base + col * CargoesField::cargo_line.width + (col - 1) * CargoesField::cargo_space.width;
2244  DrawHorConnection(lf, lf + CargoesField::cargo_space.width - dx, ypos, csp);
2245  dx = 1;
2246  }
2247  DrawHorConnection(xpos, cargo_base - dx, ypos, csp);
2248  }
2249  if (IsValidCargoID(hor_right[i])) {
2250  int col = hor_right[i];
2251  int dx = 0;
2252  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2253  for (; col < this->u.cargo.num_cargoes - 1; col++) {
2254  int lf = cargo_base + (col + 1) * CargoesField::cargo_line.width + col * CargoesField::cargo_space.width;
2255  DrawHorConnection(lf + dx - 1, lf + CargoesField::cargo_space.width - 1, ypos, csp);
2256  dx = 1;
2257  }
2258  DrawHorConnection(cargo_base + col * CargoesField::cargo_space.width + (col + 1) * CargoesField::cargo_line.width - 1 + dx, xpos + CargoesField::cargo_field_width - 1, ypos, csp);
2259  }
2261  }
2262  break;
2263  }
2264 
2265  case CFT_CARGO_LABEL:
2267  for (uint i = 0; i < MAX_CARGOES; i++) {
2268  if (IsValidCargoID(this->u.cargo_label.cargoes[i])) {
2269  const CargoSpec *csp = CargoSpec::Get(this->u.cargo_label.cargoes[i]);
2270  DrawString(xpos + WidgetDimensions::scaled.framerect.left, xpos + industry_width - 1 - WidgetDimensions::scaled.framerect.right, ypos, csp->name, TC_WHITE,
2271  (this->u.cargo_label.left_align) ? SA_LEFT : SA_RIGHT);
2272  }
2274  }
2275  break;
2276 
2277  default:
2278  NOT_REACHED();
2279  }
2280  }
2281 
2289  CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
2290  {
2291  assert(this->type == CFT_CARGO);
2292 
2293  /* Vertical matching. */
2294  int cpos = this->GetCargoBase(0);
2295  uint col;
2296  for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2297  if (pt.x < cpos) break;
2298  if (pt.x < cpos + (int)CargoesField::cargo_line.width) return this->u.cargo.vertical_cargoes[col];
2300  }
2301  /* col = 0 -> left of first col, 1 -> left of 2nd col, ... this->u.cargo.num_cargoes right of last-col. */
2302 
2304  uint row;
2305  for (row = 0; row < MAX_CARGOES; row++) {
2306  if (pt.y < vpos) return INVALID_CARGO;
2307  if (pt.y < vpos + GetCharacterHeight(FS_NORMAL)) break;
2309  }
2310  if (row == MAX_CARGOES) return INVALID_CARGO;
2311 
2312  /* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
2313  if (col == 0) {
2314  if (IsValidCargoID(this->u.cargo.supp_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2315  if (left != nullptr) {
2316  if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row];
2317  if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
2318  }
2319  return INVALID_CARGO;
2320  }
2321  if (col == this->u.cargo.num_cargoes) {
2322  if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2323  if (right != nullptr) {
2324  if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row];
2325  if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row];
2326  }
2327  return INVALID_CARGO;
2328  }
2329  if (row >= col) {
2330  /* Clicked somewhere in-between vertical cargo connection.
2331  * Since the horizontal connection is made in the same order as the vertical list, the above condition
2332  * ensures we are left-below the main diagonal, thus at the supplying side.
2333  */
2334  if (IsValidCargoID(this->u.cargo.supp_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2335  return INVALID_CARGO;
2336  }
2337  /* Clicked at a customer connection. */
2338  if (IsValidCargoID(this->u.cargo.cust_cargoes[row])) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2339  return INVALID_CARGO;
2340  }
2341 
2348  {
2349  assert(this->type == CFT_CARGO_LABEL);
2350 
2351  int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height;
2352  uint row;
2353  for (row = 0; row < MAX_CARGOES; row++) {
2354  if (pt.y < vpos) return INVALID_CARGO;
2355  if (pt.y < vpos + GetCharacterHeight(FS_NORMAL)) break;
2357  }
2358  if (row == MAX_CARGOES) return INVALID_CARGO;
2359  return this->u.cargo_label.cargoes[row];
2360  }
2361 
2362 private:
2370  static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
2371  {
2372  GfxDrawLine(left, top, right, top, CARGO_LINE_COLOUR);
2373  GfxFillRect(left, top + 1, right, top + CargoesField::cargo_line.height - 2, csp->legend_colour, FILLRECT_OPAQUE);
2374  GfxDrawLine(left, top + CargoesField::cargo_line.height - 1, right, top + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2375  }
2376 };
2377 
2378 static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
2379 static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
2380 
2386 
2393 
2395 
2398 
2400 struct CargoesRow {
2402 
2407  void ConnectIndustryProduced(int column)
2408  {
2409  CargoesField *ind_fld = this->columns + column;
2410  CargoesField *cargo_fld = this->columns + column + 1;
2411  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2412 
2413  std::fill(std::begin(ind_fld->u.industry.other_produced), std::end(ind_fld->u.industry.other_produced), INVALID_CARGO);
2414 
2415  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2416  CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
2417  int other_count = 0;
2418 
2419  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2420  assert(CargoesField::max_cargoes <= lengthof(indsp->produced_cargo));
2421  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2422  int col = cargo_fld->ConnectCargo(indsp->produced_cargo[i], true);
2423  if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2424  }
2425 
2426  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
2427  for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2428  if (!IsValidCargoID(cargo_fld->u.cargo.supp_cargoes[i])) ind_fld->u.industry.other_produced[i] = others[--other_count];
2429  }
2430  } else {
2431  /* Houses only display cargo that towns produce. */
2432  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2433  CargoID cid = cargo_fld->u.cargo.vertical_cargoes[i];
2435  if (tpe == TPE_PASSENGERS || tpe == TPE_MAIL) cargo_fld->ConnectCargo(cid, true);
2436  }
2437  }
2438  }
2439 
2445  void MakeCargoLabel(int column, bool accepting)
2446  {
2447  CargoID cargoes[MAX_CARGOES];
2448  std::fill(std::begin(cargoes), std::end(cargoes), INVALID_CARGO);
2449 
2450  CargoesField *label_fld = this->columns + column;
2451  CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2452 
2453  assert(cargo_fld->type == CFT_CARGO && label_fld->type == CFT_EMPTY);
2454  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2455  int col = cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], !accepting);
2456  if (col >= 0) cargoes[col] = cargo_fld->u.cargo.vertical_cargoes[i];
2457  }
2458  label_fld->MakeCargoLabel(cargoes, lengthof(cargoes), accepting);
2459  }
2460 
2461 
2466  void ConnectIndustryAccepted(int column)
2467  {
2468  CargoesField *ind_fld = this->columns + column;
2469  CargoesField *cargo_fld = this->columns + column - 1;
2470  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2471 
2472  std::fill(std::begin(ind_fld->u.industry.other_accepted), std::end(ind_fld->u.industry.other_accepted), INVALID_CARGO);
2473 
2474  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2475  CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
2476  int other_count = 0;
2477 
2478  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2480  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2481  int col = cargo_fld->ConnectCargo(indsp->accepts_cargo[i], false);
2482  if (col < 0) others[other_count++] = indsp->accepts_cargo[i];
2483  }
2484 
2485  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
2486  for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2487  if (!IsValidCargoID(cargo_fld->u.cargo.cust_cargoes[i])) ind_fld->u.industry.other_accepted[i] = others[--other_count];
2488  }
2489  } else {
2490  /* Houses only display what is demanded. */
2491  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2492  for (uint h = 0; h < NUM_HOUSES; h++) {
2493  HouseSpec *hs = HouseSpec::Get(h);
2494  if (!hs->enabled) continue;
2495 
2496  for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
2497  if (hs->cargo_acceptance[j] > 0 && cargo_fld->u.cargo.vertical_cargoes[i] == hs->accepts_cargo[j]) {
2498  cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], false);
2499  goto next_cargo;
2500  }
2501  }
2502  }
2503 next_cargo: ;
2504  }
2505  }
2506  }
2507 };
2508 
2509 
2538  typedef std::vector<CargoesRow> Fields;
2539 
2540  Fields fields;
2541  uint ind_cargo;
2544  Scrollbar *vscroll;
2545 
2547  {
2548  this->OnInit();
2549  this->CreateNestedTree();
2550  this->vscroll = this->GetScrollbar(WID_IC_SCROLLBAR);
2551  this->FinishInitNested(0);
2552  this->OnInvalidateData(id);
2553  }
2554 
2555  void OnInit() override
2556  {
2557  /* Initialize static CargoesField size variables. */
2558  Dimension d = GetStringBoundingBox(STR_INDUSTRY_CARGOES_PRODUCERS);
2559  d = maxdim(d, GetStringBoundingBox(STR_INDUSTRY_CARGOES_CUSTOMERS));
2562  CargoesField::small_height = d.height;
2563 
2564  /* Size of the legend blob -- slightly larger than the smallmap legend blob. */
2566  CargoesField::legend.width = CargoesField::legend.height * 9 / 6;
2567 
2568  /* Size of cargo lines. */
2571 
2572  /* Size of border between cargo lines and industry boxes. */
2575 
2576  /* Size of space between cargo lines. */
2579 
2580  /* Size of cargo stub (unconnected cargo line.) */
2582  CargoesField::cargo_stub.height = CargoesField::cargo_line.height; /* Unused */
2583 
2586 
2587  /* Decide about the size of the box holding the text of an industry type. */
2588  this->ind_textsize.width = 0;
2589  this->ind_textsize.height = 0;
2591  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2592  const IndustrySpec *indsp = GetIndustrySpec(it);
2593  if (!indsp->enabled) continue;
2594  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
2595  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->accepts_cargo, endof(indsp->accepts_cargo), IsValidCargoID));
2596  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->produced_cargo, endof(indsp->produced_cargo), IsValidCargoID));
2597  }
2598  d.width = std::max(d.width, this->ind_textsize.width);
2599  d.height = this->ind_textsize.height;
2600  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY));
2601 
2602  /* Compute max size of the cargo texts. */
2603  this->cargo_textsize.width = 0;
2604  this->cargo_textsize.height = 0;
2605  for (const CargoSpec *csp : CargoSpec::Iterate()) {
2606  if (!csp->IsValid()) continue;
2607  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name));
2608  }
2609  d = maxdim(d, this->cargo_textsize); // Box must also be wide enough to hold any cargo label.
2610  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_CARGO));
2611 
2613  /* Ensure the height is enough for the industry type text, for the horizontal connections, and for the cargo labels. */
2615  d.height = std::max(d.height + WidgetDimensions::scaled.frametext.Vertical(), min_ind_height);
2616 
2617  CargoesField::industry_width = d.width;
2619 
2620  /* Width of a #CFT_CARGO field. */
2622  }
2623 
2624  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2625  {
2626  switch (widget) {
2627  case WID_IC_PANEL:
2631  break;
2632 
2633  case WID_IC_IND_DROPDOWN:
2634  size->width = std::max(size->width, this->ind_textsize.width + padding.width);
2635  break;
2636 
2637  case WID_IC_CARGO_DROPDOWN:
2638  size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
2639  break;
2640  }
2641  }
2642 
2643 
2645  void SetStringParameters (WidgetID widget) const override
2646  {
2647  if (widget != WID_IC_CAPTION) return;
2648 
2649  if (this->ind_cargo < NUM_INDUSTRYTYPES) {
2650  const IndustrySpec *indsp = GetIndustrySpec(this->ind_cargo);
2651  SetDParam(0, indsp->name);
2652  } else {
2653  const CargoSpec *csp = CargoSpec::Get(this->ind_cargo - NUM_INDUSTRYTYPES);
2654  SetDParam(0, csp->name);
2655  }
2656  }
2657 
2666  static bool HasCommonValidCargo(const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
2667  {
2668  while (length1 > 0) {
2669  if (IsValidCargoID(*cargoes1)) {
2670  for (uint i = 0; i < length2; i++) if (*cargoes1 == cargoes2[i]) return true;
2671  }
2672  cargoes1++;
2673  length1--;
2674  }
2675  return false;
2676  }
2677 
2684  static bool HousesCanSupply(const CargoID *cargoes, uint length)
2685  {
2686  for (uint i = 0; i < length; i++) {
2687  CargoID cid = cargoes[i];
2688  if (!IsValidCargoID(cid)) continue;
2690  if (tpe == TPE_PASSENGERS || tpe == TPE_MAIL) return true;
2691  }
2692  return false;
2693  }
2694 
2701  static bool HousesCanAccept(const CargoID *cargoes, uint length)
2702  {
2703  HouseZones climate_mask;
2705  case LT_TEMPERATE: climate_mask = HZ_TEMP; break;
2706  case LT_ARCTIC: climate_mask = HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW; break;
2707  case LT_TROPIC: climate_mask = HZ_SUBTROPIC; break;
2708  case LT_TOYLAND: climate_mask = HZ_TOYLND; break;
2709  default: NOT_REACHED();
2710  }
2711  for (uint i = 0; i < length; i++) {
2712  if (!IsValidCargoID(cargoes[i])) continue;
2713 
2714  for (uint h = 0; h < NUM_HOUSES; h++) {
2715  HouseSpec *hs = HouseSpec::Get(h);
2716  if (!hs->enabled || !(hs->building_availability & climate_mask)) continue;
2717 
2718  for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
2719  if (hs->cargo_acceptance[j] > 0 && cargoes[i] == hs->accepts_cargo[j]) return true;
2720  }
2721  }
2722  }
2723  return false;
2724  }
2725 
2732  static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
2733  {
2734  int count = 0;
2735  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2736  const IndustrySpec *indsp = GetIndustrySpec(it);
2737  if (!indsp->enabled) continue;
2738 
2739  if (HasCommonValidCargo(cargoes, length, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) count++;
2740  }
2741  return count;
2742  }
2743 
2750  static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
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, length, indsp->produced_cargo, lengthof(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, lengthof(central_sp->accepts_cargo));
2833  bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
2834  /* Make a field consisting of two cargo columns. */
2835  int num_supp = CountMatchingProducingIndustries(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)) + houses_supply;
2836  int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(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, lengthof(central_sp->accepts_cargo));
2842  row.columns[2].MakeEmpty(CFT_EMPTY);
2843  row.columns[3].MakeCargo(central_sp->produced_cargo, lengthof(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, lengthof(central_sp->accepts_cargo), indsp->produced_cargo, lengthof(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, lengthof(central_sp->produced_cargo), indsp->accepts_cargo, lengthof(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  bool houses_supply = HousesCanSupply(&cid, 1);
2909  bool houses_accept = HousesCanAccept(&cid, 1);
2910  int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1; // Ensure room for the cargo label.
2911  int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
2912  int num_indrows = std::max(num_supp, num_cust);
2913  for (int i = 0; i < num_indrows; i++) {
2914  CargoesRow &row = this->fields.emplace_back();
2915  row.columns[0].MakeEmpty(CFT_EMPTY);
2916  row.columns[1].MakeCargo(&cid, 1);
2917  row.columns[2].MakeEmpty(CFT_EMPTY);
2918  row.columns[3].MakeEmpty(CFT_EMPTY);
2919  row.columns[4].MakeEmpty(CFT_EMPTY);
2920  }
2921 
2922  this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
2923 
2924  /* Add suppliers and customers of the cargo. */
2925  int supp_count = 0;
2926  int cust_count = 0;
2927  for (IndustryType it : _sorted_industry_types) {
2928  const IndustrySpec *indsp = GetIndustrySpec(it);
2929  if (!indsp->enabled) continue;
2930 
2931  if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
2932  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2933  _displayed_industries.set(it);
2934  supp_count++;
2935  }
2936  if (HasCommonValidCargo(&cid, 1, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
2937  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2938  _displayed_industries.set(it);
2939  cust_count++;
2940  }
2941  }
2942  if (houses_supply) {
2943  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2944  supp_count++;
2945  }
2946  if (houses_accept) {
2947  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
2948  cust_count++;
2949  }
2950 
2951  this->ShortenCargoColumn(1, 1, num_indrows);
2952  this->vscroll->SetCount(num_indrows);
2953  this->SetDirty();
2954  this->NotifySmallmap();
2955  }
2956 
2964  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2965  {
2966  if (!gui_scope) return;
2967  if (data == NUM_INDUSTRYTYPES) {
2969  return;
2970  }
2971 
2972  assert(data >= 0 && data < NUM_INDUSTRYTYPES);
2973  this->ComputeIndustryDisplay(data);
2974  }
2975 
2976  void DrawWidget(const Rect &r, WidgetID widget) const override
2977  {
2978  if (widget != WID_IC_PANEL) return;
2979 
2980  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
2981  DrawPixelInfo tmp_dpi;
2982  if (!FillDrawPixelInfo(&tmp_dpi, ir)) return;
2983  AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
2984 
2986  if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2;
2987  int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
2988 
2989  const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2990  int vpos = WidgetDimensions::scaled.frametext.top - WidgetDimensions::scaled.bevel.top - this->vscroll->GetPosition() * nwp->resize_y;
2991  int row_height = CargoesField::small_height;
2992  for (const auto &field : this->fields) {
2993  if (vpos + row_height >= 0) {
2994  int xpos = left_pos;
2995  int col, dir;
2996  if (_current_text_dir == TD_RTL) {
2997  col = last_column;
2998  dir = -1;
2999  } else {
3000  col = 0;
3001  dir = 1;
3002  }
3003  while (col >= 0 && col <= last_column) {
3004  field.columns[col].Draw(xpos, vpos);
3006  col += dir;
3007  }
3008  }
3009  vpos += row_height;
3010  if (vpos >= height) break;
3011  row_height = CargoesField::normal_height;
3012  }
3013  }
3014 
3022  bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
3023  {
3024  const NWidgetBase *nw = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
3025  pt.x -= nw->pos_x;
3026  pt.y -= nw->pos_y;
3027 
3028  int vpos = WidgetDimensions::scaled.framerect.top + CargoesField::small_height - this->vscroll->GetPosition() * nw->resize_y;
3029  if (pt.y < vpos) return false;
3030 
3031  int row = (pt.y - vpos) / CargoesField::normal_height; // row is relative to row 1.
3032  if (row + 1 >= (int)this->fields.size()) return false;
3033  vpos = pt.y - vpos - row * CargoesField::normal_height; // Position in the row + 1 field
3034  row++; // rebase row to match index of this->fields.
3035 
3037  if (pt.x < xpos) return false;
3038  int column;
3039  for (column = 0; column <= 5; column++) {
3041  if (pt.x < xpos + width) break;
3042  xpos += width;
3043  }
3044  int num_columns = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
3045  if (column > num_columns) return false;
3046  xpos = pt.x - xpos;
3047 
3048  /* Return both positions, compensating for RTL languages (which works due to the equal symmetry in both displays). */
3049  fieldxy->y = row;
3050  xy->y = vpos;
3051  if (_current_text_dir == TD_RTL) {
3052  fieldxy->x = num_columns - column;
3053  xy->x = ((column & 1) ? CargoesField::cargo_field_width : CargoesField::industry_width) - xpos;
3054  } else {
3055  fieldxy->x = column;
3056  xy->x = xpos;
3057  }
3058  return true;
3059  }
3060 
3061  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
3062  {
3063  switch (widget) {
3064  case WID_IC_PANEL: {
3065  Point fieldxy, xy;
3066  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return;
3067 
3068  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3069  switch (fld->type) {
3070  case CFT_INDUSTRY:
3071  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES) this->ComputeIndustryDisplay(fld->u.industry.ind_type);
3072  break;
3073 
3074  case CFT_CARGO: {
3075  CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
3076  CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
3077  CargoID cid = fld->CargoClickedAt(lft, rgt, xy);
3078  if (IsValidCargoID(cid)) this->ComputeCargoDisplay(cid);
3079  break;
3080  }
3081 
3082  case CFT_CARGO_LABEL: {
3083  CargoID cid = fld->CargoLabelClickedAt(xy);
3084  if (IsValidCargoID(cid)) this->ComputeCargoDisplay(cid);
3085  break;
3086  }
3087 
3088  default:
3089  break;
3090  }
3091  break;
3092  }
3093 
3094  case WID_IC_NOTIFY:
3097  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
3098 
3099  if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
3100  if (FindWindowByClass(WC_SMALLMAP) == nullptr) ShowSmallMap();
3101  this->NotifySmallmap();
3102  }
3103  break;
3104 
3105  case WID_IC_CARGO_DROPDOWN: {
3106  DropDownList lst;
3108  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
3109  lst.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false));
3110  }
3111  if (!lst.empty()) {
3112  int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
3113  ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN);
3114  }
3115  break;
3116  }
3117 
3118  case WID_IC_IND_DROPDOWN: {
3119  DropDownList lst;
3120  for (IndustryType ind : _sorted_industry_types) {
3121  const IndustrySpec *indsp = GetIndustrySpec(ind);
3122  if (!indsp->enabled) continue;
3123  lst.push_back(std::make_unique<DropDownListStringItem>(indsp->name, ind, false));
3124  }
3125  if (!lst.empty()) {
3126  int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
3127  ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN);
3128  }
3129  break;
3130  }
3131  }
3132  }
3133 
3134  void OnDropdownSelect(WidgetID widget, int index) override
3135  {
3136  if (index < 0) return;
3137 
3138  switch (widget) {
3139  case WID_IC_CARGO_DROPDOWN:
3140  this->ComputeCargoDisplay(index);
3141  break;
3142 
3143  case WID_IC_IND_DROPDOWN:
3144  this->ComputeIndustryDisplay(index);
3145  break;
3146  }
3147  }
3148 
3149  bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
3150  {
3151  if (widget != WID_IC_PANEL) return false;
3152 
3153  Point fieldxy, xy;
3154  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
3155 
3156  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3157  CargoID cid = INVALID_CARGO;
3158  switch (fld->type) {
3159  case CFT_CARGO: {
3160  CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
3161  CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
3162  cid = fld->CargoClickedAt(lft, rgt, xy);
3163  break;
3164  }
3165 
3166  case CFT_CARGO_LABEL: {
3167  cid = fld->CargoLabelClickedAt(xy);
3168  break;
3169  }
3170 
3171  case CFT_INDUSTRY:
3172  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
3173  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond);
3174  }
3175  return true;
3176 
3177  default:
3178  break;
3179  }
3180  if (IsValidCargoID(cid) && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) {
3181  const CargoSpec *csp = CargoSpec::Get(cid);
3182  SetDParam(0, csp->name);
3183  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, 1);
3184  return true;
3185  }
3186 
3187  return false;
3188  }
3189 
3190  void OnResize() override
3191  {
3193  }
3194 };
3195 
3200 static void ShowIndustryCargoesWindow(IndustryType id)
3201 {
3202  if (id >= NUM_INDUSTRYTYPES) {
3203  for (IndustryType ind : _sorted_industry_types) {
3204  const IndustrySpec *indsp = GetIndustrySpec(ind);
3205  if (indsp->enabled) {
3206  id = ind;
3207  break;
3208  }
3209  }
3210  if (id >= NUM_INDUSTRYTYPES) return;
3211  }
3212 
3214  if (w != nullptr) {
3215  w->InvalidateData(id);
3216  return;
3217  }
3218  new IndustryCargoesWindow(id);
3219 }
3220 
3223 {
3225 }
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition: industry_gui.cpp:220
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
_nested_industry_view_widgets
static constexpr NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
Definition: industry_gui.cpp:1178
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:278
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
ToPercent8
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
Definition: math_func.hpp:295
IndustryCargoesWindow::CountMatchingProducingIndustries
static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
Count how many industries have produced cargoes in common with one of the supplied set.
Definition: industry_gui.cpp:2750
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:355
PRODLEVEL_MINIMUM
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
Definition: industry.h:35
sound_func.h
IndustryCargoesWindow::HousesCanAccept
static bool HousesCanAccept(const CargoID *cargoes, uint length)
Can houses be used as customers of the produced cargoes?
Definition: industry_gui.cpp:2701
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
IndustrySpec::map_colour
byte map_colour
colour used for the small map
Definition: industrytype.h:126
TPE_MAIL
@ TPE_MAIL
Cargo behaves mail-like for production.
Definition: cargotype.h:37
INDUSTRY_NUM_OUTPUTS
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
Definition: industry_type.h:39
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:335
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
INDUSTRYBEH_CARGOTYPES_UNLIMITED
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
Definition: industrytype.h:80
IndustrySpec::UsesOriginalEconomy
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
Definition: industry_cmd.cpp:3144
CargoesField::num_cargoes
uint8_t num_cargoes
Number of cargoes.
Definition: industry_gui.cpp:1993
CargoesField::MakeCargo
void MakeCargo(const CargoID *cargoes, uint length, int count=-1, bool top_end=false, bool bottom_end=false)
Make a piece of cargo column.
Definition: industry_gui.cpp:2083
WC_INDUSTRY_CARGOES
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
Definition: window_type.h:516
IndustryCargoesWindow::HousesCanSupply
static bool HousesCanSupply(const CargoID *cargoes, uint length)
Can houses be used to supply one of the cargoes?
Definition: industry_gui.cpp:2684
IndustryTypeNameSorter
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
Definition: industry_gui.cpp:223
IndustryDirectoryWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: industry_gui.cpp:1866
CargoesField::INDUSTRY_LINE_COLOUR
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
Definition: industry_gui.cpp:1976
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:416
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:1230
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
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:1988
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.
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:197
CargoesField::top_end
uint8_t top_end
Stop at the top of the vertical cargoes.
Definition: industry_gui.cpp:1995
dropdown_func.h
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:327
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:807
smallmap_gui.h
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
CFT_HEADER
@ CFT_HEADER
Header text.
Definition: industry_gui.cpp:1960
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:1404
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:2543
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:687
HouseSpec::accepts_cargo
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
Definition: house.h:108
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:664
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:1106
HZ_SUBTROPIC
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition: house.h:82
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
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:3122
CSD_CARGO
@ CSD_CARGO
Display the cargo without sub-type (cb37 result 401).
Definition: industry_gui.cpp:67
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:791
WID_IC_IND_DROPDOWN
@ WID_IC_IND_DROPDOWN
Select industry dropdown.
Definition: industry_widget.h:53
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2228
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:229
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:58
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
WID_IC_NOTIFY
@ WID_IC_NOTIFY
Row of buttons at the bottom.
Definition: industry_widget.h:49
CargoesRow
A single row of CargoesField.
Definition: industry_gui.cpp:2400
IndustryDirectoryWindow::SetAcceptedCargoFilter
void SetAcceptedCargoFilter(CargoID cid)
Set accepted cargo filter for the industry list.
Definition: industry_gui.cpp:1353
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:1154
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:210
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:1974
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:131
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:1838
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:798
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
HouseSpec::enabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition: house.h:112
SortIndustryTypes
void SortIndustryTypes()
Initialize the list of sorted industry types.
Definition: industry_gui.cpp:234
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:62
CargoesField::legend
static Dimension legend
Dimension of the legend blob.
Definition: industry_gui.cpp:1970
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
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:306
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:1174
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:37
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:253
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:435
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:2334
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:526
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:585
WID_IC_CARGO_DROPDOWN
@ WID_IC_CARGO_DROPDOWN
Select cargo dropdown.
Definition: industry_widget.h:52
Industry::produced
ProducedCargoArray produced
INDUSTRY_NUM_OUTPUTS production cargo slots.
Definition: industry.h:99
Industry::RecomputeProductionMultipliers
void RecomputeProductionMultipliers()
Recompute #production_rate for current prod_level.
Definition: industry_cmd.cpp:2508
CargoSpec::Iterate
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
Definition: cargotype.h:187
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
CargoesField::ConnectCargo
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
Definition: industry_gui.cpp:2034
Industry::GetCargoProduced
ProducedCargoArray::iterator GetCargoProduced(CargoID cargo)
Get produced cargo slot for a specific cargo type.
Definition: industry.h:147
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:68
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:468
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:1159
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 > >
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:40
CargoesField::CARGO_LINE_COLOUR
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
Definition: industry_gui.cpp:1977
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:815
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:340
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:155
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:1848
clear_map.h
_industry_view_desc
static WindowDesc _industry_view_desc(__FILE__, __LINE__, WDP_AUTO, "view_industry", 260, 120, WC_INDUSTRY_VIEW, WC_NONE, 0, std::begin(_nested_industry_view_widgets), std::end(_nested_industry_view_widgets))
Window definition of the view industry gui.
PRODLEVEL_DEFAULT
@ 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
IndustryDirectoryWindow::GetIndustryListWidth
uint GetIndustryListWidth() const
Get the width needed to draw the longest industry line.
Definition: industry_gui.cpp:1394
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
CargoesField::DrawHorConnection
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
Definition: industry_gui.cpp:2370
WID_IV_GOTO
@ WID_IV_GOTO
Goto button.
Definition: industry_widget.h:30
CFT_INDUSTRY
@ CFT_INDUSTRY
Display industry.
Definition: industry_gui.cpp:1957
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
MAX_CARGOES
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
Definition: industry_gui.cpp:1963
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:2541
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:1523
CargoFilter
static bool CDECL CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
Definition: industry_gui.cpp:1255
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
genworld.h
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
WID_IC_SCROLLBAR
@ WID_IC_SCROLLBAR
Scrollbar of the panel.
Definition: industry_widget.h:51
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.
IndustryCargoesWindow::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:2644
BuildIndustryWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:738
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:2133
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
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:702
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
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:251
IndustryDirectoryWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:1638
MakeClear
void MakeClear(Tile t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
BuildIndustryWindow::list
std::vector< IndustryType > list
List of industries.
Definition: industry_gui.cpp:305
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:1958
IndustryDirectoryWindow::MAX_FILTER_LENGTH
const int MAX_FILTER_LENGTH
The max length of the filter, in chars.
Definition: industry_gui.cpp:1321
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:3190
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:2347
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:1188
_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
CargoSuffixDisplay
CargoSuffixDisplay
Ways of displaying the cargo.
Definition: industry_gui.cpp:66
IndustryCargoesWindow
Window displaying the cargo connections around an industry (or cargo).
Definition: industry_gui.cpp:2537
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
IndustrySpec::IsRawIndustry
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
Definition: industry_cmd.cpp:3102
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
CommandCost
Common return value for all commands.
Definition: command_type.h:23
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
_build_industry_desc
static WindowDesc _build_industry_desc(__FILE__, __LINE__, WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets))
Window definition of the dynamic place industries gui.
IndustryViewWindow::editable
Editability editable
Mode for changing production.
Definition: industry_gui.cpp:803
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2237
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition: house.h:29
IndustryCargoesWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:2555
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
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:2445
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
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:1244
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:343
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:1967
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:591
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:306
IndustryViewWindow::IL_NONE
@ IL_NONE
No line.
Definition: industry_gui.cpp:797
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
IndustryDirectoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1817
GUIList::SortFunction
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
Definition: sortlist_type.h:49
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:833
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2498
CargoesField::industry_width
static int industry_width
Width of an industry field.
Definition: industry_gui.cpp:1981
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
HZ_TEMP
@ HZ_TEMP
12 1000 can appear in temperate climate
Definition: house.h:80
IndustryDirectoryWindow
The list of industries.
Definition: industry_gui.cpp:1304
IndustrySpec::layouts
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
Definition: industrytype.h:106
IndustrySpec::accepts_cargo
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
Definition: industrytype.h:120
CargoesField::MakeIndustry
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
Definition: industry_gui.cpp:2020
IndustryViewWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:1099
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:1966
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
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:2000
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
CargoSuffix::display
CargoSuffixDisplay display
How to display the cargo and text.
Definition: industry_gui.cpp:75
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:254
WID_ID_FILTER_BY_ACC_CARGO
@ WID_ID_FILTER_BY_ACC_CARGO
Accepted cargo filter dropdown list.
Definition: industry_widget.h:38
WID_ID_VSCROLLBAR
@ WID_ID_VSCROLLBAR
Vertical scrollbar of the list.
Definition: industry_widget.h:43
IndustryDirectoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:1831
CargoesField::industry
struct CargoesField::@5::@6 industry
Industry data (for CFT_INDUSTRY).
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
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:1534
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:570
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
ShowIndustryCargoesWindow
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
Definition: industry_gui.cpp:3200
ZOOM_LVL_INDUSTRY
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
Definition: zoom_type.h:33
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:953
Industry::accepted
AcceptedCargoArray accepted
INDUSTRY_NUM_INPUTS input cargo slots.
Definition: industry.h:100
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:1982
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:1258
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:244
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
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:1086
timer.h
WID_ID_INDUSTRY_LIST
@ WID_ID_INDUSTRY_LIST
Industry list.
Definition: industry_widget.h:41
CST_VIEW
@ CST_VIEW
View-industry window.
Definition: industry_gui.cpp:61
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
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:308
_nested_industry_directory_widgets
static constexpr NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
Definition: industry_gui.cpp:1215
CargoesRow::ConnectIndustryProduced
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
Definition: industry_gui.cpp:2407
IndustryDirectoryWindow::SetProducedCargoFilter
void SetProducedCargoFilter(CargoID cid)
Set produced cargo filter for the industry list.
Definition: industry_gui.cpp:1336
CargoesField::HasConnection
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
Definition: industry_gui.cpp:2063
_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:56
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:59
CargoesField::header
StringID header
Header text (for CFT_HEADER).
Definition: industry_gui.cpp:2003
CargoesField::vertical_cargoes
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or #INVALID_CARGO).
Definition: industry_gui.cpp:1992
IndustryDirectoryWindow::accepted_cargo_filter_criteria
CargoID accepted_cargo_filter_criteria
Selected accepted cargo filter index.
Definition: industry_gui.cpp:1318
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:3022
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
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:1956
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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:845
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:1443
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:386
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:2146
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:2964
IndustryViewWindow::Editability
Editability
Modes for changing production.
Definition: industry_gui.cpp:789
stdafx.h
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2909
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
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:113
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:91
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:105
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:3140
CFT_CARGO_LABEL
@ CFT_CARGO_LABEL
Display cargo labels.
Definition: industry_gui.cpp:1959
CargoesField::normal_height
static int normal_height
Height of the non-header rows.
Definition: industry_gui.cpp:1979
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:1979
IACT_USERCREATION
@ IACT_USERCREATION
from the Fund/build window
Definition: newgrf_industries.h:85
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
OrthogonalTileArea::GetCenterTile
TileIndex GetCenterTile() const
Get the center tile.
Definition: tilearea_type.h:59
HouseSpec::cargo_acceptance
byte cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
Definition: house.h:107
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
CFT_EMPTY
@ CFT_EMPTY
Empty field.
Definition: industry_gui.cpp:1955
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:1571
FILLRECT_OPAQUE
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition: gfx_type.h:293
CargoesField::cargo_space
static Dimension cargo_space
Dimensions of space between cargo lines.
Definition: industry_gui.cpp:1973
IndustryViewWindow
Definition: industry_gui.cpp:786
IndustrySpec::callback_mask
uint16_t callback_mask
Bitmask of industry callbacks that have to be called.
Definition: industrytype.h:138
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:792
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
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:62
CargoesField::cargo_border
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
Definition: industry_gui.cpp:1971
IndustryDirectoryWindow::IndustryNameSorter
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b, const CargoID &)
Sort industries by name.
Definition: industry_gui.cpp:1482
IndustryTemporarilyRefusesCargo
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Definition: newgrf_industries.cpp:683
IndustryDirectoryWindow::produced_cargo_filter_criteria
CargoID produced_cargo_filter_criteria
Selected produced cargo filter index.
Definition: industry_gui.cpp:1317
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
IndustryViewWindow::IL_MULTIPLIER
@ IL_MULTIPLIER
Production multiplier.
Definition: industry_gui.cpp:798
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:2001
string_func.h
BuildIndustryWindow::MakeCargoListString
std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
Build a string of cargo names with suffixes attached.
Definition: industry_gui.cpp:369
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:140
IndustryViewWindow::cheat_line_height
int cheat_line_height
Height of each line for the WID_IV_INFO panel.
Definition: industry_gui.cpp:809
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:491
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
ConstructionSettings::raw_industry_construction
uint8_t raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
Definition: settings_type.h:381
PC_YELLOW
static const uint8_t PC_YELLOW
Yellow palette colour.
Definition: palette_func.h:68
CargoesField::cust_cargoes
CargoID cust_cargoes[MAX_CARGOES]
Cargoes leaving to the right (index in vertical_cargoes, or #INVALID_CARGO).
Definition: industry_gui.cpp:1996
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
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:775
WID_ID_DROPDOWN_CRITERIA
@ WID_ID_DROPDOWN_CRITERIA
Dropdown for the criteria of the sort.
Definition: industry_widget.h:37
WID_IC_CAPTION
@ WID_IC_CAPTION
Caption of the window.
Definition: industry_widget.h:48
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
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:757
CargoesField::MakeCargoLabel
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
Definition: industry_gui.cpp:2109
CargoSpec::town_production_effect
TownProductionEffect town_production_effect
The effect on town cargo production.
Definition: cargotype.h:81
IndustryViewWindow::IL_RATE1
@ IL_RATE1
Production rate of cargo 1.
Definition: industry_gui.cpp:799
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:384
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:1724
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:2401
CSD_CARGO_AMOUNT_TEXT
@ CSD_CARGO_AMOUNT_TEXT
Display then cargo, amount, and string (cb37 result 000-3FF).
Definition: industry_gui.cpp:70
CargoesField::MakeHeader
void MakeHeader(StringID textid)
Make a header above an industry column.
Definition: industry_gui.cpp:2122
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:349
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:556
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:137
IndustryDirectoryWindow::GetCargoTransportedSortValue
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
Definition: industry_gui.cpp:1456
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:365
industry_widget.h
Scrollbar::IsVisible
bool IsVisible(uint16_t item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:730
IndustryViewWindow::editbox_line
InfoLine editbox_line
The line clicked to open the edit box.
Definition: industry_gui.cpp:804
INVALID_INDUSTRYTYPE
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
Definition: industry_type.h:27
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
CST_FUND
@ CST_FUND
Fund-industry window.
Definition: industry_gui.cpp:60
IndustryCargoesWindow::cargo_textsize
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
Definition: industry_gui.cpp:2542
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:1954
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:304
IndustryViewWindow::EA_NONE
@ EA_NONE
Not alterable.
Definition: industry_gui.cpp:790
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
geometry_func.hpp
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:308
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:3217
IndustryDirectoryWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: industry_gui.cpp:1378
HZ_SUBARTC_ABOVE
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition: house.h:79
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:50
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
CargoesField::cargo_field_width
static int cargo_field_width
Width of a cargo field.
Definition: industry_gui.cpp:1980
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:226
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1994
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
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:327
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:141
CSD_CARGO_TEXT
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
Definition: industry_gui.cpp:69
Industry::GetIndustryTypeCount
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:242
EventState
EventState
State of handling an event.
Definition: window_type.h:738
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:805
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1114
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:1490
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:796
HouseSpec::building_availability
HouseZones building_availability
where can it be built (climates, zones)
Definition: house.h:111
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:1142
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:352
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:85
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:1734
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
WID_ID_DROPDOWN_ORDER
@ WID_ID_DROPDOWN_ORDER
Dropdown for the order of the sort.
Definition: industry_widget.h:36
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:2466
BuildIndustryWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: industry_gui.cpp:743
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
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:499
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
network.h
TownProductionEffect
TownProductionEffect
Town effect when producing cargo.
Definition: cargotype.h:34
CommandHelper
Definition: command_func.h:93
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:366
WID_ID_HSCROLLBAR
@ WID_ID_HSCROLLBAR
Horizontal scrollbar of the list.
Definition: industry_widget.h:42
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
IndustryCargoesWindow::HasCommonValidCargo
static bool HasCommonValidCargo(const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
Do the two sets of cargoes have a valid cargo in common?
Definition: industry_gui.cpp:2666
window_func.h
IndustrySpec::behaviour
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:125
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:241
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
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:1097
HZ_TOYLND
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition: house.h:83
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
CargoIDComparator
Comparator to sort CargoID by according to desired order.
Definition: cargotype.h:238
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:295
random_func.hpp
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
DrawRectOutline
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
Definition: gfx.cpp:455
GUIList< const Industry *, const CargoID &, const std::pair< CargoID, CargoID > & >::FilterFunction
bool CDECL FilterFunction(const const Industry * *, const std::pair< CargoID, CargoID > &)
Signature of filter function.
Definition: sortlist_type.h:50
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:237
CargoSuffix
Transfer storage of cargo suffix information.
Definition: industry_gui.cpp:74
CargoesField::bottom_end
uint8_t bottom_end
Stop at the bottom of the vertical cargoes.
Definition: industry_gui.cpp:1997
HouseSpec
Definition: house.h:98
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:658
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:1968
PSM_LEAVE_GAMELOOP
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
Definition: newgrf_storage.h:22
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
HouseZones
HouseZones
Definition: house.h:71
IndustryViewWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:827
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:103
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:761
_industry_directory_desc
static WindowDesc _industry_directory_desc(__FILE__, __LINE__, WDP_AUTO, "list_industries", 428, 190, WC_INDUSTRY_DIRECTORY, WC_NONE, 0, std::begin(_nested_industry_directory_widgets), std::end(_nested_industry_directory_widgets), &IndustryDirectoryWindow::hotkeys)
Window definition of the industry directory gui.
CargoesField::ind_type
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
Definition: industry_gui.cpp:1987
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:1501
IndustryDirectoryWindow::SorterType
SorterType
Definition: industry_gui.cpp:1325
BuildIndustryWindow::SetButtons
void SetButtons()
Update status of the fund and display-chain widgets.
Definition: industry_gui.cpp:351
IndustryDirectoryWindow::string_filter
StringFilter string_filter
Filter for industries.
Definition: industry_gui.cpp:1322
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
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:620
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:59
Window
Data structure for an opened window.
Definition: window_gui.h:267
Commands
Commands
List of commands.
Definition: command_type.h:187
IndustryViewWindow::clicked_button
byte clicked_button
The button that has been clicked (to raise)
Definition: industry_gui.cpp:806
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:127
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:324
IndustryViewWindow::DrawInfo
int DrawInfo(const Rect &r)
Draw the text in the WID_IV_INFO panel.
Definition: industry_gui.cpp:853
TPE_PASSENGERS
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
Definition: cargotype.h:36
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:39
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:319
Industry::prod_level
byte prod_level
general production level
Definition: industry.h:101
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:1162
settings_gui.h
CargoesField::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:1984
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
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:1109
CargoesField::MakeEmpty
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
Definition: industry_gui.cpp:2010
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
Window::RaiseWidgetWhenLowered
void RaiseWidgetWhenLowered(byte widget_index)
Marks a widget as raised and dirty (redraw), when it is marked as lowered.
Definition: window_gui.h:478
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:450
CargoesField::supp_cargoes
CargoID supp_cargoes[MAX_CARGOES]
Cargoes entering from the left (index in vertical_cargoes, or #INVALID_CARGO).
Definition: industry_gui.cpp:1994
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition: clear_map.h:23
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:2289
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
HZ_SUBARTC_BELOW
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition: house.h:81
IndustryViewWindow::IL_RATE2
@ IL_RATE2
Production rate of cargo 2.
Definition: industry_gui.cpp:800
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:130
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
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:522
CargoSuffix::text
std::string text
Cargo suffix text.
Definition: industry_gui.cpp:76
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
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:311
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:104
cpp_lengthof
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
Definition: stdafx.h:332
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
IndustryCargoesWindow::CountMatchingAcceptingIndustries
static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
Count how many industries have accepted cargoes in common with one of the supplied set.
Definition: industry_gui.cpp:2732
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:2540
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:176
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:68
IndustryViewWindow::info_height
int info_height
Height needed for the WID_IV_INFO panel.
Definition: industry_gui.cpp:808
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
IDHK_FOCUS_FILTER_BOX
@ IDHK_FOCUS_FILTER_BOX
Focus the filter box.
Definition: industry_gui.cpp:1299
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:2439
IndustryDirectoryWindow::industry_editbox
QueryString industry_editbox
Filter editbox.
Definition: industry_gui.cpp:1323
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:303
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
CargoesField::cargo_line
static Dimension cargo_line
Dimensions of cargo lines.
Definition: industry_gui.cpp:1972
CargoesField::other_accepted
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
Definition: industry_gui.cpp:1989
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:2582
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:190
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:151
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:1298
hotkeys.h
_industry_cargoes_desc
static WindowDesc _industry_cargoes_desc(__FILE__, __LINE__, WDP_AUTO, "industry_cargoes", 300, 210, WC_INDUSTRY_CARGOES, WC_NONE, 0, std::begin(_nested_industry_cargoes_widgets), std::end(_nested_industry_cargoes_widgets))
Window description for the industry cargoes window.
_nested_industry_cargoes_widgets
static constexpr NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
Definition: industry_gui.cpp:1921
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:753
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