OpenTTD Source  13.2.1
industry_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "error.h"
12 #include "gui.h"
13 #include "settings_gui.h"
14 #include "sound_func.h"
15 #include "window_func.h"
16 #include "textbuf_gui.h"
17 #include "command_func.h"
18 #include "viewport_func.h"
19 #include "industry.h"
20 #include "town.h"
21 #include "cheat_type.h"
22 #include "newgrf_industries.h"
23 #include "newgrf_text.h"
24 #include "newgrf_debug.h"
25 #include "network/network.h"
26 #include "strings_func.h"
27 #include "company_func.h"
28 #include "tilehighlight_func.h"
29 #include "string_func.h"
30 #include "sortlist_type.h"
31 #include "widgets/dropdown_func.h"
32 #include "company_base.h"
33 #include "core/geometry_func.hpp"
34 #include "core/random_func.hpp"
35 #include "core/backup_type.hpp"
36 #include "genworld.h"
37 #include "smallmap_gui.h"
38 #include "widgets/dropdown_type.h"
40 #include "clear_map.h"
41 #include "zoom_func.h"
42 #include "industry_cmd.h"
43 
44 #include "table/strings.h"
45 
46 #include <bitset>
47 
48 #include "safeguards.h"
49 
50 bool _ignore_restrictions;
51 std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
52 
58 };
59 
66 };
67 
69 struct CargoSuffix {
71  char text[512];
72 };
73 
74 static void ShowIndustryCargoesWindow(IndustryType id);
75 
85 static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix)
86 {
87  suffix.text[0] = '\0';
88  suffix.display = CSD_CARGO_AMOUNT;
89 
90  if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) {
91  TileIndex t = (cst != CST_FUND) ? ind->location.tile : INVALID_TILE;
92  uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast<Industry *>(ind), ind_type, t);
93  if (callback == CALLBACK_FAILED) return;
94 
95  if (indspec->grf_prop.grffile->grf_version < 8) {
96  if (GB(callback, 0, 8) == 0xFF) return;
97  if (callback < 0x400) {
99  GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text));
102  return;
103  }
105  return;
106 
107  } else { // GRF version 8 or higher.
108  if (callback == 0x400) return;
109  if (callback == 0x401) {
110  suffix.display = CSD_CARGO;
111  return;
112  }
113  if (callback < 0x400) {
115  GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text));
118  return;
119  }
120  if (callback >= 0x800 && callback < 0xC00) {
122  GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 - 0x800 + callback), lastof(suffix.text));
124  suffix.display = CSD_CARGO_TEXT;
125  return;
126  }
128  return;
129  }
130  }
131 }
132 
133 enum CargoSuffixInOut {
134  CARGOSUFFIX_OUT = 0,
135  CARGOSUFFIX_IN = 1,
136 };
137 
148 template <typename TC, typename TS>
149 static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
150 {
151  static_assert(lengthof(cargoes) <= lengthof(suffixes));
152 
154  /* Reworked behaviour with new many-in-many-out scheme */
155  for (uint j = 0; j < lengthof(suffixes); j++) {
156  if (cargoes[j] != CT_INVALID) {
157  byte local_id = indspec->grf_prop.grffile->cargo_map[cargoes[j]]; // should we check the value for valid?
158  uint cargotype = local_id << 16 | use_input;
159  GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffixes[j]);
160  } else {
161  suffixes[j].text[0] = '\0';
162  suffixes[j].display = CSD_CARGO;
163  }
164  }
165  } else {
166  /* Compatible behaviour with old 3-in-2-out scheme */
167  for (uint j = 0; j < lengthof(suffixes); j++) {
168  suffixes[j].text[0] = '\0';
169  suffixes[j].display = CSD_CARGO;
170  }
171  switch (use_input) {
172  case CARGOSUFFIX_OUT:
173  if (cargoes[0] != CT_INVALID) GetCargoSuffix(3, cst, ind, ind_type, indspec, suffixes[0]);
174  if (cargoes[1] != CT_INVALID) GetCargoSuffix(4, cst, ind, ind_type, indspec, suffixes[1]);
175  break;
176  case CARGOSUFFIX_IN:
177  if (cargoes[0] != CT_INVALID) GetCargoSuffix(0, cst, ind, ind_type, indspec, suffixes[0]);
178  if (cargoes[1] != CT_INVALID) GetCargoSuffix(1, cst, ind, ind_type, indspec, suffixes[1]);
179  if (cargoes[2] != CT_INVALID) GetCargoSuffix(2, cst, ind, ind_type, indspec, suffixes[2]);
180  break;
181  default:
182  NOT_REACHED();
183  }
184  }
185 }
186 
187 std::array<IndustryType, NUM_INDUSTRYTYPES> _sorted_industry_types;
188 
190 static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
191 {
192  static char industry_name[2][64];
193 
194  const IndustrySpec *indsp1 = GetIndustrySpec(a);
195  GetString(industry_name[0], indsp1->name, lastof(industry_name[0]));
196 
197  const IndustrySpec *indsp2 = GetIndustrySpec(b);
198  GetString(industry_name[1], indsp2->name, lastof(industry_name[1]));
199 
200  int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
201 
202  /* If the names are equal, sort by industry type. */
203  return (r != 0) ? r < 0 : (a < b);
204 }
205 
210 {
211  /* Add each industry type to the list. */
212  for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
213  _sorted_industry_types[i] = i;
214  }
215 
216  /* Sort industry types by name. */
218 }
219 
227 void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32, bool, uint32)
228 {
229  if (result.Succeeded()) return;
230 
231  if (indtype < NUM_INDUSTRYTYPES) {
232  const IndustrySpec *indsp = GetIndustrySpec(indtype);
233  if (indsp->enabled) {
234  SetDParam(0, indsp->name);
235  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, result.GetErrorMessage(), WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE);
236  }
237  }
238 }
239 
240 static const NWidgetPart _nested_build_industry_widgets[] = {
242  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
243  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FUND_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
244  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
245  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
246  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
247  EndContainer(),
251  SetDataTip(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP),
252  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET), SetMinimalSize(0, 12), SetFill(1, 0), SetResize(1, 0),
253  SetDataTip(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_TOOLTIP),
254  EndContainer(),
255  EndContainer(),
257  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),
258  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_DPI_SCROLLBAR),
259  EndContainer(),
260  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_DPI_INFOPANEL), SetResize(1, 0),
261  EndContainer(),
263  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_DISPLAY_WIDGET), SetFill(1, 0), SetResize(1, 0),
264  SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
265  NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_DPI_FUND_WIDGET), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
266  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
267  EndContainer(),
268 };
269 
272  WDP_AUTO, "build_industry", 170, 212,
275  _nested_build_industry_widgets, lengthof(_nested_build_industry_widgets)
276 );
277 
279 class BuildIndustryWindow : public Window {
281  IndustryType selected_type;
282  uint16 count;
283  IndustryType index[NUM_INDUSTRYTYPES + 1];
285  Scrollbar *vscroll;
287 
289  static const int MAX_MINWIDTH_LINEHEIGHTS = 20;
290 
291  void SetupArrays()
292  {
293  this->count = 0;
294 
295  for (uint i = 0; i < lengthof(this->index); i++) {
296  this->index[i] = INVALID_INDUSTRYTYPE;
297  this->enabled[i] = false;
298  }
299 
300  /* Fill the arrays with industries.
301  * The tests performed after the enabled allow to load the industries
302  * In the same way they are inserted by grf (if any)
303  */
304  for (IndustryType ind : _sorted_industry_types) {
305  const IndustrySpec *indsp = GetIndustrySpec(ind);
306  if (indsp->enabled) {
307  /* Rule is that editor mode loads all industries.
308  * In game mode, all non raw industries are loaded too
309  * and raw ones are loaded only when setting allows it */
310  if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
311  /* Unselect if the industry is no longer in the list */
312  if (this->selected_type == ind) this->selected_index = -1;
313  continue;
314  }
315  this->index[this->count] = ind;
316  this->enabled[this->count] = (_game_mode == GM_EDITOR) || GetIndustryProbabilityCallback(ind, IACT_USERCREATION, 1) > 0;
317  /* Keep the selection to the correct line */
318  if (this->selected_type == ind) this->selected_index = this->count;
319  this->count++;
320  }
321  }
322 
323  /* first industry type is selected if the current selection is invalid.
324  * I'll be damned if there are none available ;) */
325  if (this->selected_index == -1) {
326  this->selected_index = 0;
327  this->selected_type = this->index[0];
328  }
329 
330  this->vscroll->SetCount(this->count);
331  }
332 
334  void SetButtons()
335  {
336  this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled[this->selected_index]);
337  this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled[this->selected_index]);
338  }
339 
352  std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
353  {
354  std::string cargostring;
355  char buf[1024];
356  int numcargo = 0;
357  int firstcargo = -1;
358 
359  for (int j = 0; j < cargolistlen; j++) {
360  if (cargolist[j] == CT_INVALID) continue;
361  numcargo++;
362  if (firstcargo < 0) {
363  firstcargo = j;
364  continue;
365  }
366  SetDParam(0, CargoSpec::Get(cargolist[j])->name);
367  SetDParamStr(1, cargo_suffix[j].text);
368  GetString(buf, STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION, lastof(buf));
369  cargostring += buf;
370  }
371 
372  if (numcargo > 0) {
373  SetDParam(0, CargoSpec::Get(cargolist[firstcargo])->name);
374  SetDParamStr(1, cargo_suffix[firstcargo].text);
375  GetString(buf, prefixstr, lastof(buf));
376  cargostring = std::string(buf) + cargostring;
377  } else {
378  SetDParam(0, STR_JUST_NOTHING);
379  SetDParamStr(1, "");
380  GetString(buf, prefixstr, lastof(buf));
381  cargostring = std::string(buf);
382  }
383 
384  return cargostring;
385  }
386 
387 public:
389  {
390  this->selected_index = -1;
391  this->selected_type = INVALID_INDUSTRYTYPE;
392 
393  this->CreateNestedTree();
394  this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
395  this->FinishInitNested(0);
396 
397  this->SetButtons();
398 
399  /* Show scenario editor tools in editor. */
400  if (_game_mode != GM_EDITOR) {
401  auto *se_tools = this->GetWidget<NWidgetStacked>(WID_DPI_SCENARIO_EDITOR_PANE);
402  se_tools->SetDisplayedPlane(SZSP_HORIZONTAL);
403  this->ReInit();
404  }
405  }
406 
407  void OnInit() override
408  {
409  /* Width of the legend blob -- slightly larger than the smallmap legend blob. */
410  this->legend.height = FONT_HEIGHT_SMALL;
411  this->legend.width = this->legend.height * 8 / 5;
412 
413  this->SetupArrays();
414  }
415 
416  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
417  {
418  switch (widget) {
419  case WID_DPI_MATRIX_WIDGET: {
420  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
421  for (uint16 i = 0; i < this->count; i++) {
422  if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
423  d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
424  }
425  resize->height = std::max<uint>(this->legend.height, FONT_HEIGHT_NORMAL) + padding.height;
426  d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width;
427  d.height = 5 * resize->height;
428  *size = maxdim(*size, d);
429  break;
430  }
431 
432  case WID_DPI_INFOPANEL: {
433  /* Extra line for cost outside of editor. */
434  int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1);
435  uint extra_lines_req = 0;
436  uint extra_lines_prd = 0;
437  uint extra_lines_newgrf = 0;
438  uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
439  Dimension d = {0, 0};
440  for (uint16 i = 0; i < this->count; i++) {
441  if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
442 
443  const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
444  CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
445 
446  /* Measure the accepted cargoes, if any. */
447  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->index[i], indsp, indsp->accepts_cargo, cargo_suffix);
448  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
449  Dimension strdim = GetStringBoundingBox(cargostring.c_str());
450  if (strdim.width > max_minwidth) {
451  extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
452  strdim.width = max_minwidth;
453  }
454  d = maxdim(d, strdim);
455 
456  /* Measure the produced cargoes, if any. */
457  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->index[i], indsp, indsp->produced_cargo, cargo_suffix);
458  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
459  strdim = GetStringBoundingBox(cargostring.c_str());
460  if (strdim.width > max_minwidth) {
461  extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
462  strdim.width = max_minwidth;
463  }
464  d = maxdim(d, strdim);
465 
466  if (indsp->grf_prop.grffile != nullptr) {
467  /* Reserve a few extra lines for text from an industry NewGRF. */
468  extra_lines_newgrf = 4;
469  }
470  }
471 
472  /* Set it to something more sane :) */
473  height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
474  size->height = height * FONT_HEIGHT_NORMAL + padding.height;
475  size->width = d.width + padding.width;
476  break;
477  }
478 
479  case WID_DPI_FUND_WIDGET: {
480  Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
481  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY));
482  d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY));
483  d.width += padding.width;
484  d.height += padding.height;
485  *size = maxdim(*size, d);
486  break;
487  }
488  }
489  }
490 
491  void SetStringParameters(int widget) const override
492  {
493  switch (widget) {
494  case WID_DPI_FUND_WIDGET:
495  /* Raw industries might be prospected. Show this fact by changing the string
496  * In Editor, you just build, while ingame, or you fund or you prospect */
497  if (_game_mode == GM_EDITOR) {
498  /* We've chosen many random industries but no industries have been specified */
499  SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
500  } else {
501  if (count > 0) {
502  const IndustrySpec *indsp = GetIndustrySpec(this->index[this->selected_index]);
503  SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
504  } else {
505  SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
506  }
507  }
508  break;
509  }
510  }
511 
512  void DrawWidget(const Rect &r, int widget) const override
513  {
514  switch (widget) {
515  case WID_DPI_MATRIX_WIDGET: {
516  bool rtl = _current_text_dir == TD_RTL;
518  Rect icon = text.WithWidth(this->legend.width, rtl);
519  text = text.Indent(this->legend.width + WidgetDimensions::scaled.hsep_wide, rtl);
520 
521  /* Vertical offset for legend icon. */
522  icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
523  icon.bottom = icon.top + this->legend.height - 1;
524 
525  for (uint16 i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
526  bool selected = this->selected_index == i + this->vscroll->GetPosition();
527 
528  if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
529  DrawString(text, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
530  } else {
531  const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]);
532 
533  /* Draw the name of the industry in white is selected, otherwise, in orange */
534  DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE);
535  GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
537  }
538 
539  text = text.Translate(0, this->resize.step_height);
540  icon = icon.Translate(0, this->resize.step_height);
541  }
542  break;
543  }
544 
545  case WID_DPI_INFOPANEL: {
546  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
547 
548  if (this->selected_type == INVALID_INDUSTRYTYPE) {
549  DrawStringMultiLine(ir, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_TOOLTIP);
550  break;
551  }
552 
553  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
554 
555  if (_game_mode != GM_EDITOR) {
556  SetDParam(0, indsp->GetConstructionCost());
557  DrawString(ir, STR_FUND_INDUSTRY_INDUSTRY_BUILD_COST);
558  ir.top += FONT_HEIGHT_NORMAL;
559  }
560 
561  CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
562 
563  /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
564  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
565  std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
566  ir.top = DrawStringMultiLine(ir, cargostring);
567 
568  /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
569  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
570  cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
571  ir.top = DrawStringMultiLine(ir, cargostring);
572 
573  /* Get the additional purchase info text, if it has not already been queried. */
575  uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, nullptr, this->selected_type, INVALID_TILE);
576  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
577  if (callback_res > 0x400) {
579  } else {
580  StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
581  if (str != STR_UNDEFINED) {
583  DrawStringMultiLine(ir, str, TC_YELLOW);
585  }
586  }
587  }
588  }
589  break;
590  }
591  }
592  }
593 
594  static void AskManyRandomIndustriesCallback(Window *w, bool confirmed)
595  {
596  if (!confirmed) return;
597 
598  if (Town::GetNumItems() == 0) {
599  ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO);
600  } else {
601  extern void GenerateIndustries();
602  Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
606  old_generating_world.Restore();
607  }
608  }
609 
610  static void AskRemoveAllIndustriesCallback(Window *w, bool confirmed)
611  {
612  if (!confirmed) return;
613 
614  for (Industry *industry : Industry::Iterate()) delete industry;
615 
616  /* Clear farmland. */
617  for (TileIndex tile = 0; tile < MapSize(); tile++) {
618  if (IsTileType(tile, MP_CLEAR) && GetRawClearGround(tile) == CLEAR_FIELDS) {
619  MakeClear(tile, CLEAR_GRASS, 3);
620  }
621  }
622 
624  }
625 
626  void OnClick(Point pt, int widget, int click_count) override
627  {
628  switch (widget) {
630  assert(_game_mode == GM_EDITOR);
632  ShowQuery(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES_QUERY, nullptr, AskManyRandomIndustriesCallback);
633  break;
634  }
635 
637  assert(_game_mode == GM_EDITOR);
639  ShowQuery(STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_CAPTION, STR_FUND_INDUSTRY_REMOVE_ALL_INDUSTRIES_QUERY, nullptr, AskRemoveAllIndustriesCallback);
640  break;
641  }
642 
643  case WID_DPI_MATRIX_WIDGET: {
644  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_DPI_MATRIX_WIDGET);
645  if (y < this->count) { // Is it within the boundaries of available data?
646  this->selected_index = y;
647  this->selected_type = this->index[y];
648  const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type);
649 
650  this->SetDirty();
651 
652  if (_thd.GetCallbackWnd() == this &&
653  ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) ||
654  this->selected_type == INVALID_INDUSTRYTYPE ||
655  !this->enabled[this->selected_index])) {
656  /* Reset the button state if going to prospecting or "build many industries" */
657  this->RaiseButtons();
659  }
660 
661  this->SetButtons();
662  if (this->enabled[this->selected_index] && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
663  }
664  break;
665  }
666 
668  if (this->selected_type != INVALID_INDUSTRYTYPE) ShowIndustryCargoesWindow(this->selected_type);
669  break;
670 
671  case WID_DPI_FUND_WIDGET: {
672  if (this->selected_type != INVALID_INDUSTRYTYPE) {
673  if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && GetIndustrySpec(this->selected_type)->IsRawIndustry()) {
674  Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, 0, this->selected_type, 0, false, InteractiveRandom());
676  } else {
677  HandlePlacePushButton(this, WID_DPI_FUND_WIDGET, SPR_CURSOR_INDUSTRY, HT_RECT);
678  }
679  }
680  break;
681  }
682  }
683  }
684 
685  void OnResize() override
686  {
687  /* Adjust the number of items in the matrix depending of the resize */
688  this->vscroll->SetCapacityFromWidget(this, WID_DPI_MATRIX_WIDGET);
689  }
690 
691  void OnPlaceObject(Point pt, TileIndex tile) override
692  {
693  bool success = true;
694  /* We do not need to protect ourselves against "Random Many Industries" in this mode */
695  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
696  uint32 seed = InteractiveRandom();
697  uint32 layout_index = InteractiveRandomRange((uint32)indsp->layouts.size());
698 
699  if (_game_mode == GM_EDITOR) {
700  /* Show error if no town exists at all */
701  if (Town::GetNumItems() == 0) {
702  SetDParam(0, indsp->name);
703  ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO, pt.x, pt.y);
704  return;
705  }
706 
707  Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
708  Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
709  _ignore_restrictions = true;
710 
711  Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, &CcBuildIndustry, tile, this->selected_type, layout_index, false, seed);
712 
713  cur_company.Restore();
714  old_generating_world.Restore();
715  _ignore_restrictions = false;
716  } else {
717  success = Command<CMD_BUILD_INDUSTRY>::Post(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY, tile, this->selected_type, layout_index, false, seed);
718  }
719 
720  /* If an industry has been built, just reset the cursor and the system */
722  }
723 
724  void OnHundredthTick() override
725  {
726  if (_game_mode == GM_EDITOR) return;
727  if (this->count == 0) return;
728  const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
729 
730  if (indsp->enabled) {
731  bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
732 
733  /* Only if result does match the previous state would it require a redraw. */
734  if (call_back_result != this->enabled[this->selected_index]) {
735  this->enabled[this->selected_index] = call_back_result;
736  this->SetButtons();
737  this->SetDirty();
738  }
739  }
740  }
741 
742  void OnTimeout() override
743  {
744  this->RaiseButtons();
745  }
746 
747  void OnPlaceObjectAbort() override
748  {
749  this->RaiseButtons();
750  }
751 
757  void OnInvalidateData(int data = 0, bool gui_scope = true) override
758  {
759  if (!gui_scope) return;
760  this->SetupArrays();
761 
762  const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type);
763  if (indsp == nullptr) this->enabled[this->selected_index] = _settings_game.difficulty.industry_density != ID_FUND_ONLY;
764  this->SetButtons();
765  this->SetDirty();
766  }
767 };
768 
769 void ShowBuildIndustryWindow()
770 {
771  if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
773  new BuildIndustryWindow();
774 }
775 
776 static void UpdateIndustryProduction(Industry *i);
777 
778 static inline bool IsProductionAlterable(const Industry *i)
779 {
780  const IndustrySpec *is = GetIndustrySpec(i->type);
781  bool has_prod = false;
782  for (size_t j = 0; j < lengthof(is->production_rate); j++) {
783  if (is->production_rate[j] != 0) {
784  has_prod = true;
785  break;
786  }
787  }
788  return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
789  (has_prod || is->IsRawIndustry()) &&
790  !_networking);
791 }
792 
794 {
796  enum Editability {
800  };
801 
803  enum InfoLine {
808  };
809 
817 
818 public:
820  {
821  this->flags |= WF_DISABLE_VP_SCROLL;
822  this->editbox_line = IL_NONE;
823  this->clicked_line = IL_NONE;
824  this->clicked_button = 0;
825  this->info_height = WidgetDimensions::scaled.framerect.Vertical() + 2 * FONT_HEIGHT_NORMAL; // Info panel has at least two lines text.
826 
827  this->InitNested(window_number);
828  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
829  nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_INDUSTRY));
830 
831  this->InvalidateData();
832  }
833 
834  void OnInit() override
835  {
836  /* This only used when the cheat to alter industry production is enabled */
837  this->cheat_line_height = std::max(SETTING_BUTTON_HEIGHT + WidgetDimensions::scaled.vsep_normal, FONT_HEIGHT_NORMAL);
838  }
839 
840  void OnPaint() override
841  {
842  this->DrawWidgets();
843 
844  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
845 
846  const Rect r = this->GetWidget<NWidgetBase>(WID_IV_INFO)->GetCurrentRect();
847  int expected = this->DrawInfo(r);
848  if (expected != r.bottom) {
849  this->info_height = expected - r.top + 1;
850  this->ReInit();
851  return;
852  }
853  }
854 
860  int DrawInfo(const Rect &r)
861  {
862  bool rtl = _current_text_dir == TD_RTL;
864  const IndustrySpec *ind = GetIndustrySpec(i->type);
865  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
866  bool first = true;
867  bool has_accept = false;
868 
869  if (i->prod_level == PRODLEVEL_CLOSURE) {
870  DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
872  }
873 
874  CargoSuffix cargo_suffix[lengthof(i->accepts_cargo)];
875  GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
877 
878  for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
879  if (i->accepts_cargo[j] == CT_INVALID) continue;
880  has_accept = true;
881  if (first) {
882  DrawString(ir, STR_INDUSTRY_VIEW_REQUIRES);
883  ir.top += FONT_HEIGHT_NORMAL;
884  first = false;
885  }
887  SetDParam(1, i->accepts_cargo[j]);
889  SetDParamStr(3, "");
890  StringID str = STR_NULL;
891  switch (cargo_suffix[j].display) {
893  SetDParamStr(3, cargo_suffix[j].text);
894  FALLTHROUGH;
895  case CSD_CARGO_AMOUNT:
896  str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
897  break;
898 
899  case CSD_CARGO_TEXT:
900  SetDParamStr(3, cargo_suffix[j].text);
901  FALLTHROUGH;
902  case CSD_CARGO:
903  str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
904  break;
905 
906  default:
907  NOT_REACHED();
908  }
910  ir.top += FONT_HEIGHT_NORMAL;
911  }
912 
913  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, i->produced_cargo, cargo_suffix);
914  int line_height = this->editable == EA_RATE ? this->cheat_line_height : FONT_HEIGHT_NORMAL;
915  int text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
916  int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
917  first = true;
918  for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
919  if (i->produced_cargo[j] == CT_INVALID) continue;
920  if (first) {
921  if (has_accept) ir.top += WidgetDimensions::scaled.vsep_wide;
922  DrawString(ir, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
923  ir.top += FONT_HEIGHT_NORMAL;
924  if (this->editable == EA_RATE) this->production_offset_y = ir.top;
925  first = false;
926  }
927 
928  SetDParam(0, i->produced_cargo[j]);
930  SetDParamStr(2, cargo_suffix[j].text);
932  DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal : 0), rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_TRANSPORTED);
933  /* Let's put out those buttons.. */
934  if (this->editable == EA_RATE) {
935  DrawArrowButtons(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
936  i->production_rate[j] > 0, i->production_rate[j] < 255);
937  }
938  ir.top += line_height;
939  }
940 
941  /* Display production multiplier if editable */
942  if (this->editable == EA_MULTIPLIER) {
943  line_height = this->cheat_line_height;
944  text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
945  button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
947  this->production_offset_y = ir.top;
949  DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
950  DrawArrowButtons(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
952  ir.top += line_height;
953  }
954 
955  /* Get the extra message for the GUI */
957  uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
958  if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
959  if (callback_res > 0x400) {
961  } else {
962  StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
963  if (message != STR_NULL && message != STR_UNDEFINED) {
965 
967  /* Use all the available space left from where we stand up to the
968  * end of the window. We ALSO enlarge the window if needed, so we
969  * can 'go' wild with the bottom of the window. */
970  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, message, TC_BLACK);
972  }
973  }
974  }
975  }
976 
977  if (!i->text.empty()) {
978  SetDParamStr(0, i->text);
980  ir.top = DrawStringMultiLine(ir.left, ir.right, ir.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
981  }
982 
983  /* Return required bottom position, the last pixel row plus some padding. */
984  return ir.top - 1 + WidgetDimensions::scaled.framerect.bottom;
985  }
986 
987  void SetStringParameters(int widget) const override
988  {
989  if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
990  }
991 
992  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
993  {
994  if (widget == WID_IV_INFO) size->height = this->info_height;
995  }
996 
997  void OnClick(Point pt, int widget, int click_count) override
998  {
999  switch (widget) {
1000  case WID_IV_INFO: {
1001  Industry *i = Industry::Get(this->window_number);
1002  InfoLine line = IL_NONE;
1003 
1004  switch (this->editable) {
1005  case EA_NONE: break;
1006 
1007  case EA_MULTIPLIER:
1008  if (IsInsideBS(pt.y, this->production_offset_y, this->cheat_line_height)) line = IL_MULTIPLIER;
1009  break;
1010 
1011  case EA_RATE:
1012  if (pt.y >= this->production_offset_y) {
1013  int row = (pt.y - this->production_offset_y) / this->cheat_line_height;
1014  for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
1015  if (i->produced_cargo[j] == CT_INVALID) continue;
1016  row--;
1017  if (row < 0) {
1018  line = (InfoLine)(IL_RATE1 + j);
1019  break;
1020  }
1021  }
1022  }
1023  break;
1024  }
1025  if (line == IL_NONE) return;
1026 
1027  bool rtl = _current_text_dir == TD_RTL;
1028  Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(WidgetDimensions::scaled.hsep_indent, rtl);
1029 
1030  if (r.WithWidth(SETTING_BUTTON_WIDTH, rtl).Contains(pt)) {
1031  /* Clicked buttons, decrease or increase production */
1032  bool decrease = r.WithWidth(SETTING_BUTTON_WIDTH / 2, rtl).Contains(pt);
1033  switch (this->editable) {
1034  case EA_MULTIPLIER:
1035  if (decrease) {
1036  if (i->prod_level <= PRODLEVEL_MINIMUM) return;
1037  i->prod_level = std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
1038  } else {
1039  if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
1040  i->prod_level = std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
1041  }
1042  break;
1043 
1044  case EA_RATE:
1045  if (decrease) {
1046  if (i->production_rate[line - IL_RATE1] <= 0) return;
1047  i->production_rate[line - IL_RATE1] = std::max(i->production_rate[line - IL_RATE1] / 2, 0);
1048  } else {
1049  if (i->production_rate[line - IL_RATE1] >= 255) return;
1050  /* a zero production industry is unlikely to give anything but zero, so push it a little bit */
1051  int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
1052  i->production_rate[line - IL_RATE1] = std::min<uint>(new_prod, 255);
1053  }
1054  break;
1055 
1056  default: NOT_REACHED();
1057  }
1058 
1059  UpdateIndustryProduction(i);
1060  this->SetDirty();
1061  this->SetTimeout();
1062  this->clicked_line = line;
1063  this->clicked_button = (decrease ^ rtl) ? 1 : 2;
1065  /* clicked the text */
1066  this->editbox_line = line;
1067  switch (this->editable) {
1068  case EA_MULTIPLIER:
1070  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1071  break;
1072 
1073  case EA_RATE:
1074  SetDParam(0, i->production_rate[line - IL_RATE1] * 8);
1075  ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION, 10, this, CS_ALPHANUMERAL, QSF_NONE);
1076  break;
1077 
1078  default: NOT_REACHED();
1079  }
1080  }
1081  break;
1082  }
1083 
1084  case WID_IV_GOTO: {
1085  Industry *i = Industry::Get(this->window_number);
1086  if (_ctrl_pressed) {
1088  } else {
1090  }
1091  break;
1092  }
1093 
1094  case WID_IV_DISPLAY: {
1095  Industry *i = Industry::Get(this->window_number);
1097  break;
1098  }
1099  }
1100  }
1101 
1102  void OnTimeout() override
1103  {
1104  this->clicked_line = IL_NONE;
1105  this->clicked_button = 0;
1106  this->SetDirty();
1107  }
1108 
1109  void OnResize() override
1110  {
1111  if (this->viewport != nullptr) {
1112  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
1113  nvp->UpdateViewportCoordinates(this);
1114 
1115  ScrollWindowToTile(Industry::Get(this->window_number)->location.GetCenterTile(), this, true); // Re-center viewport.
1116  }
1117  }
1118 
1119  void OnQueryTextFinished(char *str) override
1120  {
1121  if (StrEmpty(str)) return;
1122 
1123  Industry *i = Industry::Get(this->window_number);
1124  uint value = atoi(str);
1125  switch (this->editbox_line) {
1126  case IL_NONE: NOT_REACHED();
1127 
1128  case IL_MULTIPLIER:
1130  break;
1131 
1132  default:
1133  i->production_rate[this->editbox_line - IL_RATE1] = ClampU(RoundDivSU(value, 8), 0, 255);
1134  break;
1135  }
1136  UpdateIndustryProduction(i);
1137  this->SetDirty();
1138  }
1139 
1145  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1146  {
1147  if (!gui_scope) return;
1148  const Industry *i = Industry::Get(this->window_number);
1149  if (IsProductionAlterable(i)) {
1150  const IndustrySpec *ind = GetIndustrySpec(i->type);
1151  this->editable = ind->UsesOriginalEconomy() ? EA_MULTIPLIER : EA_RATE;
1152  } else {
1153  this->editable = EA_NONE;
1154  }
1155  }
1156 
1157  bool IsNewGRFInspectable() const override
1158  {
1159  return ::IsNewGRFInspectable(GSF_INDUSTRIES, this->window_number);
1160  }
1161 
1162  void ShowNewGRFInspectWindow() const override
1163  {
1164  ::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->window_number);
1165  }
1166 };
1167 
1168 static void UpdateIndustryProduction(Industry *i)
1169 {
1170  const IndustrySpec *indspec = GetIndustrySpec(i->type);
1172 
1173  for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
1174  if (i->produced_cargo[j] != CT_INVALID) {
1175  i->last_month_production[j] = 8 * i->production_rate[j];
1176  }
1177  }
1178 }
1179 
1183  NWidget(WWT_CLOSEBOX, COLOUR_CREAM),
1184  NWidget(WWT_CAPTION, COLOUR_CREAM, WID_IV_CAPTION), SetDataTip(STR_INDUSTRY_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1185  NWidget(WWT_PUSHIMGBTN, COLOUR_CREAM, WID_IV_GOTO), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_INDUSTRY_VIEW_LOCATION_TOOLTIP),
1186  NWidget(WWT_DEBUGBOX, COLOUR_CREAM),
1187  NWidget(WWT_SHADEBOX, COLOUR_CREAM),
1188  NWidget(WWT_DEFSIZEBOX, COLOUR_CREAM),
1189  NWidget(WWT_STICKYBOX, COLOUR_CREAM),
1190  EndContainer(),
1191  NWidget(WWT_PANEL, COLOUR_CREAM),
1192  NWidget(WWT_INSET, COLOUR_CREAM), SetPadding(2, 2, 2, 2),
1193  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_IV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
1194  EndContainer(),
1195  EndContainer(),
1196  NWidget(WWT_PANEL, COLOUR_CREAM, WID_IV_INFO), SetMinimalSize(260, 0), SetMinimalTextLines(2, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
1197  EndContainer(),
1199  NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
1200  NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
1201  EndContainer(),
1202 };
1203 
1206  WDP_AUTO, "view_industry", 260, 120,
1208  0,
1210 );
1211 
1212 void ShowIndustryViewWindow(int industry)
1213 {
1214  AllocateWindowDescFront<IndustryViewWindow>(&_industry_view_desc, industry);
1215 }
1216 
1220  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1221  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_INDUSTRY_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1222  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1223  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1224  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1225  EndContainer(),
1229  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_ID_DROPDOWN_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
1230  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_DROPDOWN_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
1231  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_FILTER_BY_ACC_CARGO), SetMinimalSize(225, 12), SetFill(0, 1), SetDataTip(STR_INDUSTRY_DIRECTORY_ACCEPTED_CARGO_FILTER, STR_TOOLTIP_FILTER_CRITERIA),
1232  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_ID_FILTER_BY_PROD_CARGO), SetMinimalSize(225, 12), SetFill(0, 1), SetDataTip(STR_INDUSTRY_DIRECTORY_PRODUCED_CARGO_FILTER, STR_TOOLTIP_FILTER_CRITERIA),
1233  NWidget(WWT_PANEL, COLOUR_BROWN), SetResize(1, 0), EndContainer(),
1234  EndContainer(),
1235  NWidget(WWT_PANEL, COLOUR_BROWN, WID_ID_INDUSTRY_LIST), SetDataTip(0x0, STR_INDUSTRY_DIRECTORY_LIST_CAPTION), SetResize(1, 1), SetScrollbar(WID_ID_SCROLLBAR), EndContainer(),
1236  EndContainer(),
1238  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_ID_SCROLLBAR),
1239  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1240  EndContainer(),
1241  EndContainer(),
1242 };
1243 
1245 
1250 };
1251 
1259 static bool CDECL CargoFilter(const Industry * const *industry, const std::pair<CargoID, CargoID> &cargoes)
1260 {
1261  auto accepted_cargo = cargoes.first;
1262  auto produced_cargo = cargoes.second;
1263 
1264  bool accepted_cargo_matches;
1265 
1266  switch (accepted_cargo) {
1267  case CF_ANY:
1268  accepted_cargo_matches = true;
1269  break;
1270 
1271  case CF_NONE:
1272  accepted_cargo_matches = std::all_of(std::begin((*industry)->accepts_cargo), std::end((*industry)->accepts_cargo), [](CargoID cargo) {
1273  return cargo == CT_INVALID;
1274  });
1275  break;
1276 
1277  default:
1278  const auto &ac = (*industry)->accepts_cargo;
1279  accepted_cargo_matches = std::find(std::begin(ac), std::end(ac), accepted_cargo) != std::end(ac);
1280  break;
1281  }
1282 
1283  bool produced_cargo_matches;
1284 
1285  switch (produced_cargo) {
1286  case CF_ANY:
1287  produced_cargo_matches = true;
1288  break;
1289 
1290  case CF_NONE:
1291  produced_cargo_matches = std::all_of(std::begin((*industry)->produced_cargo), std::end((*industry)->produced_cargo), [](CargoID cargo) {
1292  return cargo == CT_INVALID;
1293  });
1294  break;
1295 
1296  default:
1297  const auto &pc = (*industry)->produced_cargo;
1298  produced_cargo_matches = std::find(std::begin(pc), std::end(pc), produced_cargo) != std::end(pc);
1299  break;
1300  }
1301 
1302  return accepted_cargo_matches && produced_cargo_matches;
1303 }
1304 
1305 static GUIIndustryList::FilterFunction * const _filter_funcs[] = { &CargoFilter };
1306 
1307 
1312 protected:
1313  /* Runtime saved values */
1314  static Listing last_sorting;
1315 
1316  /* Constants for sorting industries */
1317  static const StringID sorter_names[];
1318  static GUIIndustryList::SortFunction * const sorter_funcs[];
1319 
1320  GUIIndustryList industries;
1321  Scrollbar *vscroll;
1322 
1327  static CargoID produced_cargo_filter;
1328 
1329  enum class SorterType : uint8 {
1330  ByName,
1331  ByType,
1332  ByProduction,
1333  ByTransported,
1334  };
1335 
1341  {
1342  if (this->produced_cargo_filter_criteria != index) {
1343  this->produced_cargo_filter_criteria = index;
1344  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1345  bool is_filtering_necessary = this->cargo_filter[this->produced_cargo_filter_criteria] != CF_ANY || this->cargo_filter[this->accepted_cargo_filter_criteria] != CF_ANY;
1346 
1347  this->industries.SetFilterState(is_filtering_necessary);
1348  this->industries.SetFilterType(0);
1349  this->industries.ForceRebuild();
1350  }
1351  }
1352 
1358  {
1359  if (this->accepted_cargo_filter_criteria != index) {
1360  this->accepted_cargo_filter_criteria = index;
1361  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1362  bool is_filtering_necessary = this->cargo_filter[this->produced_cargo_filter_criteria] != CF_ANY || this->cargo_filter[this->accepted_cargo_filter_criteria] != CF_ANY;
1363 
1364  this->industries.SetFilterState(is_filtering_necessary);
1365  this->industries.SetFilterType(0);
1366  this->industries.ForceRebuild();
1367  }
1368  }
1369 
1374  {
1375  byte filter_items = 0;
1376 
1377  /* Add item for disabling filtering. */
1378  this->cargo_filter[filter_items] = CF_ANY;
1379  this->cargo_filter_texts[filter_items] = STR_INDUSTRY_DIRECTORY_FILTER_ALL_TYPES;
1380  this->produced_cargo_filter_criteria = filter_items;
1381  this->accepted_cargo_filter_criteria = filter_items;
1382  filter_items++;
1383 
1384  /* Add item for industries not producing anything, e.g. power plants */
1385  this->cargo_filter[filter_items] = CF_NONE;
1386  this->cargo_filter_texts[filter_items] = STR_INDUSTRY_DIRECTORY_FILTER_NONE;
1387  filter_items++;
1388 
1389  /* Collect available cargo types for filtering. */
1390  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1391  this->cargo_filter[filter_items] = cs->Index();
1392  this->cargo_filter_texts[filter_items] = cs->name;
1393  filter_items++;
1394  }
1395 
1396  /* Terminate the filter list. */
1397  this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
1398 
1399  this->industries.SetFilterFuncs(_filter_funcs);
1400 
1401  bool is_filtering_necessary = this->cargo_filter[this->produced_cargo_filter_criteria] != CF_ANY || this->cargo_filter[this->accepted_cargo_filter_criteria] != CF_ANY;
1402 
1403  this->industries.SetFilterState(is_filtering_necessary);
1404  }
1405 
1408  {
1409  if (this->industries.NeedRebuild()) {
1410  this->industries.clear();
1411 
1412  for (const Industry *i : Industry::Iterate()) {
1413  this->industries.push_back(i);
1414  }
1415 
1416  this->industries.shrink_to_fit();
1417  this->industries.RebuildDone();
1418  }
1419 
1420  auto filter = std::make_pair(this->cargo_filter[this->accepted_cargo_filter_criteria],
1421  this->cargo_filter[this->produced_cargo_filter_criteria]);
1422 
1423  this->industries.Filter(filter);
1424 
1425  IndustryDirectoryWindow::produced_cargo_filter = this->cargo_filter[this->produced_cargo_filter_criteria];
1426  this->industries.Sort();
1427 
1428  this->vscroll->SetCount((uint)this->industries.size()); // Update scrollbar as well.
1429 
1430  this->SetDirty();
1431  }
1432 
1440  static inline int GetCargoTransportedPercentsIfValid(const Industry *i, uint id)
1441  {
1442  assert(id < lengthof(i->produced_cargo));
1443 
1444  if (i->produced_cargo[id] == CT_INVALID) return -1;
1445  return ToPercent8(i->last_month_pct_transported[id]);
1446  }
1447 
1456  {
1457  CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1458  if (filter == CF_NONE) return 0;
1459 
1460  int percentage = 0, produced_cargo_count = 0;
1461  for (uint id = 0; id < lengthof(i->produced_cargo); id++) {
1462  if (filter == CF_ANY) {
1463  int transported = GetCargoTransportedPercentsIfValid(i, id);
1464  if (transported != -1) {
1465  produced_cargo_count++;
1466  percentage += transported;
1467  }
1468  if (produced_cargo_count == 0 && id == lengthof(i->produced_cargo) - 1 && percentage == 0) {
1469  return transported;
1470  }
1471  } else if (filter == i->produced_cargo[id]) {
1472  return GetCargoTransportedPercentsIfValid(i, id);
1473  }
1474  }
1475 
1476  if (produced_cargo_count == 0) return percentage;
1477  return percentage / produced_cargo_count;
1478  }
1479 
1481  static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b)
1482  {
1483  int r = strnatcmp(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
1484  if (r == 0) return a->index < b->index;
1485  return r < 0;
1486  }
1487 
1489  static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b)
1490  {
1491  int it_a = 0;
1492  while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
1493  int it_b = 0;
1494  while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
1495  int r = it_a - it_b;
1496  return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
1497  }
1498 
1500  static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b)
1501  {
1502  CargoID filter = IndustryDirectoryWindow::produced_cargo_filter;
1503  if (filter == CF_NONE) return IndustryTypeSorter(a, b);
1504 
1505  uint prod_a = 0, prod_b = 0;
1506  for (uint i = 0; i < lengthof(a->produced_cargo); i++) {
1507  if (filter == CF_ANY) {
1508  if (a->produced_cargo[i] != CT_INVALID) prod_a += a->last_month_production[i];
1509  if (b->produced_cargo[i] != CT_INVALID) prod_b += b->last_month_production[i];
1510  } else {
1511  if (a->produced_cargo[i] == filter) prod_a += a->last_month_production[i];
1512  if (b->produced_cargo[i] == filter) prod_b += b->last_month_production[i];
1513  }
1514  }
1515  int r = prod_a - prod_b;
1516 
1517  return (r == 0) ? IndustryTypeSorter(a, b) : r < 0;
1518  }
1519 
1521  static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b)
1522  {
1524  return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
1525  }
1526 
1533  {
1534  const IndustrySpec *indsp = GetIndustrySpec(i->type);
1535  byte p = 0;
1536 
1537  /* Industry name */
1538  SetDParam(p++, i->index);
1539 
1540  static CargoSuffix cargo_suffix[lengthof(i->produced_cargo)];
1541  GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_DIR, i, i->type, indsp, i->produced_cargo, cargo_suffix);
1542 
1543  /* Get industry productions (CargoID, production, suffix, transported) */
1544  struct CargoInfo {
1545  CargoID cargo_id;
1546  uint16 production;
1547  const char *suffix;
1548  uint transported;
1549  };
1550  std::vector<CargoInfo> cargos;
1551 
1552  for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
1553  if (i->produced_cargo[j] == CT_INVALID) continue;
1554  cargos.push_back({ i->produced_cargo[j], i->last_month_production[j], cargo_suffix[j].text, ToPercent8(i->last_month_pct_transported[j]) });
1555  }
1556 
1557  switch (static_cast<IndustryDirectoryWindow::SorterType>(this->industries.SortType())) {
1561  /* Sort by descending production, then descending transported */
1562  std::sort(cargos.begin(), cargos.end(), [](const CargoInfo &a, const CargoInfo &b) {
1563  if (a.production != b.production) return a.production > b.production;
1564  return a.transported > b.transported;
1565  });
1566  break;
1567 
1569  /* Sort by descending transported, then descending production */
1570  std::sort(cargos.begin(), cargos.end(), [](const CargoInfo &a, const CargoInfo &b) {
1571  if (a.transported != b.transported) return a.transported > b.transported;
1572  return a.production > b.production;
1573  });
1574  break;
1575  }
1576 
1577  /* If the produced cargo filter is active then move the filtered cargo to the beginning of the list,
1578  * because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */
1579  const CargoID cid = this->cargo_filter[this->produced_cargo_filter_criteria];
1580  if (cid != CF_ANY && cid != CF_NONE) {
1581  auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo &ci) -> bool {
1582  return ci.cargo_id == cid;
1583  });
1584  if (filtered_ci != cargos.end()) {
1585  std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1);
1586  }
1587  }
1588 
1589  /* Display first 3 cargos */
1590  for (size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
1591  CargoInfo ci = cargos[j];
1592  SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
1593  SetDParam(p++, ci.cargo_id);
1594  SetDParam(p++, ci.production);
1595  SetDParamStr(p++, ci.suffix);
1596  SetDParam(p++, ci.transported);
1597  }
1598 
1599  /* Undisplayed cargos if any */
1600  SetDParam(p++, cargos.size() - 3);
1601 
1602  /* Drawing the right string */
1603  switch (cargos.size()) {
1604  case 0: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
1605  case 1: return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
1606  case 2: return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
1607  case 3: return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
1608  default: return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
1609  }
1610  }
1611 
1612 public:
1613  IndustryDirectoryWindow(WindowDesc *desc, WindowNumber number) : Window(desc)
1614  {
1615  this->CreateNestedTree();
1616  this->vscroll = this->GetScrollbar(WID_ID_SCROLLBAR);
1617 
1618  this->industries.SetListing(this->last_sorting);
1619  this->industries.SetSortFuncs(IndustryDirectoryWindow::sorter_funcs);
1620  this->industries.ForceRebuild();
1621  this->BuildSortIndustriesList();
1622 
1623  this->FinishInitNested(0);
1624  }
1625 
1627  {
1628  this->last_sorting = this->industries.GetListing();
1629  }
1630 
1631  void OnInit() override
1632  {
1633  this->SetCargoFilterArray();
1634  }
1635 
1636  void SetStringParameters(int widget) const override
1637  {
1638  switch (widget) {
1640  SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]);
1641  break;
1642 
1644  SetDParam(0, this->cargo_filter_texts[this->accepted_cargo_filter_criteria]);
1645  break;
1646 
1648  SetDParam(0, this->cargo_filter_texts[this->produced_cargo_filter_criteria]);
1649  break;
1650  }
1651  }
1652 
1653  void DrawWidget(const Rect &r, int widget) const override
1654  {
1655  switch (widget) {
1656  case WID_ID_DROPDOWN_ORDER:
1657  this->DrawSortButtonState(widget, this->industries.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
1658  break;
1659 
1660  case WID_ID_INDUSTRY_LIST: {
1661  int n = 0;
1662  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
1663  if (this->industries.size() == 0) {
1664  DrawString(ir, STR_INDUSTRY_DIRECTORY_NONE);
1665  break;
1666  }
1667  TextColour tc;
1668  const CargoID acf_cid = this->cargo_filter[this->accepted_cargo_filter_criteria];
1669  for (uint i = this->vscroll->GetPosition(); i < this->industries.size(); i++) {
1670  tc = TC_FROMSTRING;
1671  if (acf_cid != CF_ANY && acf_cid != CF_NONE) {
1672  Industry *ind = const_cast<Industry *>(this->industries[i]);
1673  if (IndustryTemporarilyRefusesCargo(ind, acf_cid)) {
1674  tc = TC_GREY | TC_FORCED;
1675  }
1676  }
1677  DrawString(ir, this->GetIndustryString(this->industries[i]), tc);
1678 
1679  ir.top += this->resize.step_height;
1680  if (++n == this->vscroll->GetCapacity()) break; // max number of industries in 1 window
1681  }
1682  break;
1683  }
1684  }
1685  }
1686 
1687  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1688  {
1689  switch (widget) {
1690  case WID_ID_DROPDOWN_ORDER: {
1691  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1692  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1693  d.height += padding.height;
1694  *size = maxdim(*size, d);
1695  break;
1696  }
1697 
1698  case WID_ID_DROPDOWN_CRITERIA: {
1699  Dimension d = {0, 0};
1700  for (uint i = 0; IndustryDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
1701  d = maxdim(d, GetStringBoundingBox(IndustryDirectoryWindow::sorter_names[i]));
1702  }
1703  d.width += padding.width;
1704  d.height += padding.height;
1705  *size = maxdim(*size, d);
1706  break;
1707  }
1708 
1709  case WID_ID_INDUSTRY_LIST: {
1710  Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
1711  for (uint i = 0; i < this->industries.size(); i++) {
1712  d = maxdim(d, GetStringBoundingBox(this->GetIndustryString(this->industries[i])));
1713  }
1714  resize->height = d.height;
1715  d.height *= 5;
1716  d.width += padding.width;
1717  d.height += padding.height;
1718  *size = maxdim(*size, d);
1719  break;
1720  }
1721  }
1722  }
1723 
1724 
1725  void OnClick(Point pt, int widget, int click_count) override
1726  {
1727  switch (widget) {
1728  case WID_ID_DROPDOWN_ORDER:
1729  this->industries.ToggleSortOrder();
1730  this->SetDirty();
1731  break;
1732 
1734  ShowDropDownMenu(this, IndustryDirectoryWindow::sorter_names, this->industries.SortType(), WID_ID_DROPDOWN_CRITERIA, 0, 0);
1735  break;
1736 
1737  case WID_ID_FILTER_BY_ACC_CARGO: // Cargo filter dropdown
1738  ShowDropDownMenu(this, this->cargo_filter_texts, this->accepted_cargo_filter_criteria, WID_ID_FILTER_BY_ACC_CARGO, 0, 0);
1739  break;
1740 
1741  case WID_ID_FILTER_BY_PROD_CARGO: // Cargo filter dropdown
1742  ShowDropDownMenu(this, this->cargo_filter_texts, this->produced_cargo_filter_criteria, WID_ID_FILTER_BY_PROD_CARGO, 0, 0);
1743  break;
1744 
1745  case WID_ID_INDUSTRY_LIST: {
1746  uint p = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.top);
1747  if (p < this->industries.size()) {
1748  if (_ctrl_pressed) {
1749  ShowExtraViewportWindow(this->industries[p]->location.tile);
1750  } else {
1751  ScrollMainWindowToTile(this->industries[p]->location.tile);
1752  }
1753  }
1754  break;
1755  }
1756  }
1757  }
1758 
1759  void OnDropdownSelect(int widget, int index) override
1760  {
1761  switch (widget) {
1762  case WID_ID_DROPDOWN_CRITERIA: {
1763  if (this->industries.SortType() != index) {
1764  this->industries.SetSortType(index);
1765  this->BuildSortIndustriesList();
1766  }
1767  break;
1768  }
1769 
1771  this->SetAcceptedCargoFilterIndex(index);
1772  this->BuildSortIndustriesList();
1773  break;
1774  }
1775 
1777  this->SetProducedCargoFilterIndex(index);
1778  this->BuildSortIndustriesList();
1779  break;
1780  }
1781  }
1782  }
1783 
1784  void OnResize() override
1785  {
1786  this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
1787  }
1788 
1789  void OnPaint() override
1790  {
1791  if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
1792  this->DrawWidgets();
1793  }
1794 
1795  void OnHundredthTick() override
1796  {
1797  this->industries.ForceResort();
1798  this->BuildSortIndustriesList();
1799  }
1800 
1806  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1807  {
1808  switch (data) {
1809  case IDIWD_FORCE_REBUILD:
1810  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1811  this->industries.ForceRebuild();
1812  break;
1813 
1814  case IDIWD_PRODUCTION_CHANGE:
1815  if (this->industries.SortType() == 2) this->industries.ForceResort();
1816  break;
1817 
1818  default:
1819  this->industries.ForceResort();
1820  break;
1821  }
1822  }
1823 };
1824 
1825 Listing IndustryDirectoryWindow::last_sorting = {false, 0};
1826 
1827 /* Available station sorting functions. */
1828 GUIIndustryList::SortFunction * const IndustryDirectoryWindow::sorter_funcs[] = {
1829  &IndustryNameSorter,
1830  &IndustryTypeSorter,
1831  &IndustryProductionSorter,
1832  &IndustryTransportedCargoSorter
1833 };
1834 
1835 /* Names of the sorting functions */
1836 const StringID IndustryDirectoryWindow::sorter_names[] = {
1837  STR_SORT_BY_NAME,
1838  STR_SORT_BY_TYPE,
1839  STR_SORT_BY_PRODUCTION,
1840  STR_SORT_BY_TRANSPORTED,
1842 };
1843 
1844 CargoID IndustryDirectoryWindow::produced_cargo_filter = CF_ANY;
1845 
1846 
1849  WDP_AUTO, "list_industries", 428, 190,
1851  0,
1853 );
1854 
1855 void ShowIndustryDirectory()
1856 {
1857  AllocateWindowDescFront<IndustryDirectoryWindow>(&_industry_directory_desc, 0);
1858 }
1859 
1863  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1864  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_IC_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1865  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1866  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1867  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1868  EndContainer(),
1871  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_IC_SCROLLBAR),
1872  EndContainer(),
1874  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_IC_NOTIFY),
1875  SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
1876  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(0, 0), EndContainer(),
1877  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_IND_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1878  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY, STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP),
1879  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_IC_CARGO_DROPDOWN), SetFill(0, 0), SetResize(0, 0),
1880  SetDataTip(STR_INDUSTRY_CARGOES_SELECT_CARGO, STR_INDUSTRY_CARGOES_SELECT_CARGO_TOOLTIP),
1881  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1882  EndContainer(),
1883 };
1884 
1887  WDP_AUTO, "industry_cargoes", 300, 210,
1889  0,
1891 );
1892 
1901 };
1902 
1903 static const uint MAX_CARGOES = 16;
1904 
1908  static int blob_distance;
1909 
1915 
1916  static const int INDUSTRY_LINE_COLOUR;
1917  static const int CARGO_LINE_COLOUR;
1918 
1920  static int cargo_field_width;
1921  static int industry_width;
1922  static uint max_cargoes;
1923 
1925  union {
1926  struct {
1927  IndustryType ind_type;
1930  } industry;
1931  struct {
1935  byte top_end;
1937  byte bottom_end;
1938  } cargo;
1939  struct {
1941  bool left_align;
1942  } cargo_label;
1944  } u; // Data for each type.
1945 
1951  {
1952  this->type = type;
1953  }
1954 
1960  void MakeIndustry(IndustryType ind_type)
1961  {
1962  this->type = CFT_INDUSTRY;
1963  this->u.industry.ind_type = ind_type;
1964  MemSetT(this->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
1965  MemSetT(this->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
1966  }
1967 
1974  int ConnectCargo(CargoID cargo, bool producer)
1975  {
1976  assert(this->type == CFT_CARGO);
1977  if (cargo == INVALID_CARGO) return -1;
1978 
1979  /* Find the vertical cargo column carrying the cargo. */
1980  int column = -1;
1981  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
1982  if (cargo == this->u.cargo.vertical_cargoes[i]) {
1983  column = i;
1984  break;
1985  }
1986  }
1987  if (column < 0) return -1;
1988 
1989  if (producer) {
1990  assert(this->u.cargo.supp_cargoes[column] == INVALID_CARGO);
1991  this->u.cargo.supp_cargoes[column] = column;
1992  } else {
1993  assert(this->u.cargo.cust_cargoes[column] == INVALID_CARGO);
1994  this->u.cargo.cust_cargoes[column] = column;
1995  }
1996  return column;
1997  }
1998 
2004  {
2005  assert(this->type == CFT_CARGO);
2006 
2007  for (uint i = 0; i < MAX_CARGOES; i++) {
2008  if (this->u.cargo.supp_cargoes[i] != INVALID_CARGO) return true;
2009  if (this->u.cargo.cust_cargoes[i] != INVALID_CARGO) return true;
2010  }
2011  return false;
2012  }
2013 
2023  void MakeCargo(const CargoID *cargoes, uint length, int count = -1, bool top_end = false, bool bottom_end = false)
2024  {
2025  this->type = CFT_CARGO;
2026  uint i;
2027  uint num = 0;
2028  for (i = 0; i < MAX_CARGOES && i < length; i++) {
2029  if (cargoes[i] != INVALID_CARGO) {
2030  this->u.cargo.vertical_cargoes[num] = cargoes[i];
2031  num++;
2032  }
2033  }
2034  this->u.cargo.num_cargoes = (count < 0) ? num : count;
2035  for (; num < MAX_CARGOES; num++) this->u.cargo.vertical_cargoes[num] = INVALID_CARGO;
2036  this->u.cargo.top_end = top_end;
2037  this->u.cargo.bottom_end = bottom_end;
2038  MemSetT(this->u.cargo.supp_cargoes, INVALID_CARGO, MAX_CARGOES);
2039  MemSetT(this->u.cargo.cust_cargoes, INVALID_CARGO, MAX_CARGOES);
2040  }
2041 
2048  void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
2049  {
2050  this->type = CFT_CARGO_LABEL;
2051  uint i;
2052  for (i = 0; i < MAX_CARGOES && i < length; i++) this->u.cargo_label.cargoes[i] = cargoes[i];
2053  for (; i < MAX_CARGOES; i++) this->u.cargo_label.cargoes[i] = INVALID_CARGO;
2054  this->u.cargo_label.left_align = left_align;
2055  }
2056 
2061  void MakeHeader(StringID textid)
2062  {
2063  this->type = CFT_HEADER;
2064  this->u.header = textid;
2065  }
2066 
2072  int GetCargoBase(int xpos) const
2073  {
2074  assert(this->type == CFT_CARGO);
2075  int n = this->u.cargo.num_cargoes;
2076 
2077  return xpos + cargo_field_width / 2 - (CargoesField::cargo_line.width * n + CargoesField::cargo_space.width * (n - 1)) / 2;
2078  }
2079 
2085  void Draw(int xpos, int ypos) const
2086  {
2087  switch (this->type) {
2088  case CFT_EMPTY:
2089  case CFT_SMALL_EMPTY:
2090  break;
2091 
2092  case CFT_HEADER:
2093  ypos += (small_height - FONT_HEIGHT_NORMAL) / 2;
2094  DrawString(xpos, xpos + industry_width, ypos, this->u.header, TC_WHITE, SA_HOR_CENTER);
2095  break;
2096 
2097  case CFT_INDUSTRY: {
2098  int ypos1 = ypos + vert_inter_industry_space / 2;
2099  int ypos2 = ypos + normal_height - 1 - vert_inter_industry_space / 2;
2100  int xpos2 = xpos + industry_width - 1;
2101  GfxDrawLine(xpos, ypos1, xpos2, ypos1, INDUSTRY_LINE_COLOUR);
2102  GfxDrawLine(xpos, ypos1, xpos, ypos2, INDUSTRY_LINE_COLOUR);
2103  GfxDrawLine(xpos, ypos2, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
2104  GfxDrawLine(xpos2, ypos1, xpos2, ypos2, INDUSTRY_LINE_COLOUR);
2105  ypos += (normal_height - FONT_HEIGHT_NORMAL) / 2;
2106  if (this->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2107  const IndustrySpec *indsp = GetIndustrySpec(this->u.industry.ind_type);
2108  DrawString(xpos, xpos2, ypos, indsp->name, TC_WHITE, SA_HOR_CENTER);
2109 
2110  /* Draw the industry legend. */
2111  int blob_left, blob_right;
2112  if (_current_text_dir == TD_RTL) {
2113  blob_right = xpos2 - blob_distance;
2114  blob_left = blob_right - CargoesField::legend.width;
2115  } else {
2116  blob_left = xpos + blob_distance;
2117  blob_right = blob_left + CargoesField::legend.width;
2118  }
2119  GfxFillRect(blob_left, ypos2 - blob_distance - CargoesField::legend.height, blob_right, ypos2 - blob_distance, PC_BLACK); // Border
2120  GfxFillRect(blob_left + 1, ypos2 - blob_distance - CargoesField::legend.height + 1, blob_right - 1, ypos2 - blob_distance - 1, indsp->map_colour);
2121  } else {
2122  DrawString(xpos, xpos2, ypos, STR_INDUSTRY_CARGOES_HOUSES, TC_FROMSTRING, SA_HOR_CENTER);
2123  }
2124 
2125  /* Draw the other_produced/other_accepted cargoes. */
2126  const CargoID *other_right, *other_left;
2127  if (_current_text_dir == TD_RTL) {
2128  other_right = this->u.industry.other_accepted;
2129  other_left = this->u.industry.other_produced;
2130  } else {
2131  other_right = this->u.industry.other_produced;
2132  other_left = this->u.industry.other_accepted;
2133  }
2135  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2136  if (other_right[i] != INVALID_CARGO) {
2137  const CargoSpec *csp = CargoSpec::Get(other_right[i]);
2138  int xp = xpos + industry_width + CargoesField::cargo_stub.width;
2139  DrawHorConnection(xpos + industry_width, xp - 1, ypos1, csp);
2140  GfxDrawLine(xp, ypos1, xp, ypos1 + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2141  }
2142  if (other_left[i] != INVALID_CARGO) {
2143  const CargoSpec *csp = CargoSpec::Get(other_left[i]);
2144  int xp = xpos - CargoesField::cargo_stub.width;
2145  DrawHorConnection(xp + 1, xpos - 1, ypos1, csp);
2146  GfxDrawLine(xp, ypos1, xp, ypos1 + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2147  }
2149  }
2150  break;
2151  }
2152 
2153  case CFT_CARGO: {
2154  int cargo_base = this->GetCargoBase(xpos);
2155  int top = ypos + (this->u.cargo.top_end ? vert_inter_industry_space / 2 + 1 : 0);
2156  int bot = ypos - (this->u.cargo.bottom_end ? vert_inter_industry_space / 2 + 1 : 0) + normal_height - 1;
2157  int colpos = cargo_base;
2158  for (int i = 0; i < this->u.cargo.num_cargoes; i++) {
2159  if (this->u.cargo.top_end) GfxDrawLine(colpos, top - 1, colpos + CargoesField::cargo_line.width - 1, top - 1, CARGO_LINE_COLOUR);
2160  if (this->u.cargo.bottom_end) GfxDrawLine(colpos, bot + 1, colpos + CargoesField::cargo_line.width - 1, bot + 1, CARGO_LINE_COLOUR);
2161  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2162  colpos++;
2163  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[i]);
2164  GfxFillRect(colpos, top, colpos + CargoesField::cargo_line.width - 2, bot, csp->legend_colour, FILLRECT_OPAQUE);
2165  colpos += CargoesField::cargo_line.width - 2;
2166  GfxDrawLine(colpos, top, colpos, bot, CARGO_LINE_COLOUR);
2167  colpos += 1 + CargoesField::cargo_space.width;
2168  }
2169 
2170  const CargoID *hor_left, *hor_right;
2171  if (_current_text_dir == TD_RTL) {
2172  hor_left = this->u.cargo.cust_cargoes;
2173  hor_right = this->u.cargo.supp_cargoes;
2174  } else {
2175  hor_left = this->u.cargo.supp_cargoes;
2176  hor_right = this->u.cargo.cust_cargoes;
2177  }
2179  for (uint i = 0; i < MAX_CARGOES; i++) {
2180  if (hor_left[i] != INVALID_CARGO) {
2181  int col = hor_left[i];
2182  int dx = 0;
2183  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2184  for (; col > 0; col--) {
2185  int lf = cargo_base + col * CargoesField::cargo_line.width + (col - 1) * CargoesField::cargo_space.width;
2186  DrawHorConnection(lf, lf + CargoesField::cargo_space.width - dx, ypos, csp);
2187  dx = 1;
2188  }
2189  DrawHorConnection(xpos, cargo_base - dx, ypos, csp);
2190  }
2191  if (hor_right[i] != INVALID_CARGO) {
2192  int col = hor_right[i];
2193  int dx = 0;
2194  const CargoSpec *csp = CargoSpec::Get(this->u.cargo.vertical_cargoes[col]);
2195  for (; col < this->u.cargo.num_cargoes - 1; col++) {
2196  int lf = cargo_base + (col + 1) * CargoesField::cargo_line.width + col * CargoesField::cargo_space.width;
2197  DrawHorConnection(lf + dx - 1, lf + CargoesField::cargo_space.width - 1, ypos, csp);
2198  dx = 1;
2199  }
2200  DrawHorConnection(cargo_base + col * CargoesField::cargo_space.width + (col + 1) * CargoesField::cargo_line.width - 1 + dx, xpos + CargoesField::cargo_field_width - 1, ypos, csp);
2201  }
2203  }
2204  break;
2205  }
2206 
2207  case CFT_CARGO_LABEL:
2209  for (uint i = 0; i < MAX_CARGOES; i++) {
2210  if (this->u.cargo_label.cargoes[i] != INVALID_CARGO) {
2211  const CargoSpec *csp = CargoSpec::Get(this->u.cargo_label.cargoes[i]);
2212  DrawString(xpos + WidgetDimensions::scaled.framerect.left, xpos + industry_width - 1 - WidgetDimensions::scaled.framerect.right, ypos, csp->name, TC_WHITE,
2213  (this->u.cargo_label.left_align) ? SA_LEFT : SA_RIGHT);
2214  }
2216  }
2217  break;
2218 
2219  default:
2220  NOT_REACHED();
2221  }
2222  }
2223 
2231  CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
2232  {
2233  assert(this->type == CFT_CARGO);
2234 
2235  /* Vertical matching. */
2236  int cpos = this->GetCargoBase(0);
2237  uint col;
2238  for (col = 0; col < this->u.cargo.num_cargoes; col++) {
2239  if (pt.x < cpos) break;
2240  if (pt.x < cpos + (int)CargoesField::cargo_line.width) return this->u.cargo.vertical_cargoes[col];
2242  }
2243  /* col = 0 -> left of first col, 1 -> left of 2nd col, ... this->u.cargo.num_cargoes right of last-col. */
2244 
2246  uint row;
2247  for (row = 0; row < MAX_CARGOES; row++) {
2248  if (pt.y < vpos) return INVALID_CARGO;
2249  if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
2251  }
2252  if (row == MAX_CARGOES) return INVALID_CARGO;
2253 
2254  /* row = 0 -> at first horizontal row, row = 1 -> second horizontal row, 2 = 3rd horizontal row. */
2255  if (col == 0) {
2256  if (this->u.cargo.supp_cargoes[row] != INVALID_CARGO) return this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]];
2257  if (left != nullptr) {
2258  if (left->type == CFT_INDUSTRY) return left->u.industry.other_produced[row];
2259  if (left->type == CFT_CARGO_LABEL && !left->u.cargo_label.left_align) return left->u.cargo_label.cargoes[row];
2260  }
2261  return INVALID_CARGO;
2262  }
2263  if (col == this->u.cargo.num_cargoes) {
2264  if (this->u.cargo.cust_cargoes[row] != INVALID_CARGO) return this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]];
2265  if (right != nullptr) {
2266  if (right->type == CFT_INDUSTRY) return right->u.industry.other_accepted[row];
2267  if (right->type == CFT_CARGO_LABEL && right->u.cargo_label.left_align) return right->u.cargo_label.cargoes[row];
2268  }
2269  return INVALID_CARGO;
2270  }
2271  if (row >= col) {
2272  /* Clicked somewhere in-between vertical cargo connection.
2273  * Since the horizontal connection is made in the same order as the vertical list, the above condition
2274  * ensures we are left-below the main diagonal, thus at the supplying side.
2275  */
2276  return (this->u.cargo.supp_cargoes[row] != INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.supp_cargoes[row]] : INVALID_CARGO;
2277  } else {
2278  /* Clicked at a customer connection. */
2279  return (this->u.cargo.cust_cargoes[row] != INVALID_CARGO) ? this->u.cargo.vertical_cargoes[this->u.cargo.cust_cargoes[row]] : INVALID_CARGO;
2280  }
2281  }
2282 
2289  {
2290  assert(this->type == CFT_CARGO_LABEL);
2291 
2292  int vpos = vert_inter_industry_space / 2 + CargoesField::cargo_border.height;
2293  uint row;
2294  for (row = 0; row < MAX_CARGOES; row++) {
2295  if (pt.y < vpos) return INVALID_CARGO;
2296  if (pt.y < vpos + FONT_HEIGHT_NORMAL) break;
2298  }
2299  if (row == MAX_CARGOES) return INVALID_CARGO;
2300  return this->u.cargo_label.cargoes[row];
2301  }
2302 
2303 private:
2311  static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
2312  {
2313  GfxDrawLine(left, top, right, top, CARGO_LINE_COLOUR);
2314  GfxFillRect(left, top + 1, right, top + CargoesField::cargo_line.height - 2, csp->legend_colour, FILLRECT_OPAQUE);
2315  GfxDrawLine(left, top + CargoesField::cargo_line.height - 1, right, top + CargoesField::cargo_line.height - 1, CARGO_LINE_COLOUR);
2316  }
2317 };
2318 
2319 static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
2320 static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
2321 
2327 
2334 
2336 
2339 
2341 struct CargoesRow {
2343 
2348  void ConnectIndustryProduced(int column)
2349  {
2350  CargoesField *ind_fld = this->columns + column;
2351  CargoesField *cargo_fld = this->columns + column + 1;
2352  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2353 
2354  MemSetT(ind_fld->u.industry.other_produced, INVALID_CARGO, MAX_CARGOES);
2355 
2356  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2357  CargoID others[MAX_CARGOES]; // Produced cargoes not carried in the cargo column.
2358  int other_count = 0;
2359 
2360  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2361  assert(CargoesField::max_cargoes <= lengthof(indsp->produced_cargo));
2362  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2363  int col = cargo_fld->ConnectCargo(indsp->produced_cargo[i], true);
2364  if (col < 0) others[other_count++] = indsp->produced_cargo[i];
2365  }
2366 
2367  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
2368  for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2369  if (cargo_fld->u.cargo.supp_cargoes[i] == INVALID_CARGO) ind_fld->u.industry.other_produced[i] = others[--other_count];
2370  }
2371  } else {
2372  /* Houses only display what is demanded. */
2373  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2374  CargoID cid = cargo_fld->u.cargo.vertical_cargoes[i];
2375  if (cid == CT_PASSENGERS || cid == CT_MAIL) cargo_fld->ConnectCargo(cid, true);
2376  }
2377  }
2378  }
2379 
2385  void MakeCargoLabel(int column, bool accepting)
2386  {
2387  CargoID cargoes[MAX_CARGOES];
2388  MemSetT(cargoes, INVALID_CARGO, lengthof(cargoes));
2389 
2390  CargoesField *label_fld = this->columns + column;
2391  CargoesField *cargo_fld = this->columns + (accepting ? column - 1 : column + 1);
2392 
2393  assert(cargo_fld->type == CFT_CARGO && label_fld->type == CFT_EMPTY);
2394  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2395  int col = cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], !accepting);
2396  if (col >= 0) cargoes[col] = cargo_fld->u.cargo.vertical_cargoes[i];
2397  }
2398  label_fld->MakeCargoLabel(cargoes, lengthof(cargoes), accepting);
2399  }
2400 
2401 
2406  void ConnectIndustryAccepted(int column)
2407  {
2408  CargoesField *ind_fld = this->columns + column;
2409  CargoesField *cargo_fld = this->columns + column - 1;
2410  assert(ind_fld->type == CFT_INDUSTRY && cargo_fld->type == CFT_CARGO);
2411 
2412  MemSetT(ind_fld->u.industry.other_accepted, INVALID_CARGO, MAX_CARGOES);
2413 
2414  if (ind_fld->u.industry.ind_type < NUM_INDUSTRYTYPES) {
2415  CargoID others[MAX_CARGOES]; // Accepted cargoes not carried in the cargo column.
2416  int other_count = 0;
2417 
2418  const IndustrySpec *indsp = GetIndustrySpec(ind_fld->u.industry.ind_type);
2420  for (uint i = 0; i < CargoesField::max_cargoes; i++) {
2421  int col = cargo_fld->ConnectCargo(indsp->accepts_cargo[i], false);
2422  if (col < 0) others[other_count++] = indsp->accepts_cargo[i];
2423  }
2424 
2425  /* Allocate other cargoes in the empty holes of the horizontal cargo connections. */
2426  for (uint i = 0; i < CargoesField::max_cargoes && other_count > 0; i++) {
2427  if (cargo_fld->u.cargo.cust_cargoes[i] == INVALID_CARGO) ind_fld->u.industry.other_accepted[i] = others[--other_count];
2428  }
2429  } else {
2430  /* Houses only display what is demanded. */
2431  for (uint i = 0; i < cargo_fld->u.cargo.num_cargoes; i++) {
2432  for (uint h = 0; h < NUM_HOUSES; h++) {
2433  HouseSpec *hs = HouseSpec::Get(h);
2434  if (!hs->enabled) continue;
2435 
2436  for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
2437  if (hs->cargo_acceptance[j] > 0 && cargo_fld->u.cargo.vertical_cargoes[i] == hs->accepts_cargo[j]) {
2438  cargo_fld->ConnectCargo(cargo_fld->u.cargo.vertical_cargoes[i], false);
2439  goto next_cargo;
2440  }
2441  }
2442  }
2443 next_cargo: ;
2444  }
2445  }
2446  }
2447 };
2448 
2449 
2478  typedef std::vector<CargoesRow> Fields;
2479 
2480  Fields fields;
2481  uint ind_cargo;
2484  Scrollbar *vscroll;
2485 
2487  {
2488  this->OnInit();
2489  this->CreateNestedTree();
2490  this->vscroll = this->GetScrollbar(WID_IC_SCROLLBAR);
2491  this->FinishInitNested(0);
2492  this->OnInvalidateData(id);
2493  }
2494 
2495  void OnInit() override
2496  {
2497  /* Initialize static CargoesField size variables. */
2498  Dimension d = GetStringBoundingBox(STR_INDUSTRY_CARGOES_PRODUCERS);
2499  d = maxdim(d, GetStringBoundingBox(STR_INDUSTRY_CARGOES_CUSTOMERS));
2502  CargoesField::small_height = d.height;
2503 
2504  /* Size of the legend blob -- slightly larger than the smallmap legend blob. */
2506  CargoesField::legend.width = CargoesField::legend.height * 8 / 5;
2507 
2508  /* Size of cargo lines. */
2511 
2512  /* Size of border between cargo lines and industry boxes. */
2515 
2516  /* Size of space between cargo lines. */
2519 
2520  /* Size of cargo stub (unconnected cargo line.) */
2522  CargoesField::cargo_stub.height = CargoesField::cargo_line.height; /* Unused */
2523 
2526 
2527  /* Decide about the size of the box holding the text of an industry type. */
2528  this->ind_textsize.width = 0;
2529  this->ind_textsize.height = 0;
2531  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2532  const IndustrySpec *indsp = GetIndustrySpec(it);
2533  if (!indsp->enabled) continue;
2534  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
2535  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->accepts_cargo, endof(indsp->accepts_cargo), IsCargoIDValid));
2536  CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(indsp->produced_cargo, endof(indsp->produced_cargo), IsCargoIDValid));
2537  }
2538  d.width = std::max(d.width, this->ind_textsize.width);
2539  d.height = this->ind_textsize.height;
2540  this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_INDUSTRY));
2541 
2542  /* Compute max size of the cargo texts. */
2543  this->cargo_textsize.width = 0;
2544  this->cargo_textsize.height = 0;
2545  for (uint i = 0; i < NUM_CARGO; i++) {
2546  const CargoSpec *csp = CargoSpec::Get(i);
2547  if (!csp->IsValid()) continue;
2548  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(csp->name));
2549  }
2550  d = maxdim(d, this->cargo_textsize); // Box must also be wide enough to hold any cargo label.
2551  this->cargo_textsize = maxdim(this->cargo_textsize, GetStringBoundingBox(STR_INDUSTRY_CARGOES_SELECT_CARGO));
2552 
2554  /* Ensure the height is enough for the industry type text, for the horizontal connections, and for the cargo labels. */
2556  d.height = std::max(d.height + WidgetDimensions::scaled.frametext.Vertical(), min_ind_height);
2557 
2558  CargoesField::industry_width = d.width;
2560 
2561  /* Width of a #CFT_CARGO field. */
2563  }
2564 
2565  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2566  {
2567  switch (widget) {
2568  case WID_IC_PANEL:
2572  break;
2573 
2574  case WID_IC_IND_DROPDOWN:
2575  size->width = std::max(size->width, this->ind_textsize.width + padding.width);
2576  break;
2577 
2578  case WID_IC_CARGO_DROPDOWN:
2579  size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
2580  break;
2581  }
2582  }
2583 
2584 
2586  void SetStringParameters (int widget) const override
2587  {
2588  if (widget != WID_IC_CAPTION) return;
2589 
2590  if (this->ind_cargo < NUM_INDUSTRYTYPES) {
2591  const IndustrySpec *indsp = GetIndustrySpec(this->ind_cargo);
2592  SetDParam(0, indsp->name);
2593  } else {
2594  const CargoSpec *csp = CargoSpec::Get(this->ind_cargo - NUM_INDUSTRYTYPES);
2595  SetDParam(0, csp->name);
2596  }
2597  }
2598 
2607  static bool HasCommonValidCargo(const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
2608  {
2609  while (length1 > 0) {
2610  if (*cargoes1 != INVALID_CARGO) {
2611  for (uint i = 0; i < length2; i++) if (*cargoes1 == cargoes2[i]) return true;
2612  }
2613  cargoes1++;
2614  length1--;
2615  }
2616  return false;
2617  }
2618 
2625  static bool HousesCanSupply(const CargoID *cargoes, uint length)
2626  {
2627  for (uint i = 0; i < length; i++) {
2628  if (cargoes[i] == INVALID_CARGO) continue;
2629  if (cargoes[i] == CT_PASSENGERS || cargoes[i] == CT_MAIL) return true;
2630  }
2631  return false;
2632  }
2633 
2640  static bool HousesCanAccept(const CargoID *cargoes, uint length)
2641  {
2642  HouseZones climate_mask;
2644  case LT_TEMPERATE: climate_mask = HZ_TEMP; break;
2645  case LT_ARCTIC: climate_mask = HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW; break;
2646  case LT_TROPIC: climate_mask = HZ_SUBTROPIC; break;
2647  case LT_TOYLAND: climate_mask = HZ_TOYLND; break;
2648  default: NOT_REACHED();
2649  }
2650  for (uint i = 0; i < length; i++) {
2651  if (cargoes[i] == INVALID_CARGO) continue;
2652 
2653  for (uint h = 0; h < NUM_HOUSES; h++) {
2654  HouseSpec *hs = HouseSpec::Get(h);
2655  if (!hs->enabled || !(hs->building_availability & climate_mask)) continue;
2656 
2657  for (uint j = 0; j < lengthof(hs->accepts_cargo); j++) {
2658  if (hs->cargo_acceptance[j] > 0 && cargoes[i] == hs->accepts_cargo[j]) return true;
2659  }
2660  }
2661  }
2662  return false;
2663  }
2664 
2671  static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
2672  {
2673  int count = 0;
2674  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2675  const IndustrySpec *indsp = GetIndustrySpec(it);
2676  if (!indsp->enabled) continue;
2677 
2678  if (HasCommonValidCargo(cargoes, length, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) count++;
2679  }
2680  return count;
2681  }
2682 
2689  static int CountMatchingProducingIndustries(const CargoID *cargoes, uint length)
2690  {
2691  int count = 0;
2692  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2693  const IndustrySpec *indsp = GetIndustrySpec(it);
2694  if (!indsp->enabled) continue;
2695 
2696  if (HasCommonValidCargo(cargoes, length, indsp->produced_cargo, lengthof(indsp->produced_cargo))) count++;
2697  }
2698  return count;
2699  }
2700 
2707  void ShortenCargoColumn(int column, int top, int bottom)
2708  {
2709  while (top < bottom && !this->fields[top].columns[column].HasConnection()) {
2710  this->fields[top].columns[column].MakeEmpty(CFT_EMPTY);
2711  top++;
2712  }
2713  this->fields[top].columns[column].u.cargo.top_end = true;
2714 
2715  while (bottom > top && !this->fields[bottom].columns[column].HasConnection()) {
2716  this->fields[bottom].columns[column].MakeEmpty(CFT_EMPTY);
2717  bottom--;
2718  }
2719  this->fields[bottom].columns[column].u.cargo.bottom_end = true;
2720  }
2721 
2728  void PlaceIndustry(int row, int col, IndustryType it)
2729  {
2730  assert(this->fields[row].columns[col].type == CFT_EMPTY);
2731  this->fields[row].columns[col].MakeIndustry(it);
2732  if (col == 0) {
2733  this->fields[row].ConnectIndustryProduced(col);
2734  } else {
2735  this->fields[row].ConnectIndustryAccepted(col);
2736  }
2737  }
2738 
2743  {
2744  if (!this->IsWidgetLowered(WID_IC_NOTIFY)) return;
2745 
2746  /* Only notify the smallmap window if it exists. In particular, do not
2747  * bring it to the front to prevent messing up any nice layout of the user. */
2749  }
2750 
2755  void ComputeIndustryDisplay(IndustryType displayed_it)
2756  {
2757  this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
2758  this->ind_cargo = displayed_it;
2759  _displayed_industries.reset();
2760  _displayed_industries.set(displayed_it);
2761 
2762  this->fields.clear();
2763  CargoesRow &row = this->fields.emplace_back();
2764  row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
2768  row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
2769 
2770  const IndustrySpec *central_sp = GetIndustrySpec(displayed_it);
2771  bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
2772  bool houses_accept = HousesCanAccept(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
2773  /* Make a field consisting of two cargo columns. */
2774  int num_supp = CountMatchingProducingIndustries(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)) + houses_supply;
2775  int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
2776  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.
2777  for (int i = 0; i < num_indrows; i++) {
2778  CargoesRow &row = this->fields.emplace_back();
2779  row.columns[0].MakeEmpty(CFT_EMPTY);
2780  row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
2781  row.columns[2].MakeEmpty(CFT_EMPTY);
2782  row.columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
2783  row.columns[4].MakeEmpty(CFT_EMPTY);
2784  }
2785  /* Add central industry. */
2786  int central_row = 1 + num_indrows / 2;
2787  this->fields[central_row].columns[2].MakeIndustry(displayed_it);
2788  this->fields[central_row].ConnectIndustryProduced(2);
2789  this->fields[central_row].ConnectIndustryAccepted(2);
2790 
2791  /* Add cargo labels. */
2792  this->fields[central_row - 1].MakeCargoLabel(2, true);
2793  this->fields[central_row + 1].MakeCargoLabel(2, false);
2794 
2795  /* Add suppliers and customers of the 'it' industry. */
2796  int supp_count = 0;
2797  int cust_count = 0;
2798  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2799  const IndustrySpec *indsp = GetIndustrySpec(it);
2800  if (!indsp->enabled) continue;
2801 
2802  if (HasCommonValidCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo), indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
2803  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2804  _displayed_industries.set(it);
2805  supp_count++;
2806  }
2807  if (HasCommonValidCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo), indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
2808  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
2809  _displayed_industries.set(it);
2810  cust_count++;
2811  }
2812  }
2813  if (houses_supply) {
2814  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2815  supp_count++;
2816  }
2817  if (houses_accept) {
2818  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, NUM_INDUSTRYTYPES);
2819  cust_count++;
2820  }
2821 
2822  this->ShortenCargoColumn(1, 1, num_indrows);
2823  this->ShortenCargoColumn(3, 1, num_indrows);
2824  this->vscroll->SetCount(num_indrows);
2825  this->SetDirty();
2826  this->NotifySmallmap();
2827  }
2828 
2834  {
2835  this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
2836  this->ind_cargo = cid + NUM_INDUSTRYTYPES;
2837  _displayed_industries.reset();
2838 
2839  this->fields.clear();
2840  CargoesRow &row = this->fields.emplace_back();
2841  row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
2843  row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
2846 
2847  bool houses_supply = HousesCanSupply(&cid, 1);
2848  bool houses_accept = HousesCanAccept(&cid, 1);
2849  int num_supp = CountMatchingProducingIndustries(&cid, 1) + houses_supply + 1; // Ensure room for the cargo label.
2850  int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
2851  int num_indrows = std::max(num_supp, num_cust);
2852  for (int i = 0; i < num_indrows; i++) {
2853  CargoesRow &row = this->fields.emplace_back();
2854  row.columns[0].MakeEmpty(CFT_EMPTY);
2855  row.columns[1].MakeCargo(&cid, 1);
2856  row.columns[2].MakeEmpty(CFT_EMPTY);
2857  row.columns[3].MakeEmpty(CFT_EMPTY);
2858  row.columns[4].MakeEmpty(CFT_EMPTY);
2859  }
2860 
2861  this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
2862 
2863  /* Add suppliers and customers of the cargo. */
2864  int supp_count = 0;
2865  int cust_count = 0;
2866  for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
2867  const IndustrySpec *indsp = GetIndustrySpec(it);
2868  if (!indsp->enabled) continue;
2869 
2870  if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
2871  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
2872  _displayed_industries.set(it);
2873  supp_count++;
2874  }
2875  if (HasCommonValidCargo(&cid, 1, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
2876  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
2877  _displayed_industries.set(it);
2878  cust_count++;
2879  }
2880  }
2881  if (houses_supply) {
2882  this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, NUM_INDUSTRYTYPES);
2883  supp_count++;
2884  }
2885  if (houses_accept) {
2886  this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, NUM_INDUSTRYTYPES);
2887  cust_count++;
2888  }
2889 
2890  this->ShortenCargoColumn(1, 1, num_indrows);
2891  this->vscroll->SetCount(num_indrows);
2892  this->SetDirty();
2893  this->NotifySmallmap();
2894  }
2895 
2903  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2904  {
2905  if (!gui_scope) return;
2906  if (data == NUM_INDUSTRYTYPES) {
2907  if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
2908  this->RaiseWidget(WID_IC_NOTIFY);
2910  }
2911  return;
2912  }
2913 
2914  assert(data >= 0 && data < NUM_INDUSTRYTYPES);
2915  this->ComputeIndustryDisplay(data);
2916  }
2917 
2918  void DrawWidget(const Rect &r, int widget) const override
2919  {
2920  if (widget != WID_IC_PANEL) return;
2921 
2922  Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
2923  DrawPixelInfo tmp_dpi, *old_dpi;
2924  if (!FillDrawPixelInfo(&tmp_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return;
2925  old_dpi = _cur_dpi;
2926  _cur_dpi = &tmp_dpi;
2927 
2928  int left_pos = ir.left;
2929  if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2;
2930  int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
2931 
2932  const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2933  int vpos = -this->vscroll->GetPosition() * nwp->resize_y;
2934  for (uint i = 0; i < this->fields.size(); i++) {
2935  int row_height = (i == 0) ? CargoesField::small_height : CargoesField::normal_height;
2936  if (vpos + row_height >= 0) {
2937  int xpos = left_pos;
2938  int col, dir;
2939  if (_current_text_dir == TD_RTL) {
2940  col = last_column;
2941  dir = -1;
2942  } else {
2943  col = 0;
2944  dir = 1;
2945  }
2946  while (col >= 0 && col <= last_column) {
2947  this->fields[i].columns[col].Draw(xpos, vpos);
2949  col += dir;
2950  }
2951  }
2952  vpos += row_height;
2953  if (vpos >= height) break;
2954  }
2955 
2956  _cur_dpi = old_dpi;
2957  }
2958 
2966  bool CalculatePositionInWidget(Point pt, Point *fieldxy, Point *xy)
2967  {
2968  const NWidgetBase *nw = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
2969  pt.x -= nw->pos_x;
2970  pt.y -= nw->pos_y;
2971 
2972  int vpos = WidgetDimensions::scaled.framerect.top + CargoesField::small_height - this->vscroll->GetPosition() * nw->resize_y;
2973  if (pt.y < vpos) return false;
2974 
2975  int row = (pt.y - vpos) / CargoesField::normal_height; // row is relative to row 1.
2976  if (row + 1 >= (int)this->fields.size()) return false;
2977  vpos = pt.y - vpos - row * CargoesField::normal_height; // Position in the row + 1 field
2978  row++; // rebase row to match index of this->fields.
2979 
2981  if (pt.x < xpos) return false;
2982  int column;
2983  for (column = 0; column <= 5; column++) {
2985  if (pt.x < xpos + width) break;
2986  xpos += width;
2987  }
2988  int num_columns = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
2989  if (column > num_columns) return false;
2990  xpos = pt.x - xpos;
2991 
2992  /* Return both positions, compensating for RTL languages (which works due to the equal symmetry in both displays). */
2993  fieldxy->y = row;
2994  xy->y = vpos;
2995  if (_current_text_dir == TD_RTL) {
2996  fieldxy->x = num_columns - column;
2997  xy->x = ((column & 1) ? CargoesField::cargo_field_width : CargoesField::industry_width) - xpos;
2998  } else {
2999  fieldxy->x = column;
3000  xy->x = xpos;
3001  }
3002  return true;
3003  }
3004 
3005  void OnClick(Point pt, int widget, int click_count) override
3006  {
3007  switch (widget) {
3008  case WID_IC_PANEL: {
3009  Point fieldxy, xy;
3010  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return;
3011 
3012  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3013  switch (fld->type) {
3014  case CFT_INDUSTRY:
3015  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES) this->ComputeIndustryDisplay(fld->u.industry.ind_type);
3016  break;
3017 
3018  case CFT_CARGO: {
3019  CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
3020  CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
3021  CargoID cid = fld->CargoClickedAt(lft, rgt, xy);
3022  if (cid != INVALID_CARGO) this->ComputeCargoDisplay(cid);
3023  break;
3024  }
3025 
3026  case CFT_CARGO_LABEL: {
3027  CargoID cid = fld->CargoLabelClickedAt(xy);
3028  if (cid != INVALID_CARGO) this->ComputeCargoDisplay(cid);
3029  break;
3030  }
3031 
3032  default:
3033  break;
3034  }
3035  break;
3036  }
3037 
3038  case WID_IC_NOTIFY:
3041  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
3042 
3043  if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
3044  if (FindWindowByClass(WC_SMALLMAP) == nullptr) ShowSmallMap();
3045  this->NotifySmallmap();
3046  }
3047  break;
3048 
3049  case WID_IC_CARGO_DROPDOWN: {
3050  DropDownList lst;
3051  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
3052  lst.emplace_back(new DropDownListStringItem(cs->name, cs->Index(), false));
3053  }
3054  if (!lst.empty()) {
3055  int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1;
3056  ShowDropDownList(this, std::move(lst), selected, WID_IC_CARGO_DROPDOWN, 0, true);
3057  }
3058  break;
3059  }
3060 
3061  case WID_IC_IND_DROPDOWN: {
3062  DropDownList lst;
3063  for (IndustryType ind : _sorted_industry_types) {
3064  const IndustrySpec *indsp = GetIndustrySpec(ind);
3065  if (!indsp->enabled) continue;
3066  lst.emplace_back(new DropDownListStringItem(indsp->name, ind, false));
3067  }
3068  if (!lst.empty()) {
3069  int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1;
3070  ShowDropDownList(this, std::move(lst), selected, WID_IC_IND_DROPDOWN, 0, true);
3071  }
3072  break;
3073  }
3074  }
3075  }
3076 
3077  void OnDropdownSelect(int widget, int index) override
3078  {
3079  if (index < 0) return;
3080 
3081  switch (widget) {
3082  case WID_IC_CARGO_DROPDOWN:
3083  this->ComputeCargoDisplay(index);
3084  break;
3085 
3086  case WID_IC_IND_DROPDOWN:
3087  this->ComputeIndustryDisplay(index);
3088  break;
3089  }
3090  }
3091 
3092  bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
3093  {
3094  if (widget != WID_IC_PANEL) return false;
3095 
3096  Point fieldxy, xy;
3097  if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
3098 
3099  const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
3100  CargoID cid = INVALID_CARGO;
3101  switch (fld->type) {
3102  case CFT_CARGO: {
3103  CargoesField *lft = (fieldxy.x > 0) ? this->fields[fieldxy.y].columns + fieldxy.x - 1 : nullptr;
3104  CargoesField *rgt = (fieldxy.x < 4) ? this->fields[fieldxy.y].columns + fieldxy.x + 1 : nullptr;
3105  cid = fld->CargoClickedAt(lft, rgt, xy);
3106  break;
3107  }
3108 
3109  case CFT_CARGO_LABEL: {
3110  cid = fld->CargoLabelClickedAt(xy);
3111  break;
3112  }
3113 
3114  case CFT_INDUSTRY:
3115  if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
3116  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0, nullptr, close_cond);
3117  }
3118  return true;
3119 
3120  default:
3121  break;
3122  }
3123  if (cid != INVALID_CARGO && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) {
3124  const CargoSpec *csp = CargoSpec::Get(cid);
3125  uint64 params[5];
3126  params[0] = csp->name;
3127  GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, close_cond);
3128  return true;
3129  }
3130 
3131  return false;
3132  }
3133 
3134  void OnResize() override
3135  {
3137  }
3138 };
3139 
3144 static void ShowIndustryCargoesWindow(IndustryType id)
3145 {
3146  if (id >= NUM_INDUSTRYTYPES) {
3147  for (IndustryType ind : _sorted_industry_types) {
3148  const IndustrySpec *indsp = GetIndustrySpec(ind);
3149  if (indsp->enabled) {
3150  id = ind;
3151  break;
3152  }
3153  }
3154  if (id >= NUM_INDUSTRYTYPES) return;
3155  }
3156 
3158  if (w != nullptr) {
3159  w->InvalidateData(id);
3160  return;
3161  }
3162  new IndustryCargoesWindow(id);
3163 }
3164 
3167 {
3169 }
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition: industry_gui.cpp:187
PC_WHITE
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:245
CargoesField::cargo_label
struct CargoesField::@17::@20 cargo_label
Label data (for CFT_CARGO_LABEL).
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
TC_FORCED
@ TC_FORCED
Ignore colour changes from strings.
Definition: gfx_type.h:278
INVALID_CARGO
static const byte INVALID_CARGO
Constant representing invalid cargo.
Definition: cargotype.h:54
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:992
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:2689
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:295
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:282
WID_DPI_DISPLAY_WIDGET
@ WID_DPI_DISPLAY_WIDGET
Display chain button.
Definition: industry_widget.h:21
IndustryDirectoryWindow::SorterType::ByName
@ ByName
Sorter type to sort by name.
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:2640
ID_FUND_ONLY
@ ID_FUND_ONLY
The game does not build industries.
Definition: settings_type.h:54
CBM_IND_PRODUCTION_CARGO_ARRIVAL
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
Definition: newgrf_callbacks.h:353
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
Definition: industry_type.h:26
IndustrySpec::map_colour
byte map_colour
colour used for the small map
Definition: industrytype.h:126
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:85
CBM_IND_CARGO_SUFFIX
@ CBM_IND_CARGO_SUFFIX
cargo sub-type display
Definition: newgrf_callbacks.h:358
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:337
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2456
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:3053
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:2023
WC_INDUSTRY_CARGOES
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
Definition: window_type.h:503
IndustryCargoesWindow::HousesCanSupply
static bool HousesCanSupply(const CargoID *cargoes, uint length)
Can houses be used to supply one of the cargoes?
Definition: industry_gui.cpp:2625
IndustryTypeNameSorter
static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
Sort industry types by their name.
Definition: industry_gui.cpp:190
CargoesField::INDUSTRY_LINE_COLOUR
static const int INDUSTRY_LINE_COLOUR
Line colour of the industry type box.
Definition: industry_gui.cpp:1916
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
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:407
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:253
IndustryCargoesWindow::ComputeIndustryDisplay
void ComputeIndustryDisplay(IndustryType displayed_it)
Compute what and where to display for industry type it.
Definition: industry_gui.cpp:2755
CargoesField::other_produced
CargoID other_produced[MAX_CARGOES]
Cargoes produced but not used in this figure.
Definition: industry_gui.cpp:1928
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:669
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:890
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:1143
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:1440
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:319
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
dropdown_func.h
PC_YELLOW
static const uint8 PC_YELLOW
Yellow palette colour.
Definition: gfx_func.h:255
Commands
Commands
List of commands.
Definition: command_type.h:176
IndustryDirectoryWindow::SorterType::ByProduction
@ ByProduction
Sorter type to sort by production amount.
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
WID_IC_NOTIFY
@ WID_IC_NOTIFY
Row of buttons at the bottom.
Definition: industry_widget.h:47
IndustryViewWindow::production_offset_y
int production_offset_y
The offset of the production texts/buttons.
Definition: industry_gui.cpp:814
smallmap_gui.h
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
CFT_HEADER
@ CFT_HEADER
Header text.
Definition: industry_gui.cpp:1900
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:1407
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1019
company_base.h
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
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:2483
GUIList::SetFilterType
void SetFilterType(uint8 n_type)
Set the filtertype of the list.
Definition: sortlist_type.h:155
BuildIndustryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:685
CargoesField::bottom_end
byte bottom_end
Stop at the bottom of the vertical cargoes.
Definition: industry_gui.cpp:1937
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:622
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
IndustryViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1109
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:3031
CSD_CARGO
@ CSD_CARGO
Display the cargo without sub-type (cb37 result 401).
Definition: industry_gui.cpp:62
IndustryViewWindow::EA_MULTIPLIER
@ EA_MULTIPLIER
Allow changing the production multiplier.
Definition: industry_gui.cpp:798
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:175
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:255
IndustryCargoesWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: industry_gui.cpp:3077
CargoesRow
A single row of CargoesField.
Definition: industry_gui.cpp:2341
IndustryViewWindow::IsNewGRFInspectable
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition: industry_gui.cpp:1157
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:30
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:1775
CargoesField::cargo_stub
static Dimension cargo_stub
Dimensions of cargo stub (unconnected cargo line.)
Definition: industry_gui.cpp:1914
MakeClear
static void MakeClear(TileIndex t, ClearGround g, uint density)
Make a clear tile.
Definition: clear_map.h:259
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
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:2728
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:148
IndustryDirectoryWindow::SorterType::ByTransported
@ ByTransported
Sorter type to sort by transported percentage.
SortIndustryTypes
void SortIndustryTypes()
Initialize the list of sorted industry types.
Definition: industry_gui.cpp:209
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:586
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
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:18
IndustryCargoesWindow::ShortenCargoColumn
void ShortenCargoColumn(int column, int top, int bottom)
Shorten the cargo column to just the part between industries.
Definition: industry_gui.cpp:2707
CST_DIR
@ CST_DIR
Industry-directory window.
Definition: industry_gui.cpp:57
CargoesField::legend
static Dimension legend
Dimension of the legend blob.
Definition: industry_gui.cpp:1910
Cheats::setup_prod
Cheat setup_prod
setup raw-material production in game
Definition: cheat_type.h:33
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
WC_BUILD_INDUSTRY
@ WC_BUILD_INDUSTRY
Build industry; Window numbers:
Definition: window_type.h:428
zoom_func.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:597
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:821
Industry::RecomputeProductionMultipliers
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
Definition: industry_cmd.cpp:2409
IndustryDirectoryWindow::IndustryTypeSorter
static bool IndustryTypeSorter(const Industry *const &a, const Industry *const &b)
Sort industries by type and name.
Definition: industry_gui.cpp:1489
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
CargoesField::ConnectCargo
int ConnectCargo(CargoID cargo, bool producer)
Connect a cargo from an industry to the CFT_CARGO column.
Definition: industry_gui.cpp:1974
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:644
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:427
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:1759
IndustryViewWindow::ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition: industry_gui.cpp:1162
CBM_IND_PRODUCTION_256_TICKS
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Definition: newgrf_callbacks.h:354
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
CargoesField::CARGO_LINE_COLOUR
static const int CARGO_LINE_COLOUR
Line colour around the cargo.
Definition: industry_gui.cpp:1917
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:2565
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:838
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
BuildIndustryWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: industry_gui.cpp:512
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:149
clear_map.h
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:280
Industry
Defines the internal data of a functional industry.
Definition: industry.h:66
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2353
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:659
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
CargoesField::DrawHorConnection
static void DrawHorConnection(int left, int right, int top, const CargoSpec *csp)
Draw a horizontal cargo connection.
Definition: industry_gui.cpp:2311
CFT_INDUSTRY
@ CFT_INDUSTRY
Display industry.
Definition: industry_gui.cpp:1897
MAX_CARGOES
static const uint MAX_CARGOES
Maximum number of cargoes carried in a CFT_CARGO field in CargoesField.
Definition: industry_gui.cpp:1903
_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:141
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:205
IndustryCargoesWindow::ind_cargo
uint ind_cargo
If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
Definition: industry_gui.cpp:2481
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:196
CargoFilter
static bool CDECL CargoFilter(const Industry *const *industry, const std::pair< CargoID, CargoID > &cargoes)
Cargo filter functions.
Definition: industry_gui.cpp:1259
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
genworld.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
CBM_IND_FUND_MORE_TEXT
@ CBM_IND_FUND_MORE_TEXT
additional text in fund window
Definition: newgrf_callbacks.h:359
IndustryDirectoryWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: industry_gui.cpp:1653
IndustryCargoesWindow::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:2585
BuildIndustryWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: industry_gui.cpp:742
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
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:2072
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:284
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:377
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:789
WID_ID_FILTER_BY_PROD_CARGO
@ WID_ID_FILTER_BY_PROD_CARGO
Produced cargo filter dropdown list.
Definition: industry_widget.h:39
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
IndustryDirectoryWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:1631
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:569
WindowDesc
High level window description.
Definition: window_gui.h:102
WID_IV_CAPTION
@ WID_IV_CAPTION
Caption of the window.
Definition: industry_widget.h:27
CFT_CARGO
@ CFT_CARGO
Display cargo connections.
Definition: industry_gui.cpp:1898
IndustryDirectoryWindow::cargo_filter
CargoID cargo_filter[NUM_CARGO+2]
Available cargo filters; CargoID or CF_ANY or CF_NONE.
Definition: industry_gui.cpp:1323
IndustryCargoesWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:3134
CargoesField::CargoLabelClickedAt
CargoID CargoLabelClickedAt(Point pt) const
Decide what cargo the user clicked in the cargo label field.
Definition: industry_gui.cpp:2288
CcBuildIndustry
void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32, bool, uint32)
Command callback.
Definition: industry_gui.cpp:227
GetRawClearGround
static ClearGround GetRawClearGround(TileIndex t)
Get the type of clear tile but never return CLEAR_SNOW.
Definition: clear_map.h:47
CargoSuffixDisplay
CargoSuffixDisplay
Ways of displaying the cargo.
Definition: industry_gui.cpp:61
IndustryCargoesWindow
Window displaying the cargo connections around an industry (or cargo).
Definition: industry_gui.cpp:2477
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:3011
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
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
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
IndustryDirectoryWindow::IndustryTransportedCargoSorter
static bool IndustryTransportedCargoSorter(const Industry *const &a, const Industry *const &b)
Sort industries by transported cargo and name.
Definition: industry_gui.cpp:1521
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
CommandCost
Common return value for all commands.
Definition: command_type.h:24
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:773
IndustryViewWindow::editable
Editability editable
Mode for changing production.
Definition: industry_gui.cpp:810
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2331
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
NUM_HOUSES
static const HouseID NUM_HOUSES
Total number of houses.
Definition: house.h:29
IndustryCargoesWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:2495
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
CargoesRow::MakeCargoLabel
void MakeCargoLabel(int column, bool accepting)
Construct a CFT_CARGO_LABEL field.
Definition: industry_gui.cpp:2385
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1804
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
CargoesField::vert_inter_industry_space
static int vert_inter_industry_space
Amount of space between two industries in a column.
Definition: industry_gui.cpp:1907
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:249
IndustryViewWindow::IL_NONE
@ IL_NONE
No line.
Definition: industry_gui.cpp:804
CargoSuffix::text
char text[512]
Cargo suffix text.
Definition: industry_gui.cpp:71
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:99
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
IndustryDirectoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: industry_gui.cpp:1784
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
IndustryViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:840
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2445
CargoesField::industry_width
static int industry_width
Width of an industry field.
Definition: industry_gui.cpp:1921
_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:1311
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:214
IndustrySpec::layouts
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
Definition: industrytype.h:108
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
IsCargoIDValid
bool IsCargoIDValid(CargoID t)
Test whether cargo type is not CT_INVALID.
Definition: cargo_type.h:75
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:1960
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:1102
CargoesField
Data about a single field in the IndustryCargoesWindow panel.
Definition: industry_gui.cpp:1906
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
CargoesField::cargoes
CargoID cargoes[MAX_CARGOES]
Cargoes to display (or INVALID_CARGO).
Definition: industry_gui.cpp:1940
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:126
CargoSuffix::display
CargoSuffixDisplay display
How to display the cargo and text.
Definition: industry_gui.cpp:70
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
IndustryDirectoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: industry_gui.cpp:1789
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:626
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:444
WID_DPI_INFOPANEL
@ WID_DPI_INFOPANEL
Info panel about the industry.
Definition: industry_widget.h:20
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:1129
ConstructionSettings::raw_industry_construction
uint8 raw_industry_construction
type of (raw) industry construction (none, "normal", prospecting)
Definition: settings_type.h:352
dropdown_type.h
WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET
@ WID_DPI_CREATE_RANDOM_INDUSTRIES_WIDGET
Create random industries button.
Definition: industry_widget.h:17
IndustryDirectoryWindow::GetIndustryString
StringID GetIndustryString(const Industry *i) const
Get the StringID to draw and set the appropriate DParams.
Definition: industry_gui.cpp:1532
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
ShowIndustryCargoesWindow
static void ShowIndustryCargoesWindow(IndustryType id)
Open the industry and cargoes window.
Definition: industry_gui.cpp:3144
ZOOM_LVL_INDUSTRY
@ ZOOM_LVL_INDUSTRY
Default zoom level for the industry view.
Definition: zoom_type.h:35
PSM_ENTER_GAMELOOP
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
Definition: newgrf_storage.h:20
CargoesField::max_cargoes
static uint max_cargoes
Largest number of cargoes actually on any industry.
Definition: industry_gui.cpp:1922
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
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:46
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:1181
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:1115
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:62
IndustryDirectoryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:1806
CST_VIEW
@ CST_VIEW
View-industry window.
Definition: industry_gui.cpp:56
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
BuildIndustryWindow::legend
Dimension legend
Dimension of the legend 'blob'.
Definition: industry_gui.cpp:286
CargoesRow::ConnectIndustryProduced
void ConnectIndustryProduced(int column)
Connect industry production cargoes to the cargo column after it.
Definition: industry_gui.cpp:2348
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:601
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
CargoesField::HasConnection
bool HasConnection()
Does this CFT_CARGO field have a horizontal connection?
Definition: industry_gui.cpp:2003
DifficultySettings::industry_density
byte industry_density
The industry density.
Definition: settings_type.h:80
_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:51
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
CargoesField::header
StringID header
Header text (for CFT_HEADER).
Definition: industry_gui.cpp:1943
CargoesField::vertical_cargoes
CargoID vertical_cargoes[MAX_CARGOES]
Cargoes running from top to bottom (cargo ID or INVALID_CARGO).
Definition: industry_gui.cpp:1932
IndustryDirectoryWindow::cargo_filter_texts
StringID cargo_filter_texts[NUM_CARGO+3]
Texts for filter_cargo, terminated by INVALID_STRING_ID.
Definition: industry_gui.cpp:1324
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:1145
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:2966
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
CFT_SMALL_EMPTY
@ CFT_SMALL_EMPTY
Empty small field (for the header).
Definition: industry_gui.cpp:1896
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:481
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:1119
CargoesField::Draw
void Draw(int xpos, int ypos) const
Draw the field.
Definition: industry_gui.cpp:2085
IndustryViewWindow::Editability
Editability
Modes for changing production.
Definition: industry_gui.cpp:796
WID_IC_SCROLLBAR
@ WID_IC_SCROLLBAR
Scrollbar of the panel.
Definition: industry_widget.h:49
stdafx.h
WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET
@ WID_DPI_REMOVE_ALL_INDUSTRIES_WIDGET
Remove all industries button.
Definition: industry_widget.h:16
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:242
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2539
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
IndustryCargoesWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:2586
RoundDivSU
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:302
IndustryCargoesWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: industry_gui.cpp:2903
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:116
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:85
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:154
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
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:1481
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:46
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:3194
CFT_CARGO_LABEL
@ CFT_CARGO_LABEL
Display cargo labels.
Definition: industry_gui.cpp:1899
CargoesField::normal_height
static int normal_height
Height of the non-header rows.
Definition: industry_gui.cpp:1919
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
viewport_func.h
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:1919
IACT_USERCREATION
@ IACT_USERCREATION
from the Fund/build window
Definition: newgrf_industries.h:85
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
OrthogonalTileArea::GetCenterTile
TileIndex GetCenterTile() const
Get the center tile.
Definition: tilearea_type.h:59
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:997
IndustryDirectoryWindow::SorterType
SorterType
Definition: industry_gui.cpp:1329
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
IndustryDirectoryWindow::SorterType::ByType
@ ByType
Sorter type to sort by type.
WID_IC_IND_DROPDOWN
@ WID_IC_IND_DROPDOWN
Select industry dropdown.
Definition: industry_widget.h:51
CFT_EMPTY
@ CFT_EMPTY
Empty field.
Definition: industry_gui.cpp:1895
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:1786
IndustryViewWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:987
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
FILLRECT_OPAQUE
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition: gfx_type.h:293
CargoesField::cargo_space
static Dimension cargo_space
Dimensions of space between cargo lines.
Definition: industry_gui.cpp:1913
IndustryViewWindow
Definition: industry_gui.cpp:793
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:799
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:61
CargoFilterSpecialType
CargoFilterSpecialType
Special cargo filter criteria.
Definition: industry_gui.cpp:1247
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:1218
CargoesField::cargo_border
static Dimension cargo_border
Dimensions of border between cargo lines and industry boxes.
Definition: industry_gui.cpp:1911
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:1687
IndustryTemporarilyRefusesCargo
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
Definition: newgrf_industries.cpp:680
IndustryCargoesWindow::OnTooltip
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition: industry_gui.cpp:3092
IndustryViewWindow::IL_MULTIPLIER
@ IL_MULTIPLIER
Production multiplier.
Definition: industry_gui.cpp:805
CargoesField::left_align
bool left_align
Align all cargo texts to the left (else align to the right).
Definition: industry_gui.cpp:1941
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:352
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:140
IndustryViewWindow::cheat_line_height
int cheat_line_height
Height of each line for the WID_IV_INFO panel.
Definition: industry_gui.cpp:816
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:408
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:1936
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1266
WID_IC_CARGO_DROPDOWN
@ WID_IC_CARGO_DROPDOWN
Select cargo dropdown.
Definition: industry_widget.h:50
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:160
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
CargoesField::MakeCargoLabel
void MakeCargoLabel(const CargoID *cargoes, uint length, bool left_align)
Make a field displaying cargo type names.
Definition: industry_gui.cpp:2048
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
CF_ANY
@ CF_ANY
Show all industries (i.e. no filtering)
Definition: industry_gui.cpp:1248
IndustryViewWindow::IL_RATE1
@ IL_RATE1
Production rate of cargo 1.
Definition: industry_gui.cpp:806
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:386
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:48
CargoesRow::columns
CargoesField columns[5]
One row of fields.
Definition: industry_gui.cpp:2342
_sorted_standard_cargo_specs
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:154
CSD_CARGO_AMOUNT_TEXT
@ CSD_CARGO_AMOUNT_TEXT
Display then cargo, amount, and string (cb37 result 000-3FF).
Definition: industry_gui.cpp:65
CargoesField::MakeHeader
void MakeHeader(StringID textid)
Make a header above an industry column.
Definition: industry_gui.cpp:2061
BuildIndustryWindow::OnHundredthTick
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: industry_gui.cpp:724
_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:455
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:199
IndustryDirectoryWindow::GetCargoTransportedSortValue
static int GetCargoTransportedSortValue(const Industry *i)
Returns value representing industry's transported cargo percentage for industry sorting.
Definition: industry_gui.cpp:1455
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:367
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:811
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:1933
CST_FUND
@ CST_FUND
Fund-industry window.
Definition: industry_gui.cpp:55
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
IndustryCargoesWindow::cargo_textsize
Dimension cargo_textsize
Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
Definition: industry_gui.cpp:2482
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
ScaleZoomGUI
static ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
CargoesFieldType
CargoesFieldType
Available types of field.
Definition: industry_gui.cpp:1894
WID_ID_INDUSTRY_LIST
@ WID_ID_INDUSTRY_LIST
Industry list.
Definition: industry_widget.h:40
BuildIndustryWindow::selected_type
IndustryType selected_type
industry corresponding to the above index
Definition: industry_gui.cpp:281
IndustryViewWindow::EA_NONE
@ EA_NONE
Not alterable.
Definition: industry_gui.cpp:797
IndustryCargoesWindow::ComputeCargoDisplay
void ComputeCargoDisplay(CargoID cid)
Compute what and where to display for cargo id cid.
Definition: industry_gui.cpp:2833
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:19
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:394
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:3271
IndustryDirectoryWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: industry_gui.cpp:1373
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
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:2322
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:1725
cheat_type.h
industry_cmd.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:1920
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:189
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:3005
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1870
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:422
WID_DPI_FUND_WIDGET
@ WID_DPI_FUND_WIDGET
Fund button.
Definition: industry_widget.h:22
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:141
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
CSD_CARGO_TEXT
@ CSD_CARGO_TEXT
Display then cargo and supplied string (cb37 result 800-BFF).
Definition: industry_gui.cpp:64
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:812
GRFFile::cargo_map
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:128
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1176
IndustryDirectoryWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:1636
IndustryViewWindow::InfoLine
InfoLine
Specific lines in the info panel.
Definition: industry_gui.cpp:803
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
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:416
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:71
CBM_IND_WINDOW_MORE_TEXT
@ CBM_IND_WINDOW_MORE_TEXT
additional text in industry window
Definition: newgrf_callbacks.h:360
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:1791
_nested_industry_cargoes_widgets
static const NWidgetPart _nested_industry_cargoes_widgets[]
Widgets of the industry cargoes window.
Definition: industry_gui.cpp:1861
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
CargoesRow::ConnectIndustryAccepted
void ConnectIndustryAccepted(int column)
Connect industry accepted cargoes to the cargo column before it.
Definition: industry_gui.cpp:2406
GenerateIndustries
void GenerateIndustries()
This function will create random industries during game creation.
Definition: industry_cmd.cpp:2334
BuildIndustryWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: industry_gui.cpp:747
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:247
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:757
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
network.h
WID_DPI_SCROLLBAR
@ WID_DPI_SCROLLBAR
Scrollbar of the matrix.
Definition: industry_widget.h:19
CommandHelper
Definition: command_func.h:94
BuildIndustryWindow::index
IndustryType index[NUM_INDUSTRYTYPES+1]
Type of industry, in the order it was loaded.
Definition: industry_gui.cpp:283
BuildIndustryWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: industry_gui.cpp:491
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:2607
window_func.h
WID_DPI_SCENARIO_EDITOR_PANE
@ WID_DPI_SCENARIO_EDITOR_PANE
Pane containing SE-only widgets.
Definition: industry_widget.h:15
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:36
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:392
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:217
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
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:2427
HZ_TOYLND
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition: house.h:83
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1767
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:907
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:200
CargoSuffix
Transfer storage of cargo suffix information.
Definition: industry_gui.cpp:69
WID_ID_FILTER_BY_ACC_CARGO
@ WID_ID_FILTER_BY_ACC_CARGO
Accepted cargo filter dropdown list.
Definition: industry_widget.h:38
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:29
HouseSpec
Definition: house.h:98
Rect::Contains
bool Contains(const Point &pt) const
Test if a point falls inside this Rect.
Definition: geometry_type.hpp:217
CargoesField::blob_distance
static int blob_distance
Distance of the industry legend colour from the edge of the industry box.
Definition: industry_gui.cpp:1908
PSM_LEAVE_GAMELOOP
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
Definition: newgrf_storage.h:21
BasePersistentStorageArray::SwitchMode
static void SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode=false)
Clear temporary changes made since the last call to SwitchMode, and set whether subsequent changes sh...
Definition: newgrf_storage.cpp:55
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:737
IndustryDirectoryWindow::SetAcceptedCargoFilterIndex
void SetAcceptedCargoFilterIndex(byte index)
Set cargo filter list item index.
Definition: industry_gui.cpp:1357
HouseZones
HouseZones
Definition: house.h:71
IndustryViewWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: industry_gui.cpp:834
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:752
CargoesField::ind_type
IndustryType ind_type
Industry type (NUM_INDUSTRYTYPES means 'houses').
Definition: industry_gui.cpp:1927
BuildIndustryWindow::SetButtons
void SetButtons()
Update status of the fund and display-chain widgets.
Definition: industry_gui.cpp:334
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
gui.h
newgrf_industries.h
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
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:123
CargoSuffixType
CargoSuffixType
Cargo suffix type (for which window is it requested)
Definition: industry_gui.cpp:54
Window
Data structure for an opened window.
Definition: window_gui.h:213
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:813
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:326
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:412
IndustryViewWindow::DrawInfo
int DrawInfo(const Rect &r)
Draw the text in the WID_IV_INFO panel.
Definition: industry_gui.cpp:860
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
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:1795
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
_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.
settings_gui.h
CargoesField::type
CargoesFieldType type
Type of field.
Definition: industry_gui.cpp:1924
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:161
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
CargoesField::MakeEmpty
void MakeEmpty(CargoesFieldType type)
Make one of the empty fields (CFT_EMPTY or CFT_SMALL_EMPTY).
Definition: industry_gui.cpp:1950
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:621
IndustryDirectoryWindow::accepted_cargo_filter_criteria
byte accepted_cargo_filter_criteria
Selected accepted cargo filter index.
Definition: industry_gui.cpp:1326
WID_ID_DROPDOWN_CRITERIA
@ WID_ID_DROPDOWN_CRITERIA
Dropdown for the criteria of the sort.
Definition: industry_widget.h:37
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:69
CargoesField::supp_cargoes
CargoID supp_cargoes[MAX_CARGOES]
Cargoes entering from the left (index in vertical_cargoes, or INVALID_CARGO).
Definition: industry_gui.cpp:1934
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1274
CLEAR_FIELDS
@ CLEAR_FIELDS
3
Definition: clear_map.h:23
CargoesField::CargoClickedAt
CargoID CargoClickedAt(const CargoesField *left, const CargoesField *right, Point pt) const
Decide which cargo was clicked at in a CFT_CARGO field.
Definition: industry_gui.cpp:2231
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:68
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
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:807
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
IndustryDirectoryWindow::SetProducedCargoFilterIndex
void SetProducedCargoFilterIndex(byte index)
Set cargo filter list item index.
Definition: industry_gui.cpp:1340
WID_IV_VIEWPORT
@ WID_IV_VIEWPORT
Viewport of the industry.
Definition: industry_widget.h:28
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3434
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:691
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:289
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:1935
cpp_lengthof
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
Definition: stdafx.h:418
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
IndustryCargoesWindow::CountMatchingAcceptingIndustries
static int CountMatchingAcceptingIndustries(const CargoID *cargoes, uint length)
Count how many industries have accepted cargoes in common with one of the supplied set.
Definition: industry_gui.cpp:2671
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:49
IndustryCargoesWindow::fields
Fields fields
Fields to display in the WID_IC_PANEL.
Definition: industry_gui.cpp:2480
IndustryCargoesWindow::NotifySmallmap
void NotifySmallmap()
Notify smallmap that new displayed industries have been selected (in _displayed_industries).
Definition: industry_gui.cpp:2742
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:63
IndustryViewWindow::info_height
int info_height
Height needed for the WID_IV_INFO panel.
Definition: industry_gui.cpp:815
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:297
BuildIndustryWindow
Build (fund or prospect) a new industry,.
Definition: industry_gui.cpp:279
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:41
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:31
IndustryDirectoryWindow::IndustryProductionSorter
static bool IndustryProductionSorter(const Industry *const &a, const Industry *const &b)
Sort industries by production and name.
Definition: industry_gui.cpp:1500
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
CargoesField::cargo_line
static Dimension cargo_line
Dimensions of cargo lines.
Definition: industry_gui.cpp:1912
IndustryDirectoryWindow::produced_cargo_filter_criteria
byte produced_cargo_filter_criteria
Selected produced cargo filter index.
Definition: industry_gui.cpp:1325
CargoesField::other_accepted
CargoID other_accepted[MAX_CARGOES]
Cargoes accepted but not used in this figure.
Definition: industry_gui.cpp:1929
CF_NONE
@ CF_NONE
Show only industries which do not produce/accept cargo.
Definition: industry_gui.cpp:1249
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1032
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:2529
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:151
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:167
IndustryCargoesWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: industry_gui.cpp:2918
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
GetIndustryCallback
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
Definition: newgrf_industries.cpp:521
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