OpenTTD Source  1.11.0-beta1
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 
41 #include "table/strings.h"
42 
43 #include <bitset>
44 
45 #include "safeguards.h"
46 
47 bool _ignore_restrictions;
48 std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
49 
55 };
56 
63 };
64 
66 struct CargoSuffix {
68  char text[512];
69 };
70 
71 static void ShowIndustryCargoesWindow(IndustryType id);
72 
82 static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
83 {
84  suffix.text[0] = '\0';
85  suffix.display = CSD_CARGO_AMOUNT;
86 
87  if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
88  TileIndex t = (cst != CST_FUND) ? ind->location.tile : INVALID_TILE;
89  uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, t);
90  if (callback == CALLBACK_FAILED) return;
91 
92  if (indspec->grf_prop.grffile->grf_version < 8) {
93  if (GB(callback, 0, 8) == 0xFF) return;
94  if (callback < 0x400) {
96  GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text));
99  return;
100  }
102  return;
103 
104  } else { // GRF version 8 or higher.
105  if (callback == 0x400) return;
106  if (callback == 0x401) {
107  suffix.display = CSD_CARGO;
108  return;
109  }
110  if (callback < 0x400) {
112  GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text));
115  return;
116  }
117  if (callback >= 0x800 && callback < 0xC00) {
119  GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 - 0x800 + callback), lastof(suffix.text));
121  suffix.display = CSD_CARGO_TEXT;
122  return;
123  }
125  return;
126  }
127  }
128 }
129 
130 enum CargoSuffixInOut {
131  CARGOSUFFIX_OUT = 0,
132  CARGOSUFFIX_IN = 1,
133 };
134 
145 template <typename TC, typename TS>
146 static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
147 {
148  static_assert(lengthof(cargoes) <= lengthof(suffixes));
149 
151  /* Reworked behaviour with new many-in-many-out scheme */
152  for (uint j = 0; j < lengthof(suffixes); j++) {
153  if (cargoes[j] != CT_INVALID) {
154  byte local_id = indspec->grf_prop.grffile->cargo_map[cargoes[j]]; // should we check the value for valid?
155  uint cargotype = local_id << 16 | use_input;
156  GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
157  } else {
158  suffixes[j].text[0] = '\0';
159  suffixes[j].display = CSD_CARGO;
160  }
161  }
162  } else {
163  /* Compatible behaviour with old 3-in-2-out scheme */
164  for (uint j = 0; j < lengthof(suffixes); j++) {
165  suffixes[j].text[0] = '\0';
166  suffixes[j].display = CSD_CARGO;
167  }
168  switch (use_input) {
169  case CARGOSUFFIX_OUT:
170  if (cargoes[0] != CT_INVALID) GetCargoSuffix(3, cst, ind, ind_type, indspec, suffixes[0]);
171  if (cargoes[1] != CT_INVALID) GetCargoSuffix(4, cst, ind, ind_type, indspec, suffixes[1]);
172  break;
173  case CARGOSUFFIX_IN:
174  if (cargoes[0] != CT_INVALID) GetCargoSuffix(0, cst, ind, ind_type, indspec, suffixes[0]);
175  if (cargoes[1] != CT_INVALID) GetCargoSuffix(1, cst, ind, ind_type, indspec, suffixes[1]);
176  if (cargoes[2] != CT_INVALID) GetCargoSuffix(2, cst, ind, ind_type, indspec, suffixes[2]);
177  break;
178  default:
179  NOT_REACHED();
180  }
181  }
182 }
183 
184 std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
185 
187 static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
188 {
189  static char industry_name[2][64];
190 
191  const IndustrySpec *indsp1 = GetIndustrySpec(a);
192  GetString(industry_name[0], indsp1->name, lastof(industry_name[0]));
193 
194  const IndustrySpec *indsp2 = GetIndustrySpec(b);
195  GetString(industry_name[1], indsp2->name, lastof(industry_name[1]));
196 
197  int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
198 
199  /* If the names are equal, sort by industry type. */
200  return (r != 0) ? r < 0 : (a < b);
201 }
202 
207 {
208  /* Add each industry type to the list. */
209  for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
210  _sorted_industry_types[i] = i;
211  }
212 
213  /* Sort industry types by name. */
215 }
216 
225 void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
226 {
227  if (result.Succeeded()) return;
228 
229  uint8 indtype = GB(p1, 0, 8);
230  if (indtype < NUM_INDUSTRYTYPES) {
231  const IndustrySpec *indsp = GetIndustrySpec(indtype);
232  if (indsp->enabled) {
233  SetDParam(0, indsp->name);
234  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, result.GetErrorMessage(), WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE);
235  }
236  }
237 }
238 
239 static const NWidgetPart _nested_build_industry_widgets[] = {
241  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
242  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FUND_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
243  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
244  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
245  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
246  EndContainer(),
248  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),
249  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_DPI_SCROLLBAR),
250  EndContainer(),
251  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_DPI_INFOPANEL), SetResize(1, 0),
252  EndContainer(),
254  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_DISPLAY_WIDGET), SetFill(1, 0), SetResize(1, 0),
255  SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
256  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_FUND_WIDGET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
257  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
258  EndContainer(),
259 };
260 
263  WDP_AUTO, "build_industry", 170, 212,
266  _nested_build_industry_widgets, lengthof(_nested_build_industry_widgets)
267 );
268 
270 class BuildIndustryWindow : public Window {
272  IndustryType selected_type;
273  uint16 count;
274  IndustryType index[NUM_INDUSTRYTYPES + 1];
276  Scrollbar *vscroll;
277 
279  static const int MATRIX_TEXT_OFFSET = 17;
281  static const int MAX_MINWIDTH_LINEHEIGHTS = 20;
282 
283  void SetupArrays()
284  {
285  this->count = 0;
286 
287  for (uint i = 0; i < lengthof(this->index); i++) {
288  this->index[i] = INVALID_INDUSTRYTYPE;
289  this->enabled[i] = false;
290  }
291 
292  if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
293  this->index[this->count] = INVALID_INDUSTRYTYPE;
294  this->enabled[this->count] = true;
295  this->count++;
296  }
297  /* Fill the arrays with industries.
298  * The tests performed after the enabled allow to load the industries
299  * In the same way they are inserted by grf (if any)
300  */
301  for (IndustryType ind : _sorted_industry_types) {
302  const IndustrySpec *indsp = GetIndustrySpec(ind);
303  if (indsp->enabled) {
304  /* Rule is that editor mode loads all industries.
305  * In game mode, all non raw industries are loaded too
306  * and raw ones are loaded only when setting allows it */
307  if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
308  /* Unselect if the industry is no longer in the list */
309  if (this->selected_type == ind) this->selected_index = -1;
310  continue;
311  }
312  this->index[this->count] = ind;
313  this->enabled[this->count] = (_game_mode == GM_EDITOR) || GetIndustryProbabilityCallback(ind, IACT_USERCREATION, 1) > 0;
314  /* Keep the selection to the correct line */
315  if (this->selected_type == ind) this->selected_index = this->count;
316  this->count++;
317  }
318  }
319 
320  /* first industry type is selected if the current selection is invalid.
321  * I'll be damned if there are none available ;) */
322  if (this->selected_index == -1) {
323  this->selected_index = 0;
324  this->selected_type = this->index[0];
325  }
326 
327  this->vscroll->SetCount(this->count);
328  }
329 
331  void SetButtons()
332  {
333  this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled[this->selected_index]);
334  this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled[this->selected_index]);
335  }
336 
349  std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
350  {
351  std::string cargostring;
352  char buf[1024];
353  int numcargo = 0;
354  int firstcargo = -1;
355 
356  for (byte j = 0; j < cargolistlen; j++) {
357  if (cargolist[j] == CT_INVALID) continue;
358  numcargo++;
359  if (firstcargo < 0) {
360  firstcargo = j;
361  continue;
362  }
363  SetDParam(0, CargoSpec::Get(cargolist[j])->name);
364  SetDParamStr(1, cargo_suffix[j].text);
365  GetString(buf, STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION, lastof(buf));
366  cargostring += buf;
367  }
368 
369  if (numcargo > 0) {
370  SetDParam(0, CargoSpec::Get(cargolist[firstcargo])->name);
371  SetDParamStr(1, cargo_suffix[firstcargo].text);
372  GetString(buf, prefixstr, lastof(buf));
373  cargostring = std::string(buf) + cargostring;
374  } else {
375  SetDParam(0, STR_JUST_NOTHING);
376  SetDParamStr(1, "");
377  GetString(buf, prefixstr, lastof(buf));
378  cargostring = std::string(buf);
379  }
380 
381  return cargostring;
382  }
383 
384 public:
386  {
387  this->selected_index = -1;
388  this->selected_type = INVALID_INDUSTRYTYPE;
389 
390  this->CreateNestedTree();
391  this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
392  this->FinishInitNested(0);
393 
394  this->SetButtons();
395  }
396 
397  void OnInit() override
398  {
399  this->SetupArrays();
400  }
401 
402  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
403  {
404  switch (widget) {
405  case WID_DPI_MATRIX_WIDGET: {
406  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
407  for (byte i = 0; i < this->count; i++) {
408  if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
409  d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
410  }
412  d.width += MATRIX_TEXT_OFFSET + padding.width;
413  d.height = 5 * resize->height;
414  *size = maxdim(*size, d);
415  break;
416  }
417 
418  case WID_DPI_INFOPANEL: {
419  /* Extra line for cost outside of editor. */
420  int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
421  uint extra_lines_req = 0;
422  uint extra_lines_prd = 0;
423  uint extra_lines_newgrf = 0;
424  uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
425  Dimension d = {0, 0};
426  for (byte i = 0; i < this->count; i++) {
427  if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
428 
429  const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
430  CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
431 
432  /* Measure the accepted cargoes, if any. */
433  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->index[i], indsp, indsp->accepts_cargo, cargo_suffix);
434  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
435  Dimension strdim = GetStringBoundingBox(cargostring.c_str());
436  if (strdim.width > max_minwidth) {
437  extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
438  strdim.width = max_minwidth;
439  }
440  d = maxdim(d, strdim);
441 
442  /* Measure the produced cargoes, if any. */
443  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->index[i], indsp, indsp->produced_cargo, cargo_suffix);
444  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
445  strdim = GetStringBoundingBox(cargostring.c_str());
446  if (strdim.width > max_minwidth) {
447  extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
448  strdim.width = max_minwidth;
449  }
450  d = maxdim(d, strdim);
451 
452  if (indsp->grf_prop.grffile != nullptr) {
453  /* Reserve a few extra lines for text from an industry NewGRF. */
454  extra_lines_newgrf = 4;
455  }
456  }
457 
458  /* Set it to something more sane :) */
459  height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
461  size->width = d.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
462  break;
463  }
464 
465  case WID_DPI_FUND_WIDGET: {
466  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
467  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY));
468  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY));
469  d.width += padding.width;
470  d.height += padding.height;
471  *size = maxdim(*size, d);
472  break;
473  }
474  }
475  }
476 
477  void SetStringParameters(int widget) const override
478  {
479  switch (widget) {
480  case WID_DPI_FUND_WIDGET:
481  /* Raw industries might be prospected. Show this fact by changing the string
482  * In Editor, you just build, while ingame, or you fund or you prospect */
483  if (_game_mode == GM_EDITOR) {
484  /* We've chosen many random industries but no industries have been specified */
485  SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
486  } else {
487  const IndustrySpec *indsp = GetIndustrySpec(this->index[this->selected_index]);
488  SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
489  }
490  break;
491  }
492  }
493 
494  void DrawWidget(const Rect &r, int widget) const override
495  {
496  switch (widget) {
497  case WID_DPI_MATRIX_WIDGET: {
498  uint text_left, text_right, icon_left, icon_right;
499  if (_current_text_dir == TD_RTL) {
500  icon_right = r.right - WD_MATRIX_RIGHT;
501  icon_left = icon_right - 10;
502  text_right = icon_right - BuildIndustryWindow::MATRIX_TEXT_OFFSET;
503  text_left = r.left + WD_MATRIX_LEFT;
504  } else {
505  icon_left = r.left + WD_MATRIX_LEFT;
506  icon_right = icon_left + 10;
507  text_left = icon_left + BuildIndustryWindow::MATRIX_TEXT_OFFSET;
508  text_right = r.right - WD_MATRIX_RIGHT;
509  }
510 
511  for (byte i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
512  int y = r.top + WD_MATRIX_TOP + i * this->resize.step_height;
513  bool selected = this->selected_index == i + this->vscroll->GetPosition();
514 
515  if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
516  DrawString(text_left, text_right, y, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
517  continue;
518  }
519  const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]);
520 
521  /* Draw the name of the industry in white is selected, otherwise, in orange */
522  DrawString(text_left, text_right, y, indsp->name, selected ? TC_WHITE : TC_ORANGE);
523  GfxFillRect(icon_left, y + 1, icon_right, y + 7, selected ? PC_WHITE : PC_BLACK);
524  GfxFillRect(icon_left + 1, y + 2, icon_right - 1, y + 6, indsp->map_colour);
525  }
526  break;
527  }
528 
529  case WID_DPI_INFOPANEL: {
530  int y = r.top + WD_FRAMERECT_TOP;
531  int bottom = r.bottom - WD_FRAMERECT_BOTTOM;
532  int left = r.left + WD_FRAMERECT_LEFT;
533  int right = r.right - WD_FRAMERECT_RIGHT;
534 
535  if (this->selected_type == INVALID_INDUSTRYTYPE) {
536  DrawStringMultiLine(left, right, y, bottom, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
537  break;
538  }
539 
540  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
541 
542  if (_game_mode != GM_EDITOR) {
543  SetDParam(0, indsp->GetConstructionCost());
544  DrawString(left, right, y, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
545  y += FONT_HEIGHT_NORMAL;
546  }
547 
548  CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
549 
550  /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
551  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
552  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
553  y = DrawStringMultiLine(left, right, y, bottom, cargostring.c_str());
554 
555  /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
556  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
557  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
558  y = DrawStringMultiLine(left, right, y, bottom, cargostring.c_str());
559 
560  /* Get the additional purchase info text, if it has not already been queried. */
562  uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, nullptr, this->selected_type, INVALID_TILE);
563  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
564  if (callback_res > 0x400) {
566  } else {
567  StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
568  if (str != STR_UNDEFINED) {
570  DrawStringMultiLine(left, right, y, bottom, str, TC_YELLOW);
572  }
573  }
574  }
575  }
576  break;
577  }
578  }
579  }
580 
581  void OnClick(Point pt, int widget, int click_count) override
582  {
583  switch (widget) {
584  case WID_DPI_MATRIX_WIDGET: {
585  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_DPI_MATRIX_WIDGET);
586  if (y < this->count) { // Is it within the boundaries of available data?
587  this->selected_index = y;
588  this->selected_type = this->index[y];
589  const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type);
590 
591  this->SetDirty();
592 
593  if (_thd.GetCallbackWnd() == this &&
594  ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) ||
595  this->selected_type == INVALID_INDUSTRYTYPE ||
596  !this->enabled[this->selected_index])) {
597  /* Reset the button state if going to prospecting or "build many industries" */
598  this->RaiseButtons();
600  }
601 
602  this->SetButtons();
603  if (this->enabled[this->selected_index] && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
604  }
605  break;
606  }
607 
609  if (this->selected_type != INVALID_INDUSTRYTYPE) ShowIndustryCargoesWindow(this->selected_type);
610  break;
611 
612  case WID_DPI_FUND_WIDGET: {
613  if (this->selected_type == INVALID_INDUSTRYTYPE) {
615 
616  if (Town::GetNumItems() == 0) {
617  ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO);
618  } else {
619  extern void GenerateIndustries();
620  _generating_world = true;
622  _generating_world = false;
623  }
624  } else if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
625  DoCommandP(0, this->selected_type, InteractiveRandom(), CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
627  } else {
628  HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);
629  }
630  break;
631  }
632  }
633  }
634 
635  void OnResize() override
636  {
637  /* Adjust the number of items in the matrix depending of the resize */
638  this->vscroll->SetCapacityFromWidget(this, WID_DPI_MATRIX_WIDGET);
639  }
640 
641  void OnPlaceObject(Point pt, TileIndex tile) override
642  {
643  bool success = true;
644  /* We do not need to protect ourselves against "Random Many Industries" in this mode */
645  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
646  uint32 seed = InteractiveRandom();
647  uint32 layout_index = InteractiveRandomRange((uint32)indsp->layouts.size());
648 
649  if (_game_mode == GM_EDITOR) {
650  /* Show error if no town exists at all */
651  if (Town::GetNumItems() == 0) {
652  SetDParam(0, indsp->name);
653  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO, pt.x, pt.y);
654  return;
655  }
656 
657  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
658  _generating_world = true;
659  _ignore_restrictions = true;
660 
661  DoCommandP(tile, (layout_index << 8) | this->selected_type, seed,
662  CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY), &CcBuildIndustry);
663 
664  cur_company.Restore();
665  _ignore_restrictions = false;
666  _generating_world = false;
667  } else {
668  success = DoCommandP(tile, (layout_index << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
669  }
670 
671  /* If an industry has been built, just reset the cursor and the system */
673  }
674 
675  void OnHundredthTick() override
676  {
677  if (_game_mode == GM_EDITOR) return;
678  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
679 
680  if (indsp->enabled) {
681  bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
682 
683  /* Only if result does match the previous state would it require a redraw. */
684  if (call_back_result != this->enabled[this->selected_index]) {
685  this->enabled[this->selected_index] = call_back_result;
686  this->SetButtons();
687  this->SetDirty();
688  }
689  }
690  }
691 
692  void OnTimeout() override
693  {
694  this->RaiseButtons();
695  }
696 
697  void OnPlaceObjectAbort() override
698  {
699  this->RaiseButtons();
700  }
701 
707  void OnInvalidateData(int data = 0, bool gui_scope = true) override
708  {
709  if (!gui_scope) return;
710  this->SetupArrays();
711 
712  const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type);
713  if (indsp == nullptr) this->enabled[this->selected_index] = _settings_game.difficulty.industry_density != ID_FUND_ONLY;
714  this->SetButtons();
715  }
716 };
717 
718 void ShowBuildIndustryWindow()
719 {
720  if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
722  new BuildIndustryWindow();
723 }
724 
725 static void UpdateIndustryProduction(Industry *i);
726 
727 static inline bool IsProductionAlterable(const Industry *i)
728 {
729  const IndustrySpec *is = GetIndustrySpec(i->type);
730  bool has_prod = false;
731  for (size_t j = 0; j < lengthof(is->production_rate); j++) {
732  if (is->production_rate[j] != 0) {
733  has_prod = true;
734  break;
735  }
736  }
737  return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
738  (has_prod || is->IsRawIndustry()) &&
739  !_networking);
740 }
741 
743 {
745  enum Editability {
749  };
750 
752  enum InfoLine {
757  };
758 
765 
766 public:
768  {
769  this->flags |= WF_DISABLE_VP_SCROLL;
770  this->editbox_line = IL_NONE;
771  this->clicked_line = IL_NONE;
772  this->clicked_button = 0;
773  this->info_height = WD_FRAMERECT_TOP + 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + 1; // Info panel has at least two lines text.
774 
775  this->InitNested(window_number);
776  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
777  nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ZOOM_LVL_INDUSTRY);
778 
779  this->InvalidateData();
780  }
781 
782  void OnPaint() override
783  {
784  this->DrawWidgets();
785 
786  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
787 
788  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_IV_INFO);
789  uint expected = this->DrawInfo(nwi->pos_x, nwi->pos_x + nwi->current_x - 1, nwi->pos_y) - nwi->pos_y;
790  if (expected > nwi->current_y - 1) {
791  this->info_height = expected + 1;
792  this->ReInit();
793  return;
794  }
795  }
796 
804  int DrawInfo(uint left, uint right, uint top)
805  {
807  const IndustrySpec *ind = GetIndustrySpec(i->type);
808  int y = top + WD_FRAMERECT_TOP;
809  bool first = true;
810  bool has_accept = false;
811 
812  if (i->prod_level == PRODLEVEL_CLOSURE) {
813  DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
814  y += 2 * FONT_HEIGHT_NORMAL;
815  }
816 
817  CargoSuffix cargo_suffix[lengthof(i->accepts_cargo)];
818  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
820 
821  uint left_side = left + WD_FRAMERECT_LEFT * 4; // Indent accepted cargoes.
822  for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
823  if (i->accepts_cargo[j] == CT_INVALID) continue;
824  has_accept = true;
825  if (first) {
826  DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_REQUIRES);
827  y += FONT_HEIGHT_NORMAL;
828  first = false;
829  }
831  SetDParam(1, i->accepts_cargo[j]);
833  SetDParamStr(3, "");
834  StringID str = STR_NULL;
835  switch (cargo_suffix[j].display) {
837  SetDParamStr(3, cargo_suffix[j].text);
838  FALLTHROUGH;
839  case CSD_CARGO_AMOUNT:
840  str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
841  break;
842 
843  case CSD_CARGO_TEXT:
844  SetDParamStr(3, cargo_suffix[j].text);
845  FALLTHROUGH;
846  case CSD_CARGO:
847  str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
848  break;
849 
850  default:
851  NOT_REACHED();
852  }
853  DrawString(left_side, right - WD_FRAMERECT_RIGHT, y, str);
854  y += FONT_HEIGHT_NORMAL;
855  }
856 
857  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, i->produced_cargo, cargo_suffix);
858  first = true;
859  for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
860  if (i->produced_cargo[j] == CT_INVALID) continue;
861  if (first) {
862  if (has_accept) y += WD_PAR_VSEP_WIDE;
863  DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
864  y += FONT_HEIGHT_NORMAL;
865  if (this->editable == EA_RATE) this->production_offset_y = y;
866  first = false;
867  }
868 
869  SetDParam(0, i->produced_cargo[j]);
871  SetDParamStr(2, cargo_suffix[j].text);
873  uint x = left + WD_FRAMETEXT_LEFT + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + 10 : 0);
874  DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
875  /* Let's put out those buttons.. */
876  if (this->editable == EA_RATE) {
877  DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
878  i->production_rate[j] > 0, i->production_rate[j] < 255);
879  }
880  y += FONT_HEIGHT_NORMAL;
881  }
882 
883  /* Display production multiplier if editable */
884  if (this->editable == EA_MULTIPLIER) {
885  y += WD_PAR_VSEP_WIDE;
886  this->production_offset_y = y;
888  uint x = left + WD_FRAMETEXT_LEFT + SETTING_BUTTON_WIDTH + 10;
889  DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
890  DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
892  y += FONT_HEIGHT_NORMAL;
893  }
894 
895  /* Get the extra message for the GUI */
897  uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
898  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
899  if (callback_res > 0x400) {
901  } else {
902  StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
903  if (message != STR_NULL && message != STR_UNDEFINED) {
904  y += WD_PAR_VSEP_WIDE;
905 
907  /* Use all the available space left from where we stand up to the
908  * end of the window. We ALSO enlarge the window if needed, so we
909  * can 'go' wild with the bottom of the window. */
910  y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, message, TC_BLACK);
912  }
913  }
914  }
915  }
916 
917  if (!i->text.empty()) {
918  SetDParamStr(0, i->text.c_str());
919  y += WD_PAR_VSEP_WIDE;
920  y = DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, y, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
921  }
922 
923  return y + WD_FRAMERECT_BOTTOM;
924  }
925 
926  void SetStringParameters(int widget) const override
927  {
928  if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
929  }
930 
931  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
932  {
933  if (widget == WID_IV_INFO) size->height = this->info_height;
934  }
935 
936  void OnClick(Point pt, int widget, int click_count) override
937  {
938  switch (widget) {
939  case WID_IV_INFO: {
941  InfoLine line = IL_NONE;
942 
943  switch (this->editable) {
944  case EA_NONE: break;
945 
946  case EA_MULTIPLIER:
947  if (IsInsideBS(pt.y, this->production_offset_y, FONT_HEIGHT_NORMAL)) line = IL_MULTIPLIER;
948  break;
949 
950  case EA_RATE:
951  if (pt.y >= this->production_offset_y) {
952  int row = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
953  for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
954  if (i->produced_cargo[j] == CT_INVALID) continue;
955  row--;
956  if (row < 0) {
957  line = (InfoLine)(IL_RATE1 + j);
958  break;
959  }
960  }
961  }
962  break;
963  }
964  if (line == IL_NONE) return;
965 
966  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
967  int left = nwi->pos_x + WD_FRAMETEXT_LEFT;
968  int right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
969  if (IsInsideMM(pt.x, left, left + SETTING_BUTTON_WIDTH)) {
970  /* Clicked buttons, decrease or increase production */
971  byte button = (pt.x < left + SETTING_BUTTON_WIDTH / 2) ? 1 : 2;
972  switch (this->editable) {
973  case EA_MULTIPLIER:
974  if (button == 1) {
975  if (i->prod_level <= PRODLEVEL_MINIMUM) return;
976  i->prod_level = std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
977  } else {
978  if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
979  i->prod_level = std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
980  }
981  break;
982 
983  case EA_RATE:
984  if (button == 1) {
985  if (i->production_rate[line - IL_RATE1] <= 0) return;
986  i->production_rate[line - IL_RATE1] = std::max(i->production_rate[line - IL_RATE1] / 2, 0);
987  } else {
988  if (i->production_rate[line - IL_RATE1] >= 255) return;
989  /* a zero production industry is unlikely to give anything but zero, so push it a little bit */
990  int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
991  i->production_rate[line - IL_RATE1] = std::min<uint>(new_prod, 255);
992  }
993  break;
994 
995  default: NOT_REACHED();
996  }
997 
998  UpdateIndustryProduction(i);
999  this->SetDirty();
1000  this->SetTimeout();
1001  this->clicked_line = line;
1002  this->clicked_button = button;
1003  } else if (IsInsideMM(pt.x, left + SETTING_BUTTON_WIDTH + 10, right)) {
1004  /* clicked the text */
1005  this->editbox_line = line;
1006  switch (this->editable) {
1007  case EA_MULTIPLIER:
1009  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1010  break;
1011 
1012  case EA_RATE:
1013  SetDParam(0, i->production_rate[line - IL_RATE1] * 8);
1014  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1015  break;
1016 
1017  default: NOT_REACHED();
1018  }
1019  }
1020  break;
1021  }
1022 
1023  case WID_IV_GOTO: {
1024  Industry *i = Industry::Get(this->window_number);
1025  if (_ctrl_pressed) {
1027  } else {
1029  }
1030  break;
1031  }
1032 
1033  case WID_IV_DISPLAY: {
1034  Industry *i = Industry::Get(this->window_number);
1036  break;
1037  }
1038  }
1039  }
1040 
1041  void OnTimeout() override
1042  {
1043  this->clicked_line = IL_NONE;
1044  this->clicked_button = 0;
1045  this->SetDirty();
1046  }
1047 
1048  void OnResize() override
1049  {
1050  if (this->viewport != nullptr) {
1051  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
1052  nvp->UpdateViewportCoordinates(this);
1053 
1054  ScrollWindowToTile(Industry::Get(this->window_number)->location.GetCenterTile(), this, true); // Re-center viewport.
1055  }
1056  }
1057 
1058  void OnQueryTextFinished(char *str) override
1059  {
1060  if (StrEmpty(str)) return;
1061 
1062  Industry *i = Industry::Get(this->window_number);
1063  uint value = atoi(str);
1064  switch (this->editbox_line) {
1065  case IL_NONE: NOT_REACHED();
1066 
1067  case IL_MULTIPLIER:
1069  break;
1070 
1071  default:
1072  i->production_rate[this->editbox_line - IL_RATE1] = ClampU(RoundDivSU(value, 8), 0, 255);
1073  break;
1074  }
1075  UpdateIndustryProduction(i);
1076  this->SetDirty();
1077  }
1078 
1084  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1085  {
1086  if (!gui_scope) return;
1087  const Industry *i = Industry::Get(this->window_number);
1088  if (IsProductionAlterable(i)) {
1089  const IndustrySpec *ind = GetIndustrySpec(i->type);
1090  this->editable = ind->UsesOriginalEconomy() ? EA_MULTIPLIER : EA_RATE;
1091  } else {
1092  this->editable = EA_NONE;
1093  }
1094  }
1095 
1096  bool IsNewGRFInspectable() const override
1097  {
1098  return ::IsNewGRFInspectable(GSF_INDUSTRIES, this->window_number);
1099  }
1100 
1101  void ShowNewGRFInspectWindow() const override
1102  {
1103  ::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->window_number);
1104  }
1105 };
1106 
1107 static void UpdateIndustryProduction(Industry *i)
1108 {
1109  const IndustrySpec *indspec = GetIndustrySpec(i->type);
1111 
1112  for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
1113  if (i->produced_cargo[j] != CT_INVALID) {
1114  i->last_month_production[j] = 8 * i->production_rate[j];
1115  }
1116  }
1117 }
1118 
1122  NWidget(WWT_CLOSEBOX, COLOUR_CREAM),
1123  NWidget(WWT_CAPTION, COLOUR_CREAM, WID_IV_CAPTION), SetDataTip(STR_INDUSTRY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1124  NWidget(WWT_PUSHIMGBTN, COLOUR_CREAM, WID_IV_GOTO), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
1125  NWidget(WWT_DEBUGBOX, COLOUR_CREAM),
1126  NWidget(WWT_SHADEBOX, COLOUR_CREAM),
1127  NWidget(WWT_DEFSIZEBOX, COLOUR_CREAM),
1128  NWidget(WWT_STICKYBOX, COLOUR_CREAM),
1129  EndContainer(),
1130  NWidget(WWT_PANEL, COLOUR_CREAM),
1131  NWidget(WWT_INSET, COLOUR_CREAM), SetPadding(2, 2, 2, 2),
1132  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_IV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetPadding(1, 1, 1, 1), SetResize(1, 1),
1133  EndContainer(),
1134  EndContainer(),
1135  NWidget(WWT_PANEL, COLOUR_CREAM, WID_IV_INFO), SetMinimalSize(260, 2), SetResize(1, 0),
1136  EndContainer(),
1138  NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
1139  NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
1140  EndContainer(),
1141 };
1142 
1145  WDP_AUTO, "view_industry", 260, 120,
1147  0,
1149 );
1150 
1151 void ShowIndustryViewWindow(int industry)
1152 {
1153  AllocateWindowDescFront<IndustryViewWindow>(&_industry_view_desc, industry);
1154 }
1155 
1159  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1160  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_INDUSTRY_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1161  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1162  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1163  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1164  EndContainer(),
1168  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
1169  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
1170  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),
1171  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),
1172  NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(),
1173  EndContainer(),
1174  NWidget(WWT_PANEL, COLOUR_BROWN, WID_ID_INDUSTRY_LIST), SetDataTip(0x0, STR_INDUSTRY_DIRECTORY_LIST_CAPTION), SetResize(1, 1), SetScrollbar(WID_ID_SCROLLBAR), EndContainer(),
1175  EndContainer(),
1177  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_ID_SCROLLBAR),
1178  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1179  EndContainer(),
1180  EndContainer(),
1181 };
1182 
1184 
1189 };
1190 
1198 static bool CDECL CargoFilter(const Industry * const *industry, const std::pair<CargoID, CargoID> &cargoes)
1199 {
1200  auto accepted_cargo = cargoes.first;
1201  auto produced_cargo = cargoes.second;
1202 
1203  bool accepted_cargo_matches;
1204 
1205  switch (accepted_cargo) {
1206  case CF_ANY:
1207  accepted_cargo_matches = true;
1208  break;
1209 
1210  case CF_NONE:
1211  accepted_cargo_matches = std::all_of(std::begin((*industry)->accepts_cargo), std::end((*industry)->accepts_cargo), [](CargoID cargo) {
1212  return cargo == CT_INVALID;
1213  });
1214  break;
1215 
1216  default:
1217  const auto &ac = (*industry)->accepts_cargo;
1218  accepted_cargo_matches = std::find(std::begin(ac), std::end(ac), accepted_cargo) != std::end(ac);
1219  break;
1220  }
1221 
1222  bool produced_cargo_matches;
1223 
1224  switch (produced_cargo) {
1225  case CF_ANY:
1226  produced_cargo_matches = true;
1227  break;
1228 
1229  case CF_NONE:
1230  produced_cargo_matches = std::all_of(std::begin((*industry)->produced_cargo), std::end((*industry)->produced_cargo), [](CargoID cargo) {
1231  return cargo == CT_INVALID;
1232  });
1233  break;
1234 
1235  default:
1236  const auto &pc = (*industry)->produced_cargo;
1237  produced_cargo_matches = std::find(std::begin(pc), std::end(pc), produced_cargo) != std::end(pc);
1238  break;
1239  }
1240 
1241  return accepted_cargo_matches && produced_cargo_matches;
1242 }
1243 
1244 static GUIIndustryList::FilterFunction * const _filter_funcs[] = { &CargoFilter };
1245 
1246 
1251 protected:
1252  /* Runtime saved values */
1253  static Listing last_sorting;
1254 
1255  /* Constants for sorting stations */
1256  static const StringID sorter_names[];
1257  static GUIIndustryList::SortFunction * const sorter_funcs[];
1258 
1259  GUIIndustryList industries;
1260  Scrollbar *vscroll;
1261 
1266 
1272  {
1273  if (this->produced_cargo_filter_criteria != index) {
1274  this->produced_cargo_filter_criteria = index;
1275  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1276  bool is_filtering_necessary = this->cargo_filter[this->produced_cargo_filter_criteria] != CF_ANY || this->cargo_filter[this->accepted_cargo_filter_criteria] != CF_ANY;
1277 
1278  this->industries.SetFilterState(is_filtering_necessary);
1279  this->industries.SetFilterType(0);
1280  this->industries.ForceRebuild();
1281  }
1282  }
1283 
1289  {
1290  if (this->accepted_cargo_filter_criteria != index) {
1291  this->accepted_cargo_filter_criteria = index;
1292  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1293  bool is_filtering_necessary = this->cargo_filter[this->produced_cargo_filter_criteria] != CF_ANY || this->cargo_filter[this->accepted_cargo_filter_criteria] != CF_ANY;
1294 
1295  this->industries.SetFilterState(is_filtering_necessary);
1296  this->industries.SetFilterType(0);
1297  this->industries.ForceRebuild();
1298  }
1299  }
1300 
1305  {
1306  byte filter_items = 0;
1307 
1308  /* Add item for disabling filtering. */
1309  this->cargo_filter[filter_items] = CF_ANY;
1310  this->cargo_filter_texts[filter_items] = STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
1311  this->produced_cargo_filter_criteria = filter_items;
1312  this->accepted_cargo_filter_criteria = filter_items;
1313  filter_items++;
1314 
1315  /* Add item for industries not producing anything, e.g. power plants */
1316  this->cargo_filter[filter_items] = CF_NONE;
1317  this->cargo_filter_texts[filter_items] = STR_INDUSTRY_DIRECTORY_FILTER_NONE;
1318  filter_items++;
1319 
1320  /* Collect available cargo types for filtering. */
1321  const CargoSpec *cs;
1323  this->cargo_filter[filter_items] = cs->Index();
1324  this->cargo_filter_texts[filter_items] = cs->name;
1325  filter_items++;
1326  }
1327 
1328  /* Terminate the filter list. */
1329  this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
1330 
1331  this->industries.SetFilterFuncs(_filter_funcs);
1332 
1333  bool is_filtering_necessary = this->cargo_filter[this->produced_cargo_filter_criteria] != CF_ANY || this->cargo_filter[this->accepted_cargo_filter_criteria] != CF_ANY;
1334 
1335  this->industries.SetFilterState(is_filtering_necessary);
1336  }
1337 
1340  {
1341  if (this->industries.NeedRebuild()) {
1342  this->industries.clear();
1343 
1344  for (const Industry *i : Industry::Iterate()) {
1345  this->industries.push_back(i);
1346  }
1347 
1348  this->industries.shrink_to_fit();
1349  this->industries.RebuildDone();
1350  }
1351 
1352  auto filter = std::make_pair(this->cargo_filter[this->accepted_cargo_filter_criteria],
1353  this->cargo_filter[this->produced_cargo_filter_criteria]);
1354 
1355  this->industries.Filter(filter);
1356  this->industries.Sort();
1357 
1358  this->vscroll->SetCount((uint)this->industries.size()); // Update scrollbar as well.
1359 
1360  this->SetDirty();
1361  }
1362 
1370  static inline int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
1371  {
1372  assert(id < lengthof(i->produced_cargo));
1373 
1374  if (i->produced_cargo[id] == CT_INVALID) return 101;
1375  return ToPercent8(i->last_month_pct_transported[id]);
1376  }
1377 
1386  {
1387  int p1 = GetCargoTransportedPercentsIfValid(i, 0);
1388  int p2 = GetCargoTransportedPercentsIfValid(i, 1);
1389 
1390  if (p1 > p2) Swap(p1, p2); // lower value has higher priority
1391 
1392  return (p1 << 8) + p2;
1393  }
1394 
1396  static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b)
1397  {
1398  int r = strnatcmp(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
1399  if (r == 0) return a->index < b->index;
1400  return r < 0;
1401  }
1402 
1404  static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b)
1405  {
1406  int it_a = 0;
1407  while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
1408  int it_b = 0;
1409  while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
1410  int r = it_a - it_b;
1411  return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
1412  }
1413 
1415  static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b)
1416  {
1417  uint prod_a = 0, prod_b = 0;
1418  for (uint i = 0; i < lengthof(a->produced_cargo); i++) {
1419  if (a->produced_cargo[i] != CT_INVALID) prod_a += a->last_month_production[i];
1420  if (b->produced_cargo[i] != CT_INVALID) prod_b += b->last_month_production[i];
1421  }
1422  int r = prod_a - prod_b;
1423 
1424  return (r == 0) ? IndustryTypeSorter(a, b) : r < 0;
1425  }
1426 
1428  static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b)
1429  {
1431  return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
1432  }
1433 
1440  {
1441  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1442  byte p = 0;
1443 
1444  /* Industry name */
1445  SetDParam(p++, i->index);
1446 
1447  static CargoSuffix cargo_suffix[lengthof(i->produced_cargo)];
1448  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_DIR, i, i->type, indsp, i->produced_cargo, cargo_suffix);
1449 
1450  /* Get industry productions (CargoID, production, suffix, transported) */
1451  typedef std::tuple<CargoID, uint16, const char*, uint> CargoInfo;
1452  std::vector<CargoInfo> cargos;
1453 
1454  for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
1455  if (i->produced_cargo[j] == CT_INVALID) continue;
1456  cargos.emplace_back(i->produced_cargo[j], i->last_month_production[j], cargo_suffix[j].text, ToPercent8(i->last_month_pct_transported[j]));
1457  }
1458 
1459  /* Sort by descending production, then descending transported */
1460  std::sort(cargos.begin(), cargos.end(), [](const CargoInfo a, const CargoInfo b) {
1461  if (std::get<1>(a) != std::get<1>(b)) return std::get<1>(a) > std::get<1>(b);
1462  return std::get<3>(a) > std::get<3>(b);
1463  });
1464 
1465  /* If the produced cargo filter is active then move the filtered cargo to the beginning of the list,
1466  * because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */
1467  const CargoID cid = this->cargo_filter[this->produced_cargo_filter_criteria];
1468  if (cid != CF_ANY && cid != CF_NONE) {
1469  auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo& ci) -> bool {
1470  return std::get<0>(ci) == cid;
1471  });
1472  if (filtered_ci != cargos.end()) {
1473  std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1474  }
1475  }
1476 
1477  /* Display first 3 cargos */
1478  for (size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1479  CargoInfo ci = cargos[j];
1480  SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1481  SetDParam(p++, std::get<0>(ci));
1482  SetDParam(p++, std::get<1>(ci));
1483  SetDParamStr(p++, std::get<2>(ci));
1484  SetDParam(p++, std::get<3>(ci));
1485  }
1486 
1487  /* Undisplayed cargos if any */
1488  SetDParam(p++, cargos.size() - 3);
1489 
1490  /* Drawing the right string */
1491  switch (cargos.size()) {
1492  case 0: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1493  case 1: return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1494  case 2: return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1495  case 3: return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1496  default: return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1497  }
1498  }
1499 
1500 public:
1501  IndustryDirectoryWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
1502  {
1503  this->CreateNestedTree();
1504  this->vscroll = this->GetScrollbar(WID_ID_SCROLLBAR);
1505 
1506  this->industries.SetListing(this->last_sorting);
1507  this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1508  this->industries.ForceRebuild();
1509  this->BuildSortIndustriesList();
1510 
1511  this->FinishInitNested(0);
1512  }
1513 
1515  {
1516  this->last_sorting = this->industries.GetListing();
1517  }
1518 
1519  void OnInit() override
1520  {
1521  this->SetCargoFilterArray();
1522  }
1523 
1524  void SetStringParameters(int widget) const override
1525  {
1526  switch (widget) {
1528  SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]);
1529  break;
1530 
1532  SetDParam(0, this->cargo_filter_texts[this->accepted_cargo_filter_criteria]);
1533  break;
1534 
1536  SetDParam(0, this->cargo_filter_texts[this->produced_cargo_filter_criteria]);
1537  break;
1538  }
1539  }
1540 
1541  void DrawWidget(const Rect &r, int widget) const override
1542  {
1543  switch (widget) {
1544  case WID_ID_DROPDOWN_ORDER:
1545  this->DrawSortButtonState(widget, this->industries.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
1546  break;
1547 
1548  case WID_ID_INDUSTRY_LIST: {
1549  int n = 0;
1550  int y = r.top + WD_FRAMERECT_TOP;
1551  if (this->industries.size() == 0) {
1552  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_DIRECTORY_NONE);
1553  break;
1554  }
1555  TextColour tc;
1556  const CargoID acf_cid = this->cargo_filter[this->accepted_cargo_filter_criteria];
1557  for (uint i = this->vscroll->GetPosition(); i < this->industries.size(); i++) {
1558  tc = TC_FROMSTRING;
1559  if (acf_cid != CF_ANY && acf_cid != CF_NONE) {
1560  Industry *ind = const_cast<Industry *>(this->industries[i]);
1561  if (IndustryTemporarilyRefusesCargo(ind, acf_cid)) {
1562  tc = TC_GREY | TC_FORCED;
1563  }
1564  }
1565  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, this->GetIndustryString(this->industries[i]), tc);
1566 
1567  y += this->resize.step_height;
1568  if (++n == this->vscroll->GetCapacity()) break; // max number of industries in 1 window
1569  }
1570  break;
1571  }
1572  }
1573  }
1574 
1575  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1576  {
1577  switch (widget) {
1578  case WID_ID_DROPDOWN_ORDER: {
1579  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1580  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1581  d.height += padding.height;
1582  *size = maxdim(*size, d);
1583  break;
1584  }
1585 
1586  case WID_ID_DROPDOWN_CRITERIA: {
1587  Dimension d = {0, 0};
1588  for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
1589  d = maxdim(d, GetStringBoundingBox(IndustryDirectoryWindow::sorter_names[i]));
1590  }
1591  d.width += padding.width;
1592  d.height += padding.height;
1593  *size = maxdim(*size, d);
1594  break;
1595  }
1596 
1597  case WID_ID_INDUSTRY_LIST: {
1598  Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
1599  for (uint i = 0; i < this->industries.size(); i++) {
1600  d = maxdim(d, GetStringBoundingBox(this->GetIndustryString(this->industries[i])));
1601  }
1602  resize->height = d.height;
1603  d.height *= 5;
1604  d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
1605  d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
1606  *size = maxdim(*size, d);
1607  break;
1608  }
1609  }
1610  }
1611 
1612 
1613  void OnClick(Point pt, int widget, int click_count) override
1614  {
1615  switch (widget) {
1616  case WID_ID_DROPDOWN_ORDER:
1617  this->industries.ToggleSortOrder();
1618  this->SetDirty();
1619  break;
1620 
1622  ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0);
1623  break;
1624 
1625  case WID_ID_FILTER_BY_ACC_CARGO: // Cargo filter dropdown
1626  ShowDropDownMenu(this, this->cargo_filter_texts, this->accepted_cargo_filter_criteria, WID_ID_FILTER_BY_ACC_CARGO, 0, 0);
1627  break;
1628 
1629  case WID_ID_FILTER_BY_PROD_CARGO: // Cargo filter dropdown
1630  ShowDropDownMenu(this, this->cargo_filter_texts, this->produced_cargo_filter_criteria, WID_ID_FILTER_BY_PROD_CARGO, 0, 0);
1631  break;
1632 
1633  case WID_ID_INDUSTRY_LIST: {
1634  uint p = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ID_INDUSTRY_LIST, WD_FRAMERECT_TOP);
1635  if (p < this->industries.size()) {
1636  if (_ctrl_pressed) {
1637  ShowExtraViewportWindow(this->industries[p]->location.tile);
1638  } else {
1639  ScrollMainWindowToTile(this->industries[p]->location.tile);
1640  }
1641  }
1642  break;
1643  }
1644  }
1645  }
1646 
1647  void OnDropdownSelect(int widget, int index) override
1648  {
1649  switch (widget) {
1650  case WID_ID_DROPDOWN_CRITERIA: {
1651  if (this->industries.SortType() != index) {
1652  this->industries.SetSortType(index);
1653  this->BuildSortIndustriesList();
1654  }
1655  break;
1656  }
1657 
1659  this->SetAcceptedCargoFilterIndex(index);
1660  this->BuildSortIndustriesList();
1661  break;
1662  }
1663 
1665  this->SetProducedCargoFilterIndex(index);
1666  this->BuildSortIndustriesList();
1667  break;
1668  }
1669  }
1670  }
1671 
1672  void OnResize() override
1673  {
1674  this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
1675  }
1676 
1677  void OnPaint() override
1678  {
1679  if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
1680  this->DrawWidgets();
1681  }
1682 
1683  void OnHundredthTick() override
1684  {
1685  this->industries.ForceResort();
1686  this->BuildSortIndustriesList();
1687  }
1688 
1694  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1695  {
1696  switch (data) {
1697  case IDIWD_FORCE_REBUILD:
1698  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1699  this->industries.ForceRebuild();
1700  break;
1701 
1702  case IDIWD_PRODUCTION_CHANGE:
1703  if (this->industries.SortType() == 2) this->industries.ForceResort();
1704  break;
1705 
1706  default:
1707  this->industries.ForceResort();
1708  break;
1709  }
1710  }
1711 };
1712 
1713 Listing IndustryDirectoryWindow::last_sorting = {false, 0};
1714 
1715 /* Available station sorting functions. */
1716 GUIIndustryList::SortFunction * const IndustryDirectoryWindow::sorter_funcs[] = {
1717  &IndustryNameSorter,
1718  &IndustryTypeSorter,
1719  &IndustryProductionSorter,
1720  &IndustryTransportedCargoSorter
1721 };
1722 
1723 /* Names of the sorting functions */
1724 const StringID IndustryDirectoryWindow::sorter_names[] = {
1725  STR_SORT_BY_NAME,
1726  STR_SORT_BY_TYPE,
1727  STR_SORT_BY_PRODUCTION,
1728  STR_SORT_BY_TRANSPORTED,
1730 };
1731 
1732 
1735  WDP_AUTO, "list_industries", 428, 190,
1737  0,
1739 );
1740 
1741 void ShowIndustryDirectory()
1742 {
1743  AllocateWindowDescFront<IndustryDirectoryWindow>(&_industry_directory_desc, 0);
1744 }
1745 
1749  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1750  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_IC_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1751  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1752  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1753  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1754  EndContainer(),
1759  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_NOTIFY),
1760  SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1761  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(0, 0), EndContainer(),
1762  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_IND_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1763  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1764  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_CARGO_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1765  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1766  EndContainer(),
1767  EndContainer(),
1769  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_IC_SCROLLBAR),
1770  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1771  EndContainer(),
1772  EndContainer(),
1773 };
1774 
1777  WDP_AUTO, "industry_cargoes", 300, 210,
1779  0,
1781 );
1782 
1791 };
1792 
1793 static const uint MAX_CARGOES = 16;
1794 
1797  static const int VERT_INTER_INDUSTRY_SPACE;
1798  static const int HOR_CARGO_BORDER_SPACE;
1799  static const int CARGO_STUB_WIDTH;
1803 
1804  static const int INDUSTRY_LINE_COLOUR;
1805  static const int CARGO_LINE_COLOUR;
1806 
1808  static int cargo_field_width;
1809  static int industry_width;
1810  static uint max_cargoes;
1811 
1813  union {
1814  struct {
1815  IndustryType ind_type;
1818  } industry;
1819  struct {
1823  byte top_end;
1825  byte bottom_end;
1826  } cargo;
1827  struct {
1829  bool left_align;
1830  } cargo_label;
1832  } u; // Data for each type.
1833 
1839  {
1840  this->type = type;
1841  }
1842 
1848  void MakeIndustry(IndustryType ind_type)
1849  {
1850  this->type = CFT_INDUSTRY;
1851  this->u.industry.ind_type = ind_type;
1852  MemSetT(this->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
1853  MemSetT(this->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
1854  }
1855 
1862  int ConnectCargo(CargoID cargo, bool producer)
1863  {
1864  assert(this->type == CFT_CARGO);
1865  if (cargo == INVALID_CARGO) return -1;
1866 
1867  /* Find the vertical cargo column carrying the cargo. */
1868  int column = -1;
1869  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
1870  if (cargo == this->u.cargo.vertical_cargoes[i]) {
1871  column = i;
1872  break;
1873  }
1874  }
1875  if (column < 0) return -1;
1876 
1877  if (producer) {
1878  assert(this->u.cargo.supp_cargoes[column] == INVALID_CARGO);
1879  this->u.cargo.supp_cargoes[column] = column;
1880  } else {
1881  assert(this->u.cargo.cust_cargoes[column] == INVALID_CARGO);
1882  this->u.cargo.cust_cargoes[column] = column;
1883  }
1884  return column;
1885  }
1886 
1892  {
1893  assert(this->type == CFT_CARGO);
1894 
1895  for (uint i = 0; i < MAX_CARGOES; i++) {
1896  if (this->u.cargo.supp_cargoes[i] != INVALID_CARGO) return true;
1897  if (this->u.cargo.cust_cargoes[i] != INVALID_CARGO) return true;
1898  }
1899  return false;
1900  }
1901 
1911  void MakeCargo(const CargoID *cargoes, uint length, int count = -1, bool top_end = false, bool bottom_end = false)
1912  {
1913  this->type = CFT_CARGO;
1914  uint i;
1915  uint num = 0;
1916  for (i = 0; i < MAX_CARGOES && i < length; i++) {
1917  if (cargoes[i] != INVALID_CARGO) {
1918  this->u.cargo.vertical_cargoes[num] = cargoes[i];
1919  num++;
1920  }
1921  }
1922  this->u.cargo.num_cargoes = (count < 0) ? num : count;
1923  for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = INVALID_CARGO;
1924  this->u.cargo.top_end = top_end;
1925  this->u.cargo.bottom_end = bottom_end;
1926  MemSetT(this->u.cargo.supp_cargoes, INVALID_CARGO, MAX_CARGOES);
1927  MemSetT(this->u.cargo.cust_cargoes, INVALID_CARGO, MAX_CARGOES);
1928  }
1929 
1936  void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
1937  {
1938  this->type = CFT_CARGO_LABEL;
1939  uint i;
1940  for (i = 0; i < MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i];
1941  for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
1942  this->u.cargo_label.left_align = left_align;
1943  }
1944 
1949  void MakeHeader(StringID textid)
1950  {
1951  this->type = CFT_HEADER;
1952  this->u.header = textid;
1953  }
1954 
1960  int GetCargoBase(int xpos) const
1961  {
1962  assert(this->type == CFT_CARGO);
1963  int n = this->u.cargo.num_cargoes;
1964 
1965  if (n % 2 == 0) {
1966  return xpos + cargo_field_width / 2 - (HOR_CARGO_WIDTH + HOR_CARGO_SPACE / 2) * (n / 2);
1967  } else {
1968  return xpos + cargo_field_width / 2 - HOR_CARGO_WIDTH / 2 - (HOR_CARGO_WIDTH + HOR_CARGO_SPACE) * (n / 2);
1969  }
1970  }
1971 
1977  void Draw(int xpos, int ypos) const
1978  {
1979  switch (this->type) {
1980  case CFT_EMPTY:
1981  case CFT_SMALL_EMPTY:
1982  break;
1983 
1984  case CFT_HEADER:
1985  ypos += (small_height - FONT_HEIGHT_NORMAL) / 2;
1986  DrawString(xpos, xpos + industry_width, ypos, this->u.header, TC_WHITE, SA_HOR_CENTER);
1987  break;
1988 
1989  case CFT_INDUSTRY: {
1990  int ypos1 = ypos + VERT_INTER_INDUSTRY_SPACE / 2;
1991  int ypos2 = ypos + normal_height - 1 - VERT_INTER_INDUSTRY_SPACE / 2;
1992  int xpos2 = xpos + industry_width - 1;
1993  GfxDrawLine(xpos, ypos1, xpos2, ypos1, INDUSTRY_LINE_COLOUR);
1994  GfxDrawLine(xpos, ypos1, xpos, ypos2, INDUSTRY_LINE_COLOUR);
1995  GfxDrawLine(xpos, ypos2, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
1996  GfxDrawLine(xpos2, ypos1, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
1997  ypos += (normal_height - FONT_HEIGHT_NORMAL) / 2;
1998  if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) {
1999  const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type);
2000  DrawString(xpos, xpos2, ypos, indsp->name, TC_WHITE, SA_HOR_CENTER);
2001 
2002  /* Draw the industry legend. */
2003  int blob_left, blob_right;
2004  if (_current_text_dir == TD_RTL) {
2005  blob_right = xpos2 - BLOB_DISTANCE;
2006  blob_left = blob_right - BLOB_WIDTH;
2007  } else {
2008  blob_left = xpos + BLOB_DISTANCE;
2009  blob_right = blob_left + BLOB_WIDTH;
2010  }
2011  GfxFillRect(blob_left, ypos2 - BLOB_DISTANCE - BLOB_HEIGHT, blob_right, ypos2 - BLOB_DISTANCE, PC_BLACK); // Border
2012  GfxFillRect(blob_left + 1, ypos2 - BLOB_DISTANCE - BLOB_HEIGHT + 1, blob_right - 1, ypos2 - BLOB_DISTANCE - 1, indsp->map_colour);
2013  } else {
2014  DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TC_FROMSTRING, SA_HOR_CENTER);
2015  }
2016 
2017  /* Draw the other_produced/other_accepted cargoes. */
2018  const CargoID *other_right, *other_left;
2019  if (_current_text_dir == TD_RTL) {
2020  other_right = this->u.industry.other_accepted;
2021  other_left = this->u.industry.other_produced;
2022  } else {
2023  other_right = this->u.industry.other_produced;
2024  other_left = this->u.industry.other_accepted;
2025  }
2026  ypos1 += VERT_CARGO_EDGE;
2027  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2028  if (other_right[i] != INVALID_CARGO) {
2029  const CargoSpec *csp = CargoSpec::Get(other_right[i]);
2030  int xp = xpos + industry_width + CARGO_STUB_WIDTH;
2031  DrawHorConnection(xpos + industry_width, xp - 1, ypos1, csp);
2032  GfxDrawLine(xp, ypos1, xp, ypos1 + FONT_HEIGHT_NORMAL - 1, CARGO_LINE_COLOUR);
2033  }
2034  if (other_left[i] != INVALID_CARGO) {
2035  const CargoSpec *csp = CargoSpec::Get(other_left[i]);
2036  int xp = xpos - CARGO_STUB_WIDTH;
2037  DrawHorConnection(xp + 1, xpos - 1, ypos1, csp);
2038  GfxDrawLine(xp, ypos1, xp, ypos1 + FONT_HEIGHT_NORMAL - 1, CARGO_LINE_COLOUR);
2039  }
2041  }
2042  break;
2043  }
2044 
2045  case CFT_CARGO: {
2046  int cargo_base = this->GetCargoBase(xpos);
2047  int top = ypos + (this->u.cargo.top_end ? VERT_INTER_INDUSTRY_SPACE / 2 + 1 : 0);
2048  int bot = ypos - (this->u.cargo.bottom_end ? VERT_INTER_INDUSTRY_SPACE / 2 + 1 : 0) + normal_height - 1;
2049  int colpos = cargo_base;
2050  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
2051  if (this->u.cargo.top_end) GfxDrawLine(colpos, top - 1, colpos + HOR_CARGO_WIDTH - 1, top - 1, CARGO_LINE_COLOUR);
2052  if (this->u.cargo.bottom_end) GfxDrawLine(colpos, bot + 1, colpos + HOR_CARGO_WIDTH - 1, bot + 1, CARGO_LINE_COLOUR);
2053  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2054  colpos++;
2055  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[i]);
2056  GfxFillRect(colpos, top, colpos + HOR_CARGO_WIDTH - 2, bot, csp->legend_colour, FILLRECT_OPAQUE);
2057  colpos += HOR_CARGO_WIDTH - 2;
2058  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2059  colpos += 1 + HOR_CARGO_SPACE;
2060  }
2061 
2062  const CargoID *hor_left, *hor_right;
2063  if (_current_text_dir == TD_RTL) {
2064  hor_left = this->u.cargo.cust_cargoes;
2065  hor_right = this->u.cargo.supp_cargoes;
2066  } else {
2067  hor_left = this->u.cargo.supp_cargoes;
2068  hor_right = this->u.cargo.cust_cargoes;
2069  }
2071  for (uint i = 0; i < MAX_CARGOES; i++) {
2072  if (hor_left[i] != INVALID_CARGO) {
2073  int col = hor_left[i];
2074  int dx = 0;
2075  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2076  for (; col > 0; col--) {
2077  int lf = cargo_base + col * HOR_CARGO_WIDTH + (col - 1) * HOR_CARGO_SPACE;
2078  DrawHorConnection(lf, lf + HOR_CARGO_SPACE - dx, ypos, csp);
2079  dx = 1;
2080  }
2081  DrawHorConnection(xpos, cargo_base - dx, ypos, csp);
2082  }
2083  if (hor_right[i] != INVALID_CARGO) {
2084  int col = hor_right[i];
2085  int dx = 0;
2086  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2087  for (; col < this->u.cargo.num_cargoes - 1; col++) {
2088  int lf = cargo_base + (col + 1) * HOR_CARGO_WIDTH + col * HOR_CARGO_SPACE;
2089  DrawHorConnection(lf + dx - 1, lf + HOR_CARGO_SPACE - 1, ypos, csp);
2090  dx = 1;
2091  }
2092  DrawHorConnection(cargo_base + col * HOR_CARGO_SPACE + (col + 1) * HOR_CARGO_WIDTH - 1 + dx, xpos + CargoesField::cargo_field_width - 1, ypos, csp);
2093  }
2095  }
2096  break;
2097  }
2098 
2099  case CFT_CARGO_LABEL:
2101  for (uint i = 0; i < MAX_CARGOES; i++) {
2102  if (this->u.cargo_label.cargoes[i] != INVALID_CARGO) {
2103  const CargoSpec *csp = CargoSpec::Get(this->u.cargo_label.cargoes[i]);
2104  DrawString(xpos + WD_FRAMERECT_LEFT, xpos + industry_width - 1 - WD_FRAMERECT_RIGHT, ypos, csp->name, TC_WHITE,
2105  (this->u.cargo_label.left_align) ? SA_LEFT : SA_RIGHT);
2106  }
2108  }
2109  break;
2110 
2111  default:
2112  NOT_REACHED();
2113  }
2114  }
2115 
2123  CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
2124  {
2125  assert(this->type == CFT_CARGO);
2126 
2127  /* Vertical matching. */
2128  int cpos = this->GetCargoBase(0);
2129  uint col;
2130  for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2131  if (pt.x < cpos) break;
2132  if (pt.x < cpos + CargoesField::HOR_CARGO_WIDTH) return this->u.cargo.vertical_cargoes[col];
2134  }
2135  /* col = 0 -> left of first col, 1 -> left of 2nd col, ... this->u.cargo.num_cargoes right of last-col. */
2136 
2137  int vpos = VERT_INTER_INDUSTRY_SPACE / 2 + VERT_CARGO_EDGE;
2138  uint row;
2139  for (row = 0; row < MAX_CARGOES; row++) {
2140  if (pt.y < vpos) return INVALID_CARGO;
2141  if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
2143  }
2144  if (row == MAX_CARGOES) return INVALID_CARGO;
2145 
2146  /* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
2147  if (col == 0) {
2148  if (this->u.cargo.supp_cargoes[row] != INVALID_CARGO) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2149  if (left != nullptr) {
2150  if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row];
2151  if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
2152  }
2153  return INVALID_CARGO;
2154  }
2155  if (col == this->u.cargo.num_cargoes) {
2156  if (this->u.cargo.cust_cargoes[row] != INVALID_CARGO) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2157  if (right != nullptr) {
2158  if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row];
2159  if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row];
2160  }
2161  return INVALID_CARGO;
2162  }
2163  if (row >= col) {
2164  /* Clicked somewhere in-between vertical cargo connection.
2165  * Since the horizontal connection is made in the same order as the vertical list, the above condition
2166  * ensures we are left-below the main diagonal, thus at the supplying side.
2167  */
2168  return (this->u.cargo.supp_cargoes[row] != INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]] : INVALID_CARGO;
2169  } else {
2170  /* Clicked at a customer connection. */
2171  return (this->u.cargo.cust_cargoes[row] != INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]] : INVALID_CARGO;
2172  }
2173  }
2174 
2181  {
2182  assert(this->type == CFT_CARGO_LABEL);
2183 
2184  int vpos = VERT_INTER_INDUSTRY_SPACE / 2 + VERT_CARGO_EDGE;
2185  uint row;
2186  for (row = 0; row < MAX_CARGOES; row++) {
2187  if (pt.y < vpos) return INVALID_CARGO;
2188  if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
2190  }
2191  if (row == MAX_CARGOES) return INVALID_CARGO;
2192  return this->u.cargo_label.cargoes[row];
2193  }
2194 
2195 private:
2203  static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
2204  {
2205  GfxDrawLine(left, top, right, top, CARGO_LINE_COLOUR);
2206  GfxFillRect(left, top + 1, right, top + FONT_HEIGHT_NORMAL - 2, csp->legend_colour, FILLRECT_OPAQUE);
2207  GfxDrawLine(left, top + FONT_HEIGHT_NORMAL - 1, right, top + FONT_HEIGHT_NORMAL - 1, CARGO_LINE_COLOUR);
2208  }
2209 };
2210 
2211 static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
2212 static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
2213 
2220 
2221 const int CargoesField::HOR_CARGO_BORDER_SPACE = 15;
2222 const int CargoesField::CARGO_STUB_WIDTH = 10;
2223 const int CargoesField::HOR_CARGO_WIDTH = 15;
2224 const int CargoesField::HOR_CARGO_SPACE = 5;
2225 const int CargoesField::VERT_CARGO_EDGE = 4;
2226 const int CargoesField::VERT_CARGO_SPACE = 4;
2227 
2228 const int CargoesField::BLOB_DISTANCE = 5;
2229 const int CargoesField::BLOB_WIDTH = 12;
2230 const int CargoesField::BLOB_HEIGHT = 9;
2231 
2234 
2236 struct CargoesRow {
2238 
2243  void ConnectIndustryProduced(int column)
2244  {
2245  CargoesField *ind_fld = this->columns + column;
2246  CargoesField *cargo_fld = this->columns + column + 1;
2247  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2248 
2249  MemSetT(ind_fld->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
2250 
2251  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2252  CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
2253  int other_count = 0;
2254 
2255  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2256  assert(CargoesField::max_cargoes <= lengthof(indsp->produced_cargo));
2257  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2258  int col = cargo_fld->ConnectCargo(indsp->produced_cargo[i], true);
2259  if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2260  }
2261 
2262  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
2263  for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2264  if (cargo_fld->u.cargo.supp_cargoes[i] == INVALID_CARGO) ind_fld->u.industry.other_produced[i] = others[--other_count];
2265  }
2266  } else {
2267  /* Houses only display what is demanded. */
2268  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2269  CargoID cid = cargo_fld->u.cargo.vertical_cargoes[i];
2270  if (cid == CT_PASSENGERS || cid == CT_MAIL) cargo_fld->ConnectCargo(cid, true);
2271  }
2272  }
2273  }
2274 
2280  void MakeCargoLabel(int column, bool accepting)
2281  {
2282  CargoID cargoes[MAX_CARGOES];
2283  MemSetT(cargoes, INVALID_CARGO, lengthof(cargoes));
2284 
2285  CargoesField *label_fld = this->columns + column;
2286  CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2287 
2288  assert(cargo_fld->type == CFT_CARGO && label_fld->type == CFT_EMPTY);
2289  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2290  int col = cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], !accepting);
2291  if (col >= 0) cargoes[col] = cargo_fld->u.cargo.vertical_cargoes[i];
2292  }
2293  label_fld->MakeCargoLabel(cargoes, lengthof(cargoes), accepting);
2294  }
2295 
2296 
2301  void ConnectIndustryAccepted(int column)
2302  {
2303  CargoesField *ind_fld = this->columns + column;
2304  CargoesField *cargo_fld = this->columns + column - 1;
2305  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2306 
2307  MemSetT(ind_fld->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
2308 
2309  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2310  CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
2311  int other_count = 0;
2312 
2313  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2315  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2316  int col = cargo_fld->ConnectCargo(indsp->accepts_cargo[i], false);
2317  if (col < 0) others[other_count++] = indsp->accepts_cargo[i];
2318  }
2319 
2320  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
2321  for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2322  if (cargo_fld->u.cargo.cust_cargoes[i] == INVALID_CARGO) ind_fld->u.industry.other_accepted[i] = others[--other_count];
2323  }
2324  } else {
2325  /* Houses only display what is demanded. */
2326  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2327  for (uint h = 0; h < NUM_HOUSES; h++) {
2328  HouseSpec *hs = HouseSpec::Get(h);
2329  if (!hs->enabled) continue;
2330 
2331  for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
2332  if (hs->cargo_acceptance[j] > 0 && cargo_fld->u.cargo.vertical_cargoes[i] == hs->accepts_cargo[j]) {
2333  cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], false);
2334  goto next_cargo;
2335  }
2336  }
2337  }
2338 next_cargo: ;
2339  }
2340  }
2341  }
2342 };
2343 
2344 
2374 
2375  typedef std::vector<CargoesRow> Fields;
2376 
2377  Fields fields;
2378  uint ind_cargo;
2381  Scrollbar *vscroll;
2382 
2384  {
2385  this->OnInit();
2386  this->CreateNestedTree();
2387  this->vscroll = this->GetScrollbar(WID_IC_SCROLLBAR);
2388  this->FinishInitNested(0);
2389  this->OnInvalidateData(id);
2390  }
2391 
2392  void OnInit() override
2393  {
2394  /* Initialize static CargoesField size variables. */
2395  Dimension d = GetStringBoundingBox(STR_INDUSTRY_CARGOES_PRODUCERS);
2396  d = maxdim(d, GetStringBoundingBox(STR_INDUSTRY_CARGOES_CUSTOMERS));
2398  d.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM;
2399  CargoesField::small_height = d.height;
2400 
2401  /* Decide about the size of the box holding the text of an industry type. */
2402  this->ind_textsize.width = 0;
2403  this->ind_textsize.height = 0;
2405  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2406  const IndustrySpec *indsp = GetIndustrySpec(it);
2407  if (!indsp->enabled) continue;
2408  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
2409  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->accepts_cargo, endof(indsp->accepts_cargo), IsCargoIDValid));
2410  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->produced_cargo, endof(indsp->produced_cargo), IsCargoIDValid));
2411  }
2412  d.width = std::max(d.width, this->ind_textsize.width);
2413  d.height = this->ind_textsize.height;
2414  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY));
2415 
2416  /* Compute max size of the cargo texts. */
2417  this->cargo_textsize.width = 0;
2418  this->cargo_textsize.height = 0;
2419  for (uint i = 0; i < NUM_CARGO; i++) {
2420  const CargoSpec *csp = CargoSpec::Get(i);
2421  if (!csp->IsValid()) continue;
2422  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name));
2423  }
2424  d = maxdim(d, this->cargo_textsize); // Box must also be wide enough to hold any cargo label.
2425  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_CARGO));
2426 
2427  d.width += 2 * HOR_TEXT_PADDING;
2428  /* Ensure the height is enough for the industry type text, for the horizontal connections, and for the cargo labels. */
2430  d.height = std::max(d.height + 2 * VERT_TEXT_PADDING, min_ind_height);
2431 
2432  CargoesField::industry_width = d.width;
2434 
2435  /* Width of a #CFT_CARGO field. */
2437  }
2438 
2439  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2440  {
2441  switch (widget) {
2442  case WID_IC_PANEL:
2444  break;
2445 
2446  case WID_IC_IND_DROPDOWN:
2447  size->width = std::max(size->width, this->ind_textsize.width + padding.width);
2448  break;
2449 
2450  case WID_IC_CARGO_DROPDOWN:
2451  size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
2452  break;
2453  }
2454  }
2455 
2456 
2458  void SetStringParameters (int widget) const override
2459  {
2460  if (widget != WID_IC_CAPTION) return;
2461 
2462  if (this->ind_cargo < NUM_INDUSTRYTYPES) {
2463  const IndustrySpec *indsp = GetIndustrySpec(this->ind_cargo);
2464  SetDParam(0, indsp->name);
2465  } else {
2466  const CargoSpec *csp = CargoSpec::Get(this->ind_cargo - NUM_INDUSTRYTYPES);
2467  SetDParam(0, csp->name);
2468  }
2469  }
2470 
2479  static bool HasCommonValidCargo(const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
2480  {
2481  while (length1 > 0) {
2482  if (*cargoes1 != INVALID_CARGO) {
2483  for (uint i = 0; i < length2; i++) if (*cargoes1 == cargoes2[i]) return true;
2484  }
2485  cargoes1++;
2486  length1--;
2487  }
2488  return false;
2489  }
2490 
2497  static bool HousesCanSupply(const CargoID *cargoes, uint length)
2498  {
2499  for (uint i = 0; i < length; i++) {
2500  if (cargoes[i] == INVALID_CARGO) continue;
2501  if (cargoes[i] == CT_PASSENGERS || cargoes[i] == CT_MAIL) return true;
2502  }
2503  return false;
2504  }
2505 
2512  static bool HousesCanAccept(const CargoID *cargoes, uint length)
2513  {
2514  HouseZones climate_mask;
2516  case LT_TEMPERATE: climate_mask = HZ_TEMP; break;
2517  case LT_ARCTIC: climate_mask = HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW; break;
2518  case LT_TROPIC: climate_mask = HZ_SUBTROPIC; break;
2519  case LT_TOYLAND: climate_mask = HZ_TOYLND; break;
2520  default: NOT_REACHED();
2521  }
2522  for (uint i = 0; i < length; i++) {
2523  if (cargoes[i] == INVALID_CARGO) continue;
2524 
2525  for (uint h = 0; h < NUM_HOUSES; h++) {
2526  HouseSpec *hs = HouseSpec::Get(h);
2527  if (!hs->enabled || !(hs->building_availability & climate_mask)) continue;
2528 
2529  for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
2530  if (hs->cargo_acceptance[j] > 0 && cargoes[i] == hs->accepts_cargo[j]) return true;
2531  }
2532  }
2533  }
2534  return false;
2535  }
2536 
2543  static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
2544  {
2545  int count = 0;
2546  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2547  const IndustrySpec *indsp = GetIndustrySpec(it);
2548  if (!indsp->enabled) continue;
2549 
2550  if (HasCommonValidCargo(cargoes, length, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) count++;
2551  }
2552  return count;
2553  }
2554 
2561  static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
2562  {
2563  int count = 0;
2564  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2565  const IndustrySpec *indsp = GetIndustrySpec(it);
2566  if (!indsp->enabled) continue;
2567 
2568  if (HasCommonValidCargo(cargoes, length, indsp->produced_cargo, lengthof(indsp->produced_cargo))) count++;
2569  }
2570  return count;
2571  }
2572 
2579  void ShortenCargoColumn(int column, int top, int bottom)
2580  {
2581  while (top < bottom && !this->fields[top].columns[column].HasConnection()) {
2582  this->fields[top].columns[column].MakeEmpty(CFT_EMPTY);
2583  top++;
2584  }
2585  this->fields[top].columns[column].u.cargo.top_end = true;
2586 
2587  while (bottom > top && !this->fields[bottom].columns[column].HasConnection()) {
2588  this->fields[bottom].columns[column].MakeEmpty(CFT_EMPTY);
2589  bottom--;
2590  }
2591  this->fields[bottom].columns[column].u.cargo.bottom_end = true;
2592  }
2593 
2600  void PlaceIndustry(int row, int col, IndustryType it)
2601  {
2602  assert(this->fields[row].columns[col].type == CFT_EMPTY);
2603  this->fields[row].columns[col].MakeIndustry(it);
2604  if (col == 0) {
2605  this->fields[row].ConnectIndustryProduced(col);
2606  } else {
2607  this->fields[row].ConnectIndustryAccepted(col);
2608  }
2609  }
2610 
2615  {
2616  if (!this->IsWidgetLowered(WID_IC_NOTIFY)) return;
2617 
2618  /* Only notify the smallmap window if it exists. In particular, do not
2619  * bring it to the front to prevent messing up any nice layout of the user. */
2621  }
2622 
2627  void ComputeIndustryDisplay(IndustryType it)
2628  {
2629  this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2630  this->ind_cargo = it;
2631  _displayed_industries.reset();
2632  _displayed_industries.set(it);
2633 
2634  this->fields.clear();
2635  CargoesRow &row = this->fields.emplace_back();
2636  row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
2640  row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
2641 
2642  const IndustrySpec *central_sp = GetIndustrySpec(it);
2643  bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
2644  bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
2645  /* Make a field consisting of two cargo columns. */
2646  int num_supp = CountMatchingProducingIndustries(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)) + houses_supply;
2647  int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
2648  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.
2649  for (int i = 0; i < num_indrows; i++) {
2650  CargoesRow &row = this->fields.emplace_back();
2651  row.columns[0].MakeEmpty(CFT_EMPTY);
2652  row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
2653  row.columns[2].MakeEmpty(CFT_EMPTY);
2654  row.columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
2655  row.columns[4].MakeEmpty(CFT_EMPTY);
2656  }
2657  /* Add central industry. */
2658  int central_row = 1 + num_indrows / 2;
2659  this->fields[central_row].columns[2].MakeIndustry(it);
2660  this->fields[central_row].ConnectIndustryProduced(2);
2661  this->fields[central_row].ConnectIndustryAccepted(2);
2662 
2663  /* Add cargo labels. */
2664  this->fields[central_row - 1].MakeCargoLabel(2, true);
2665  this->fields[central_row + 1].MakeCargoLabel(2, false);
2666 
2667  /* Add suppliers and customers of the 'it' industry. */
2668  int supp_count = 0;
2669  int cust_count = 0;
2670  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2671  const IndustrySpec *indsp = GetIndustrySpec(it);
2672  if (!indsp->enabled) continue;
2673 
2674  if (HasCommonValidCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo), indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
2675  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2676  _displayed_industries.set(it);
2677  supp_count++;
2678  }
2679  if (HasCommonValidCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo), indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
2680  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2681  _displayed_industries.set(it);
2682  cust_count++;
2683  }
2684  }
2685  if (houses_supply) {
2686  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2687  supp_count++;
2688  }
2689  if (houses_accept) {
2690  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, NUM_INDUSTRYTYPES);
2691  cust_count++;
2692  }
2693 
2694  this->ShortenCargoColumn(1, 1, num_indrows);
2695  this->ShortenCargoColumn(3, 1, num_indrows);
2696  const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2698  this->SetDirty();
2699  this->NotifySmallmap();
2700  }
2701 
2707  {
2708  this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2709  this->ind_cargo = cid + NUM_INDUSTRYTYPES;
2710  _displayed_industries.reset();
2711 
2712  this->fields.clear();
2713  CargoesRow &row = this->fields.emplace_back();
2714  row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
2716  row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
2719 
2720  bool houses_supply = HousesCanSupply(&cid, 1);
2721  bool houses_accept = HousesCanAccept(&cid, 1);
2722  int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1; // Ensure room for the cargo label.
2723  int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
2724  int num_indrows = std::max(num_supp, num_cust);
2725  for (int i = 0; i < num_indrows; i++) {
2726  CargoesRow &row = this->fields.emplace_back();
2727  row.columns[0].MakeEmpty(CFT_EMPTY);
2728  row.columns[1].MakeCargo(&cid, 1);
2729  row.columns[2].MakeEmpty(CFT_EMPTY);
2730  row.columns[3].MakeEmpty(CFT_EMPTY);
2731  row.columns[4].MakeEmpty(CFT_EMPTY);
2732  }
2733 
2734  this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
2735 
2736  /* Add suppliers and customers of the cargo. */
2737  int supp_count = 0;
2738  int cust_count = 0;
2739  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2740  const IndustrySpec *indsp = GetIndustrySpec(it);
2741  if (!indsp->enabled) continue;
2742 
2743  if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
2744  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2745  _displayed_industries.set(it);
2746  supp_count++;
2747  }
2748  if (HasCommonValidCargo(&cid, 1, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
2749  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2750  _displayed_industries.set(it);
2751  cust_count++;
2752  }
2753  }
2754  if (houses_supply) {
2755  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2756  supp_count++;
2757  }
2758  if (houses_accept) {
2759  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
2760  cust_count++;
2761  }
2762 
2763  this->ShortenCargoColumn(1, 1, num_indrows);
2764  const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2766  this->SetDirty();
2767  this->NotifySmallmap();
2768  }
2769 
2777  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2778  {
2779  if (!gui_scope) return;
2780  if (data == NUM_INDUSTRYTYPES) {
2781  if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
2782  this->RaiseWidget(WID_IC_NOTIFY);
2784  }
2785  return;
2786  }
2787 
2788  assert(data >= 0 && data < NUM_INDUSTRYTYPES);
2789  this->ComputeIndustryDisplay(data);
2790  }
2791 
2792  void DrawWidget(const Rect &r, int widget) const override
2793  {
2794  if (widget != WID_IC_PANEL) return;
2795 
2796  DrawPixelInfo tmp_dpi, *old_dpi;
2797  int width = r.right - r.left + 1;
2798  int height = r.bottom - r.top + 1 - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM;
2799  if (!FillDrawPixelInfo(&tmp_dpi, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, width, height)) return;
2800  old_dpi = _cur_dpi;
2801  _cur_dpi = &tmp_dpi;
2802 
2803  int left_pos = WD_FRAMERECT_LEFT;
2804  if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2;
2805  int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
2806 
2807  const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2808  int vpos = -this->vscroll->GetPosition() * nwp->resize_y;
2809  for (uint i = 0; i < this->fields.size(); i++) {
2810  int row_height = (i == 0) ? CargoesField::small_height : CargoesField::normal_height;
2811  if (vpos + row_height >= 0) {
2812  int xpos = left_pos;
2813  int col, dir;
2814  if (_current_text_dir == TD_RTL) {
2815  col = last_column;
2816  dir = -1;
2817  } else {
2818  col = 0;
2819  dir = 1;
2820  }
2821  while (col >= 0 && col <= last_column) {
2822  this->fields[i].columns[col].Draw(xpos, vpos);
2824  col += dir;
2825  }
2826  }
2827  vpos += row_height;
2828  if (vpos >= height) break;
2829  }
2830 
2831  _cur_dpi = old_dpi;
2832  }
2833 
2841  bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
2842  {
2843  const NWidgetBase *nw = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2844  pt.x -= nw->pos_x;
2845  pt.y -= nw->pos_y;
2846 
2847  int vpos = WD_FRAMERECT_TOP + CargoesField::small_height - this->vscroll->GetPosition() * nw->resize_y;
2848  if (pt.y < vpos) return false;
2849 
2850  int row = (pt.y - vpos) / CargoesField::normal_height; // row is relative to row 1.
2851  if (row + 1 >= (int)this->fields.size()) return false;
2852  vpos = pt.y - vpos - row * CargoesField::normal_height; // Position in the row + 1 field
2853  row++; // rebase row to match index of this->fields.
2854 
2855  int xpos = 2 * WD_FRAMERECT_LEFT + ((this->ind_cargo < NUM_INDUSTRYTYPES) ? 0 : (CargoesField::industry_width + CargoesField::cargo_field_width) / 2);
2856  if (pt.x < xpos) return false;
2857  int column;
2858  for (column = 0; column <= 5; column++) {
2860  if (pt.x < xpos + width) break;
2861  xpos += width;
2862  }
2863  int num_columns = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
2864  if (column > num_columns) return false;
2865  xpos = pt.x - xpos;
2866 
2867  /* Return both positions, compensating for RTL languages (which works due to the equal symmetry in both displays). */
2868  fieldxy->y = row;
2869  xy->y = vpos;
2870  if (_current_text_dir == TD_RTL) {
2871  fieldxy->x = num_columns - column;
2872  xy->x = ((column & 1) ? CargoesField::cargo_field_width : CargoesField::industry_width) - xpos;
2873  } else {
2874  fieldxy->x = column;
2875  xy->x = xpos;
2876  }
2877  return true;
2878  }
2879 
2880  void OnClick(Point pt, int widget, int click_count) override
2881  {
2882  switch (widget) {
2883  case WID_IC_PANEL: {
2884  Point fieldxy, xy;
2885  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return;
2886 
2887  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
2888  switch (fld->type) {
2889  case CFT_INDUSTRY:
2890  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES) this->ComputeIndustryDisplay(fld->u.industry.ind_type);
2891  break;
2892 
2893  case CFT_CARGO: {
2894  CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
2895  CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
2896  CargoID cid = fld->CargoClickedAt(lft, rgt, xy);
2897  if (cid != INVALID_CARGO) this->ComputeCargoDisplay(cid);
2898  break;
2899  }
2900 
2901  case CFT_CARGO_LABEL: {
2902  CargoID cid = fld->CargoLabelClickedAt(xy);
2903  if (cid != INVALID_CARGO) this->ComputeCargoDisplay(cid);
2904  break;
2905  }
2906 
2907  default:
2908  break;
2909  }
2910  break;
2911  }
2912 
2913  case WID_IC_NOTIFY:
2916  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
2917 
2918  if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
2919  if (FindWindowByClass(WC_SMALLMAP) == nullptr) ShowSmallMap();
2920  this->NotifySmallmap();
2921  }
2922  break;
2923 
2924  case WID_IC_CARGO_DROPDOWN: {
2925  DropDownList lst;
2926  const CargoSpec *cs;
2928  lst.emplace_back(new DropDownListStringItem(cs->name, cs->Index(), false));
2929  }
2930  if (!lst.empty()) {
2931  int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
2932  ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN, 0, true);
2933  }
2934  break;
2935  }
2936 
2937  case WID_IC_IND_DROPDOWN: {
2938  DropDownList lst;
2939  for (IndustryType ind : _sorted_industry_types) {
2940  const IndustrySpec *indsp = GetIndustrySpec(ind);
2941  if (!indsp->enabled) continue;
2942  lst.emplace_back(new DropDownListStringItem(indsp->name, ind, false));
2943  }
2944  if (!lst.empty()) {
2945  int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
2946  ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN, 0, true);
2947  }
2948  break;
2949  }
2950  }
2951  }
2952 
2953  void OnDropdownSelect(int widget, int index) override
2954  {
2955  if (index < 0) return;
2956 
2957  switch (widget) {
2958  case WID_IC_CARGO_DROPDOWN:
2959  this->ComputeCargoDisplay(index);
2960  break;
2961 
2962  case WID_IC_IND_DROPDOWN:
2963  this->ComputeIndustryDisplay(index);
2964  break;
2965  }
2966  }
2967 
2968  bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
2969  {
2970  if (widget != WID_IC_PANEL) return false;
2971 
2972  Point fieldxy, xy;
2973  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
2974 
2975  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
2976  CargoID cid = INVALID_CARGO;
2977  switch (fld->type) {
2978  case CFT_CARGO: {
2979  CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
2980  CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
2981  cid = fld->CargoClickedAt(lft, rgt, xy);
2982  break;
2983  }
2984 
2985  case CFT_CARGO_LABEL: {
2986  cid = fld->CargoLabelClickedAt(xy);
2987  break;
2988  }
2989 
2990  case CFT_INDUSTRY:
2991  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
2992  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0, nullptr, close_cond);
2993  }
2994  return true;
2995 
2996  default:
2997  break;
2998  }
2999  if (cid != INVALID_CARGO && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) {
3000  const CargoSpec *csp = CargoSpec::Get(cid);
3001  uint64 params[5];
3002  params[0] = csp->name;
3003  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, close_cond);
3004  return true;
3005  }
3006 
3007  return false;
3008  }
3009 
3010  void OnResize() override
3011  {
3012  this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL);
3013  }
3014 };
3015 
3018 
3023 static void ShowIndustryCargoesWindow(IndustryType id)
3024 {
3025  if (id >= NUM_INDUSTRYTYPES) {
3026  for (IndustryType ind : _sorted_industry_types) {
3027  const IndustrySpec *indsp = GetIndustrySpec(ind);
3028  if (indsp->enabled) {
3029  id = ind;
3030  break;
3031  }
3032  }
3033  if (id >= NUM_INDUSTRYTYPES) return;
3034  }
3035 
3037  if (w != nullptr) {
3038  w->InvalidateData(id);
3039  return;
3040  }
3041  new IndustryCargoesWindow(id);
3042 }
3043 
3046 {
3048 }
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition: industry_gui.cpp:184
PC_WHITE
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:207
CargoesField::cargo_label
struct CargoesField::@17::@20 cargo_label
Label data (for CFT_CARGO_LABEL).
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:275
INVALID_CARGO
static const byte INVALID_CARGO
Constant representing invalid cargo.
Definition: cargotype.h:52
IndustryViewWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: industry_gui.cpp:931
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:2561
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:366
PRODLEVEL_MINIMUM
@ PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
Definition: industry.h:31
BuildIndustryWindow::count
uint16 count
How many industries are loaded.
Definition: industry_gui.cpp:273
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
WID_DPI_DISPLAY_WIDGET
@ WID_DPI_DISPLAY_WIDGET
Display chain button.
Definition: industry_widget.h:18
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:2512
ID_FUND_ONLY
@ ID_FUND_ONLY
The game does not build industries.
Definition: settings_type.h:43
CBM_IND_PRODUCTION_CARGO_ARRIVAL
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
Definition: newgrf_callbacks.h:349
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
FOR_ALL_SORTED_STANDARD_CARGOSPECS
#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var)
Loop header for iterating over 'real' cargoes, sorted by name.
Definition: cargotype.h:171
IndustrySpec::map_colour
byte map_colour
colour used for the small map
Definition: industrytype.h:126
CBM_IND_CARGO_SUFFIX
@ CBM_IND_CARGO_SUFFIX
cargo sub-type display
Definition: newgrf_callbacks.h:354
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2443
INDUSTRYBEH_CARGOTYPES_UNLIMITED
@ INDUSTRYBEH_CARGOTYPES_UNLIMITED
Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types.
Definition: industrytype.h:82
IndustrySpec::UsesOriginalEconomy
bool UsesOriginalEconomy() const
Determines whether this industrytype uses standard/newgrf production changes.
Definition: industry_cmd.cpp:3022
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:1911
WC_INDUSTRY_CARGOES
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
Definition: window_type.h:504
IndustryCargoesWindow::HousesCanSupply
static bool HousesCanSupply(const CargoID *cargoes, uint length)
Can houses be used to supply one of the cargoes?
Definition: industry_gui.cpp:2497
IndustryTypeNameSorter
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
Definition: industry_gui.cpp:187
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: window_gui.h:77
CargoesField::INDUSTRY_LINE_COLOUR
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
Definition: industry_gui.cpp:1804
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
BuildIndustryWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:397
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
ToPercent8
static uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
Definition: math_func.hpp:227
CargoesField::other_produced
CargoID other_produced[MAX_CARGOES]
Cargoes produced but not used in this figure.
Definition: industry_gui.cpp:1816
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:621
command_func.h
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:636
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1045
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
IndustryDirectoryWindow::GetCargoTransportedPercentsIfValid
static int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
Returns percents of cargo transported if industry produces this cargo, else -1.
Definition: industry_gui.cpp:1370
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
dropdown_func.h
PC_YELLOW
static const uint8 PC_YELLOW
Yellow palette colour.
Definition: gfx_func.h:217
WID_IC_NOTIFY
@ WID_IC_NOTIFY
Row of buttons at the bottom.
Definition: industry_widget.h:44
IndustryViewWindow::production_offset_y
int production_offset_y
The offset of the production texts/buttons.
Definition: industry_gui.cpp:763
smallmap_gui.h
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:293
CFT_HEADER
@ CFT_HEADER
Header text.
Definition: industry_gui.cpp:1790
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:1339
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:995
company_base.h
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:2380
GUIList::SetFilterType
void SetFilterType(uint8 n_type)
Set the filtertype of the list.
Definition: sortlist_type.h:155
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:78
BuildIndustryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:635
CargoesField::bottom_end
byte bottom_end
Stop at the bottom of the vertical cargoes.
Definition: industry_gui.cpp:1825
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:574
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
CMD_BUILD_INDUSTRY
@ CMD_BUILD_INDUSTRY
build a new industry
Definition: command_type.h:232
IndustryViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1048
HZ_SUBTROPIC
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition: house.h:82
PRODLEVEL_CLOSURE
@ PRODLEVEL_CLOSURE
signal set to actually close the industry
Definition: industry.h:30
IndustrySpec::GetConstructionCost
Money GetConstructionCost() const
Get the cost for constructing this industry.
Definition: industry_cmd.cpp:3000
CSD_CARGO
@ CSD_CARGO
Display the cargo without sub-type (cb37 result 401).
Definition: industry_gui.cpp:59
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1966
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_func.h:96
IndustryViewWindow::EA_MULTIPLIER
@ EA_MULTIPLIER
Allow changing the production multiplier.
Definition: industry_gui.cpp:747
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:239
GUIList
List template of 'things' T to sort in a GUI.
Definition: sortlist_type.h:46
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:326
IndustryCargoesWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: industry_gui.cpp:2953
CargoesRow
A single row of CargoesField.
Definition: industry_gui.cpp:2236
IndustryViewWindow::IsNewGRFInspectable
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition: industry_gui.cpp:1096
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:99
WID_IV_GOTO
@ WID_IV_GOTO
Goto button.
Definition: industry_widget.h:27
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
WC_INDUSTRY_VIEW
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Definition: window_type.h:356
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_func.h:94
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
_build_industry_desc
static WindowDesc _build_industry_desc(WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, _nested_build_industry_widgets, lengthof(_nested_build_industry_widgets))
Window definition of the dynamic place industries gui.
IndustryCargoesWindow::PlaceIndustry
void PlaceIndustry(int row, int col, IndustryType it)
Place an industry in the fields.
Definition: industry_gui.cpp:2600
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:57
HouseSpec::enabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition: house.h:111
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
BuildIndustryWindow::MATRIX_TEXT_OFFSET
static const int MATRIX_TEXT_OFFSET
The offset for the text in the matrix.
Definition: industry_gui.cpp:279
SortIndustryTypes
void SortIndustryTypes()
Initialize the list of sorted industry types.
Definition: industry_gui.cpp:206
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:547
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Industry::last_month_production
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
Definition: industry.h:79
WID_DPI_MATRIX_WIDGET
@ WID_DPI_MATRIX_WIDGET
Matrix of the industries.
Definition: industry_widget.h:15
IndustryCargoesWindow::ShortenCargoColumn
void ShortenCargoColumn(int column, int top, int bottom)
Shorten the cargo column to just the part between industries.
Definition: industry_gui.cpp:2579
CST_DIR
@ CST_DIR
Industry-directory window.
Definition: industry_gui.cpp:54
Cheats::setup_prod
Cheat setup_prod
setup raw-material production in game
Definition: cheat_type.h:35
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
WC_BUILD_INDUSTRY
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
Definition: window_type.h:428
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:573
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:72
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:822
Industry::RecomputeProductionMultipliers
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
Definition: industry_cmd.cpp:2378
IndustryDirectoryWindow::IndustryTypeSorter
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b)
Sort industries by type and name.
Definition: industry_gui.cpp:1404
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
CargoesField::ConnectCargo
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
Definition: industry_gui.cpp:1862
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:636
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:55
newgrf_debug.h
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
IndustryDirectoryWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: industry_gui.cpp:1647
IndustryViewWindow::ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition: industry_gui.cpp:1101
CBM_IND_PRODUCTION_256_TICKS
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Definition: newgrf_callbacks.h:350
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
CargoesField::CARGO_LINE_COLOUR
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
Definition: industry_gui.cpp:1805
IndustryCargoesWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: industry_gui.cpp:2439
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:839
BuildIndustryWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: industry_gui.cpp:494
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:146
PRODLEVEL_DEFAULT
@ PRODLEVEL_DEFAULT
default level set when the industry is created
Definition: industry.h:32
BuildIndustryWindow::selected_index
int selected_index
index of the element in the matrix
Definition: industry_gui.cpp:271
CargoesField::BLOB_HEIGHT
static const int BLOB_HEIGHT
Height of the industry legend colour, including border.
Definition: industry_gui.cpp:1802
Industry
Defines the internal data of a functional industry.
Definition: industry.h:66
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:95
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Window::HandleButtonClick
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:635
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
CargoesField::DrawHorConnection
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
Definition: industry_gui.cpp:2203
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:70
CFT_INDUSTRY
@ CFT_INDUSTRY
Display industry.
Definition: industry_gui.cpp:1787
MAX_CARGOES
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
Definition: industry_gui.cpp:1793
_industry_cargoes_desc
static WindowDesc _industry_cargoes_desc(WDP_AUTO, "industry_cargoes", 300, 210, WC_INDUSTRY_CARGOES, WC_NONE, 0, _nested_industry_cargoes_widgets, lengthof(_nested_industry_cargoes_widgets))
Window description for the industry cargoes window.
CargoesField::cargo
struct CargoesField::@17::@19 cargo
Cargo data (for CFT_CARGO).
CommandCost::GetErrorMessage
StringID GetErrorMessage() const
Returns the error message of a command.
Definition: command_type.h:140
IndustryCargoesWindow::ind_cargo
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
Definition: industry_gui.cpp:2378
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
CargoFilter
static bool CDECL CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
Definition: industry_gui.cpp:1198
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
genworld.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
CBM_IND_FUND_MORE_TEXT
@ CBM_IND_FUND_MORE_TEXT
additional text in fund window
Definition: newgrf_callbacks.h:355
IndustryDirectoryWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: industry_gui.cpp:1541
IndustryCargoesWindow::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:2457
BuildIndustryWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:692
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:838
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:341
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:1960
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
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
BuildIndustryWindow::enabled
bool enabled[NUM_INDUSTRYTYPES+1]
availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever)
Definition: industry_gui.cpp:275
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:372
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:759
WID_ID_FILTER_BY_PROD_CARGO
@ WID_ID_FILTER_BY_PROD_CARGO
Produced cargo filter dropdown list.
Definition: industry_widget.h:36
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:548
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
IndustryDirectoryWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:1519
GetIndustryProbabilityCallback
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
Definition: newgrf_industries.cpp:565
WindowDesc
High level window description.
Definition: window_gui.h:166
WID_IV_CAPTION
@ WID_IV_CAPTION
Caption of the window.
Definition: industry_widget.h:24
CFT_CARGO
@ CFT_CARGO
Display cargo connections.
Definition: industry_gui.cpp:1788
IndustryDirectoryWindow::cargo_filter
CargoID cargo_filter[NUM_CARGO+2]
Available cargo filters; CargoID or CF_ANY or CF_NONE.
Definition: industry_gui.cpp:1262
IndustryCargoesWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:3010
CargoesField::CargoLabelClickedAt
CargoID CargoLabelClickedAt(Point pt) const
Decide what cargo the user clicked in the cargo label field.
Definition: industry_gui.cpp:2180
CcBuildIndustry
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback.
Definition: industry_gui.cpp:225
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:88
CargoSuffixDisplay
CargoSuffixDisplay
Ways of displaying the cargo.
Definition: industry_gui.cpp:58
CargoesField::HOR_CARGO_WIDTH
static const int HOR_CARGO_WIDTH
Width of a vertical cargo column (inclusive the border line).
Definition: industry_gui.cpp:1800
CargoesField::CARGO_STUB_WIDTH
static const int CARGO_STUB_WIDTH
Width of a cargo not carried in the column (should be less than HOR_CARGO_BORDER_SPACE).
Definition: industry_gui.cpp:1799
IndustryCargoesWindow
Window displaying the cargo connections around an industry (or cargo).
Definition: industry_gui.cpp:2372
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
IndustrySpec::IsRawIndustry
bool IsRawIndustry() const
Is an industry with the spec a raw industry?
Definition: industry_cmd.cpp:2980
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:154
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
IndustryDirectoryWindow::IndustryTransportedCargoSorter
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b)
Sort industries by transported cargo and name.
Definition: industry_gui.cpp:1428
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
CommandCost
Common return value for all commands.
Definition: command_type.h:23
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:67
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition: misc_gui.cpp:781
IndustryViewWindow::editable
Editability editable
Mode for changing production.
Definition: industry_gui.cpp:759
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:1943
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:568
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition: house.h:29
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
IndustryCargoesWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:2392
CargoesRow::MakeCargoLabel
void MakeCargoLabel(int column, bool accepting)
Construct a CFT_CARGO_LABEL field.
Definition: industry_gui.cpp:2280
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1861
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
Industry::type
IndustryType type
type of industry.
Definition: industry.h:83
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
IndustryViewWindow::IL_NONE
@ IL_NONE
No line.
Definition: industry_gui.cpp:753
CargoSuffix::text
char text[512]
Cargo suffix text.
Definition: industry_gui.cpp:68
GUIList< const Industry *, const std::pair< CargoID, CargoID > & >::SortFunction
bool SortFunction(const const Industry * &, const const Industry * &)
Signature of sort function.
Definition: sortlist_type.h:48
CargoSpec::IsValid
bool IsValid() const
Tests for validity of this cargospec.
Definition: cargotype.h:98
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
IndustryDirectoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1672
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
WC_INDUSTRY_DIRECTORY
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
Definition: window_type.h:259
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
IndustryViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:782
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2432
CargoesField::industry_width
static int industry_width
Width of an industry field.
Definition: industry_gui.cpp:1809
_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:1250
IsInsideBS
static 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:188
IndustrySpec::layouts
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
Definition: industrytype.h:108
CargoesField::BLOB_DISTANCE
static const int BLOB_DISTANCE
Distance of the industry legend colour from the edge of the industry box.
Definition: industry_gui.cpp:1802
IsCargoIDValid
bool IsCargoIDValid(CargoID t)
Test whether cargo type is not CT_INVALID.
Definition: cargo_type.h:74
IndustrySpec::accepts_cargo
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
Definition: industrytype.h:121
CargoesField::MakeIndustry
void MakeIndustry(IndustryType ind_type)
Make an industry type field.
Definition: industry_gui.cpp:1848
CargoesField::VERT_CARGO_SPACE
static const int VERT_CARGO_SPACE
Amount of vertical space between two connected cargoes at an industry.
Definition: industry_gui.cpp:1801
CargoesField::BLOB_WIDTH
static const int BLOB_WIDTH
Width of the industry legend colour, including border.
Definition: industry_gui.cpp:1802
Industry::produced_cargo
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
Definition: industry.h:70
IndustryViewWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:1041
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
CargoesField
Data about a single field in the IndustryCargoesWindow panel.
Definition: industry_gui.cpp:1796
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
CargoesField::cargoes
CargoID cargoes[MAX_CARGOES]
Cargoes to display (or INVALID_CARGO).
Definition: industry_gui.cpp:1828
Industry::incoming_cargo_waiting
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
Definition: industry.h:72
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
CargoSuffix::display
CargoSuffixDisplay display
How to display the cargo and text.
Definition: industry_gui.cpp:67
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:73
IndustryDirectoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:1677
BuildIndustryWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: industry_gui.cpp:581
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:453
WID_DPI_INFOPANEL
@ WID_DPI_INFOPANEL
Info panel about the industry.
Definition: industry_widget.h:17
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1031
ConstructionSettings::raw_industry_construction
uint8 raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
Definition: settings_type.h:315
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:1439
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
ShowIndustryCargoesWindow
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
Definition: industry_gui.cpp:3023
ZOOM_LVL_INDUSTRY
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
Definition: zoom_type.h:35
CargoesField::max_cargoes
static uint max_cargoes
Largest number of cargoes actually on any industry.
Definition: industry_gui.cpp:1810
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:45
PRODLEVEL_MAXIMUM
@ PRODLEVEL_MAXIMUM
the industry is running at full speed
Definition: industry.h:33
_nested_industry_view_widgets
static const NWidgetPart _nested_industry_view_widgets[]
Widget definition of the view industry gui.
Definition: industry_gui.cpp:1120
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
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:1131
HandlePlacePushButton
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:61
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:317
IndustryDirectoryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:1694
CST_VIEW
@ CST_VIEW
View-industry window.
Definition: industry_gui.cpp:53
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:310
CargoesRow::ConnectIndustryProduced
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
Definition: industry_gui.cpp:2243
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:602
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
CargoesField::HasConnection
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
Definition: industry_gui.cpp:1891
DifficultySettings::industry_density
byte industry_density
The industry density.
Definition: settings_type.h:57
_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:48
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:52
CargoesField::header
StringID header
Header text (for CFT_HEADER).
Definition: industry_gui.cpp:1831
CargoesField::vertical_cargoes
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or INVALID_CARGO).
Definition: industry_gui.cpp:1820
IndustryDirectoryWindow::cargo_filter_texts
StringID cargo_filter_texts[NUM_CARGO+3]
Texts for filter_cargo, terminated by INVALID_STRING_ID.
Definition: industry_gui.cpp:1263
newgrf_text.h
IndustryViewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:1084
CargoesField::industry
struct CargoesField::@17::@18 industry
Industry data (for CFT_INDUSTRY).
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:2841
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
IndustryCargoesWindow::VERT_TEXT_PADDING
static const int VERT_TEXT_PADDING
Vertical padding around the industry type text.
Definition: industry_gui.cpp:2373
CFT_SMALL_EMPTY
@ CFT_SMALL_EMPTY
Empty small field (for the header).
Definition: industry_gui.cpp:1786
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:494
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
IndustryViewWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: industry_gui.cpp:1058
CargoesField::Draw
void Draw(int xpos, int ypos) const
Draw the field.
Definition: industry_gui.cpp:1977
IndustryViewWindow::Editability
Editability
Modes for changing production.
Definition: industry_gui.cpp:745
WID_IC_SCROLLBAR
@ WID_IC_SCROLLBAR
Scrollbar of the panel.
Definition: industry_widget.h:46
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:71
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:204
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2419
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
IndustryCargoesWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:2458
RoundDivSU
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:276
IndustryCargoesWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:2777
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:110
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:82
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:218
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:107
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:233
IndustryDirectoryWindow::IndustryNameSorter
static bool IndustryNameSorter(const Industry *const &a, const Industry *const &b)
Sort industries by name.
Definition: industry_gui.cpp:1396
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
WID_IC_CAPTION
@ WID_IC_CAPTION
Caption of the window.
Definition: industry_widget.h:43
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:3259
CFT_CARGO_LABEL
@ CFT_CARGO_LABEL
Display cargo labels.
Definition: industry_gui.cpp:1789
CargoesField::normal_height
static int normal_height
Height of the non-header rows.
Definition: industry_gui.cpp:1807
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
viewport_func.h
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:173
Industry::text
std::string text
General text with additional information.
Definition: industry.h:101
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
CargoesField::small_height
static int small_height
Height of the header row.
Definition: industry_gui.cpp:1807
IACT_USERCREATION
@ IACT_USERCREATION
from the Fund/build window
Definition: newgrf_industries.h:85
OrthogonalTileArea::GetCenterTile
TileIndex GetCenterTile() const
Get the center tile.
Definition: tilearea_type.h:57
IndustryViewWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: industry_gui.cpp:936
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:75
WID_IC_IND_DROPDOWN
@ WID_IC_IND_DROPDOWN
Select industry dropdown.
Definition: industry_widget.h:48
CFT_EMPTY
@ CFT_EMPTY
Empty field.
Definition: industry_gui.cpp:1785
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:1629
IndustryViewWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:926
FILLRECT_OPAQUE
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition: gfx_type.h:287
IndustryViewWindow
Definition: industry_gui.cpp:742
Industry::last_month_pct_transported
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
Definition: industry.h:78
IndustryViewWindow::EA_RATE
@ EA_RATE
Allow changing the production rates.
Definition: industry_gui.cpp:748
CargoesField::VERT_CARGO_EDGE
static const int VERT_CARGO_EDGE
Amount of vertical space between top/bottom and the top/bottom connected cargo at an industry.
Definition: industry_gui.cpp:1801
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:60
CargoFilterSpecialType
CargoFilterSpecialType
Special cargo filter criteria.
Definition: industry_gui.cpp:1186
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
_nested_industry_directory_widgets
static const NWidgetPart _nested_industry_directory_widgets[]
Widget definition of the industry directory gui.
Definition: industry_gui.cpp:1157
IndustryDirectoryWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: industry_gui.cpp:1575
IndustryTemporarilyRefusesCargo
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Definition: newgrf_industries.cpp:676
IndustryCargoesWindow::OnTooltip
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition: industry_gui.cpp:2968
IndustryViewWindow::IL_MULTIPLIER
@ IL_MULTIPLIER
Production multiplier.
Definition: industry_gui.cpp:754
CargoesField::left_align
bool left_align
Align all cargo texts to the left (else align to the right).
Definition: industry_gui.cpp:1829
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:349
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:140
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CargoesField::cust_cargoes
CargoID cust_cargoes[MAX_CARGOES]
Cargoes leaving to the right (index in vertical_cargoes, or INVALID_CARGO).
Definition: industry_gui.cpp:1824
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
WID_IC_CARGO_DROPDOWN
@ WID_IC_CARGO_DROPDOWN
Select cargo dropdown.
Definition: industry_widget.h:47
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:224
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:46
CargoesField::MakeCargoLabel
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
Definition: industry_gui.cpp:1936
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
CF_ANY
@ CF_ANY
Show all industries (i.e. no filtering)
Definition: industry_gui.cpp:1187
IndustryViewWindow::IL_RATE1
@ IL_RATE1
Production rate of cargo 1.
Definition: industry_gui.cpp:755
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:378
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
WID_IC_PANEL
@ WID_IC_PANEL
Panel that shows the chain.
Definition: industry_widget.h:45
CargoesRow::columns
CargoesField columns[5]
One row of fields.
Definition: industry_gui.cpp:2237
CSD_CARGO_AMOUNT_TEXT
@ CSD_CARGO_AMOUNT_TEXT
Display then cargo, amount, and string (cb37 result 000-3FF).
Definition: industry_gui.cpp:62
CargoesField::MakeHeader
void MakeHeader(StringID textid)
Make a header above an industry column.
Definition: industry_gui.cpp:1949
BuildIndustryWindow::OnHundredthTick
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: industry_gui.cpp:675
_industry_directory_desc
static WindowDesc _industry_directory_desc(WDP_AUTO, "list_industries", 428, 190, WC_INDUSTRY_DIRECTORY, WC_NONE, 0, _nested_industry_directory_widgets, lengthof(_nested_industry_directory_widgets))
Window definition of the industry directory gui.
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:524
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
IndustryDirectoryWindow::GetCargoTransportedSortValue
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
Definition: industry_gui.cpp:1385
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:359
CargoesField::HOR_CARGO_SPACE
static const int HOR_CARGO_SPACE
Amount of horizontal space between two vertical cargoes.
Definition: industry_gui.cpp:1800
industry_widget.h
Backup::Restore
void Restore()
Restore the variable.
Definition: backup_type.hpp:112
IndustryViewWindow::editbox_line
InfoLine editbox_line
The line clicked to open the edit box.
Definition: industry_gui.cpp:760
INVALID_INDUSTRYTYPE
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
Definition: industry_type.h:27
CargoesField::num_cargoes
byte num_cargoes
Number of cargoes.
Definition: industry_gui.cpp:1821
CST_FUND
@ CST_FUND
Fund-industry window.
Definition: industry_gui.cpp:52
IndustryCargoesWindow::cargo_textsize
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
Definition: industry_gui.cpp:2379
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:177
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
CargoesFieldType
CargoesFieldType
Available types of field.
Definition: industry_gui.cpp:1784
WID_ID_INDUSTRY_LIST
@ WID_ID_INDUSTRY_LIST
Industry list.
Definition: industry_widget.h:37
BuildIndustryWindow::selected_type
IndustryType selected_type
industry corresponding to the above index
Definition: industry_gui.cpp:272
IndustryViewWindow::EA_NONE
@ EA_NONE
Not alterable.
Definition: industry_gui.cpp:746
IndustryCargoesWindow::ComputeCargoDisplay
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
Definition: industry_gui.cpp:2706
geometry_func.hpp
GUIList< const Industry *, 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:49
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:385
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:3337
IndustryDirectoryWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: industry_gui.cpp:1304
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
HZ_SUBARTC_ABOVE
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition: house.h:79
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:1934
IndustryDirectoryWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: industry_gui.cpp:1613
cheat_type.h
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:116
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:1808
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:165
IndustryCargoesWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: industry_gui.cpp:2880
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1856
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:493
WID_DPI_FUND_WIDGET
@ WID_DPI_FUND_WIDGET
Fund button.
Definition: industry_widget.h:19
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:141
CargoesField::VERT_INTER_INDUSTRY_SPACE
static const int VERT_INTER_INDUSTRY_SPACE
Amount of space between two industries in a column.
Definition: industry_gui.cpp:1797
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
CSD_CARGO_TEXT
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
Definition: industry_gui.cpp:61
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:761
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:127
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1149
IndustryDirectoryWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:1524
IndustryViewWindow::InfoLine
InfoLine
Specific lines in the info panel.
Definition: industry_gui.cpp:752
HouseSpec::building_availability
HouseZones building_availability
where can it be built (climates, zones)
Definition: house.h:110
BuildIndustryWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: industry_gui.cpp:402
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:70
CBM_IND_WINDOW_MORE_TEXT
@ CBM_IND_WINDOW_MORE_TEXT
additional text in industry window
Definition: newgrf_callbacks.h:356
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
_nested_industry_cargoes_widgets
static const NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
Definition: industry_gui.cpp:1747
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
IndustrySpec::callback_mask
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
Definition: industrytype.h:138
IndustryViewWindow::DrawInfo
int DrawInfo(uint left, uint right, uint top)
Draw the text in the WID_IV_INFO panel.
Definition: industry_gui.cpp:804
CargoesRow::ConnectIndustryAccepted
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
Definition: industry_gui.cpp:2301
GenerateIndustries
void GenerateIndustries()
This function will create random industries during game creation.
Definition: industry_cmd.cpp:2303
BuildIndustryWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: industry_gui.cpp:697
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:318
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
BuildIndustryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:707
network.h
WID_DPI_SCROLLBAR
@ WID_DPI_SCROLLBAR
Scrollbar of the matrix.
Definition: industry_widget.h:16
BuildIndustryWindow::index
IndustryType index[NUM_INDUSTRYTYPES+1]
Type of industry, in the order it was loaded.
Definition: industry_gui.cpp:274
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
BuildIndustryWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:477
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:2479
window_func.h
IndustrySpec::behaviour
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
Definition: industrytype.h:125
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
WID_ID_DROPDOWN_ORDER
@ WID_ID_DROPDOWN_ORDER
Dropdown for the order of the sort.
Definition: industry_widget.h:33
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:463
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:186
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:377
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:1980
HZ_TOYLND
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition: house.h:83
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:656
random_func.hpp
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
CargoSuffix
Transfer storage of cargo suffix information.
Definition: industry_gui.cpp:66
WID_ID_FILTER_BY_ACC_CARGO
@ WID_ID_FILTER_BY_ACC_CARGO
Accepted cargo filter dropdown list.
Definition: industry_widget.h:35
MemSetT
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49
WID_IV_INFO
@ WID_IV_INFO
Info of the industry.
Definition: industry_widget.h:26
HouseSpec
Definition: house.h:98
IndustryCargoesWindow::HOR_TEXT_PADDING
static const int HOR_TEXT_PADDING
Horizontal padding around the industry type text.
Definition: industry_gui.cpp:2373
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
CBID_INDUSTRY_WINDOW_MORE_TEXT
@ CBID_INDUSTRY_WINDOW_MORE_TEXT
Called to determine more text in the industry window.
Definition: newgrf_callbacks.h:171
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:625
IndustryDirectoryWindow::SetAcceptedCargoFilterIndex
void SetAcceptedCargoFilterIndex(byte index)
Set cargo filter list item index.
Definition: industry_gui.cpp:1288
HouseZones
HouseZones
Definition: house.h:71
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:754
CargoesField::ind_type
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
Definition: industry_gui.cpp:1815
BuildIndustryWindow::SetButtons
void SetButtons()
Update status of the fund and display-chain widgets.
Definition: industry_gui.cpp:331
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
gui.h
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
newgrf_industries.h
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:549
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:516
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:121
CargoSuffixType
CargoSuffixType
Cargo suffix type (for which window is it requested)
Definition: industry_gui.cpp:51
Window
Data structure for an opened window.
Definition: window_gui.h:276
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
IndustryViewWindow::clicked_button
byte clicked_button
The button that has been clicked (to raise)
Definition: industry_gui.cpp:762
Industry::accepts_cargo
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
Definition: industry.h:75
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:318
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:483
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:76
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:320
Industry::prod_level
byte prod_level
general production level
Definition: industry.h:74
IndustryDirectoryWindow::OnHundredthTick
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: industry_gui.cpp:1683
_industry_view_desc
static WindowDesc _industry_view_desc(WDP_AUTO, "view_industry", 260, 120, WC_INDUSTRY_VIEW, WC_NONE, 0, _nested_industry_view_widgets, lengthof(_nested_industry_view_widgets))
Window definition of the view industry gui.
Swap
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:215
settings_gui.h
CargoesField::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:1812
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:225
CargoesField::MakeEmpty
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
Definition: industry_gui.cpp:1838
IndustryCargoesWindow::ComputeIndustryDisplay
void ComputeIndustryDisplay(IndustryType it)
Compute what and where to display for industry type it.
Definition: industry_gui.cpp:2627
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:68
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
IndustryDirectoryWindow::accepted_cargo_filter_criteria
byte accepted_cargo_filter_criteria
Selected accepted cargo filter index.
Definition: industry_gui.cpp:1265
WID_ID_DROPDOWN_CRITERIA
@ WID_ID_DROPDOWN_CRITERIA
Dropdown for the criteria of the sort.
Definition: industry_widget.h:34
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:61
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
CargoesField::supp_cargoes
CargoID supp_cargoes[MAX_CARGOES]
Cargoes entering from the left (index in vertical_cargoes, or INVALID_CARGO).
Definition: industry_gui.cpp:1822
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1262
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:2123
CT_NO_REFIT
@ CT_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:67
HZ_SUBARTC_BELOW
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition: house.h:81
Industry::production_rate
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
Definition: industry.h:73
IndustryViewWindow::IL_RATE2
@ IL_RATE2
Production rate of cargo 2.
Definition: industry_gui.cpp:756
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:393
WD_PAR_VSEP_WIDE
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:138
IndustryDirectoryWindow::SetProducedCargoFilterIndex
void SetProducedCargoFilterIndex(byte index)
Set cargo filter list item index.
Definition: industry_gui.cpp:1271
WID_IV_VIEWPORT
@ WID_IV_VIEWPORT
Viewport of the industry.
Definition: industry_widget.h:25
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3421
BuildIndustryWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: industry_gui.cpp:641
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:281
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:97
CargoesField::top_end
byte top_end
Stop at the top of the vertical cargoes.
Definition: industry_gui.cpp:1823
cpp_lengthof
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
Definition: stdafx.h:414
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:2543
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:48
IndustryCargoesWindow::fields
Fields fields
Fields to display in the WID_IC_PANEL.
Definition: industry_gui.cpp:2377
IndustryCargoesWindow::NotifySmallmap
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
Definition: industry_gui.cpp:2614
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:60
IndustryViewWindow::info_height
int info_height
Height needed for the WID_IV_INFO panel.
Definition: industry_gui.cpp:764
CargoesField::HOR_CARGO_BORDER_SPACE
static const int HOR_CARGO_BORDER_SPACE
Amount of space between the left/right edge of a CFT_CARGO field, and the left/right most vertical ca...
Definition: industry_gui.cpp:1798
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
BuildIndustryWindow
Build (fund or prospect) a new industry,.
Definition: industry_gui.cpp:270
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
WID_ID_SCROLLBAR
@ WID_ID_SCROLLBAR
Scrollbar of the list.
Definition: industry_widget.h:38
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
WID_IV_DISPLAY
@ WID_IV_DISPLAY
Display chain button.
Definition: industry_widget.h:28
IndustryDirectoryWindow::IndustryProductionSorter
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b)
Sort industries by production and name.
Definition: industry_gui.cpp:1415
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:565
IndustryDirectoryWindow::produced_cargo_filter_criteria
byte produced_cargo_filter_criteria
Selected produced cargo filter index.
Definition: industry_gui.cpp:1264
CargoesField::other_accepted
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
Definition: industry_gui.cpp:1817
CF_NONE
@ CF_NONE
Show only industries which do not produce/accept cargo.
Definition: industry_gui.cpp:1188
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
TileHighlightData::GetCallbackWnd
Window * GetCallbackWnd()
Get the window that started the current highlighting.
Definition: viewport.cpp:2516
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:141
IndustryCargoesWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: industry_gui.cpp:2792
GetIndustryCallback
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
Definition: newgrf_industries.cpp:517
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
backup_type.hpp