OpenTTD Source  13.0-beta1
station_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 "debug.h"
12 #include "gui.h"
13 #include "textbuf_gui.h"
14 #include "company_func.h"
15 #include "command_func.h"
16 #include "vehicle_gui.h"
17 #include "cargotype.h"
18 #include "station_gui.h"
19 #include "strings_func.h"
20 #include "string_func.h"
21 #include "window_func.h"
22 #include "viewport_func.h"
23 #include "widgets/dropdown_func.h"
24 #include "station_base.h"
25 #include "waypoint_base.h"
26 #include "tilehighlight_func.h"
27 #include "company_base.h"
28 #include "sortlist_type.h"
29 #include "core/geometry_func.hpp"
30 #include "vehiclelist.h"
31 #include "town.h"
32 #include "linkgraph/linkgraph.h"
33 #include "zoom_func.h"
34 #include "station_cmd.h"
35 
36 #include "widgets/station_widget.h"
37 
38 #include "table/strings.h"
39 
40 #include <set>
41 #include <vector>
42 
43 #include "safeguards.h"
44 
55 int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
56 {
57  TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
58  CargoTypes cargo_mask = 0;
59  if (_thd.drawstyle == HT_RECT && tile < MapSize()) {
60  CargoArray cargoes;
61  if (supplies) {
62  cargoes = GetProductionAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
63  } else {
64  cargoes = GetAcceptanceAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
65  }
66 
67  /* Convert cargo counts to a set of cargo bits, and draw the result. */
68  for (CargoID i = 0; i < NUM_CARGO; i++) {
69  switch (sct) {
70  case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
71  case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
72  case SCT_ALL: break;
73  default: NOT_REACHED();
74  }
75  if (cargoes[i] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, i);
76  }
77  }
78  SetDParam(0, cargo_mask);
79  return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
80 }
81 
87 {
88  /* With distant join we don't know which station will be selected, so don't show any */
89  if (_ctrl_pressed) {
90  SetViewportCatchmentStation(nullptr, true);
91  return;
92  }
93 
94  /* Tile area for TileHighlightData */
95  TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1);
96 
97  /* Extended area by one tile */
98  uint x = TileX(location.tile);
99  uint y = TileY(location.tile);
100 
101  int max_c = 1;
102  TileArea ta(TileXY(std::max<int>(0, x - max_c), std::max<int>(0, y - max_c)), TileXY(std::min<int>(MapMaxX(), x + location.w + max_c), std::min<int>(MapMaxY(), y + location.h + max_c)));
103 
104  Station *adjacent = nullptr;
105 
106  /* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
107  for (TileIndex tile : ta) {
108  if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) {
109  Station *st = Station::GetByTile(tile);
110  if (st == nullptr) continue;
111  if (adjacent != nullptr && st != adjacent) {
112  /* Multiple nearby, distant join is required. */
113  adjacent = nullptr;
114  break;
115  }
116  adjacent = st;
117  }
118  }
119  SetViewportCatchmentStation(adjacent, true);
120 }
121 
128 {
129  /* Test if ctrl state changed */
130  static bool _last_ctrl_pressed;
131  if (_ctrl_pressed != _last_ctrl_pressed) {
132  _thd.dirty = 0xff;
133  _last_ctrl_pressed = _ctrl_pressed;
134  }
135 
136  if (_thd.dirty & 1) {
137  _thd.dirty &= ~1;
138  w->SetDirty();
139 
142  }
143  }
144 }
145 
158 static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
159 {
160  static const uint units_full = 576;
161  static const uint rating_full = 224;
162 
163  const CargoSpec *cs = CargoSpec::Get(type);
164  if (!cs->IsValid()) return;
165 
166  int padding = ScaleFontTrad(1);
167  int width = right - left;
168  int colour = cs->rating_colour;
169  TextColour tc = GetContrastColour(colour);
170  uint w = std::min(amount + 5, units_full) * width / units_full;
171 
172  int height = GetCharacterHeight(FS_SMALL) + padding - 1;
173 
174  if (amount > 30) {
175  /* Draw total cargo (limited) on station */
176  GfxFillRect(left, y, left + w - 1, y + height, colour);
177  } else {
178  /* Draw a (scaled) one pixel-wide bar of additional cargo meter, useful
179  * for stations with only a small amount (<=30) */
180  uint rest = ScaleFontTrad(amount) / 5;
181  if (rest != 0) {
182  GfxFillRect(left, y + height - rest, left + padding - 1, y + height, colour);
183  }
184  }
185 
186  DrawString(left + padding, right, y, cs->abbrev, tc);
187 
188  /* Draw green/red ratings bar (fits under the waiting bar) */
189  y += height + padding + 1;
190  GfxFillRect(left + padding, y, right - padding - 1, y + padding - 1, PC_RED);
191  w = std::min<uint>(rating, rating_full) * (width - padding - padding) / rating_full;
192  if (w != 0) GfxFillRect(left + padding, y, left + w - 1, y + padding - 1, PC_GREEN);
193 }
194 
196 
201 {
202 protected:
203  /* Runtime saved values */
204  static Listing last_sorting;
205  static byte facilities; // types of stations of interest
206  static bool include_empty; // whether we should include stations without waiting cargo
207  static const CargoTypes cargo_filter_max;
208  static CargoTypes cargo_filter; // bitmap of cargo types to include
209 
210  /* Constants for sorting stations */
211  static const StringID sorter_names[];
212  static GUIStationList::SortFunction * const sorter_funcs[];
213 
214  GUIStationList stations;
215  Scrollbar *vscroll;
216  uint rating_width;
217 
224  {
225  if (!this->stations.NeedRebuild()) return;
226 
227  Debug(misc, 3, "Building station list for company {}", owner);
228 
229  this->stations.clear();
230 
231  for (const Station *st : Station::Iterate()) {
232  if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
233  if (this->facilities & st->facilities) { // only stations with selected facilities
234  int num_waiting_cargo = 0;
235  for (CargoID j = 0; j < NUM_CARGO; j++) {
236  if (st->goods[j].HasRating()) {
237  num_waiting_cargo++; // count number of waiting cargo
238  if (HasBit(this->cargo_filter, j)) {
239  this->stations.push_back(st);
240  break;
241  }
242  }
243  }
244  /* stations without waiting cargo */
245  if (num_waiting_cargo == 0 && this->include_empty) {
246  this->stations.push_back(st);
247  }
248  }
249  }
250  }
251 
252  this->stations.shrink_to_fit();
253  this->stations.RebuildDone();
254 
255  this->vscroll->SetCount((uint)this->stations.size()); // Update the scrollbar
256  }
257 
259  static bool StationNameSorter(const Station * const &a, const Station * const &b)
260  {
261  int r = strnatcmp(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
262  if (r == 0) return a->index < b->index;
263  return r < 0;
264  }
265 
267  static bool StationTypeSorter(const Station * const &a, const Station * const &b)
268  {
269  return a->facilities < b->facilities;
270  }
271 
273  static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b)
274  {
275  int diff = 0;
276 
277  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
278  diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount();
279  }
280 
281  return diff < 0;
282  }
283 
285  static bool StationWaitingAvailableSorter(const Station * const &a, const Station * const &b)
286  {
287  int diff = 0;
288 
289  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
290  diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
291  }
292 
293  return diff < 0;
294  }
295 
297  static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b)
298  {
299  byte maxr1 = 0;
300  byte maxr2 = 0;
301 
302  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
303  if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating);
304  if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating);
305  }
306 
307  return maxr1 < maxr2;
308  }
309 
311  static bool StationRatingMinSorter(const Station * const &a, const Station * const &b)
312  {
313  byte minr1 = 255;
314  byte minr2 = 255;
315 
316  for (CargoID j = 0; j < NUM_CARGO; j++) {
317  if (!HasBit(cargo_filter, j)) continue;
318  if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating);
319  if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating);
320  }
321 
322  return minr1 > minr2;
323  }
324 
327  {
328  if (!this->stations.Sort()) return;
329 
330  /* Set the modified widget dirty */
332  }
333 
334 public:
336  {
337  this->stations.SetListing(this->last_sorting);
338  this->stations.SetSortFuncs(this->sorter_funcs);
339  this->stations.ForceRebuild();
340  this->stations.NeedResort();
341  this->SortStationsList();
342 
343  this->CreateNestedTree();
344  this->vscroll = this->GetScrollbar(WID_STL_SCROLLBAR);
345  this->FinishInitNested(window_number);
346  this->owner = (Owner)this->window_number;
347 
348  uint8 index = 0;
349  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
350  if (HasBit(this->cargo_filter, cs->Index())) {
351  this->LowerWidget(WID_STL_CARGOSTART + index);
352  }
353  index++;
354  }
355 
356  if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;
357 
358  for (uint i = 0; i < 5; i++) {
359  if (HasBit(this->facilities, i)) this->LowerWidget(i + WID_STL_TRAIN);
360  }
361  this->SetWidgetLoweredState(WID_STL_NOCARGOWAITING, this->include_empty);
362 
363  this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
364  }
365 
367  {
368  this->last_sorting = this->stations.GetListing();
369  }
370 
371  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
372  {
373  switch (widget) {
374  case WID_STL_SORTBY: {
375  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
376  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
377  d.height += padding.height;
378  *size = maxdim(*size, d);
379  break;
380  }
381 
382  case WID_STL_SORTDROPBTN: {
383  Dimension d = {0, 0};
384  for (int i = 0; this->sorter_names[i] != INVALID_STRING_ID; i++) {
385  d = maxdim(d, GetStringBoundingBox(this->sorter_names[i]));
386  }
387  d.width += padding.width;
388  d.height += padding.height;
389  *size = maxdim(*size, d);
390  break;
391  }
392 
393  case WID_STL_LIST:
394  resize->height = std::max(FONT_HEIGHT_NORMAL, FONT_HEIGHT_SMALL + ScaleFontTrad(3));
395  size->height = WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM;
396 
397  /* Determine appropriate width for mini station rating graph */
398  this->rating_width = 0;
399  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
400  this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev).width);
401  }
402  /* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
403  this->rating_width = this->rating_width * 16 / 10;
404  break;
405 
406  default:
407  if (widget >= WID_STL_CARGOSTART) {
409  d.width += padding.width + 2;
410  d.height += padding.height;
411  *size = maxdim(*size, d);
412  }
413  break;
414  }
415  }
416 
417  void OnPaint() override
418  {
419  this->BuildStationsList((Owner)this->window_number);
420  this->SortStationsList();
421 
422  this->DrawWidgets();
423  }
424 
425  void DrawWidget(const Rect &r, int widget) const override
426  {
427  switch (widget) {
428  case WID_STL_SORTBY:
429  /* draw arrow pointing up/down for ascending/descending sorting */
431  break;
432 
433  case WID_STL_LIST: {
434  bool rtl = _current_text_dir == TD_RTL;
435  int max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size());
436  int y = r.top + WD_FRAMERECT_TOP;
437  uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
438  /* Spacing between station name and first rating graph. */
439  int text_spacing = ScaleFontTrad(5);
440  /* Spacing between additional rating graphs. */
441  int rating_spacing = ScaleFontTrad(4);
442 
443  for (int i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner
444  const Station *st = this->stations[i];
445  assert(st->xy != INVALID_TILE);
446 
447  /* Do not do the complex check HasStationInUse here, it may be even false
448  * when the order had been removed and the station list hasn't been removed yet */
449  assert(st->owner == owner || st->owner == OWNER_NONE);
450 
451  SetDParam(0, st->index);
452  SetDParam(1, st->facilities);
453  int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + (line_height - FONT_HEIGHT_NORMAL) / 2, STR_STATION_LIST_STATION);
454  x += rtl ? -text_spacing : text_spacing;
455 
456  /* show cargo waiting and station ratings */
457  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
458  CargoID cid = cs->Index();
459  if (st->goods[cid].cargo.TotalCount() > 0) {
460  /* For RTL we work in exactly the opposite direction. So
461  * decrement the space needed first, then draw to the left
462  * instead of drawing to the left and then incrementing
463  * the space. */
464  if (rtl) {
465  x -= rating_width + rating_spacing;
466  if (x < r.left + WD_FRAMERECT_LEFT) break;
467  }
468  StationsWndShowStationRating(x, x + rating_width, y, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
469  if (!rtl) {
470  x += rating_width + rating_spacing;
471  if (x > r.right - WD_FRAMERECT_RIGHT) break;
472  }
473  }
474  }
475  y += line_height;
476  }
477 
478  if (this->vscroll->GetCount() == 0) { // company has no stations
479  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_NONE);
480  return;
481  }
482  break;
483  }
484 
485  default:
486  if (widget >= WID_STL_CARGOSTART) {
487  const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
488  int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 1 : 0;
489  GfxFillRect(r.left + cg_ofst + 1, r.top + cg_ofst + 1, r.right - 1 + cg_ofst, r.bottom - 1 + cg_ofst, cs->rating_colour);
490  TextColour tc = GetContrastColour(cs->rating_colour);
491  DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, cs->abbrev, tc, SA_HOR_CENTER);
492  }
493  break;
494  }
495  }
496 
497  void SetStringParameters(int widget) const override
498  {
499  if (widget == WID_STL_CAPTION) {
500  SetDParam(0, this->window_number);
501  SetDParam(1, this->vscroll->GetCount());
502  }
503  }
504 
505  void OnClick(Point pt, int widget, int click_count) override
506  {
507  switch (widget) {
508  case WID_STL_LIST: {
509  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_STL_LIST);
510  if (id_v >= this->stations.size()) return; // click out of list bound
511 
512  const Station *st = this->stations[id_v];
513  /* do not check HasStationInUse - it is slow and may be invalid */
514  assert(st->owner == (Owner)this->window_number || st->owner == OWNER_NONE);
515 
516  if (_ctrl_pressed) {
518  } else {
520  }
521  break;
522  }
523 
524  case WID_STL_TRAIN:
525  case WID_STL_TRUCK:
526  case WID_STL_BUS:
527  case WID_STL_AIRPLANE:
528  case WID_STL_SHIP:
529  if (_ctrl_pressed) {
530  ToggleBit(this->facilities, widget - WID_STL_TRAIN);
531  this->ToggleWidgetLoweredState(widget);
532  } else {
533  for (uint i : SetBitIterator(this->facilities)) {
534  this->RaiseWidget(i + WID_STL_TRAIN);
535  }
536  this->facilities = 1 << (widget - WID_STL_TRAIN);
537  this->LowerWidget(widget);
538  }
539  this->stations.ForceRebuild();
540  this->SetDirty();
541  break;
542 
543  case WID_STL_FACILALL:
544  for (uint i = WID_STL_TRAIN; i <= WID_STL_SHIP; i++) {
545  this->LowerWidget(i);
546  }
547 
549  this->stations.ForceRebuild();
550  this->SetDirty();
551  break;
552 
553  case WID_STL_CARGOALL: {
554  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
555  this->LowerWidget(WID_STL_CARGOSTART + i);
556  }
558 
559  this->cargo_filter = _cargo_mask;
560  this->include_empty = true;
561  this->stations.ForceRebuild();
562  this->SetDirty();
563  break;
564  }
565 
566  case WID_STL_SORTBY: // flip sorting method asc/desc
567  this->stations.ToggleSortOrder();
568  this->SetDirty();
569  break;
570 
571  case WID_STL_SORTDROPBTN: // select sorting criteria dropdown menu
572  ShowDropDownMenu(this, this->sorter_names, this->stations.SortType(), WID_STL_SORTDROPBTN, 0, 0);
573  break;
574 
576  if (_ctrl_pressed) {
577  this->include_empty = !this->include_empty;
579  } else {
580  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
581  this->RaiseWidget(WID_STL_CARGOSTART + i);
582  }
583 
584  this->cargo_filter = 0;
585  this->include_empty = true;
586 
588  }
589  this->stations.ForceRebuild();
590  this->SetDirty();
591  break;
592 
593  default:
594  if (widget >= WID_STL_CARGOSTART) { // change cargo_filter
595  /* Determine the selected cargo type */
596  const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
597 
598  if (_ctrl_pressed) {
599  ToggleBit(this->cargo_filter, cs->Index());
600  this->ToggleWidgetLoweredState(widget);
601  } else {
602  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
603  this->RaiseWidget(WID_STL_CARGOSTART + i);
604  }
606 
607  this->cargo_filter = 0;
608  this->include_empty = false;
609 
610  SetBit(this->cargo_filter, cs->Index());
611  this->LowerWidget(widget);
612  }
613  this->stations.ForceRebuild();
614  this->SetDirty();
615  }
616  break;
617  }
618  }
619 
620  void OnDropdownSelect(int widget, int index) override
621  {
622  if (this->stations.SortType() != index) {
623  this->stations.SetSortType(index);
624 
625  /* Display the current sort variant */
626  this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
627 
628  this->SetDirty();
629  }
630  }
631 
632  void OnGameTick() override
633  {
634  if (this->stations.NeedResort()) {
635  Debug(misc, 3, "Periodic rebuild station list company {}", this->window_number);
636  this->SetDirty();
637  }
638  }
639 
640  void OnResize() override
641  {
643  }
644 
650  void OnInvalidateData(int data = 0, bool gui_scope = true) override
651  {
652  if (data == 0) {
653  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
654  this->stations.ForceRebuild();
655  } else {
656  this->stations.ForceResort();
657  }
658  }
659 };
660 
661 Listing CompanyStationsWindow::last_sorting = {false, 0};
662 byte CompanyStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
663 bool CompanyStationsWindow::include_empty = true;
664 const CargoTypes CompanyStationsWindow::cargo_filter_max = ALL_CARGOTYPES;
665 CargoTypes CompanyStationsWindow::cargo_filter = ALL_CARGOTYPES;
666 
667 /* Available station sorting functions */
668 GUIStationList::SortFunction * const CompanyStationsWindow::sorter_funcs[] = {
669  &StationNameSorter,
670  &StationTypeSorter,
671  &StationWaitingTotalSorter,
672  &StationWaitingAvailableSorter,
673  &StationRatingMaxSorter,
674  &StationRatingMinSorter
675 };
676 
677 /* Names of the sorting functions */
678 const StringID CompanyStationsWindow::sorter_names[] = {
679  STR_SORT_BY_NAME,
680  STR_SORT_BY_FACILITY,
681  STR_SORT_BY_WAITING_TOTAL,
682  STR_SORT_BY_WAITING_AVAILABLE,
683  STR_SORT_BY_RATING_MAX,
684  STR_SORT_BY_RATING_MIN,
686 };
687 
693 static NWidgetBase *CargoWidgets(int *biggest_index)
694 {
695  NWidgetHorizontal *container = new NWidgetHorizontal();
696 
697  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
698  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
699  panel->SetMinimalSize(14, 0);
700  panel->SetMinimalTextLines(1, 0, FS_NORMAL);
701  panel->SetResize(0, 0);
702  panel->SetFill(0, 1);
703  panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
704  container->Add(panel);
705  }
706  *biggest_index = WID_STL_CARGOSTART + static_cast<int>(_sorted_standard_cargo_specs.size());
707  return container;
708 }
709 
710 static const NWidgetPart _nested_company_stations_widgets[] = {
712  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
713  NWidget(WWT_CAPTION, COLOUR_GREY, WID_STL_CAPTION), SetDataTip(STR_STATION_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
714  NWidget(WWT_SHADEBOX, COLOUR_GREY),
715  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
716  NWidget(WWT_STICKYBOX, COLOUR_GREY),
717  EndContainer(),
719  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRAIN), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_TRAIN, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
720  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRUCK), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_LORRY, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
721  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_BUS), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
722  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_SHIP), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
723  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_AIRPLANE), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
724  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetFill(0, 1),
725  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
727  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_ABBREV_NONE, STR_STATION_LIST_NO_WAITING_CARGO), SetFill(0, 1),
728  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_TYPES), SetFill(0, 1),
729  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
730  EndContainer(),
732  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_SORTBY), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
733  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_STL_SORTDROPBTN), SetMinimalSize(163, 12), SetDataTip(STR_SORT_BY_NAME, STR_TOOLTIP_SORT_CRITERIA), // widget_data gets overwritten.
734  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
735  EndContainer(),
737  NWidget(WWT_PANEL, COLOUR_GREY, WID_STL_LIST), SetMinimalSize(346, 125), SetResize(1, 10), SetDataTip(0x0, STR_STATION_LIST_TOOLTIP), SetScrollbar(WID_STL_SCROLLBAR), EndContainer(),
740  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
741  EndContainer(),
742  EndContainer(),
743 };
744 
745 static WindowDesc _company_stations_desc(
746  WDP_AUTO, "list_stations", 358, 162,
748  0,
749  _nested_company_stations_widgets, lengthof(_nested_company_stations_widgets)
750 );
751 
758 {
759  if (!Company::IsValidID(company)) return;
760 
761  AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
762 }
763 
764 static const NWidgetPart _nested_station_view_widgets[] = {
766  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
767  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
768  NWidget(WWT_CAPTION, COLOUR_GREY, WID_SV_CAPTION), SetDataTip(STR_STATION_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
769  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_STATION_VIEW_CENTER_TOOLTIP),
770  NWidget(WWT_SHADEBOX, COLOUR_GREY),
771  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
772  NWidget(WWT_STICKYBOX, COLOUR_GREY),
773  EndContainer(),
775  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_GROUP), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_STATION_VIEW_GROUP, 0x0),
776  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_GROUP_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
777  EndContainer(),
779  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SORT_ORDER), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
780  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_SORT_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
781  EndContainer(),
785  EndContainer(),
788  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ACCEPTS_RATINGS), SetMinimalSize(46, 12), SetResize(1, 0), SetFill(1, 1),
789  SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
790  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
791  SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
792  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
793  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
794  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
795  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
796  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_PLANES), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
797  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
798  EndContainer(),
799 };
800 
810 static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int y)
811 {
812  int width = ScaleGUITrad(10);
813  uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow
814  if (num == 0) return;
815 
816  SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon();
817 
818  int x = _current_text_dir == TD_RTL ? left : right - num * width;
819  do {
820  DrawSprite(sprite, PAL_NONE, x, y);
821  x += width;
822  } while (--num);
823 }
824 
825 enum SortOrder {
826  SO_DESCENDING,
827  SO_ASCENDING
828 };
829 
830 class CargoDataEntry;
831 
838 };
839 
840 class CargoSorter {
841 public:
842  CargoSorter(CargoSortType t = ST_STATION_ID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
843  CargoSortType GetSortType() {return this->type;}
844  bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
845 
846 private:
847  CargoSortType type;
848  SortOrder order;
849 
850  template<class Tid>
851  bool SortId(Tid st1, Tid st2) const;
852  bool SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
853  bool SortStation (StationID st1, StationID st2) const;
854 };
855 
856 typedef std::set<CargoDataEntry *, CargoSorter> CargoDataSet;
857 
864 public:
865  CargoDataEntry();
866  ~CargoDataEntry();
867 
874  {
875  return this->InsertOrRetrieve<StationID>(station);
876  }
877 
884  {
885  return this->InsertOrRetrieve<CargoID>(cargo);
886  }
887 
888  void Update(uint count);
889 
894  void Remove(StationID station)
895  {
897  this->Remove(&t);
898  }
899 
905  {
907  this->Remove(&t);
908  }
909 
915  CargoDataEntry *Retrieve(StationID station) const
916  {
918  return this->Retrieve(this->children->find(&t));
919  }
920 
927  {
929  return this->Retrieve(this->children->find(&t));
930  }
931 
932  void Resort(CargoSortType type, SortOrder order);
933 
937  StationID GetStation() const { return this->station; }
938 
942  CargoID GetCargo() const { return this->cargo; }
943 
947  uint GetCount() const { return this->count; }
948 
952  CargoDataEntry *GetParent() const { return this->parent; }
953 
957  uint GetNumChildren() const { return this->num_children; }
958 
962  CargoDataSet::iterator Begin() const { return this->children->begin(); }
963 
967  CargoDataSet::iterator End() const { return this->children->end(); }
968 
972  bool HasTransfers() const { return this->transfers; }
973 
977  void SetTransfers(bool value) { this->transfers = value; }
978 
979  void Clear();
980 private:
981 
982  CargoDataEntry(StationID st, uint c, CargoDataEntry *p);
983  CargoDataEntry(CargoID car, uint c, CargoDataEntry *p);
984  CargoDataEntry(StationID st);
985  CargoDataEntry(CargoID car);
986 
987  CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
988 
989  template<class Tid>
991 
992  void Remove(CargoDataEntry *comp);
993  void IncrementSize();
994 
996  const union {
997  StationID station;
998  struct {
1000  bool transfers;
1001  };
1002  };
1004  uint count;
1005  CargoDataSet *children;
1006 };
1007 
1008 CargoDataEntry::CargoDataEntry() :
1009  parent(nullptr),
1010  station(INVALID_STATION),
1011  num_children(0),
1012  count(0),
1013  children(new CargoDataSet(CargoSorter(ST_CARGO_ID)))
1014 {}
1015 
1016 CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
1017  parent(parent),
1018  cargo(cargo),
1019  num_children(0),
1020  count(count),
1021  children(new CargoDataSet)
1022 {}
1023 
1024 CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
1025  parent(parent),
1026  station(station),
1027  num_children(0),
1028  count(count),
1029  children(new CargoDataSet)
1030 {}
1031 
1032 CargoDataEntry::CargoDataEntry(StationID station) :
1033  parent(nullptr),
1034  station(station),
1035  num_children(0),
1036  count(0),
1037  children(nullptr)
1038 {}
1039 
1040 CargoDataEntry::CargoDataEntry(CargoID cargo) :
1041  parent(nullptr),
1042  cargo(cargo),
1043  num_children(0),
1044  count(0),
1045  children(nullptr)
1046 {}
1047 
1048 CargoDataEntry::~CargoDataEntry()
1049 {
1050  this->Clear();
1051  delete this->children;
1052 }
1053 
1058 {
1059  if (this->children != nullptr) {
1060  for (CargoDataSet::iterator i = this->children->begin(); i != this->children->end(); ++i) {
1061  assert(*i != this);
1062  delete *i;
1063  }
1064  this->children->clear();
1065  }
1066  if (this->parent != nullptr) this->parent->count -= this->count;
1067  this->count = 0;
1068  this->num_children = 0;
1069 }
1070 
1078 {
1079  CargoDataSet::iterator i = this->children->find(child);
1080  if (i != this->children->end()) {
1081  delete *i;
1082  this->children->erase(i);
1083  }
1084 }
1085 
1092 template<class Tid>
1094 {
1095  CargoDataEntry tmp(child_id);
1096  CargoDataSet::iterator i = this->children->find(&tmp);
1097  if (i == this->children->end()) {
1098  IncrementSize();
1099  return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first);
1100  } else {
1101  CargoDataEntry *ret = *i;
1102  assert(this->children->value_comp().GetSortType() != ST_COUNT);
1103  return ret;
1104  }
1105 }
1106 
1112 void CargoDataEntry::Update(uint count)
1113 {
1114  this->count += count;
1115  if (this->parent != nullptr) this->parent->Update(count);
1116 }
1117 
1122 {
1123  ++this->num_children;
1124  if (this->parent != nullptr) this->parent->IncrementSize();
1125 }
1126 
1127 void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
1128 {
1129  CargoDataSet *new_subs = new CargoDataSet(this->children->begin(), this->children->end(), CargoSorter(type, order));
1130  delete this->children;
1131  this->children = new_subs;
1132 }
1133 
1134 CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
1135 {
1136  if (i == this->children->end()) {
1137  return nullptr;
1138  } else {
1139  assert(this->children->value_comp().GetSortType() != ST_COUNT);
1140  return *i;
1141  }
1142 }
1143 
1144 bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1145 {
1146  switch (this->type) {
1147  case ST_STATION_ID:
1148  return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation());
1149  case ST_CARGO_ID:
1150  return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo());
1151  case ST_COUNT:
1152  return this->SortCount(cd1, cd2);
1153  case ST_STATION_STRING:
1154  return this->SortStation(cd1->GetStation(), cd2->GetStation());
1155  default:
1156  NOT_REACHED();
1157  }
1158 }
1159 
1160 template<class Tid>
1161 bool CargoSorter::SortId(Tid st1, Tid st2) const
1162 {
1163  return (this->order == SO_ASCENDING) ? st1 < st2 : st2 < st1;
1164 }
1165 
1166 bool CargoSorter::SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1167 {
1168  uint c1 = cd1->GetCount();
1169  uint c2 = cd2->GetCount();
1170  if (c1 == c2) {
1171  return this->SortStation(cd1->GetStation(), cd2->GetStation());
1172  } else if (this->order == SO_ASCENDING) {
1173  return c1 < c2;
1174  } else {
1175  return c2 < c1;
1176  }
1177 }
1178 
1179 bool CargoSorter::SortStation(StationID st1, StationID st2) const
1180 {
1181  if (!Station::IsValidID(st1)) {
1182  return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
1183  } else if (!Station::IsValidID(st2)) {
1184  return order == SO_DESCENDING;
1185  }
1186 
1187  int res = strnatcmp(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
1188  if (res == 0) {
1189  return this->SortId(st1, st2);
1190  } else {
1191  return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
1192  }
1193 }
1194 
1198 struct StationViewWindow : public Window {
1202  struct RowDisplay {
1203  RowDisplay(CargoDataEntry *f, StationID n) : filter(f), next_station(n) {}
1205 
1210  union {
1214  StationID next_station;
1215 
1220  };
1221  };
1222 
1223  typedef std::vector<RowDisplay> CargoDataVector;
1224 
1225  static const int NUM_COLUMNS = 4;
1226 
1231  INV_FLOWS = 0x100,
1232  INV_CARGO = 0x200
1233  };
1234 
1238  enum Grouping {
1243  };
1244 
1248  enum Mode {
1251  };
1252 
1256  Scrollbar *vscroll;
1257 
1260  ALH_RATING = 13,
1262  };
1263 
1264  static const StringID _sort_names[];
1265  static const StringID _group_names[];
1266 
1274 
1277 
1282 
1285  CargoDataVector displayed_rows;
1286 
1288  scroll_to_row(INT_MAX), grouping_index(0)
1289  {
1290  this->rating_lines = ALH_RATING;
1291  this->accepts_lines = ALH_ACCEPTS;
1292 
1293  this->CreateNestedTree();
1294  this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
1295  /* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
1296  this->FinishInitNested(window_number);
1297 
1298  this->groupings[0] = GR_CARGO;
1299  this->sortings[0] = ST_AS_GROUPING;
1302  this->sort_orders[0] = SO_ASCENDING;
1304  this->owner = Station::Get(window_number)->owner;
1305  }
1306 
1307  void Close() override
1308  {
1309  CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false);
1310  CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false);
1311  CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false);
1312  CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false);
1313 
1314  SetViewportCatchmentStation(Station::Get(this->window_number), false);
1315  this->Window::Close();
1316  }
1317 
1328  void ShowCargo(CargoDataEntry *data, CargoID cargo, StationID source, StationID next, StationID dest, uint count)
1329  {
1330  if (count == 0) return;
1331  bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1332  const CargoDataEntry *expand = &this->expanded_rows;
1333  for (int i = 0; i < NUM_COLUMNS && expand != nullptr; ++i) {
1334  switch (groupings[i]) {
1335  case GR_CARGO:
1336  assert(i == 0);
1337  data = data->InsertOrRetrieve(cargo);
1338  data->SetTransfers(source != this->window_number);
1339  expand = expand->Retrieve(cargo);
1340  break;
1341  case GR_SOURCE:
1342  if (auto_distributed || source != this->window_number) {
1343  data = data->InsertOrRetrieve(source);
1344  expand = expand->Retrieve(source);
1345  }
1346  break;
1347  case GR_NEXT:
1348  if (auto_distributed) {
1349  data = data->InsertOrRetrieve(next);
1350  expand = expand->Retrieve(next);
1351  }
1352  break;
1353  case GR_DESTINATION:
1354  if (auto_distributed) {
1355  data = data->InsertOrRetrieve(dest);
1356  expand = expand->Retrieve(dest);
1357  }
1358  break;
1359  }
1360  }
1361  data->Update(count);
1362  }
1363 
1364  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1365  {
1366  switch (widget) {
1367  case WID_SV_WAITING:
1368  resize->height = FONT_HEIGHT_NORMAL;
1369  size->height = WD_FRAMERECT_TOP + 4 * resize->height + WD_FRAMERECT_BOTTOM;
1370  this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
1371  break;
1372 
1374  size->height = WD_FRAMERECT_TOP + ((this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) ? this->accepts_lines : this->rating_lines) * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
1375  break;
1376 
1377  case WID_SV_CLOSE_AIRPORT:
1378  if (!(Station::Get(this->window_number)->facilities & FACIL_AIRPORT)) {
1379  /* Hide 'Close Airport' button if no airport present. */
1380  size->width = 0;
1381  resize->width = 0;
1382  fill->width = 0;
1383  }
1384  break;
1385  }
1386  }
1387 
1388  void OnPaint() override
1389  {
1390  const Station *st = Station::Get(this->window_number);
1391  CargoDataEntry cargo;
1392  BuildCargoList(&cargo, st);
1393 
1394  this->vscroll->SetCount(cargo.GetNumChildren()); // update scrollbar
1395 
1396  /* disable some buttons */
1402  this->SetWidgetDisabledState(WID_SV_CLOSE_AIRPORT, !(st->facilities & FACIL_AIRPORT) || st->owner != _local_company || st->owner == OWNER_NONE); // Also consider SE, where _local_company == OWNER_NONE
1404 
1405  extern const Station *_viewport_highlight_station;
1407  this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st);
1408 
1409  this->DrawWidgets();
1410 
1411  if (!this->IsShaded()) {
1412  /* Draw 'accepted cargo' or 'cargo ratings'. */
1413  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SV_ACCEPT_RATING_LIST);
1414  const Rect r = wid->GetCurrentRect();
1415  if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1416  int lines = this->DrawAcceptedCargo(r);
1417  if (lines > this->accepts_lines) { // Resize the widget, and perform re-initialization of the window.
1418  this->accepts_lines = lines;
1419  this->ReInit();
1420  return;
1421  }
1422  } else {
1423  int lines = this->DrawCargoRatings(r);
1424  if (lines > this->rating_lines) { // Resize the widget, and perform re-initialization of the window.
1425  this->rating_lines = lines;
1426  this->ReInit();
1427  return;
1428  }
1429  }
1430 
1431  /* Draw arrow pointing up/down for ascending/descending sorting */
1432  this->DrawSortButtonState(WID_SV_SORT_ORDER, sort_orders[1] == SO_ASCENDING ? SBS_UP : SBS_DOWN);
1433 
1434  int pos = this->vscroll->GetPosition();
1435 
1436  int maxrows = this->vscroll->GetCapacity();
1437 
1438  displayed_rows.clear();
1439 
1440  /* Draw waiting cargo. */
1441  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SV_WAITING);
1442  Rect waiting_rect = nwi->GetCurrentRect();
1443  this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0);
1444  scroll_to_row = INT_MAX;
1445  }
1446  }
1447 
1448  void SetStringParameters(int widget) const override
1449  {
1450  const Station *st = Station::Get(this->window_number);
1451  SetDParam(0, st->index);
1452  SetDParam(1, st->facilities);
1453  }
1454 
1461  {
1462  const Station *st = Station::Get(this->window_number);
1464  cargo_entry->Clear();
1465 
1466  const FlowStatMap &flows = st->goods[i].flows;
1467  for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1468  StationID from = it->first;
1469  CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from);
1470  const FlowStat::SharesMap *shares = it->second.GetShares();
1471  uint32 prev_count = 0;
1472  for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1473  StationID via = flow_it->second;
1474  CargoDataEntry *via_entry = source_entry->InsertOrRetrieve(via);
1475  if (via == this->window_number) {
1476  via_entry->InsertOrRetrieve(via)->Update(flow_it->first - prev_count);
1477  } else {
1478  EstimateDestinations(i, from, via, flow_it->first - prev_count, via_entry);
1479  }
1480  prev_count = flow_it->first;
1481  }
1482  }
1483  }
1484 
1494  void EstimateDestinations(CargoID cargo, StationID source, StationID next, uint count, CargoDataEntry *dest)
1495  {
1496  if (Station::IsValidID(next) && Station::IsValidID(source)) {
1497  CargoDataEntry tmp;
1498  const FlowStatMap &flowmap = Station::Get(next)->goods[cargo].flows;
1499  FlowStatMap::const_iterator map_it = flowmap.find(source);
1500  if (map_it != flowmap.end()) {
1501  const FlowStat::SharesMap *shares = map_it->second.GetShares();
1502  uint32 prev_count = 0;
1503  for (FlowStat::SharesMap::const_iterator i = shares->begin(); i != shares->end(); ++i) {
1504  tmp.InsertOrRetrieve(i->second)->Update(i->first - prev_count);
1505  prev_count = i->first;
1506  }
1507  }
1508 
1509  if (tmp.GetCount() == 0) {
1510  dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1511  } else {
1512  uint sum_estimated = 0;
1513  while (sum_estimated < count) {
1514  for (CargoDataSet::iterator i = tmp.Begin(); i != tmp.End() && sum_estimated < count; ++i) {
1515  CargoDataEntry *child = *i;
1516  uint estimate = DivideApprox(child->GetCount() * count, tmp.GetCount());
1517  if (estimate == 0) estimate = 1;
1518 
1519  sum_estimated += estimate;
1520  if (sum_estimated > count) {
1521  estimate -= sum_estimated - count;
1522  sum_estimated = count;
1523  }
1524 
1525  if (estimate > 0) {
1526  if (child->GetStation() == next) {
1527  dest->InsertOrRetrieve(next)->Update(estimate);
1528  } else {
1529  EstimateDestinations(cargo, source, child->GetStation(), estimate, dest);
1530  }
1531  }
1532  }
1533 
1534  }
1535  }
1536  } else {
1537  dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1538  }
1539  }
1540 
1547  void BuildFlowList(CargoID i, const FlowStatMap &flows, CargoDataEntry *cargo)
1548  {
1549  const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1550  for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1551  StationID from = it->first;
1552  const CargoDataEntry *source_entry = source_dest->Retrieve(from);
1553  const FlowStat::SharesMap *shares = it->second.GetShares();
1554  for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1555  const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second);
1556  for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1557  CargoDataEntry *dest_entry = *dest_it;
1558  ShowCargo(cargo, i, from, flow_it->second, dest_entry->GetStation(), dest_entry->GetCount());
1559  }
1560  }
1561  }
1562  }
1563 
1570  void BuildCargoList(CargoID i, const StationCargoList &packets, CargoDataEntry *cargo)
1571  {
1572  const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1573  for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) {
1574  const CargoPacket *cp = *it;
1575  StationID next = it.GetKey();
1576 
1577  const CargoDataEntry *source_entry = source_dest->Retrieve(cp->SourceStation());
1578  if (source_entry == nullptr) {
1579  this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count());
1580  continue;
1581  }
1582 
1583  const CargoDataEntry *via_entry = source_entry->Retrieve(next);
1584  if (via_entry == nullptr) {
1585  this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count());
1586  continue;
1587  }
1588 
1589  for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1590  CargoDataEntry *dest_entry = *dest_it;
1591  uint val = DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount());
1592  this->ShowCargo(cargo, i, cp->SourceStation(), next, dest_entry->GetStation(), val);
1593  }
1594  }
1595  this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
1596  }
1597 
1603  void BuildCargoList(CargoDataEntry *cargo, const Station *st)
1604  {
1605  for (CargoID i = 0; i < NUM_CARGO; i++) {
1606 
1607  if (this->cached_destinations.Retrieve(i) == nullptr) {
1608  this->RecalcDestinations(i);
1609  }
1610 
1611  if (this->current_mode == MODE_WAITING) {
1612  this->BuildCargoList(i, st->goods[i].cargo, cargo);
1613  } else {
1614  this->BuildFlowList(i, st->goods[i].flows, cargo);
1615  }
1616  }
1617  }
1618 
1624  {
1625  std::list<StationID> stations;
1626  const CargoDataEntry *parent = data->GetParent();
1627  if (parent->GetParent() == nullptr) {
1628  this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, data->GetCargo()));
1629  return;
1630  }
1631 
1632  StationID next = data->GetStation();
1633  while (parent->GetParent()->GetParent() != nullptr) {
1634  stations.push_back(parent->GetStation());
1635  parent = parent->GetParent();
1636  }
1637 
1638  CargoID cargo = parent->GetCargo();
1639  CargoDataEntry *filter = this->expanded_rows.Retrieve(cargo);
1640  while (!stations.empty()) {
1641  filter = filter->Retrieve(stations.back());
1642  stations.pop_back();
1643  }
1644 
1645  this->displayed_rows.push_back(RowDisplay(filter, next));
1646  }
1647 
1656  StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any)
1657  {
1658  if (station == this->window_number) {
1659  return here;
1660  } else if (station == INVALID_STATION) {
1661  return any;
1662  } else if (station == NEW_STATION) {
1663  return STR_STATION_VIEW_RESERVED;
1664  } else {
1665  SetDParam(2, station);
1666  return other_station;
1667  }
1668  }
1669 
1677  StringID SearchNonStop(CargoDataEntry *cd, StationID station, int column)
1678  {
1679  CargoDataEntry *parent = cd->GetParent();
1680  for (int i = column - 1; i > 0; --i) {
1681  if (this->groupings[i] == GR_DESTINATION) {
1682  if (parent->GetStation() == station) {
1683  return STR_STATION_VIEW_NONSTOP;
1684  } else {
1685  return STR_STATION_VIEW_VIA;
1686  }
1687  }
1688  parent = parent->GetParent();
1689  }
1690 
1691  if (this->groupings[column + 1] == GR_DESTINATION) {
1692  CargoDataSet::iterator begin = cd->Begin();
1693  CargoDataSet::iterator end = cd->End();
1694  if (begin != end && ++(cd->Begin()) == end && (*(begin))->GetStation() == station) {
1695  return STR_STATION_VIEW_NONSTOP;
1696  } else {
1697  return STR_STATION_VIEW_VIA;
1698  }
1699  }
1700 
1701  return STR_STATION_VIEW_VIA;
1702  }
1703 
1714  int DrawEntries(CargoDataEntry *entry, Rect &r, int pos, int maxrows, int column, CargoID cargo = CT_INVALID)
1715  {
1716  if (this->sortings[column] == ST_AS_GROUPING) {
1717  if (this->groupings[column] != GR_CARGO) {
1718  entry->Resort(ST_STATION_STRING, this->sort_orders[column]);
1719  }
1720  } else {
1721  entry->Resort(ST_COUNT, this->sort_orders[column]);
1722  }
1723  for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) {
1724  CargoDataEntry *cd = *i;
1725 
1726  Grouping grouping = this->groupings[column];
1727  if (grouping == GR_CARGO) cargo = cd->GetCargo();
1728  bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1729 
1730  if (pos > -maxrows && pos <= 0) {
1731  StringID str = STR_EMPTY;
1732  int y = r.top + WD_FRAMERECT_TOP - pos * FONT_HEIGHT_NORMAL;
1733  SetDParam(0, cargo);
1734  SetDParam(1, cd->GetCount());
1735 
1736  if (this->groupings[column] == GR_CARGO) {
1737  str = STR_STATION_VIEW_WAITING_CARGO;
1738  DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + WD_FRAMERECT_LEFT + this->expand_shrink_width, r.right - WD_FRAMERECT_RIGHT - this->expand_shrink_width, y);
1739  } else {
1740  if (!auto_distributed) grouping = GR_SOURCE;
1741  StationID station = cd->GetStation();
1742 
1743  switch (grouping) {
1744  case GR_SOURCE:
1745  str = this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
1746  break;
1747  case GR_NEXT:
1748  str = this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
1749  if (str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
1750  break;
1751  case GR_DESTINATION:
1752  str = this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
1753  break;
1754  default:
1755  NOT_REACHED();
1756  }
1757  if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
1758  ScrollMainWindowToTile(Station::Get(station)->xy);
1759  }
1760  }
1761 
1762  bool rtl = _current_text_dir == TD_RTL;
1763  int text_left = rtl ? r.left + this->expand_shrink_width : r.left + WD_FRAMERECT_LEFT + column * this->expand_shrink_width;
1764  int text_right = rtl ? r.right - WD_FRAMERECT_LEFT - column * this->expand_shrink_width : r.right - this->expand_shrink_width;
1765  int shrink_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - this->expand_shrink_width + WD_FRAMERECT_LEFT;
1766  int shrink_right = rtl ? r.left + this->expand_shrink_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
1767 
1768  DrawString(text_left, text_right, y, str);
1769 
1770  if (column < NUM_COLUMNS - 1) {
1771  const char *sym = nullptr;
1772  if (cd->GetNumChildren() > 0) {
1773  sym = "-";
1774  } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
1775  sym = "+";
1776  } else {
1777  /* Only draw '+' if there is something to be shown. */
1778  const StationCargoList &list = Station::Get(this->window_number)->goods[cargo].cargo;
1779  if (grouping == GR_CARGO && (list.ReservedCount() > 0 || cd->HasTransfers())) {
1780  sym = "+";
1781  }
1782  }
1783  if (sym) DrawString(shrink_left, shrink_right, y, sym, TC_YELLOW);
1784  }
1785  this->SetDisplayedRow(cd);
1786  }
1787  --pos;
1788  if (auto_distributed || column == 0) {
1789  pos = this->DrawEntries(cd, r, pos, maxrows, column + 1, cargo);
1790  }
1791  }
1792  return pos;
1793  }
1794 
1800  int DrawAcceptedCargo(const Rect &r) const
1801  {
1802  const Station *st = Station::Get(this->window_number);
1803 
1804  CargoTypes cargo_mask = 0;
1805  for (CargoID i = 0; i < NUM_CARGO; i++) {
1806  if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(cargo_mask, i);
1807  }
1808  SetDParam(0, cargo_mask);
1809  int bottom = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO);
1810  return CeilDiv(bottom - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
1811  }
1812 
1818  int DrawCargoRatings(const Rect &r) const
1819  {
1820  const Station *st = Station::Get(this->window_number);
1821  int y = r.top + WD_FRAMERECT_TOP;
1822 
1823  if (st->town->exclusive_counter > 0) {
1824  SetDParam(0, st->town->exclusivity);
1825  y = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY);
1826  y += WD_PAR_VSEP_WIDE;
1827  }
1828 
1829  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_VIEW_SUPPLY_RATINGS_TITLE);
1830  y += FONT_HEIGHT_NORMAL;
1831 
1832  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1833  const GoodsEntry *ge = &st->goods[cs->Index()];
1834  if (!ge->HasRating()) continue;
1835 
1836  const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph);
1837  SetDParam(0, cs->name);
1838  SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].Supply()) : 0);
1839  SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
1840  SetDParam(3, ToPercent8(ge->rating));
1841  DrawString(r.left + WD_FRAMERECT_LEFT + 6, r.right - WD_FRAMERECT_RIGHT - 6, y, STR_STATION_VIEW_CARGO_SUPPLY_RATING);
1842  y += FONT_HEIGHT_NORMAL;
1843  }
1844  return CeilDiv(y - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
1845  }
1846 
1852  template<class Tid>
1853  void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
1854  {
1855  if (filter->Retrieve(next) != nullptr) {
1856  filter->Remove(next);
1857  } else {
1858  filter->InsertOrRetrieve(next);
1859  }
1860  }
1861 
1867  {
1868  if (row < 0 || (uint)row >= this->displayed_rows.size()) return;
1869  if (_ctrl_pressed) {
1870  this->scroll_to_row = row;
1871  } else {
1872  RowDisplay &display = this->displayed_rows[row];
1873  if (display.filter == &this->expanded_rows) {
1874  this->HandleCargoWaitingClick<CargoID>(display.filter, display.next_cargo);
1875  } else {
1876  this->HandleCargoWaitingClick<StationID>(display.filter, display.next_station);
1877  }
1878  }
1880  }
1881 
1882  void OnClick(Point pt, int widget, int click_count) override
1883  {
1884  switch (widget) {
1885  case WID_SV_WAITING:
1886  this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP) - this->vscroll->GetPosition());
1887  break;
1888 
1889  case WID_SV_CATCHMENT:
1891  break;
1892 
1893  case WID_SV_LOCATION:
1894  if (_ctrl_pressed) {
1895  ShowExtraViewportWindow(Station::Get(this->window_number)->xy);
1896  } else {
1897  ScrollMainWindowToTile(Station::Get(this->window_number)->xy);
1898  }
1899  break;
1900 
1901  case WID_SV_ACCEPTS_RATINGS: {
1902  /* Swap between 'accepts' and 'ratings' view. */
1903  int height_change;
1904  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS);
1905  if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1906  nwi->SetDataTip(STR_STATION_VIEW_ACCEPTS_BUTTON, STR_STATION_VIEW_ACCEPTS_TOOLTIP); // Switch to accepts view.
1907  height_change = this->rating_lines - this->accepts_lines;
1908  } else {
1909  nwi->SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP); // Switch to ratings view.
1910  height_change = this->accepts_lines - this->rating_lines;
1911  }
1912  this->ReInit(0, height_change * FONT_HEIGHT_NORMAL);
1913  break;
1914  }
1915 
1916  case WID_SV_RENAME:
1917  SetDParam(0, this->window_number);
1918  ShowQueryString(STR_STATION_NAME, STR_STATION_VIEW_RENAME_STATION_CAPTION, MAX_LENGTH_STATION_NAME_CHARS,
1920  break;
1921 
1922  case WID_SV_CLOSE_AIRPORT:
1923  Command<CMD_OPEN_CLOSE_AIRPORT>::Post(this->window_number);
1924  break;
1925 
1926  case WID_SV_TRAINS: // Show list of scheduled trains to this station
1927  case WID_SV_ROADVEHS: // Show list of scheduled road-vehicles to this station
1928  case WID_SV_SHIPS: // Show list of scheduled ships to this station
1929  case WID_SV_PLANES: { // Show list of scheduled aircraft to this station
1930  Owner owner = Station::Get(this->window_number)->owner;
1931  ShowVehicleListWindow(owner, (VehicleType)(widget - WID_SV_TRAINS), (StationID)this->window_number);
1932  break;
1933  }
1934 
1935  case WID_SV_SORT_BY: {
1936  /* The initial selection is composed of current mode and
1937  * sorting criteria for columns 1, 2, and 3. Column 0 is always
1938  * sorted by cargo ID. The others can theoretically be sorted
1939  * by different things but there is no UI for that. */
1941  this->current_mode * 2 + (this->sortings[1] == ST_COUNT ? 1 : 0),
1942  WID_SV_SORT_BY, 0, 0);
1943  break;
1944  }
1945 
1946  case WID_SV_GROUP_BY: {
1947  ShowDropDownMenu(this, _group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
1948  break;
1949  }
1950 
1951  case WID_SV_SORT_ORDER: { // flip sorting method asc/desc
1952  this->SelectSortOrder(this->sort_orders[1] == SO_ASCENDING ? SO_DESCENDING : SO_ASCENDING);
1953  this->SetTimeout();
1955  break;
1956  }
1957  }
1958  }
1959 
1964  void SelectSortOrder(SortOrder order)
1965  {
1966  this->sort_orders[1] = this->sort_orders[2] = this->sort_orders[3] = order;
1967  _settings_client.gui.station_gui_sort_order = this->sort_orders[1];
1968  this->SetDirty();
1969  }
1970 
1975  void SelectSortBy(int index)
1976  {
1978  switch (_sort_names[index]) {
1979  case STR_STATION_VIEW_WAITING_STATION:
1980  this->current_mode = MODE_WAITING;
1981  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING;
1982  break;
1983  case STR_STATION_VIEW_WAITING_AMOUNT:
1984  this->current_mode = MODE_WAITING;
1985  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT;
1986  break;
1987  case STR_STATION_VIEW_PLANNED_STATION:
1988  this->current_mode = MODE_PLANNED;
1989  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING;
1990  break;
1991  case STR_STATION_VIEW_PLANNED_AMOUNT:
1992  this->current_mode = MODE_PLANNED;
1993  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT;
1994  break;
1995  default:
1996  NOT_REACHED();
1997  }
1998  /* Display the current sort variant */
1999  this->GetWidget<NWidgetCore>(WID_SV_SORT_BY)->widget_data = _sort_names[index];
2000  this->SetDirty();
2001  }
2002 
2007  void SelectGroupBy(int index)
2008  {
2009  this->grouping_index = index;
2011  this->GetWidget<NWidgetCore>(WID_SV_GROUP_BY)->widget_data = _group_names[index];
2012  switch (_group_names[index]) {
2013  case STR_STATION_VIEW_GROUP_S_V_D:
2014  this->groupings[1] = GR_SOURCE;
2015  this->groupings[2] = GR_NEXT;
2016  this->groupings[3] = GR_DESTINATION;
2017  break;
2018  case STR_STATION_VIEW_GROUP_S_D_V:
2019  this->groupings[1] = GR_SOURCE;
2020  this->groupings[2] = GR_DESTINATION;
2021  this->groupings[3] = GR_NEXT;
2022  break;
2023  case STR_STATION_VIEW_GROUP_V_S_D:
2024  this->groupings[1] = GR_NEXT;
2025  this->groupings[2] = GR_SOURCE;
2026  this->groupings[3] = GR_DESTINATION;
2027  break;
2028  case STR_STATION_VIEW_GROUP_V_D_S:
2029  this->groupings[1] = GR_NEXT;
2030  this->groupings[2] = GR_DESTINATION;
2031  this->groupings[3] = GR_SOURCE;
2032  break;
2033  case STR_STATION_VIEW_GROUP_D_S_V:
2034  this->groupings[1] = GR_DESTINATION;
2035  this->groupings[2] = GR_SOURCE;
2036  this->groupings[3] = GR_NEXT;
2037  break;
2038  case STR_STATION_VIEW_GROUP_D_V_S:
2039  this->groupings[1] = GR_DESTINATION;
2040  this->groupings[2] = GR_NEXT;
2041  this->groupings[3] = GR_SOURCE;
2042  break;
2043  }
2044  this->SetDirty();
2045  }
2046 
2047  void OnDropdownSelect(int widget, int index) override
2048  {
2049  if (widget == WID_SV_SORT_BY) {
2050  this->SelectSortBy(index);
2051  } else {
2052  this->SelectGroupBy(index);
2053  }
2054  }
2055 
2056  void OnQueryTextFinished(char *str) override
2057  {
2058  if (str == nullptr) return;
2059 
2060  Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, str);
2061  }
2062 
2063  void OnResize() override
2064  {
2066  }
2067 
2073  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2074  {
2075  if (gui_scope) {
2076  if (data >= 0 && data < NUM_CARGO) {
2077  this->cached_destinations.Remove((CargoID)data);
2078  } else {
2079  this->ReInit();
2080  }
2081  }
2082  }
2083 };
2084 
2086  STR_STATION_VIEW_WAITING_STATION,
2087  STR_STATION_VIEW_WAITING_AMOUNT,
2088  STR_STATION_VIEW_PLANNED_STATION,
2089  STR_STATION_VIEW_PLANNED_AMOUNT,
2091 };
2092 
2094  STR_STATION_VIEW_GROUP_S_V_D,
2095  STR_STATION_VIEW_GROUP_S_D_V,
2096  STR_STATION_VIEW_GROUP_V_S_D,
2097  STR_STATION_VIEW_GROUP_V_D_S,
2098  STR_STATION_VIEW_GROUP_D_S_V,
2099  STR_STATION_VIEW_GROUP_D_V_S,
2101 };
2102 
2103 static WindowDesc _station_view_desc(
2104  WDP_AUTO, "view_station", 249, 117,
2106  0,
2107  _nested_station_view_widgets, lengthof(_nested_station_view_widgets)
2108 );
2109 
2115 void ShowStationViewWindow(StationID station)
2116 {
2117  AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
2118 }
2119 
2123  StationID station;
2124 };
2125 
2126 static std::vector<TileAndStation> _deleted_stations_nearby;
2127 static std::vector<StationID> _stations_nearby_list;
2128 
2136 template <class T>
2137 static bool AddNearbyStation(TileIndex tile, void *user_data)
2138 {
2139  TileArea *ctx = (TileArea *)user_data;
2140 
2141  /* First check if there were deleted stations here */
2142  for (uint i = 0; i < _deleted_stations_nearby.size(); i++) {
2143  auto ts = _deleted_stations_nearby.begin() + i;
2144  if (ts->tile == tile) {
2145  _stations_nearby_list.push_back(_deleted_stations_nearby[i].station);
2146  _deleted_stations_nearby.erase(ts);
2147  i--;
2148  }
2149  }
2150 
2151  /* Check if own station and if we stay within station spread */
2152  if (!IsTileType(tile, MP_STATION)) return false;
2153 
2154  StationID sid = GetStationIndex(tile);
2155 
2156  /* This station is (likely) a waypoint */
2157  if (!T::IsValidID(sid)) return false;
2158 
2159  T *st = T::Get(sid);
2160  if (st->owner != _local_company || std::find(_stations_nearby_list.begin(), _stations_nearby_list.end(), sid) != _stations_nearby_list.end()) return false;
2161 
2162  if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
2163  _stations_nearby_list.push_back(sid);
2164  }
2165 
2166  return false; // We want to include *all* nearby stations
2167 }
2168 
2178 template <class T>
2179 static const T *FindStationsNearby(TileArea ta, bool distant_join)
2180 {
2181  TileArea ctx = ta;
2182 
2183  _stations_nearby_list.clear();
2184  _deleted_stations_nearby.clear();
2185 
2186  /* Check the inside, to return, if we sit on another station */
2187  for (TileIndex t : ta) {
2188  if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
2189  }
2190 
2191  /* Look for deleted stations */
2192  for (const BaseStation *st : BaseStation::Iterate()) {
2193  if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
2194  /* Include only within station spread (yes, it is strictly less than) */
2195  if (std::max(DistanceMax(ta.tile, st->xy), DistanceMax(TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1), st->xy)) < _settings_game.station.station_spread) {
2196  _deleted_stations_nearby.push_back({st->xy, st->index});
2197 
2198  /* Add the station when it's within where we're going to build */
2199  if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
2200  IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
2201  AddNearbyStation<T>(st->xy, &ctx);
2202  }
2203  }
2204  }
2205  }
2206 
2207  /* Only search tiles where we have a chance to stay within the station spread.
2208  * The complete check needs to be done in the callback as we don't know the
2209  * extent of the found station, yet. */
2210  if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return nullptr;
2211  uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1;
2212 
2213  TileIndex tile = TileAddByDir(ctx.tile, DIR_N);
2214  CircularTileSearch(&tile, max_dist, ta.w, ta.h, AddNearbyStation<T>, &ctx);
2215 
2216  return nullptr;
2217 }
2218 
2219 static const NWidgetPart _nested_select_station_widgets[] = {
2221  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
2222  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_JS_CAPTION), SetDataTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2223  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
2224  EndContainer(),
2226  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_JS_PANEL), SetResize(1, 0), SetScrollbar(WID_JS_SCROLLBAR), EndContainer(),
2228  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_JS_SCROLLBAR),
2229  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
2230  EndContainer(),
2231  EndContainer(),
2232 };
2233 
2238 template <class T>
2240  StationPickerCmdProc select_station_proc;
2242  Scrollbar *vscroll;
2243 
2244  SelectStationWindow(WindowDesc *desc, TileArea ta, StationPickerCmdProc&& proc) :
2245  Window(desc),
2246  select_station_proc(std::move(proc)),
2247  area(ta)
2248  {
2249  this->CreateNestedTree();
2250  this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR);
2251  this->GetWidget<NWidgetCore>(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION;
2252  this->FinishInitNested(0);
2253  this->OnInvalidateData(0);
2254 
2255  _thd.freeze = true;
2256  }
2257 
2258  void Close() override
2259  {
2261 
2262  _thd.freeze = false;
2263  this->Window::Close();
2264  }
2265 
2266  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2267  {
2268  if (widget != WID_JS_PANEL) return;
2269 
2270  /* Determine the widest string */
2271  Dimension d = GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2272  for (uint i = 0; i < _stations_nearby_list.size(); i++) {
2273  const T *st = T::Get(_stations_nearby_list[i]);
2274  SetDParam(0, st->index);
2275  SetDParam(1, st->facilities);
2276  d = maxdim(d, GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION));
2277  }
2278 
2279  resize->height = d.height;
2280  d.height *= 5;
2282  d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
2283  *size = d;
2284  }
2285 
2286  void DrawWidget(const Rect &r, int widget) const override
2287  {
2288  if (widget != WID_JS_PANEL) return;
2289 
2290  uint y = r.top + WD_FRAMERECT_TOP;
2291  if (this->vscroll->GetPosition() == 0) {
2292  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2293  y += this->resize.step_height;
2294  }
2295 
2296  for (uint i = std::max<uint>(1, this->vscroll->GetPosition()); i <= _stations_nearby_list.size(); ++i, y += this->resize.step_height) {
2297  /* Don't draw anything if it extends past the end of the window. */
2298  if (i - this->vscroll->GetPosition() >= this->vscroll->GetCapacity()) break;
2299 
2300  const T *st = T::Get(_stations_nearby_list[i - 1]);
2301  SetDParam(0, st->index);
2302  SetDParam(1, st->facilities);
2303  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION);
2304  }
2305  }
2306 
2307  void OnClick(Point pt, int widget, int click_count) override
2308  {
2309  if (widget != WID_JS_PANEL) return;
2310 
2311  uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP);
2312  bool distant_join = (st_index > 0);
2313  if (distant_join) st_index--;
2314 
2315  if (distant_join && st_index >= _stations_nearby_list.size()) return;
2316 
2317  /* Execute stored Command */
2318  this->select_station_proc(false, distant_join ? _stations_nearby_list[st_index] : NEW_STATION);
2319 
2320  /* Close Window; this might cause double frees! */
2322  }
2323 
2324  void OnRealtimeTick(uint delta_ms) override
2325  {
2326  if (_thd.dirty & 2) {
2327  _thd.dirty &= ~2;
2328  this->SetDirty();
2329  }
2330  }
2331 
2332  void OnResize() override
2333  {
2334  this->vscroll->SetCapacityFromWidget(this, WID_JS_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
2335  }
2336 
2342  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2343  {
2344  if (!gui_scope) return;
2345  FindStationsNearby<T>(this->area, true);
2346  this->vscroll->SetCount((uint)_stations_nearby_list.size() + 1);
2347  this->SetDirty();
2348  }
2349 
2350  void OnMouseOver(Point pt, int widget) override
2351  {
2352  if (widget != WID_JS_PANEL || T::EXPECTED_FACIL == FACIL_WAYPOINT) {
2353  SetViewportCatchmentStation(nullptr, true);
2354  return;
2355  }
2356 
2357  /* Show coverage area of station under cursor */
2358  uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP);
2359  if (st_index == 0 || st_index > _stations_nearby_list.size()) {
2360  SetViewportCatchmentStation(nullptr, true);
2361  } else {
2362  st_index--;
2363  SetViewportCatchmentStation(Station::Get(_stations_nearby_list[st_index]), true);
2364  }
2365  }
2366 };
2367 
2368 static WindowDesc _select_station_desc(
2369  WDP_AUTO, "build_station_join", 200, 180,
2372  _nested_select_station_widgets, lengthof(_nested_select_station_widgets)
2373 );
2374 
2375 
2383 template <class T>
2384 static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
2385 {
2386  /* Only show selection if distant join is enabled in the settings */
2387  if (!_settings_game.station.distant_join_stations) return false;
2388 
2389  /* If a window is already opened and we didn't ctrl-click,
2390  * return true (i.e. just flash the old window) */
2391  Window *selection_window = FindWindowById(WC_SELECT_STATION, 0);
2392  if (selection_window != nullptr) {
2393  /* Abort current distant-join and start new one */
2394  selection_window->Close();
2396  }
2397 
2398  /* only show the popup, if we press ctrl */
2399  if (!_ctrl_pressed) return false;
2400 
2401  /* Now check if we could build there */
2402  if (!proc(true, INVALID_STATION)) return false;
2403 
2404  /* Test for adjacent station or station below selection.
2405  * If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
2406  * but join the other station immediately. */
2407  const T *st = FindStationsNearby<T>(ta, false);
2408  return st == nullptr && (_settings_game.station.adjacent_stations || _stations_nearby_list.size() == 0);
2409 }
2410 
2417 template <class T>
2418 void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc&& proc)
2419 {
2420  if (StationJoinerNeeded<T>(ta, proc)) {
2422  new SelectStationWindow<T>(&_select_station_desc, ta, std::move(proc));
2423  } else {
2424  proc(false, INVALID_STATION);
2425  }
2426 }
2427 
2433 void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
2434 {
2435  ShowSelectBaseStationIfNeeded<Station>(ta, std::move(proc));
2436 }
2437 
2443 void ShowSelectWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
2444 {
2445  ShowSelectBaseStationIfNeeded<Waypoint>(ta, std::move(proc));
2446 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
StationViewWindow::grouping_index
int grouping_index
Currently selected entry in the grouping drop down.
Definition: station_gui.cpp:1279
StationJoinerNeeded
static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
Check whether we need to show the station selection window.
Definition: station_gui.cpp:2384
StationViewWindow::HandleCargoWaitingClick
void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
Expand or collapse a specific row.
Definition: station_gui.cpp:1853
CompanyStationsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:650
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:63
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:360
StationViewWindow
The StationView window.
Definition: station_gui.cpp:1198
CargoList< StationCargoList, StationCargoPacketMap >::ConstIterator
StationCargoPacketMap ::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:208
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:306
CompanyStationsWindow::StationRatingMaxSorter
static bool StationRatingMaxSorter(const Station *const &a, const Station *const &b)
Sort stations by their rating.
Definition: station_gui.cpp:297
WID_STL_SORTBY
@ WID_STL_SORTBY
'Sort by' button - reverse sort direction.
Definition: station_widget.h:52
TileHighlightData::size
Point size
Size, in tile "units", of the white/red selection area.
Definition: tilehighlight_type.h:48
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:483
StationViewWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: station_gui.cpp:1307
StationViewWindow::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: station_gui.cpp:1882
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1241
GUIList::SortType
uint8 SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:93
GUISettings::station_show_coverage
bool station_show_coverage
whether to highlight coverage area
Definition: settings_type.h:164
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2446
vehicle_gui.h
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:592
StationViewWindow::ALH_ACCEPTS
@ ALH_ACCEPTS
Height of the accepted cargo view.
Definition: station_gui.cpp:1261
UpdateTileSelection
void UpdateTileSelection()
Updates tile highlighting for all cases.
Definition: viewport.cpp:2533
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:39
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1190
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
StationViewWindow::RowDisplay::filter
CargoDataEntry * filter
Parent of the cargo entry belonging to the row.
Definition: station_gui.cpp:1209
DivideApprox
int DivideApprox(int a, int b)
Deterministic approximate division.
Definition: math_func.cpp:57
ToPercent8
static uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
Definition: math_func.hpp:227
GetAcceptanceAroundTiles
CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
Get the acceptance of cargoes around the tile in 1/8.
Definition: station_cmd.cpp:548
ScaleFontTrad
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Definition: zoom_func.h:127
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:664
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:670
GUISettings::station_gui_sort_by
uint8 station_gui_sort_by
sort cargo entries in the station gui by station name or amount
Definition: settings_type.h:181
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Pool::PoolItem<&_link_graph_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
dropdown_func.h
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
CargoDataEntry::InsertOrRetrieve
CargoDataEntry * InsertOrRetrieve(StationID station)
Insert a new child or retrieve an existing child using a station ID as ID.
Definition: station_gui.cpp:873
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:152
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1004
company_base.h
StationViewWindow::INV_FLOWS
@ INV_FLOWS
The planned flows have been recalculated and everything has to be updated.
Definition: station_gui.cpp:1231
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1047
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:247
CargoDataEntry::cargo
CargoID cargo
ID of the cargo this entry is associated with.
Definition: station_gui.cpp:999
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:61
CompanyStationsWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: station_gui.cpp:497
GetContrastColour
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
Definition: gfx.cpp:1418
CompanyStationsWindow
The list of stations per company.
Definition: station_gui.cpp:200
FACIL_TRUCK_STOP
@ FACIL_TRUCK_STOP
Station with truck stops.
Definition: station_type.h:54
CompanyStationsWindow::BuildStationsList
void BuildStationsList(const Owner owner)
(Re)Build station list
Definition: station_gui.cpp:223
WID_SV_WAITING
@ WID_SV_WAITING
List of waiting cargo.
Definition: station_widget.h:20
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Station
Station data structure.
Definition: station_base.h:454
CheckRedrawStationCoverage
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Definition: station_gui.cpp:127
StationViewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:2073
GUIList< const Station * >
GUISettings::station_gui_group_order
uint8 station_gui_group_order
the order of grouping cargo entries in the station gui
Definition: settings_type.h:180
StationViewWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: station_gui.cpp:2047
SelectStationWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2332
PC_RED
static const uint8 PC_RED
Red palette colour.
Definition: gfx_func.h:211
vehiclelist.h
TileAddByDir
static TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition: map_func.h:370
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
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:892
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
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
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
DT_MANUAL
@ DT_MANUAL
Manual distribution. No link graph calculations are run.
Definition: linkgraph_type.h:25
StationViewWindow::cached_destinations
CargoDataEntry cached_destinations
Cache for the flows passing through this station.
Definition: station_gui.cpp:1284
StationViewWindow::RowDisplay
A row being displayed in the cargo view (as opposed to being "hidden" behind a plus sign).
Definition: station_gui.cpp:1202
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1146
WID_SV_GROUP_BY
@ WID_SV_GROUP_BY
'Group by' button
Definition: station_widget.h:17
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
CargoDataEntry::GetCargo
CargoID GetCargo() const
Get the cargo ID for this entry.
Definition: station_gui.cpp:942
StationViewWindow::SelectSortBy
void SelectSortBy(int index)
Select a new sort criterium for the cargo view.
Definition: station_gui.cpp:1975
StationViewWindow::DrawEntries
int DrawEntries(CargoDataEntry *entry, Rect &r, int pos, int maxrows, int column, CargoID cargo=CT_INVALID)
Draw the given cargo entries in the station GUI.
Definition: station_gui.cpp:1714
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:712
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
WID_STL_LIST
@ WID_STL_LIST
The main panel, list of stations.
Definition: station_widget.h:38
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:449
StationViewWindow::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: station_gui.cpp:1364
StationViewWindow::BuildCargoList
void BuildCargoList(CargoID i, const StationCargoList &packets, CargoDataEntry *cargo)
Build up the cargo view for WAITING mode and a specific cargo.
Definition: station_gui.cpp:1570
DrawCargoIcons
static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int y)
Draws icons of waiting cargo in the StationView window.
Definition: station_gui.cpp:810
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:995
zoom_func.h
FACIL_NONE
@ FACIL_NONE
The station has no facilities at all.
Definition: station_type.h:52
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
StationViewWindow::BuildCargoList
void BuildCargoList(CargoDataEntry *cargo, const Station *st)
Build up the cargo view for all cargoes.
Definition: station_gui.cpp:1603
StationViewWindow::DrawCargoRatings
int DrawCargoRatings(const Rect &r) const
Draw cargo ratings in the WID_SV_ACCEPT_RATING_LIST widget.
Definition: station_gui.cpp:1818
ShowCompanyStations
void ShowCompanyStations(CompanyID company)
Opens window with list of company's stations.
Definition: station_gui.cpp:757
AddNearbyStation
static bool AddNearbyStation(TileIndex tile, void *user_data)
Add station on this tile to _stations_nearby_list if it's fully within the station spread.
Definition: station_gui.cpp:2137
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:219
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
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:645
StationViewWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: station_gui.cpp:2056
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
SpecializedStation< Station, false >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Definition: base_station_base.h:210
CargoDataEntry::GetCount
uint GetCount() const
Get the cargo count for this entry.
Definition: station_gui.cpp:947
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:319
FindStationsAroundSelection
static void FindStationsAroundSelection()
Find stations adjacent to the current tile highlight area, so that existing coverage area can be draw...
Definition: station_gui.cpp:86
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
WC_STATION_VIEW
@ WC_STATION_VIEW
Station view; Window numbers:
Definition: window_type.h:337
WID_STL_CAPTION
@ WID_STL_CAPTION
Caption of the window.
Definition: station_widget.h:37
CargoSpec::GetCargoIcon
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
Definition: cargotype.cpp:139
StationViewWindow::_sort_names
static const StringID _sort_names[]
Names of the sorting options in the dropdown.
Definition: station_gui.cpp:1264
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:41
CompanyStationsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:417
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:2138
StationViewWindow::GR_DESTINATION
@ GR_DESTINATION
Group by estimated final destination ("to").
Definition: station_gui.cpp:1241
WID_SV_SORT_BY
@ WID_SV_SORT_BY
'Sort by' button
Definition: station_widget.h:19
StationViewWindow::SearchNonStop
StringID SearchNonStop(CargoDataEntry *cd, StationID station, int column)
Determine if we need to show the special "non-stop" string.
Definition: station_gui.cpp:1677
SelectStationWindow::area
TileArea area
Location of new station.
Definition: station_gui.cpp:2241
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:631
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:62
DIR_N
@ DIR_N
North.
Definition: direction_type.h:26
StationViewWindow::expand_shrink_width
uint expand_shrink_width
The width allocated to the expand/shrink 'button'.
Definition: station_gui.cpp:1253
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
StationViewWindow::MODE_PLANNED
@ MODE_PLANNED
Show cargo planned to pass through the station.
Definition: station_gui.cpp:1250
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
CargoDataEntry::children
CargoDataSet * children
the children of this entry.
Definition: station_gui.cpp:1005
GoodsEntry::status
byte status
Status of this cargo, see GoodsEntryStatus.
Definition: station_base.h:223
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
StationViewWindow::GR_SOURCE
@ GR_SOURCE
Group by source of cargo ("from").
Definition: station_gui.cpp:1239
StationViewWindow::AcceptListHeight
AcceptListHeight
Height of the WID_SV_ACCEPT_RATING_LIST widget for different views.
Definition: station_gui.cpp:1259
ShowStationViewWindow
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
Definition: station_gui.cpp:2115
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:527
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:891
textbuf_gui.h
CompanyStationsWindow::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: station_gui.cpp:505
StationViewWindow::INV_CARGO
@ INV_CARGO
Some cargo has been added or removed.
Definition: station_gui.cpp:1232
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
StationViewWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: station_gui.cpp:1448
CompanyStationsWindow::StationWaitingAvailableSorter
static bool StationWaitingAvailableSorter(const Station *const &a, const Station *const &b)
Sort stations by their available waiting cargo.
Definition: station_gui.cpp:285
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:790
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
CargoDataEntry::InsertOrRetrieve
CargoDataEntry * InsertOrRetrieve(CargoID cargo)
Insert a new child or retrieve an existing child using a cargo ID as ID.
Definition: station_gui.cpp:883
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:270
WID_SV_ROADVEHS
@ WID_SV_ROADVEHS
List of scheduled road vehs button.
Definition: station_widget.h:28
ST_STATION_ID
@ ST_STATION_ID
by station id
Definition: station_gui.cpp:836
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
StationViewWindow::current_mode
Mode current_mode
Currently selected display mode of cargo view.
Definition: station_gui.cpp:1280
WID_SV_CATCHMENT
@ WID_SV_CATCHMENT
Toggle catchment area highlight.
Definition: station_widget.h:31
StationViewWindow::NUM_COLUMNS
static const int NUM_COLUMNS
Number of "columns" in the cargo view: cargo, from, via, to.
Definition: station_gui.cpp:1225
WindowDesc
High level window description.
Definition: window_gui.h:168
StationViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2063
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:252
CargoDataEntry::num_children
uint num_children
the number of subentries belonging to this entry.
Definition: station_gui.cpp:1003
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:464
FACIL_BUS_STOP
@ FACIL_BUS_STOP
Station with bus stops.
Definition: station_type.h:55
GetProductionAroundTiles
CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
Get the cargo types being produced around the tile (in a rectangle).
Definition: station_cmd.cpp:509
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:89
StationViewWindow::GetEntryString
StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any)
Select the correct string for an entry referring to the specified station.
Definition: station_gui.cpp:1656
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:223
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
SCT_PASSENGERS_ONLY
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
Definition: station_gui.h:22
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
StationViewWindow::sortings
CargoSortType sortings[NUM_COLUMNS]
Sort types of the different 'columns'.
Definition: station_gui.cpp:1273
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:329
CargoDataEntry::GetNumChildren
uint GetNumChildren() const
Get the number of children for this entry.
Definition: station_gui.cpp:957
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:655
tilehighlight_func.h
CircularTileSearch
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition: map.cpp:258
WID_STL_CARGOSTART
@ WID_STL_CARGOSTART
Widget numbers used for list of cargo types (not present in _company_stations_widgets).
Definition: station_widget.h:55
CargoPacket::SourceStation
StationID SourceStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:159
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
CompanyStationsWindow::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: station_gui.cpp:371
StationViewWindow::DrawAcceptedCargo
int DrawAcceptedCargo(const Rect &r) const
Draw accepted cargo in the WID_SV_ACCEPT_RATING_LIST widget.
Definition: station_gui.cpp:1800
StationCoverageType
StationCoverageType
Types of cargo to display for station coverage.
Definition: station_gui.h:21
StationViewWindow::SetDisplayedRow
void SetDisplayedRow(const CargoDataEntry *data)
Mark a specific row, characterized by its CargoDataEntry, as expanded.
Definition: station_gui.cpp:1623
StationViewWindow::ShowCargo
void ShowCargo(CargoDataEntry *data, CargoID cargo, StationID source, StationID next, StationID dest, uint count)
Show a certain cargo entry characterized by source/next/dest station, cargo ID and amount of cargo at...
Definition: station_gui.cpp:1328
StationViewWindow::RowDisplay::next_station
StationID next_station
ID of the station belonging to the entry actually displayed if it's to/from/via.
Definition: station_gui.cpp:1214
WID_STL_TRUCK
@ WID_STL_TRUCK
'TRUCK' button - list only facilities where is a truck stop.
Definition: station_widget.h:43
GoodsEntry::HasRating
bool HasRating() const
Does this cargo have a rating at this station?
Definition: station_base.h:270
CompanyStationsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:640
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:916
GUIList< const Station * >::SortFunction
bool SortFunction(const const Station * &, const const Station * &)
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:993
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
StationViewWindow::HandleCargoWaitingClick
void HandleCargoWaitingClick(int row)
Handle a click on a specific row in the cargo view.
Definition: station_gui.cpp:1866
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:208
IsInsideBS
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:188
StationViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:1388
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
GoodsEntry::node
NodeID node
ID of node in link graph referring to this goods entry.
Definition: station_base.h:255
station_cmd.h
CargoSortType
CargoSortType
Definition: station_gui.cpp:832
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
StationsWndShowStationRating
static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
Draw small boxes of cargo amount and ratings data at the given coordinates.
Definition: station_gui.cpp:158
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
_cargo_mask
CargoTypes _cargo_mask
Bitmask of cargo types available.
Definition: cargotype.cpp:28
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:468
WID_SV_SORT_ORDER
@ WID_SV_SORT_ORDER
'Sort order' button
Definition: station_widget.h:18
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
CargoWidgets
static NWidgetBase * CargoWidgets(int *biggest_index)
Make a horizontal row of cargo buttons, starting at widget WID_STL_CARGOSTART.
Definition: station_gui.cpp:693
ShowSelectStationIfNeeded
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
Definition: station_gui.cpp:2433
CompanyStationsWindow::StationTypeSorter
static bool StationTypeSorter(const Station *const &a, const Station *const &b)
Sort stations by their type.
Definition: station_gui.cpp:267
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
StationViewWindow::BuildFlowList
void BuildFlowList(CargoID i, const FlowStatMap &flows, CargoDataEntry *cargo)
Build up the cargo view for PLANNED mode and a specific cargo.
Definition: station_gui.cpp:1547
SelectStationWindow
Window for selecting stations/waypoints to (distant) join to.
Definition: station_gui.cpp:2239
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:332
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
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:1125
CargoDataEntry::Retrieve
CargoDataEntry * Retrieve(CargoID cargo) const
Retrieve a child for the given cargo.
Definition: station_gui.cpp:926
ShowSelectWaypointIfNeeded
void ShowSelectWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the waypoint selection window when needed.
Definition: station_gui.cpp:2443
Airport::flags
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:305
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:312
CargoDataEntry::station
StationID station
ID of the station this entry is associated with.
Definition: station_gui.cpp:997
StationViewWindow::groupings
Grouping groupings[NUM_COLUMNS]
Grouping modes for the different columns.
Definition: station_gui.cpp:1281
StationViewWindow::RecalcDestinations
void RecalcDestinations(CargoID i)
Rebuild the cache for estimated destinations which is used to quickly show the "destination" entries ...
Definition: station_gui.cpp:1460
CargoPacket::Count
uint16 Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:100
TileHighlightData::pos
Point pos
Location, in tile "units", of the northern tile of the selected area.
Definition: tilehighlight_type.h:47
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1044
WID_SV_LOCATION
@ WID_SV_LOCATION
'Location' button.
Definition: station_widget.h:23
TileAndStation::tile
TileIndex tile
TileIndex.
Definition: station_gui.cpp:2122
StationViewWindow::MODE_WAITING
@ MODE_WAITING
Show cargo waiting at the station.
Definition: station_gui.cpp:1249
CargoDataEntry::Remove
void Remove(StationID station)
Remove a child associated with the given station.
Definition: station_gui.cpp:894
GoodsEntry::rating
byte rating
Station rating for this cargo.
Definition: station_base.h:232
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
ST_CARGO_ID
@ ST_CARGO_ID
by cargo id
Definition: station_gui.cpp:837
GameSettings::linkgraph
LinkGraphSettings linkgraph
settings for link graph calculations
Definition: settings_type.h:591
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:300
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:508
WID_STL_CARGOALL
@ WID_STL_CARGOALL
'ALL' button - list all stations.
Definition: station_widget.h:50
CargoDataEntry::GetParent
CargoDataEntry * GetParent() const
Get the parent entry for this entry.
Definition: station_gui.cpp:952
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:480
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:57
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:557
CompanyStationsWindow::StationWaitingTotalSorter
static bool StationWaitingTotalSorter(const Station *const &a, const Station *const &b)
Sort stations by their waiting cargo.
Definition: station_gui.cpp:273
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
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:119
GoodsEntry::link_graph
LinkGraphID link_graph
Link graph this station belongs to.
Definition: station_base.h:254
SelectStationWindow::OnMouseOver
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
Definition: station_gui.cpp:2350
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
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
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:199
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
viewport_func.h
CompanyStationsWindow::SortStationsList
void SortStationsList()
Sort the stations list.
Definition: station_gui.cpp:326
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
StationViewWindow::_group_names
static const StringID _group_names[]
Names of the grouping options in the dropdown.
Definition: station_gui.cpp:1265
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
FACIL_WAYPOINT
@ FACIL_WAYPOINT
Station is a waypoint.
Definition: station_type.h:58
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:905
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:165
WID_STL_SHIP
@ WID_STL_SHIP
'SHIP' button - list only facilities where is a dock.
Definition: station_widget.h:46
OrthogonalTileArea::h
uint16 h
The height of the area.
Definition: tilearea_type.h:21
DistanceMax
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition: map.cpp:189
StationCargoList::ReservedCount
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Definition: cargopacket.h:517
WID_STL_NOCARGOWAITING
@ WID_STL_NOCARGOWAITING
'NO' button - list stations where no cargo is waiting.
Definition: station_widget.h:49
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
MAX_LENGTH_STATION_NAME_CHARS
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
Definition: station_type.h:88
TileHighlightData::dirty
byte dirty
Whether the build station window needs to redraw due to the changed selection.
Definition: tilehighlight_type.h:58
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
TileHighlightData::drawstyle
HighLightStyle drawstyle
Lower bits 0-3 are reserved for detailed highlight information.
Definition: tilehighlight_type.h:64
DrawStationCoverageAreaText
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
Definition: station_gui.cpp:55
WID_STL_SORTDROPBTN
@ WID_STL_SORTDROPBTN
Dropdown button.
Definition: station_widget.h:53
string_func.h
AIRPORT_CLOSED_block
static const uint64 AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
Definition: airport.h:128
SCT_ALL
@ SCT_ALL
Draw all cargoes.
Definition: station_gui.h:24
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:226
CargoDataEntry::SetTransfers
void SetTransfers(bool value)
Set the transfers state.
Definition: station_gui.cpp:977
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:167
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:234
station_base.h
Pool::PoolItem<&_station_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
ST_STATION_STRING
@ ST_STATION_STRING
by station name
Definition: station_gui.cpp:835
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
_sorted_standard_cargo_specs
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:153
StationViewWindow::Invalidation
Invalidation
Type of data invalidation.
Definition: station_gui.cpp:1230
StationViewWindow::displayed_rows
CargoDataVector displayed_rows
Parent entry of currently displayed rows (including collapsed ones).
Definition: station_gui.cpp:1285
NWidgetCore::SetDataTip
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:962
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:520
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:495
CargoDataEntry::Update
void Update(uint count)
Update the count for this entry and propagate the change to the parent entry if there is one.
Definition: station_gui.cpp:1112
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
CargoDataEntry::Retrieve
CargoDataEntry * Retrieve(StationID station) const
Retrieve a child for the given station.
Definition: station_gui.cpp:915
CargoDataEntry::Clear
void Clear()
Delete all subentries, reset count and num_children and adapt parent's count.
Definition: station_gui.cpp:1057
CargoDataEntry::GetStation
StationID GetStation() const
Get the station ID for this entry.
Definition: station_gui.cpp:937
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:53
StationViewWindow::RowDisplay::next_cargo
CargoID next_cargo
ID of the cargo belonging to the entry actually displayed if it's cargo.
Definition: station_gui.cpp:1219
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:168
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:256
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:107
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1209
StationViewWindow::sort_orders
SortOrder sort_orders[NUM_COLUMNS]
Sort order (ascending/descending) for the 'columns'.
Definition: station_gui.cpp:1276
SCT_NON_PASSENGERS_ONLY
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition: station_gui.h:23
geometry_func.hpp
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
SelectStationWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: station_gui.cpp:2286
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
WID_STL_BUS
@ WID_STL_BUS
'BUS' button - list only facilities where is a bus stop.
Definition: station_widget.h:44
WID_SV_ACCEPT_RATING_LIST
@ WID_SV_ACCEPT_RATING_LIST
List of accepted cargoes / rating of cargoes.
Definition: station_widget.h:22
FlowStatMap
Flow descriptions by origin stations.
Definition: station_base.h:149
TileAndStation::station
StationID station
StationID.
Definition: station_gui.cpp:2123
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
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
GUISettings::station_gui_sort_order
uint8 station_gui_sort_order
the sort order of entries in the station gui - ascending or descending
Definition: settings_type.h:182
WID_SV_GROUP
@ WID_SV_GROUP
label for "group by"
Definition: station_widget.h:16
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
GoodsEntry::GES_ACCEPTANCE
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
Definition: station_base.h:174
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:238
waypoint_base.h
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:673
cargotype.h
WID_STL_AIRPLANE
@ WID_STL_AIRPLANE
'AIRPLANE' button - list only facilities where is an airport.
Definition: station_widget.h:45
WID_SV_ACCEPTS_RATINGS
@ WID_SV_ACCEPTS_RATINGS
'Accepts' / 'Ratings' button.
Definition: station_widget.h:24
linkgraph.h
StationViewWindow::Mode
Mode
Display mode of the cargo view.
Definition: station_gui.cpp:1248
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:53
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
HasStationInUse
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Definition: station_cmd.cpp:2448
company_func.h
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3523
CargoDataEntry::HasTransfers
bool HasTransfers() const
Has this entry transfers.
Definition: station_gui.cpp:972
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
CargoSpec::abbrev
StringID abbrev
Two letter abbreviation for this cargo type.
Definition: cargotype.h:75
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition: settings_type.h:555
StationViewWindow::GR_NEXT
@ GR_NEXT
Group by next station ("via").
Definition: station_gui.cpp:1240
CommandHelper
Definition: command_func.h:94
StationViewWindow::ALH_RATING
@ ALH_RATING
Height of the cargo ratings view.
Definition: station_gui.cpp:1260
StationSettings::adjacent_stations
bool adjacent_stations
allow stations to be built directly adjacent to other stations
Definition: settings_type.h:554
WID_STL_SCROLLBAR
@ WID_STL_SCROLLBAR
Scrollbar next to the main panel.
Definition: station_widget.h:39
window_func.h
CargoDataEntry
A cargo data entry representing one possible row in the station view window's top part.
Definition: station_gui.cpp:863
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:457
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:57
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
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:314
SelectStationWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:2342
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:43
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:2212
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
StationViewWindow::SelectSortOrder
void SelectSortOrder(SortOrder order)
Select a new sort order for the cargo view.
Definition: station_gui.cpp:1964
StationViewWindow::SelectGroupBy
void SelectGroupBy(int index)
Select a new grouping mode for the cargo view.
Definition: station_gui.cpp:2007
WID_STL_TRAIN
@ WID_STL_TRAIN
'TRAIN' button - list only facilities where is a railroad station.
Definition: station_widget.h:42
CargoDataEntry::count
uint count
sum of counts of all children or amount of cargo for this entry.
Definition: station_gui.cpp:1004
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
WID_STL_FACILALL
@ WID_STL_FACILALL
'ALL' button - list all facilities.
Definition: station_widget.h:47
StationViewWindow::accepts_lines
int accepts_lines
Number of lines in the accepted cargo view.
Definition: station_gui.cpp:1255
SelectStationWindow::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: station_gui.cpp:2266
CargoDataEntry::parent
CargoDataEntry * parent
the parent of this entry.
Definition: station_gui.cpp:995
ST_AS_GROUPING
@ ST_AS_GROUPING
by the same principle the entries are being grouped
Definition: station_gui.cpp:833
StationViewWindow::scroll_to_row
int scroll_to_row
If set, scroll the main viewport to the station pointed to by this row.
Definition: station_gui.cpp:1278
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:736
CargoSorter
Definition: station_gui.cpp:840
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
CargoDataEntry::Remove
void Remove(CargoID cargo)
Remove a child associated with the given cargo.
Definition: station_gui.cpp:904
gui.h
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
StationViewWindow::GR_CARGO
@ GR_CARGO
Group by cargo type.
Definition: station_gui.cpp:1242
WID_SV_CLOSE_AIRPORT
@ WID_SV_CLOSE_AIRPORT
'Close airport' button.
Definition: station_widget.h:26
Window
Data structure for an opened window.
Definition: window_gui.h:279
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
ST_COUNT
@ ST_COUNT
by amount of cargo
Definition: station_gui.cpp:834
CompanyStationsWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: station_gui.cpp:632
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:477
StationViewWindow::rating_lines
int rating_lines
Number of lines in the cargo ratings view.
Definition: station_gui.cpp:1254
_viewport_highlight_station
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
Definition: viewport.cpp:991
SelectStationWindow::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: station_gui.cpp:2307
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
StationViewWindow::expanded_rows
CargoDataEntry expanded_rows
Parent entry of currently expanded rows.
Definition: station_gui.cpp:1283
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:56
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:586
CompanyStationsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: station_gui.cpp:425
StationViewWindow::Grouping
Grouping
Type of grouping used in each of the "columns".
Definition: station_gui.cpp:1238
CompanyStationsWindow::StationNameSorter
static bool StationNameSorter(const Station *const &a, const Station *const &b)
Sort stations by their name.
Definition: station_gui.cpp:259
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:227
CompanyStationsWindow::StationRatingMinSorter
static bool StationRatingMinSorter(const Station *const &a, const Station *const &b)
Sort stations by their rating.
Definition: station_gui.cpp:311
WID_SV_SCROLLBAR
@ WID_SV_SCROLLBAR
Scrollbar.
Definition: station_widget.h:21
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:311
WID_SV_CAPTION
@ WID_SV_CAPTION
Caption of the window.
Definition: station_widget.h:15
IsCargoInClass
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:193
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
StationViewWindow::EstimateDestinations
void EstimateDestinations(CargoID cargo, StationID source, StationID next, uint count, CargoDataEntry *dest)
Estimate the amounts of cargo per final destination for a given cargo, source station and next hop an...
Definition: station_gui.cpp:1494
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
WID_SV_SHIPS
@ WID_SV_SHIPS
List of scheduled ships button.
Definition: station_widget.h:29
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:468
TileAndStation
Struct containing TileIndex and StationID.
Definition: station_gui.cpp:2121
Town::exclusivity
CompanyID exclusivity
which company has exclusivity
Definition: town.h:71
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:318
FindStationsNearby
static const T * FindStationsNearby(TileArea ta, bool distant_join)
Circulate around the to-be-built station to find stations we could join.
Definition: station_gui.cpp:2179
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
Town::exclusive_counter
uint8 exclusive_counter
months till the exclusivity expires
Definition: town.h:72
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:294
WD_PAR_VSEP_WIDE
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:140
SelectStationWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: station_gui.cpp:2324
WID_SV_TRAINS
@ WID_SV_TRAINS
List of scheduled trains button.
Definition: station_widget.h:27
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3424
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:866
PC_GREEN
static const uint8 PC_GREEN
Green palette colour.
Definition: gfx_func.h:221
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
station_gui.h
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
TileHighlightData::freeze
bool freeze
Freeze highlight in place.
Definition: tilehighlight_type.h:53
CompanyStationsWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: station_gui.cpp:620
CargoDataEntry::Begin
CargoDataSet::iterator Begin() const
Get an iterator pointing to the begin of the set of children.
Definition: station_gui.cpp:962
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:598
station_widget.h
debug.h
WID_SV_PLANES
@ WID_SV_PLANES
List of scheduled planes button.
Definition: station_widget.h:30
LinkGraph::Monthly
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
Definition: linkgraph.h:527
CargoDataEntry::transfers
bool transfers
If there are transfers for this cargo.
Definition: station_gui.cpp:1000
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:1030
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:165
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
ShowSelectBaseStationIfNeeded
void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc &&proc)
Show the station selection window when needed.
Definition: station_gui.cpp:2418
SelectStationWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: station_gui.cpp:2258
CargoDataEntry::IncrementSize
void IncrementSize()
Increment.
Definition: station_gui.cpp:1121
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092
CargoDataEntry::End
CargoDataSet::iterator End() const
Get an iterator pointing to the end of the set of children.
Definition: station_gui.cpp:967
WID_SV_RENAME
@ WID_SV_RENAME
'Rename' button.
Definition: station_widget.h:25