OpenTTD Source  1.11.2
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 
35 #include "widgets/station_widget.h"
36 
37 #include "table/strings.h"
38 
39 #include <set>
40 #include <vector>
41 
42 #include "safeguards.h"
43 
54 int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
55 {
56  TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
57  CargoTypes cargo_mask = 0;
58  if (_thd.drawstyle == HT_RECT && tile < MapSize()) {
59  CargoArray cargoes;
60  if (supplies) {
61  cargoes = GetProductionAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
62  } else {
63  cargoes = GetAcceptanceAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
64  }
65 
66  /* Convert cargo counts to a set of cargo bits, and draw the result. */
67  for (CargoID i = 0; i < NUM_CARGO; i++) {
68  switch (sct) {
69  case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
70  case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
71  case SCT_ALL: break;
72  default: NOT_REACHED();
73  }
74  if (cargoes[i] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, i);
75  }
76  }
77  SetDParam(0, cargo_mask);
78  return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
79 }
80 
86 {
87  /* With distant join we don't know which station will be selected, so don't show any */
88  if (_ctrl_pressed) {
89  SetViewportCatchmentStation(nullptr, true);
90  return;
91  }
92 
93  /* Tile area for TileHighlightData */
94  TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1);
95 
96  /* Extended area by one tile */
97  uint x = TileX(location.tile);
98  uint y = TileY(location.tile);
99 
100  int max_c = 1;
101  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)));
102 
103  Station *adjacent = nullptr;
104 
105  /* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
106  TILE_AREA_LOOP(tile, ta) {
107  if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) {
108  Station *st = Station::GetByTile(tile);
109  if (st == nullptr) continue;
110  if (adjacent != nullptr && st != adjacent) {
111  /* Multiple nearby, distant join is required. */
112  adjacent = nullptr;
113  break;
114  }
115  adjacent = st;
116  }
117  }
118  SetViewportCatchmentStation(adjacent, true);
119 }
120 
127 {
128  /* Test if ctrl state changed */
129  static bool _last_ctrl_pressed;
130  if (_ctrl_pressed != _last_ctrl_pressed) {
131  _thd.dirty = 0xff;
132  _last_ctrl_pressed = _ctrl_pressed;
133  }
134 
135  if (_thd.dirty & 1) {
136  _thd.dirty &= ~1;
137  w->SetDirty();
138 
141  }
142  }
143 }
144 
157 static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
158 {
159  static const uint units_full = 576;
160  static const uint rating_full = 224;
161 
162  const CargoSpec *cs = CargoSpec::Get(type);
163  if (!cs->IsValid()) return;
164 
165  int padding = ScaleFontTrad(1);
166  int width = right - left;
167  int colour = cs->rating_colour;
168  TextColour tc = GetContrastColour(colour);
169  uint w = std::min(amount + 5, units_full) * width / units_full;
170 
171  int height = GetCharacterHeight(FS_SMALL) + padding - 1;
172 
173  if (amount > 30) {
174  /* Draw total cargo (limited) on station */
175  GfxFillRect(left, y, left + w - 1, y + height, colour);
176  } else {
177  /* Draw a (scaled) one pixel-wide bar of additional cargo meter, useful
178  * for stations with only a small amount (<=30) */
179  uint rest = ScaleFontTrad(amount) / 5;
180  if (rest != 0) {
181  GfxFillRect(left, y + height - rest, left + padding - 1, y + height, colour);
182  }
183  }
184 
185  DrawString(left + padding, right, y, cs->abbrev, tc);
186 
187  /* Draw green/red ratings bar (fits under the waiting bar) */
188  y += height + padding + 1;
189  GfxFillRect(left + padding, y, right - padding - 1, y + padding - 1, PC_RED);
190  w = std::min<uint>(rating, rating_full) * (width - padding - padding) / rating_full;
191  if (w != 0) GfxFillRect(left + padding, y, left + w - 1, y + padding - 1, PC_GREEN);
192 }
193 
195 
200 {
201 protected:
202  /* Runtime saved values */
203  static Listing last_sorting;
204  static byte facilities; // types of stations of interest
205  static bool include_empty; // whether we should include stations without waiting cargo
206  static const CargoTypes cargo_filter_max;
207  static CargoTypes cargo_filter; // bitmap of cargo types to include
208 
209  /* Constants for sorting stations */
210  static const StringID sorter_names[];
211  static GUIStationList::SortFunction * const sorter_funcs[];
212 
213  GUIStationList stations;
214  Scrollbar *vscroll;
215  uint rating_width;
216 
223  {
224  if (!this->stations.NeedRebuild()) return;
225 
226  DEBUG(misc, 3, "Building station list for company %d", owner);
227 
228  this->stations.clear();
229 
230  for (const Station *st : Station::Iterate()) {
231  if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
232  if (this->facilities & st->facilities) { // only stations with selected facilities
233  int num_waiting_cargo = 0;
234  for (CargoID j = 0; j < NUM_CARGO; j++) {
235  if (st->goods[j].HasRating()) {
236  num_waiting_cargo++; // count number of waiting cargo
237  if (HasBit(this->cargo_filter, j)) {
238  this->stations.push_back(st);
239  break;
240  }
241  }
242  }
243  /* stations without waiting cargo */
244  if (num_waiting_cargo == 0 && this->include_empty) {
245  this->stations.push_back(st);
246  }
247  }
248  }
249  }
250 
251  this->stations.shrink_to_fit();
252  this->stations.RebuildDone();
253 
254  this->vscroll->SetCount((uint)this->stations.size()); // Update the scrollbar
255  }
256 
258  static bool StationNameSorter(const Station * const &a, const Station * const &b)
259  {
260  int r = strnatcmp(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
261  if (r == 0) return a->index < b->index;
262  return r < 0;
263  }
264 
266  static bool StationTypeSorter(const Station * const &a, const Station * const &b)
267  {
268  return a->facilities < b->facilities;
269  }
270 
272  static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b)
273  {
274  int diff = 0;
275 
276  CargoID j;
277  FOR_EACH_SET_CARGO_ID(j, 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  CargoID j;
290  FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
291  diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
292  }
293 
294  return diff < 0;
295  }
296 
298  static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b)
299  {
300  byte maxr1 = 0;
301  byte maxr2 = 0;
302 
303  CargoID j;
304  FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
305  if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating);
306  if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating);
307  }
308 
309  return maxr1 < maxr2;
310  }
311 
313  static bool StationRatingMinSorter(const Station * const &a, const Station * const &b)
314  {
315  byte minr1 = 255;
316  byte minr2 = 255;
317 
318  for (CargoID j = 0; j < NUM_CARGO; j++) {
319  if (!HasBit(cargo_filter, j)) continue;
320  if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating);
321  if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating);
322  }
323 
324  return minr1 > minr2;
325  }
326 
329  {
330  if (!this->stations.Sort()) return;
331 
332  /* Set the modified widget dirty */
334  }
335 
336 public:
338  {
339  this->stations.SetListing(this->last_sorting);
340  this->stations.SetSortFuncs(this->sorter_funcs);
341  this->stations.ForceRebuild();
342  this->stations.NeedResort();
343  this->SortStationsList();
344 
345  this->CreateNestedTree();
346  this->vscroll = this->GetScrollbar(WID_STL_SCROLLBAR);
347  this->FinishInitNested(window_number);
348  this->owner = (Owner)this->window_number;
349 
350  const CargoSpec *cs;
352  if (!HasBit(this->cargo_filter, cs->Index())) continue;
353  this->LowerWidget(WID_STL_CARGOSTART + 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  const CargoSpec *cs;
401  this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev).width);
402  }
403  /* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
404  this->rating_width = this->rating_width * 16 / 10;
405  break;
406 
407  case WID_STL_CARGOALL:
408  case WID_STL_FACILALL:
409  case WID_STL_NOCARGOWAITING: {
410  Dimension d = GetStringBoundingBox(widget == WID_STL_NOCARGOWAITING ? STR_ABBREV_NONE : STR_ABBREV_ALL);
411  d.width += padding.width + 2;
412  d.height += padding.height;
413  *size = maxdim(*size, d);
414  break;
415  }
416 
417  default:
418  if (widget >= WID_STL_CARGOSTART) {
420  d.width += padding.width + 2;
421  d.height += padding.height;
422  *size = maxdim(*size, d);
423  }
424  break;
425  }
426  }
427 
428  void OnPaint() override
429  {
430  this->BuildStationsList((Owner)this->window_number);
431  this->SortStationsList();
432 
433  this->DrawWidgets();
434  }
435 
436  void DrawWidget(const Rect &r, int widget) const override
437  {
438  switch (widget) {
439  case WID_STL_SORTBY:
440  /* draw arrow pointing up/down for ascending/descending sorting */
442  break;
443 
444  case WID_STL_LIST: {
445  bool rtl = _current_text_dir == TD_RTL;
446  int max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size());
447  int y = r.top + WD_FRAMERECT_TOP;
448  uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
449  /* Spacing between station name and first rating graph. */
450  int text_spacing = ScaleFontTrad(5);
451  /* Spacing between additional rating graphs. */
452  int rating_spacing = ScaleFontTrad(4);
453 
454  for (int i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner
455  const Station *st = this->stations[i];
456  assert(st->xy != INVALID_TILE);
457 
458  /* Do not do the complex check HasStationInUse here, it may be even false
459  * when the order had been removed and the station list hasn't been removed yet */
460  assert(st->owner == owner || st->owner == OWNER_NONE);
461 
462  SetDParam(0, st->index);
463  SetDParam(1, st->facilities);
464  int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + (line_height - FONT_HEIGHT_NORMAL) / 2, STR_STATION_LIST_STATION);
465  x += rtl ? -text_spacing : text_spacing;
466 
467  /* show cargo waiting and station ratings */
468  for (uint j = 0; j < _sorted_standard_cargo_specs_size; j++) {
469  CargoID cid = _sorted_cargo_specs[j]->Index();
470  if (st->goods[cid].cargo.TotalCount() > 0) {
471  /* For RTL we work in exactly the opposite direction. So
472  * decrement the space needed first, then draw to the left
473  * instead of drawing to the left and then incrementing
474  * the space. */
475  if (rtl) {
476  x -= rating_width + rating_spacing;
477  if (x < r.left + WD_FRAMERECT_LEFT) break;
478  }
479  StationsWndShowStationRating(x, x + rating_width, y, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
480  if (!rtl) {
481  x += rating_width + rating_spacing;
482  if (x > r.right - WD_FRAMERECT_RIGHT) break;
483  }
484  }
485  }
486  y += line_height;
487  }
488 
489  if (this->vscroll->GetCount() == 0) { // company has no stations
490  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_NONE);
491  return;
492  }
493  break;
494  }
495 
496  case WID_STL_NOCARGOWAITING: {
497  int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
498  DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_NONE, TC_BLACK, SA_HOR_CENTER);
499  break;
500  }
501 
502  case WID_STL_CARGOALL: {
503  int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
504  DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
505  break;
506  }
507 
508  case WID_STL_FACILALL: {
509  int cg_ofst = this->IsWidgetLowered(widget) ? 1 : 0;
510  DrawString(r.left + cg_ofst, r.right + cg_ofst, r.top + (r.bottom - r.top - FONT_HEIGHT_SMALL) / 2 + cg_ofst, STR_ABBREV_ALL, TC_BLACK, SA_HOR_CENTER);
511  break;
512  }
513 
514  default:
515  if (widget >= WID_STL_CARGOSTART) {
516  const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
517  int cg_ofst = HasBit(this->cargo_filter, cs->Index()) ? 1 : 0;
518  GfxFillRect(r.left + cg_ofst + 1, r.top + cg_ofst + 1, r.right - 1 + cg_ofst, r.bottom - 1 + cg_ofst, cs->rating_colour);
519  TextColour tc = GetContrastColour(cs->rating_colour);
520  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);
521  }
522  break;
523  }
524  }
525 
526  void SetStringParameters(int widget) const override
527  {
528  if (widget == WID_STL_CAPTION) {
529  SetDParam(0, this->window_number);
530  SetDParam(1, this->vscroll->GetCount());
531  }
532  }
533 
534  void OnClick(Point pt, int widget, int click_count) override
535  {
536  switch (widget) {
537  case WID_STL_LIST: {
538  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_STL_LIST, 0, FONT_HEIGHT_NORMAL);
539  if (id_v >= this->stations.size()) return; // click out of list bound
540 
541  const Station *st = this->stations[id_v];
542  /* do not check HasStationInUse - it is slow and may be invalid */
543  assert(st->owner == (Owner)this->window_number || st->owner == OWNER_NONE);
544 
545  if (_ctrl_pressed) {
547  } else {
549  }
550  break;
551  }
552 
553  case WID_STL_TRAIN:
554  case WID_STL_TRUCK:
555  case WID_STL_BUS:
556  case WID_STL_AIRPLANE:
557  case WID_STL_SHIP:
558  if (_ctrl_pressed) {
559  ToggleBit(this->facilities, widget - WID_STL_TRAIN);
560  this->ToggleWidgetLoweredState(widget);
561  } else {
562  uint i;
563  FOR_EACH_SET_BIT(i, this->facilities) {
564  this->RaiseWidget(i + WID_STL_TRAIN);
565  }
566  this->facilities = 1 << (widget - WID_STL_TRAIN);
567  this->LowerWidget(widget);
568  }
569  this->stations.ForceRebuild();
570  this->SetDirty();
571  break;
572 
573  case WID_STL_FACILALL:
574  for (uint i = WID_STL_TRAIN; i <= WID_STL_SHIP; i++) {
575  this->LowerWidget(i);
576  }
577 
579  this->stations.ForceRebuild();
580  this->SetDirty();
581  break;
582 
583  case WID_STL_CARGOALL: {
584  for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
585  this->LowerWidget(WID_STL_CARGOSTART + i);
586  }
588 
589  this->cargo_filter = _cargo_mask;
590  this->include_empty = true;
591  this->stations.ForceRebuild();
592  this->SetDirty();
593  break;
594  }
595 
596  case WID_STL_SORTBY: // flip sorting method asc/desc
597  this->stations.ToggleSortOrder();
598  this->SetDirty();
599  break;
600 
601  case WID_STL_SORTDROPBTN: // select sorting criteria dropdown menu
602  ShowDropDownMenu(this, this->sorter_names, this->stations.SortType(), WID_STL_SORTDROPBTN, 0, 0);
603  break;
604 
606  if (_ctrl_pressed) {
607  this->include_empty = !this->include_empty;
609  } else {
610  for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
611  this->RaiseWidget(WID_STL_CARGOSTART + i);
612  }
613 
614  this->cargo_filter = 0;
615  this->include_empty = true;
616 
618  }
619  this->stations.ForceRebuild();
620  this->SetDirty();
621  break;
622 
623  default:
624  if (widget >= WID_STL_CARGOSTART) { // change cargo_filter
625  /* Determine the selected cargo type */
626  const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
627 
628  if (_ctrl_pressed) {
629  ToggleBit(this->cargo_filter, cs->Index());
630  this->ToggleWidgetLoweredState(widget);
631  } else {
632  for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
633  this->RaiseWidget(WID_STL_CARGOSTART + i);
634  }
636 
637  this->cargo_filter = 0;
638  this->include_empty = false;
639 
640  SetBit(this->cargo_filter, cs->Index());
641  this->LowerWidget(widget);
642  }
643  this->stations.ForceRebuild();
644  this->SetDirty();
645  }
646  break;
647  }
648  }
649 
650  void OnDropdownSelect(int widget, int index) override
651  {
652  if (this->stations.SortType() != index) {
653  this->stations.SetSortType(index);
654 
655  /* Display the current sort variant */
656  this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
657 
658  this->SetDirty();
659  }
660  }
661 
662  void OnGameTick() override
663  {
664  if (this->stations.NeedResort()) {
665  DEBUG(misc, 3, "Periodic rebuild station list company %d", this->window_number);
666  this->SetDirty();
667  }
668  }
669 
670  void OnResize() override
671  {
673  }
674 
680  void OnInvalidateData(int data = 0, bool gui_scope = true) override
681  {
682  if (data == 0) {
683  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
684  this->stations.ForceRebuild();
685  } else {
686  this->stations.ForceResort();
687  }
688  }
689 };
690 
691 Listing CompanyStationsWindow::last_sorting = {false, 0};
692 byte CompanyStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
693 bool CompanyStationsWindow::include_empty = true;
694 const CargoTypes CompanyStationsWindow::cargo_filter_max = ALL_CARGOTYPES;
695 CargoTypes CompanyStationsWindow::cargo_filter = ALL_CARGOTYPES;
696 
697 /* Available station sorting functions */
698 GUIStationList::SortFunction * const CompanyStationsWindow::sorter_funcs[] = {
699  &StationNameSorter,
700  &StationTypeSorter,
701  &StationWaitingTotalSorter,
702  &StationWaitingAvailableSorter,
703  &StationRatingMaxSorter,
704  &StationRatingMinSorter
705 };
706 
707 /* Names of the sorting functions */
708 const StringID CompanyStationsWindow::sorter_names[] = {
709  STR_SORT_BY_NAME,
710  STR_SORT_BY_FACILITY,
711  STR_SORT_BY_WAITING_TOTAL,
712  STR_SORT_BY_WAITING_AVAILABLE,
713  STR_SORT_BY_RATING_MAX,
714  STR_SORT_BY_RATING_MIN,
716 };
717 
723 static NWidgetBase *CargoWidgets(int *biggest_index)
724 {
725  NWidgetHorizontal *container = new NWidgetHorizontal();
726 
727  for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
728  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
729  panel->SetMinimalSize(14, 0);
730  panel->SetMinimalTextLines(1, 0, FS_NORMAL);
731  panel->SetResize(0, 0);
732  panel->SetFill(0, 1);
733  panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
734  container->Add(panel);
735  }
737  return container;
738 }
739 
740 static const NWidgetPart _nested_company_stations_widgets[] = {
742  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
743  NWidget(WWT_CAPTION, COLOUR_GREY, WID_STL_CAPTION), SetDataTip(STR_STATION_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
744  NWidget(WWT_SHADEBOX, COLOUR_GREY),
745  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
746  NWidget(WWT_STICKYBOX, COLOUR_GREY),
747  EndContainer(),
749  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),
750  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),
751  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),
752  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),
753  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),
754  NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetFill(0, 1),
755  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
757  NWidget(WWT_PANEL, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_NO_WAITING_CARGO), SetFill(0, 1), EndContainer(),
758  NWidget(WWT_PUSHBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 0), SetMinimalTextLines(1, 0), SetDataTip(0x0, STR_STATION_LIST_SELECT_ALL_TYPES), SetFill(0, 1),
759  NWidget(WWT_PANEL, COLOUR_GREY), SetDataTip(0x0, STR_NULL), SetResize(1, 0), SetFill(1, 1), EndContainer(),
760  EndContainer(),
762  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_SORTBY), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
763  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_STL_SORTDROPBTN), SetMinimalSize(163, 12), SetDataTip(STR_SORT_BY_NAME, STR_TOOLTIP_SORT_CRITERIA), // widget_data gets overwritten.
764  NWidget(WWT_PANEL, COLOUR_GREY), SetDataTip(0x0, STR_NULL), SetResize(1, 0), SetFill(1, 1), EndContainer(),
765  EndContainer(),
767  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(),
770  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
771  EndContainer(),
772  EndContainer(),
773 };
774 
775 static WindowDesc _company_stations_desc(
776  WDP_AUTO, "list_stations", 358, 162,
778  0,
779  _nested_company_stations_widgets, lengthof(_nested_company_stations_widgets)
780 );
781 
788 {
789  if (!Company::IsValidID(company)) return;
790 
791  AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
792 }
793 
794 static const NWidgetPart _nested_station_view_widgets[] = {
796  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
797  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
798  NWidget(WWT_CAPTION, COLOUR_GREY, WID_SV_CAPTION), SetDataTip(STR_STATION_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
799  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_STATION_VIEW_CENTER_TOOLTIP),
800  NWidget(WWT_SHADEBOX, COLOUR_GREY),
801  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
802  NWidget(WWT_STICKYBOX, COLOUR_GREY),
803  EndContainer(),
805  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_GROUP), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_STATION_VIEW_GROUP, 0x0),
806  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_GROUP_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
807  EndContainer(),
809  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SORT_ORDER), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
810  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_SORT_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
811  EndContainer(),
815  EndContainer(),
818  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ACCEPTS_RATINGS), SetMinimalSize(46, 12), SetResize(1, 0), SetFill(1, 1),
819  SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
820  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
821  SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
822  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
823  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
824  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
825  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
826  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_PLANES), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
827  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
828  EndContainer(),
829 };
830 
840 static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int y)
841 {
842  int width = ScaleGUITrad(10);
843  uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow
844  if (num == 0) return;
845 
846  SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon();
847 
848  int x = _current_text_dir == TD_RTL ? left : right - num * width;
849  do {
850  DrawSprite(sprite, PAL_NONE, x, y);
851  x += width;
852  } while (--num);
853 }
854 
855 enum SortOrder {
856  SO_DESCENDING,
857  SO_ASCENDING
858 };
859 
860 class CargoDataEntry;
861 
868 };
869 
870 class CargoSorter {
871 public:
872  CargoSorter(CargoSortType t = ST_STATION_ID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
873  CargoSortType GetSortType() {return this->type;}
874  bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
875 
876 private:
877  CargoSortType type;
878  SortOrder order;
879 
880  template<class Tid>
881  bool SortId(Tid st1, Tid st2) const;
882  bool SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
883  bool SortStation (StationID st1, StationID st2) const;
884 };
885 
886 typedef std::set<CargoDataEntry *, CargoSorter> CargoDataSet;
887 
894 public:
895  CargoDataEntry();
896  ~CargoDataEntry();
897 
904  {
905  return this->InsertOrRetrieve<StationID>(station);
906  }
907 
914  {
915  return this->InsertOrRetrieve<CargoID>(cargo);
916  }
917 
918  void Update(uint count);
919 
924  void Remove(StationID station)
925  {
927  this->Remove(&t);
928  }
929 
935  {
937  this->Remove(&t);
938  }
939 
945  CargoDataEntry *Retrieve(StationID station) const
946  {
948  return this->Retrieve(this->children->find(&t));
949  }
950 
957  {
959  return this->Retrieve(this->children->find(&t));
960  }
961 
962  void Resort(CargoSortType type, SortOrder order);
963 
967  StationID GetStation() const { return this->station; }
968 
972  CargoID GetCargo() const { return this->cargo; }
973 
977  uint GetCount() const { return this->count; }
978 
982  CargoDataEntry *GetParent() const { return this->parent; }
983 
987  uint GetNumChildren() const { return this->num_children; }
988 
992  CargoDataSet::iterator Begin() const { return this->children->begin(); }
993 
997  CargoDataSet::iterator End() const { return this->children->end(); }
998 
1002  bool HasTransfers() const { return this->transfers; }
1003 
1007  void SetTransfers(bool value) { this->transfers = value; }
1008 
1009  void Clear();
1010 private:
1011 
1012  CargoDataEntry(StationID st, uint c, CargoDataEntry *p);
1013  CargoDataEntry(CargoID car, uint c, CargoDataEntry *p);
1014  CargoDataEntry(StationID st);
1015  CargoDataEntry(CargoID car);
1016 
1017  CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
1018 
1019  template<class Tid>
1021 
1022  void Remove(CargoDataEntry *comp);
1023  void IncrementSize();
1024 
1026  const union {
1027  StationID station;
1028  struct {
1030  bool transfers;
1031  };
1032  };
1034  uint count;
1035  CargoDataSet *children;
1036 };
1037 
1038 CargoDataEntry::CargoDataEntry() :
1039  parent(nullptr),
1040  station(INVALID_STATION),
1041  num_children(0),
1042  count(0),
1043  children(new CargoDataSet(CargoSorter(ST_CARGO_ID)))
1044 {}
1045 
1046 CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
1047  parent(parent),
1048  cargo(cargo),
1049  num_children(0),
1050  count(count),
1051  children(new CargoDataSet)
1052 {}
1053 
1054 CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
1055  parent(parent),
1056  station(station),
1057  num_children(0),
1058  count(count),
1059  children(new CargoDataSet)
1060 {}
1061 
1062 CargoDataEntry::CargoDataEntry(StationID station) :
1063  parent(nullptr),
1064  station(station),
1065  num_children(0),
1066  count(0),
1067  children(nullptr)
1068 {}
1069 
1070 CargoDataEntry::CargoDataEntry(CargoID cargo) :
1071  parent(nullptr),
1072  cargo(cargo),
1073  num_children(0),
1074  count(0),
1075  children(nullptr)
1076 {}
1077 
1078 CargoDataEntry::~CargoDataEntry()
1079 {
1080  this->Clear();
1081  delete this->children;
1082 }
1083 
1088 {
1089  if (this->children != nullptr) {
1090  for (CargoDataSet::iterator i = this->children->begin(); i != this->children->end(); ++i) {
1091  assert(*i != this);
1092  delete *i;
1093  }
1094  this->children->clear();
1095  }
1096  if (this->parent != nullptr) this->parent->count -= this->count;
1097  this->count = 0;
1098  this->num_children = 0;
1099 }
1100 
1108 {
1109  CargoDataSet::iterator i = this->children->find(child);
1110  if (i != this->children->end()) {
1111  delete *i;
1112  this->children->erase(i);
1113  }
1114 }
1115 
1122 template<class Tid>
1124 {
1125  CargoDataEntry tmp(child_id);
1126  CargoDataSet::iterator i = this->children->find(&tmp);
1127  if (i == this->children->end()) {
1128  IncrementSize();
1129  return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first);
1130  } else {
1131  CargoDataEntry *ret = *i;
1132  assert(this->children->value_comp().GetSortType() != ST_COUNT);
1133  return ret;
1134  }
1135 }
1136 
1142 void CargoDataEntry::Update(uint count)
1143 {
1144  this->count += count;
1145  if (this->parent != nullptr) this->parent->Update(count);
1146 }
1147 
1152 {
1153  ++this->num_children;
1154  if (this->parent != nullptr) this->parent->IncrementSize();
1155 }
1156 
1157 void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
1158 {
1159  CargoDataSet *new_subs = new CargoDataSet(this->children->begin(), this->children->end(), CargoSorter(type, order));
1160  delete this->children;
1161  this->children = new_subs;
1162 }
1163 
1164 CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
1165 {
1166  if (i == this->children->end()) {
1167  return nullptr;
1168  } else {
1169  assert(this->children->value_comp().GetSortType() != ST_COUNT);
1170  return *i;
1171  }
1172 }
1173 
1174 bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1175 {
1176  switch (this->type) {
1177  case ST_STATION_ID:
1178  return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation());
1179  case ST_CARGO_ID:
1180  return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo());
1181  case ST_COUNT:
1182  return this->SortCount(cd1, cd2);
1183  case ST_STATION_STRING:
1184  return this->SortStation(cd1->GetStation(), cd2->GetStation());
1185  default:
1186  NOT_REACHED();
1187  }
1188 }
1189 
1190 template<class Tid>
1191 bool CargoSorter::SortId(Tid st1, Tid st2) const
1192 {
1193  return (this->order == SO_ASCENDING) ? st1 < st2 : st2 < st1;
1194 }
1195 
1196 bool CargoSorter::SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1197 {
1198  uint c1 = cd1->GetCount();
1199  uint c2 = cd2->GetCount();
1200  if (c1 == c2) {
1201  return this->SortStation(cd1->GetStation(), cd2->GetStation());
1202  } else if (this->order == SO_ASCENDING) {
1203  return c1 < c2;
1204  } else {
1205  return c2 < c1;
1206  }
1207 }
1208 
1209 bool CargoSorter::SortStation(StationID st1, StationID st2) const
1210 {
1211  if (!Station::IsValidID(st1)) {
1212  return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
1213  } else if (!Station::IsValidID(st2)) {
1214  return order == SO_DESCENDING;
1215  }
1216 
1217  int res = strnatcmp(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
1218  if (res == 0) {
1219  return this->SortId(st1, st2);
1220  } else {
1221  return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
1222  }
1223 }
1224 
1228 struct StationViewWindow : public Window {
1232  struct RowDisplay {
1233  RowDisplay(CargoDataEntry *f, StationID n) : filter(f), next_station(n) {}
1235 
1240  union {
1244  StationID next_station;
1245 
1250  };
1251  };
1252 
1253  typedef std::vector<RowDisplay> CargoDataVector;
1254 
1255  static const int NUM_COLUMNS = 4;
1256 
1261  INV_FLOWS = 0x100,
1262  INV_CARGO = 0x200
1263  };
1264 
1268  enum Grouping {
1273  };
1274 
1278  enum Mode {
1281  };
1282 
1286  Scrollbar *vscroll;
1287 
1290  ALH_RATING = 13,
1292  };
1293 
1294  static const StringID _sort_names[];
1295  static const StringID _group_names[];
1296 
1304 
1307 
1312 
1315  CargoDataVector displayed_rows;
1316 
1318  scroll_to_row(INT_MAX), grouping_index(0)
1319  {
1320  this->rating_lines = ALH_RATING;
1321  this->accepts_lines = ALH_ACCEPTS;
1322 
1323  this->CreateNestedTree();
1324  this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
1325  /* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
1326  this->FinishInitNested(window_number);
1327 
1328  this->groupings[0] = GR_CARGO;
1329  this->sortings[0] = ST_AS_GROUPING;
1332  this->sort_orders[0] = SO_ASCENDING;
1334  this->owner = Station::Get(window_number)->owner;
1335  }
1336 
1338  {
1339  DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false);
1340  DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false);
1341  DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false);
1342  DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false);
1343 
1344  SetViewportCatchmentStation(Station::Get(this->window_number), false);
1345  }
1346 
1357  void ShowCargo(CargoDataEntry *data, CargoID cargo, StationID source, StationID next, StationID dest, uint count)
1358  {
1359  if (count == 0) return;
1360  bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1361  const CargoDataEntry *expand = &this->expanded_rows;
1362  for (int i = 0; i < NUM_COLUMNS && expand != nullptr; ++i) {
1363  switch (groupings[i]) {
1364  case GR_CARGO:
1365  assert(i == 0);
1366  data = data->InsertOrRetrieve(cargo);
1367  data->SetTransfers(source != this->window_number);
1368  expand = expand->Retrieve(cargo);
1369  break;
1370  case GR_SOURCE:
1371  if (auto_distributed || source != this->window_number) {
1372  data = data->InsertOrRetrieve(source);
1373  expand = expand->Retrieve(source);
1374  }
1375  break;
1376  case GR_NEXT:
1377  if (auto_distributed) {
1378  data = data->InsertOrRetrieve(next);
1379  expand = expand->Retrieve(next);
1380  }
1381  break;
1382  case GR_DESTINATION:
1383  if (auto_distributed) {
1384  data = data->InsertOrRetrieve(dest);
1385  expand = expand->Retrieve(dest);
1386  }
1387  break;
1388  }
1389  }
1390  data->Update(count);
1391  }
1392 
1393  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1394  {
1395  switch (widget) {
1396  case WID_SV_WAITING:
1397  resize->height = FONT_HEIGHT_NORMAL;
1398  size->height = WD_FRAMERECT_TOP + 4 * resize->height + WD_FRAMERECT_BOTTOM;
1399  this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
1400  break;
1401 
1403  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;
1404  break;
1405 
1406  case WID_SV_CLOSE_AIRPORT:
1407  if (!(Station::Get(this->window_number)->facilities & FACIL_AIRPORT)) {
1408  /* Hide 'Close Airport' button if no airport present. */
1409  size->width = 0;
1410  resize->width = 0;
1411  fill->width = 0;
1412  }
1413  break;
1414  }
1415  }
1416 
1417  void OnPaint() override
1418  {
1419  const Station *st = Station::Get(this->window_number);
1420  CargoDataEntry cargo;
1421  BuildCargoList(&cargo, st);
1422 
1423  this->vscroll->SetCount(cargo.GetNumChildren()); // update scrollbar
1424 
1425  /* disable some buttons */
1431  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
1433 
1434  extern const Station *_viewport_highlight_station;
1436  this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st);
1437 
1438  this->DrawWidgets();
1439 
1440  if (!this->IsShaded()) {
1441  /* Draw 'accepted cargo' or 'cargo ratings'. */
1442  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SV_ACCEPT_RATING_LIST);
1443  const Rect r = {(int)wid->pos_x, (int)wid->pos_y, (int)(wid->pos_x + wid->current_x - 1), (int)(wid->pos_y + wid->current_y - 1)};
1444  if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1445  int lines = this->DrawAcceptedCargo(r);
1446  if (lines > this->accepts_lines) { // Resize the widget, and perform re-initialization of the window.
1447  this->accepts_lines = lines;
1448  this->ReInit();
1449  return;
1450  }
1451  } else {
1452  int lines = this->DrawCargoRatings(r);
1453  if (lines > this->rating_lines) { // Resize the widget, and perform re-initialization of the window.
1454  this->rating_lines = lines;
1455  this->ReInit();
1456  return;
1457  }
1458  }
1459 
1460  /* Draw arrow pointing up/down for ascending/descending sorting */
1461  this->DrawSortButtonState(WID_SV_SORT_ORDER, sort_orders[1] == SO_ASCENDING ? SBS_UP : SBS_DOWN);
1462 
1463  int pos = this->vscroll->GetPosition();
1464 
1465  int maxrows = this->vscroll->GetCapacity();
1466 
1467  displayed_rows.clear();
1468 
1469  /* Draw waiting cargo. */
1470  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SV_WAITING);
1471  Rect waiting_rect = { (int)nwi->pos_x, (int)nwi->pos_y, (int)(nwi->pos_x + nwi->current_x - 1), (int)(nwi->pos_y + nwi->current_y - 1)};
1472  this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0);
1473  scroll_to_row = INT_MAX;
1474  }
1475  }
1476 
1477  void SetStringParameters(int widget) const override
1478  {
1479  const Station *st = Station::Get(this->window_number);
1480  SetDParam(0, st->index);
1481  SetDParam(1, st->facilities);
1482  }
1483 
1490  {
1491  const Station *st = Station::Get(this->window_number);
1493  cargo_entry->Clear();
1494 
1495  const FlowStatMap &flows = st->goods[i].flows;
1496  for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1497  StationID from = it->first;
1498  CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from);
1499  const FlowStat::SharesMap *shares = it->second.GetShares();
1500  uint32 prev_count = 0;
1501  for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1502  StationID via = flow_it->second;
1503  CargoDataEntry *via_entry = source_entry->InsertOrRetrieve(via);
1504  if (via == this->window_number) {
1505  via_entry->InsertOrRetrieve(via)->Update(flow_it->first - prev_count);
1506  } else {
1507  EstimateDestinations(i, from, via, flow_it->first - prev_count, via_entry);
1508  }
1509  prev_count = flow_it->first;
1510  }
1511  }
1512  }
1513 
1523  void EstimateDestinations(CargoID cargo, StationID source, StationID next, uint count, CargoDataEntry *dest)
1524  {
1525  if (Station::IsValidID(next) && Station::IsValidID(source)) {
1526  CargoDataEntry tmp;
1527  const FlowStatMap &flowmap = Station::Get(next)->goods[cargo].flows;
1528  FlowStatMap::const_iterator map_it = flowmap.find(source);
1529  if (map_it != flowmap.end()) {
1530  const FlowStat::SharesMap *shares = map_it->second.GetShares();
1531  uint32 prev_count = 0;
1532  for (FlowStat::SharesMap::const_iterator i = shares->begin(); i != shares->end(); ++i) {
1533  tmp.InsertOrRetrieve(i->second)->Update(i->first - prev_count);
1534  prev_count = i->first;
1535  }
1536  }
1537 
1538  if (tmp.GetCount() == 0) {
1539  dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1540  } else {
1541  uint sum_estimated = 0;
1542  while (sum_estimated < count) {
1543  for (CargoDataSet::iterator i = tmp.Begin(); i != tmp.End() && sum_estimated < count; ++i) {
1544  CargoDataEntry *child = *i;
1545  uint estimate = DivideApprox(child->GetCount() * count, tmp.GetCount());
1546  if (estimate == 0) estimate = 1;
1547 
1548  sum_estimated += estimate;
1549  if (sum_estimated > count) {
1550  estimate -= sum_estimated - count;
1551  sum_estimated = count;
1552  }
1553 
1554  if (estimate > 0) {
1555  if (child->GetStation() == next) {
1556  dest->InsertOrRetrieve(next)->Update(estimate);
1557  } else {
1558  EstimateDestinations(cargo, source, child->GetStation(), estimate, dest);
1559  }
1560  }
1561  }
1562 
1563  }
1564  }
1565  } else {
1566  dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1567  }
1568  }
1569 
1576  void BuildFlowList(CargoID i, const FlowStatMap &flows, CargoDataEntry *cargo)
1577  {
1578  const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1579  for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1580  StationID from = it->first;
1581  const CargoDataEntry *source_entry = source_dest->Retrieve(from);
1582  const FlowStat::SharesMap *shares = it->second.GetShares();
1583  for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1584  const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second);
1585  for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1586  CargoDataEntry *dest_entry = *dest_it;
1587  ShowCargo(cargo, i, from, flow_it->second, dest_entry->GetStation(), dest_entry->GetCount());
1588  }
1589  }
1590  }
1591  }
1592 
1599  void BuildCargoList(CargoID i, const StationCargoList &packets, CargoDataEntry *cargo)
1600  {
1601  const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1602  for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) {
1603  const CargoPacket *cp = *it;
1604  StationID next = it.GetKey();
1605 
1606  const CargoDataEntry *source_entry = source_dest->Retrieve(cp->SourceStation());
1607  if (source_entry == nullptr) {
1608  this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count());
1609  continue;
1610  }
1611 
1612  const CargoDataEntry *via_entry = source_entry->Retrieve(next);
1613  if (via_entry == nullptr) {
1614  this->ShowCargo(cargo, i, cp->SourceStation(), next, INVALID_STATION, cp->Count());
1615  continue;
1616  }
1617 
1618  for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1619  CargoDataEntry *dest_entry = *dest_it;
1620  uint val = DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount());
1621  this->ShowCargo(cargo, i, cp->SourceStation(), next, dest_entry->GetStation(), val);
1622  }
1623  }
1624  this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
1625  }
1626 
1632  void BuildCargoList(CargoDataEntry *cargo, const Station *st)
1633  {
1634  for (CargoID i = 0; i < NUM_CARGO; i++) {
1635 
1636  if (this->cached_destinations.Retrieve(i) == nullptr) {
1637  this->RecalcDestinations(i);
1638  }
1639 
1640  if (this->current_mode == MODE_WAITING) {
1641  this->BuildCargoList(i, st->goods[i].cargo, cargo);
1642  } else {
1643  this->BuildFlowList(i, st->goods[i].flows, cargo);
1644  }
1645  }
1646  }
1647 
1653  {
1654  std::list<StationID> stations;
1655  const CargoDataEntry *parent = data->GetParent();
1656  if (parent->GetParent() == nullptr) {
1657  this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, data->GetCargo()));
1658  return;
1659  }
1660 
1661  StationID next = data->GetStation();
1662  while (parent->GetParent()->GetParent() != nullptr) {
1663  stations.push_back(parent->GetStation());
1664  parent = parent->GetParent();
1665  }
1666 
1667  CargoID cargo = parent->GetCargo();
1668  CargoDataEntry *filter = this->expanded_rows.Retrieve(cargo);
1669  while (!stations.empty()) {
1670  filter = filter->Retrieve(stations.back());
1671  stations.pop_back();
1672  }
1673 
1674  this->displayed_rows.push_back(RowDisplay(filter, next));
1675  }
1676 
1685  StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any)
1686  {
1687  if (station == this->window_number) {
1688  return here;
1689  } else if (station == INVALID_STATION) {
1690  return any;
1691  } else if (station == NEW_STATION) {
1692  return STR_STATION_VIEW_RESERVED;
1693  } else {
1694  SetDParam(2, station);
1695  return other_station;
1696  }
1697  }
1698 
1706  StringID SearchNonStop(CargoDataEntry *cd, StationID station, int column)
1707  {
1708  CargoDataEntry *parent = cd->GetParent();
1709  for (int i = column - 1; i > 0; --i) {
1710  if (this->groupings[i] == GR_DESTINATION) {
1711  if (parent->GetStation() == station) {
1712  return STR_STATION_VIEW_NONSTOP;
1713  } else {
1714  return STR_STATION_VIEW_VIA;
1715  }
1716  }
1717  parent = parent->GetParent();
1718  }
1719 
1720  if (this->groupings[column + 1] == GR_DESTINATION) {
1721  CargoDataSet::iterator begin = cd->Begin();
1722  CargoDataSet::iterator end = cd->End();
1723  if (begin != end && ++(cd->Begin()) == end && (*(begin))->GetStation() == station) {
1724  return STR_STATION_VIEW_NONSTOP;
1725  } else {
1726  return STR_STATION_VIEW_VIA;
1727  }
1728  }
1729 
1730  return STR_STATION_VIEW_VIA;
1731  }
1732 
1743  int DrawEntries(CargoDataEntry *entry, Rect &r, int pos, int maxrows, int column, CargoID cargo = CT_INVALID)
1744  {
1745  if (this->sortings[column] == ST_AS_GROUPING) {
1746  if (this->groupings[column] != GR_CARGO) {
1747  entry->Resort(ST_STATION_STRING, this->sort_orders[column]);
1748  }
1749  } else {
1750  entry->Resort(ST_COUNT, this->sort_orders[column]);
1751  }
1752  for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) {
1753  CargoDataEntry *cd = *i;
1754 
1755  Grouping grouping = this->groupings[column];
1756  if (grouping == GR_CARGO) cargo = cd->GetCargo();
1757  bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1758 
1759  if (pos > -maxrows && pos <= 0) {
1760  StringID str = STR_EMPTY;
1761  int y = r.top + WD_FRAMERECT_TOP - pos * FONT_HEIGHT_NORMAL;
1762  SetDParam(0, cargo);
1763  SetDParam(1, cd->GetCount());
1764 
1765  if (this->groupings[column] == GR_CARGO) {
1766  str = STR_STATION_VIEW_WAITING_CARGO;
1767  DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + WD_FRAMERECT_LEFT + this->expand_shrink_width, r.right - WD_FRAMERECT_RIGHT - this->expand_shrink_width, y);
1768  } else {
1769  if (!auto_distributed) grouping = GR_SOURCE;
1770  StationID station = cd->GetStation();
1771 
1772  switch (grouping) {
1773  case GR_SOURCE:
1774  str = this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
1775  break;
1776  case GR_NEXT:
1777  str = this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
1778  if (str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
1779  break;
1780  case GR_DESTINATION:
1781  str = this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
1782  break;
1783  default:
1784  NOT_REACHED();
1785  }
1786  if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
1787  ScrollMainWindowToTile(Station::Get(station)->xy);
1788  }
1789  }
1790 
1791  bool rtl = _current_text_dir == TD_RTL;
1792  int text_left = rtl ? r.left + this->expand_shrink_width : r.left + WD_FRAMERECT_LEFT + column * this->expand_shrink_width;
1793  int text_right = rtl ? r.right - WD_FRAMERECT_LEFT - column * this->expand_shrink_width : r.right - this->expand_shrink_width;
1794  int shrink_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - this->expand_shrink_width + WD_FRAMERECT_LEFT;
1795  int shrink_right = rtl ? r.left + this->expand_shrink_width - WD_FRAMERECT_RIGHT : r.right - WD_FRAMERECT_RIGHT;
1796 
1797  DrawString(text_left, text_right, y, str);
1798 
1799  if (column < NUM_COLUMNS - 1) {
1800  const char *sym = nullptr;
1801  if (cd->GetNumChildren() > 0) {
1802  sym = "-";
1803  } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
1804  sym = "+";
1805  } else {
1806  /* Only draw '+' if there is something to be shown. */
1807  const StationCargoList &list = Station::Get(this->window_number)->goods[cargo].cargo;
1808  if (grouping == GR_CARGO && (list.ReservedCount() > 0 || cd->HasTransfers())) {
1809  sym = "+";
1810  }
1811  }
1812  if (sym) DrawString(shrink_left, shrink_right, y, sym, TC_YELLOW);
1813  }
1814  this->SetDisplayedRow(cd);
1815  }
1816  --pos;
1817  if (auto_distributed || column == 0) {
1818  pos = this->DrawEntries(cd, r, pos, maxrows, column + 1, cargo);
1819  }
1820  }
1821  return pos;
1822  }
1823 
1829  int DrawAcceptedCargo(const Rect &r) const
1830  {
1831  const Station *st = Station::Get(this->window_number);
1832 
1833  CargoTypes cargo_mask = 0;
1834  for (CargoID i = 0; i < NUM_CARGO; i++) {
1835  if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(cargo_mask, i);
1836  }
1837  SetDParam(0, cargo_mask);
1838  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);
1839  return CeilDiv(bottom - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
1840  }
1841 
1847  int DrawCargoRatings(const Rect &r) const
1848  {
1849  const Station *st = Station::Get(this->window_number);
1850  int y = r.top + WD_FRAMERECT_TOP;
1851 
1852  if (st->town->exclusive_counter > 0) {
1853  SetDParam(0, st->town->exclusivity);
1854  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);
1855  y += WD_PAR_VSEP_WIDE;
1856  }
1857 
1858  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_VIEW_SUPPLY_RATINGS_TITLE);
1859  y += FONT_HEIGHT_NORMAL;
1860 
1861  const CargoSpec *cs;
1863  const GoodsEntry *ge = &st->goods[cs->Index()];
1864  if (!ge->HasRating()) continue;
1865 
1866  const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph);
1867  SetDParam(0, cs->name);
1868  SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].Supply()) : 0);
1869  SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
1870  SetDParam(3, ToPercent8(ge->rating));
1871  DrawString(r.left + WD_FRAMERECT_LEFT + 6, r.right - WD_FRAMERECT_RIGHT - 6, y, STR_STATION_VIEW_CARGO_SUPPLY_RATING);
1872  y += FONT_HEIGHT_NORMAL;
1873  }
1874  return CeilDiv(y - r.top - WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
1875  }
1876 
1882  template<class Tid>
1883  void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
1884  {
1885  if (filter->Retrieve(next) != nullptr) {
1886  filter->Remove(next);
1887  } else {
1888  filter->InsertOrRetrieve(next);
1889  }
1890  }
1891 
1897  {
1898  if (row < 0 || (uint)row >= this->displayed_rows.size()) return;
1899  if (_ctrl_pressed) {
1900  this->scroll_to_row = row;
1901  } else {
1902  RowDisplay &display = this->displayed_rows[row];
1903  if (display.filter == &this->expanded_rows) {
1904  this->HandleCargoWaitingClick<CargoID>(display.filter, display.next_cargo);
1905  } else {
1906  this->HandleCargoWaitingClick<StationID>(display.filter, display.next_station);
1907  }
1908  }
1910  }
1911 
1912  void OnClick(Point pt, int widget, int click_count) override
1913  {
1914  switch (widget) {
1915  case WID_SV_WAITING:
1916  this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL) - this->vscroll->GetPosition());
1917  break;
1918 
1919  case WID_SV_CATCHMENT:
1921  break;
1922 
1923  case WID_SV_LOCATION:
1924  if (_ctrl_pressed) {
1925  ShowExtraViewportWindow(Station::Get(this->window_number)->xy);
1926  } else {
1927  ScrollMainWindowToTile(Station::Get(this->window_number)->xy);
1928  }
1929  break;
1930 
1931  case WID_SV_ACCEPTS_RATINGS: {
1932  /* Swap between 'accepts' and 'ratings' view. */
1933  int height_change;
1934  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS);
1935  if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1936  nwi->SetDataTip(STR_STATION_VIEW_ACCEPTS_BUTTON, STR_STATION_VIEW_ACCEPTS_TOOLTIP); // Switch to accepts view.
1937  height_change = this->rating_lines - this->accepts_lines;
1938  } else {
1939  nwi->SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP); // Switch to ratings view.
1940  height_change = this->accepts_lines - this->rating_lines;
1941  }
1942  this->ReInit(0, height_change * FONT_HEIGHT_NORMAL);
1943  break;
1944  }
1945 
1946  case WID_SV_RENAME:
1947  SetDParam(0, this->window_number);
1948  ShowQueryString(STR_STATION_NAME, STR_STATION_VIEW_RENAME_STATION_CAPTION, MAX_LENGTH_STATION_NAME_CHARS,
1950  break;
1951 
1952  case WID_SV_CLOSE_AIRPORT:
1953  DoCommandP(0, this->window_number, 0, CMD_OPEN_CLOSE_AIRPORT);
1954  break;
1955 
1956  case WID_SV_TRAINS: // Show list of scheduled trains to this station
1957  case WID_SV_ROADVEHS: // Show list of scheduled road-vehicles to this station
1958  case WID_SV_SHIPS: // Show list of scheduled ships to this station
1959  case WID_SV_PLANES: { // Show list of scheduled aircraft to this station
1960  Owner owner = Station::Get(this->window_number)->owner;
1961  ShowVehicleListWindow(owner, (VehicleType)(widget - WID_SV_TRAINS), (StationID)this->window_number);
1962  break;
1963  }
1964 
1965  case WID_SV_SORT_BY: {
1966  /* The initial selection is composed of current mode and
1967  * sorting criteria for columns 1, 2, and 3. Column 0 is always
1968  * sorted by cargo ID. The others can theoretically be sorted
1969  * by different things but there is no UI for that. */
1971  this->current_mode * 2 + (this->sortings[1] == ST_COUNT ? 1 : 0),
1972  WID_SV_SORT_BY, 0, 0);
1973  break;
1974  }
1975 
1976  case WID_SV_GROUP_BY: {
1977  ShowDropDownMenu(this, _group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
1978  break;
1979  }
1980 
1981  case WID_SV_SORT_ORDER: { // flip sorting method asc/desc
1982  this->SelectSortOrder(this->sort_orders[1] == SO_ASCENDING ? SO_DESCENDING : SO_ASCENDING);
1983  this->SetTimeout();
1985  break;
1986  }
1987  }
1988  }
1989 
1994  void SelectSortOrder(SortOrder order)
1995  {
1996  this->sort_orders[1] = this->sort_orders[2] = this->sort_orders[3] = order;
1997  _settings_client.gui.station_gui_sort_order = this->sort_orders[1];
1998  this->SetDirty();
1999  }
2000 
2005  void SelectSortBy(int index)
2006  {
2008  switch (_sort_names[index]) {
2009  case STR_STATION_VIEW_WAITING_STATION:
2010  this->current_mode = MODE_WAITING;
2011  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING;
2012  break;
2013  case STR_STATION_VIEW_WAITING_AMOUNT:
2014  this->current_mode = MODE_WAITING;
2015  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT;
2016  break;
2017  case STR_STATION_VIEW_PLANNED_STATION:
2018  this->current_mode = MODE_PLANNED;
2019  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_AS_GROUPING;
2020  break;
2021  case STR_STATION_VIEW_PLANNED_AMOUNT:
2022  this->current_mode = MODE_PLANNED;
2023  this->sortings[1] = this->sortings[2] = this->sortings[3] = ST_COUNT;
2024  break;
2025  default:
2026  NOT_REACHED();
2027  }
2028  /* Display the current sort variant */
2029  this->GetWidget<NWidgetCore>(WID_SV_SORT_BY)->widget_data = _sort_names[index];
2030  this->SetDirty();
2031  }
2032 
2037  void SelectGroupBy(int index)
2038  {
2039  this->grouping_index = index;
2041  this->GetWidget<NWidgetCore>(WID_SV_GROUP_BY)->widget_data = _group_names[index];
2042  switch (_group_names[index]) {
2043  case STR_STATION_VIEW_GROUP_S_V_D:
2044  this->groupings[1] = GR_SOURCE;
2045  this->groupings[2] = GR_NEXT;
2046  this->groupings[3] = GR_DESTINATION;
2047  break;
2048  case STR_STATION_VIEW_GROUP_S_D_V:
2049  this->groupings[1] = GR_SOURCE;
2050  this->groupings[2] = GR_DESTINATION;
2051  this->groupings[3] = GR_NEXT;
2052  break;
2053  case STR_STATION_VIEW_GROUP_V_S_D:
2054  this->groupings[1] = GR_NEXT;
2055  this->groupings[2] = GR_SOURCE;
2056  this->groupings[3] = GR_DESTINATION;
2057  break;
2058  case STR_STATION_VIEW_GROUP_V_D_S:
2059  this->groupings[1] = GR_NEXT;
2060  this->groupings[2] = GR_DESTINATION;
2061  this->groupings[3] = GR_SOURCE;
2062  break;
2063  case STR_STATION_VIEW_GROUP_D_S_V:
2064  this->groupings[1] = GR_DESTINATION;
2065  this->groupings[2] = GR_SOURCE;
2066  this->groupings[3] = GR_NEXT;
2067  break;
2068  case STR_STATION_VIEW_GROUP_D_V_S:
2069  this->groupings[1] = GR_DESTINATION;
2070  this->groupings[2] = GR_NEXT;
2071  this->groupings[3] = GR_SOURCE;
2072  break;
2073  }
2074  this->SetDirty();
2075  }
2076 
2077  void OnDropdownSelect(int widget, int index) override
2078  {
2079  if (widget == WID_SV_SORT_BY) {
2080  this->SelectSortBy(index);
2081  } else {
2082  this->SelectGroupBy(index);
2083  }
2084  }
2085 
2086  void OnQueryTextFinished(char *str) override
2087  {
2088  if (str == nullptr) return;
2089 
2090  DoCommandP(0, this->window_number, 0, CMD_RENAME_STATION | CMD_MSG(STR_ERROR_CAN_T_RENAME_STATION), nullptr, str);
2091  }
2092 
2093  void OnResize() override
2094  {
2096  }
2097 
2103  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2104  {
2105  if (gui_scope) {
2106  if (data >= 0 && data < NUM_CARGO) {
2107  this->cached_destinations.Remove((CargoID)data);
2108  } else {
2109  this->ReInit();
2110  }
2111  }
2112  }
2113 };
2114 
2116  STR_STATION_VIEW_WAITING_STATION,
2117  STR_STATION_VIEW_WAITING_AMOUNT,
2118  STR_STATION_VIEW_PLANNED_STATION,
2119  STR_STATION_VIEW_PLANNED_AMOUNT,
2121 };
2122 
2124  STR_STATION_VIEW_GROUP_S_V_D,
2125  STR_STATION_VIEW_GROUP_S_D_V,
2126  STR_STATION_VIEW_GROUP_V_S_D,
2127  STR_STATION_VIEW_GROUP_V_D_S,
2128  STR_STATION_VIEW_GROUP_D_S_V,
2129  STR_STATION_VIEW_GROUP_D_V_S,
2131 };
2132 
2133 static WindowDesc _station_view_desc(
2134  WDP_AUTO, "view_station", 249, 117,
2136  0,
2137  _nested_station_view_widgets, lengthof(_nested_station_view_widgets)
2138 );
2139 
2145 void ShowStationViewWindow(StationID station)
2146 {
2147  AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
2148 }
2149 
2153  StationID station;
2154 };
2155 
2156 static std::vector<TileAndStation> _deleted_stations_nearby;
2157 static std::vector<StationID> _stations_nearby_list;
2158 
2166 template <class T>
2167 static bool AddNearbyStation(TileIndex tile, void *user_data)
2168 {
2169  TileArea *ctx = (TileArea *)user_data;
2170 
2171  /* First check if there were deleted stations here */
2172  for (uint i = 0; i < _deleted_stations_nearby.size(); i++) {
2173  auto ts = _deleted_stations_nearby.begin() + i;
2174  if (ts->tile == tile) {
2175  _stations_nearby_list.push_back(_deleted_stations_nearby[i].station);
2176  _deleted_stations_nearby.erase(ts);
2177  i--;
2178  }
2179  }
2180 
2181  /* Check if own station and if we stay within station spread */
2182  if (!IsTileType(tile, MP_STATION)) return false;
2183 
2184  StationID sid = GetStationIndex(tile);
2185 
2186  /* This station is (likely) a waypoint */
2187  if (!T::IsValidID(sid)) return false;
2188 
2189  T *st = T::Get(sid);
2190  if (st->owner != _local_company || std::find(_stations_nearby_list.begin(), _stations_nearby_list.end(), sid) != _stations_nearby_list.end()) return false;
2191 
2192  if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
2193  _stations_nearby_list.push_back(sid);
2194  }
2195 
2196  return false; // We want to include *all* nearby stations
2197 }
2198 
2208 template <class T>
2209 static const T *FindStationsNearby(TileArea ta, bool distant_join)
2210 {
2211  TileArea ctx = ta;
2212 
2213  _stations_nearby_list.clear();
2214  _deleted_stations_nearby.clear();
2215 
2216  /* Check the inside, to return, if we sit on another station */
2217  TILE_AREA_LOOP(t, ta) {
2218  if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
2219  }
2220 
2221  /* Look for deleted stations */
2222  for (const BaseStation *st : BaseStation::Iterate()) {
2223  if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
2224  /* Include only within station spread (yes, it is strictly less than) */
2225  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) {
2226  _deleted_stations_nearby.push_back({st->xy, st->index});
2227 
2228  /* Add the station when it's within where we're going to build */
2229  if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
2230  IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
2231  AddNearbyStation<T>(st->xy, &ctx);
2232  }
2233  }
2234  }
2235  }
2236 
2237  /* Only search tiles where we have a chance to stay within the station spread.
2238  * The complete check needs to be done in the callback as we don't know the
2239  * extent of the found station, yet. */
2240  if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return nullptr;
2241  uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1;
2242 
2243  TileIndex tile = TileAddByDir(ctx.tile, DIR_N);
2244  CircularTileSearch(&tile, max_dist, ta.w, ta.h, AddNearbyStation<T>, &ctx);
2245 
2246  return nullptr;
2247 }
2248 
2249 static const NWidgetPart _nested_select_station_widgets[] = {
2251  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
2252  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_JS_CAPTION), SetDataTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2253  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
2254  EndContainer(),
2256  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_JS_PANEL), SetResize(1, 0), SetScrollbar(WID_JS_SCROLLBAR), EndContainer(),
2258  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_JS_SCROLLBAR),
2259  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
2260  EndContainer(),
2261  EndContainer(),
2262 };
2263 
2268 template <class T>
2272  Scrollbar *vscroll;
2273 
2274  SelectStationWindow(WindowDesc *desc, const CommandContainer &cmd, TileArea ta) :
2275  Window(desc),
2276  select_station_cmd(cmd),
2277  area(ta)
2278  {
2279  this->CreateNestedTree();
2280  this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR);
2281  this->GetWidget<NWidgetCore>(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION;
2282  this->FinishInitNested(0);
2283  this->OnInvalidateData(0);
2284 
2285  _thd.freeze = true;
2286  }
2287 
2289  {
2291 
2292  _thd.freeze = false;
2293  }
2294 
2295  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2296  {
2297  if (widget != WID_JS_PANEL) return;
2298 
2299  /* Determine the widest string */
2300  Dimension d = GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2301  for (uint i = 0; i < _stations_nearby_list.size(); i++) {
2302  const T *st = T::Get(_stations_nearby_list[i]);
2303  SetDParam(0, st->index);
2304  SetDParam(1, st->facilities);
2305  d = maxdim(d, GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION));
2306  }
2307 
2308  resize->height = d.height;
2309  d.height *= 5;
2311  d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
2312  *size = d;
2313  }
2314 
2315  void DrawWidget(const Rect &r, int widget) const override
2316  {
2317  if (widget != WID_JS_PANEL) return;
2318 
2319  uint y = r.top + WD_FRAMERECT_TOP;
2320  if (this->vscroll->GetPosition() == 0) {
2321  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);
2322  y += this->resize.step_height;
2323  }
2324 
2325  for (uint i = std::max<uint>(1, this->vscroll->GetPosition()); i <= _stations_nearby_list.size(); ++i, y += this->resize.step_height) {
2326  /* Don't draw anything if it extends past the end of the window. */
2327  if (i - this->vscroll->GetPosition() >= this->vscroll->GetCapacity()) break;
2328 
2329  const T *st = T::Get(_stations_nearby_list[i - 1]);
2330  SetDParam(0, st->index);
2331  SetDParam(1, st->facilities);
2332  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);
2333  }
2334  }
2335 
2336  void OnClick(Point pt, int widget, int click_count) override
2337  {
2338  if (widget != WID_JS_PANEL) return;
2339 
2340  uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP);
2341  bool distant_join = (st_index > 0);
2342  if (distant_join) st_index--;
2343 
2344  if (distant_join && st_index >= _stations_nearby_list.size()) return;
2345 
2346  /* Insert station to be joined into stored command */
2347  SB(this->select_station_cmd.p2, 16, 16,
2348  (distant_join ? _stations_nearby_list[st_index] : NEW_STATION));
2349 
2350  /* Execute stored Command */
2351  DoCommandP(&this->select_station_cmd);
2352 
2353  /* Close Window; this might cause double frees! */
2355  }
2356 
2357  void OnRealtimeTick(uint delta_ms) override
2358  {
2359  if (_thd.dirty & 2) {
2360  _thd.dirty &= ~2;
2361  this->SetDirty();
2362  }
2363  }
2364 
2365  void OnResize() override
2366  {
2367  this->vscroll->SetCapacityFromWidget(this, WID_JS_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
2368  }
2369 
2375  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2376  {
2377  if (!gui_scope) return;
2378  FindStationsNearby<T>(this->area, true);
2379  this->vscroll->SetCount((uint)_stations_nearby_list.size() + 1);
2380  this->SetDirty();
2381  }
2382 
2383  void OnMouseOver(Point pt, int widget) override
2384  {
2385  if (widget != WID_JS_PANEL || T::EXPECTED_FACIL == FACIL_WAYPOINT) {
2386  SetViewportCatchmentStation(nullptr, true);
2387  return;
2388  }
2389 
2390  /* Show coverage area of station under cursor */
2391  uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP);
2392  if (st_index == 0 || st_index > _stations_nearby_list.size()) {
2393  SetViewportCatchmentStation(nullptr, true);
2394  } else {
2395  st_index--;
2396  SetViewportCatchmentStation(Station::Get(_stations_nearby_list[st_index]), true);
2397  }
2398  }
2399 };
2400 
2401 static WindowDesc _select_station_desc(
2402  WDP_AUTO, "build_station_join", 200, 180,
2405  _nested_select_station_widgets, lengthof(_nested_select_station_widgets)
2406 );
2407 
2408 
2416 template <class T>
2417 static bool StationJoinerNeeded(const CommandContainer &cmd, TileArea ta)
2418 {
2419  /* Only show selection if distant join is enabled in the settings */
2420  if (!_settings_game.station.distant_join_stations) return false;
2421 
2422  /* If a window is already opened and we didn't ctrl-click,
2423  * return true (i.e. just flash the old window) */
2424  Window *selection_window = FindWindowById(WC_SELECT_STATION, 0);
2425  if (selection_window != nullptr) {
2426  /* Abort current distant-join and start new one */
2427  delete selection_window;
2429  }
2430 
2431  /* only show the popup, if we press ctrl */
2432  if (!_ctrl_pressed) return false;
2433 
2434  /* Now check if we could build there */
2435  if (DoCommand(&cmd, CommandFlagsToDCFlags(GetCommandFlags(cmd.cmd))).Failed()) return false;
2436 
2437  /* Test for adjacent station or station below selection.
2438  * If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
2439  * but join the other station immediately. */
2440  const T *st = FindStationsNearby<T>(ta, false);
2441  return st == nullptr && (_settings_game.station.adjacent_stations || _stations_nearby_list.size() == 0);
2442 }
2443 
2450 template <class T>
2452 {
2453  if (StationJoinerNeeded<T>(cmd, ta)) {
2455  new SelectStationWindow<T>(&_select_station_desc, cmd, ta);
2456  } else {
2457  DoCommandP(&cmd);
2458  }
2459 }
2460 
2467 {
2468  ShowSelectBaseStationIfNeeded<Station>(cmd, ta);
2469 }
2470 
2477 {
2478  ShowSelectBaseStationIfNeeded<Waypoint>(cmd, ta);
2479 }
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:1309
StationViewWindow::HandleCargoWaitingClick
void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
Expand or collapse a specific row.
Definition: station_gui.cpp:1883
CompanyStationsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:680
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:367
StationViewWindow
The StationView window.
Definition: station_gui.cpp:1228
CargoList< StationCargoList, StationCargoPacketMap >::ConstIterator
StationCargoPacketMap ::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:207
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:307
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
CommandContainer::cmd
uint32 cmd
command being executed.
Definition: command_type.h:483
CompanyStationsWindow::StationRatingMaxSorter
static bool StationRatingMaxSorter(const Station *const &a, const Station *const &b)
Sort stations by their rating.
Definition: station_gui.cpp:298
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:479
FOR_ALL_SORTED_STANDARD_CARGOSPECS
#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var)
Loop header for iterating over 'real' cargoes, sorted by name.
Definition: cargotype.h:171
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:1912
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1155
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
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:150
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2443
vehicle_gui.h
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:575
StationViewWindow::ALH_ACCEPTS
@ ALH_ACCEPTS
Height of the accepted cargo view.
Definition: station_gui.cpp:1291
UpdateTileSelection
void UpdateTileSelection()
Updates tile highlighting for all cases.
Definition: viewport.cpp:2530
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:1104
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:1239
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
ScaleFontTrad
static int ScaleFontTrad(int value)
Scale traditional pixel dimensions to Font zoom level.
Definition: zoom_func.h:96
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:631
command_func.h
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:636
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:167
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:340
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:309
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
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:903
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:132
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:995
company_base.h
StationViewWindow::INV_FLOWS
@ INV_FLOWS
The planned flows have been recalculated and everything has to be updated.
Definition: station_gui.cpp:1261
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:951
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:246
CargoDataEntry::cargo
CargoID cargo
ID of the cargo this entry is associated with.
Definition: station_gui.cpp:1029
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:526
GetContrastColour
TextColour GetContrastColour(uint8 background, uint8 threshold)
Determine a contrasty text colour for a coloured background.
Definition: gfx.cpp:1262
CompanyStationsWindow
The list of stations per company.
Definition: station_gui.cpp:199
FACIL_TRUCK_STOP
@ FACIL_TRUCK_STOP
Station with truck stops.
Definition: station_type.h:53
CompanyStationsWindow::BuildStationsList
void BuildStationsList(const Owner owner)
(Re)Build station list
Definition: station_gui.cpp:222
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:450
CheckRedrawStationCoverage
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Definition: station_gui.cpp:126
StationViewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:2103
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1972
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:166
StationViewWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: station_gui.cpp:2077
SelectStationWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2365
PC_RED
static const uint8 PC_RED
Red palette colour.
Definition: gfx_func.h:213
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:827
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:117
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:81
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:1314
StationViewWindow::RowDisplay
A row being displayed in the cargo view (as opposed to being "hidden" behind a plus sign).
Definition: station_gui.cpp:1232
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
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
CargoDataEntry::GetCargo
CargoID GetCargo() const
Get the cargo ID for this entry.
Definition: station_gui.cpp:972
StationViewWindow::SelectSortBy
void SelectSortBy(int index)
Select a new sort criterium for the cargo view.
Definition: station_gui.cpp:2005
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:1743
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:679
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
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:448
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:1393
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:1599
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:840
ShowSelectBaseStationIfNeeded
void ShowSelectBaseStationIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the station selection window when needed.
Definition: station_gui.cpp:2451
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:939
CommandContainer::p2
uint32 p2
parameter p2.
Definition: command_type.h:482
zoom_func.h
FACIL_NONE
@ FACIL_NONE
The station has no facilities at all.
Definition: station_type.h:51
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
StationViewWindow::BuildCargoList
void BuildCargoList(CargoDataEntry *cargo, const Station *st)
Build up the cargo view for all cargoes.
Definition: station_gui.cpp:1632
StationViewWindow::DrawCargoRatings
int DrawCargoRatings(const Rect &r) const
Draw cargo ratings in the WID_SV_ACCEPT_RATING_LIST widget.
Definition: station_gui.cpp:1847
ShowCompanyStations
void ShowCompanyStations(CompanyID company)
Opens window with list of company's stations.
Definition: station_gui.cpp:787
CommandContainer
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:479
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:2167
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:79
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:640
StationViewWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: station_gui.cpp:2086
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:55
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:977
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:325
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:85
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:338
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:119
StationViewWindow::_sort_names
static const StringID _sort_names[]
Names of the sorting options in the dropdown.
Definition: station_gui.cpp:1294
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:39
CompanyStationsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:428
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:97
GUIList::SetSortType
void SetSortType(uint8 n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:103
StationViewWindow::GR_DESTINATION
@ GR_DESTINATION
Group by estimated final destination ("to").
Definition: station_gui.cpp:1271
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:1706
SelectStationWindow::area
TileArea area
Location of new station.
Definition: station_gui.cpp:2271
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:598
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:1283
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
StationViewWindow::MODE_PLANNED
@ MODE_PLANNED
Show cargo planned to pass through the station.
Definition: station_gui.cpp:1280
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:919
CargoDataEntry::children
CargoDataSet * children
the children of this entry.
Definition: station_gui.cpp:1035
GoodsEntry::status
byte status
Status of this cargo, see GoodsEntryStatus.
Definition: station_base.h:226
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1023
StationViewWindow::GR_SOURCE
@ GR_SOURCE
Group by source of cargo ("from").
Definition: station_gui.cpp:1269
StationViewWindow::AcceptListHeight
AcceptListHeight
Height of the WID_SV_ACCEPT_RATING_LIST widget for different views.
Definition: station_gui.cpp:1289
ShowStationViewWindow
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
Definition: station_gui.cpp:2145
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:526
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
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:534
StationViewWindow::INV_CARGO
@ INV_CARGO
Some cargo has been added or removed.
Definition: station_gui.cpp:1262
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:1477
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:763
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:913
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:866
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:1310
CMD_OPEN_CLOSE_AIRPORT
@ CMD_OPEN_CLOSE_AIRPORT
open/close an airport to incoming aircraft
Definition: command_type.h:336
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:1255
WindowDesc
High level window description.
Definition: window_gui.h:166
StationViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2093
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:255
CargoDataEntry::num_children
uint num_children
the number of subentries belonging to this entry.
Definition: station_gui.cpp:1033
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:438
FACIL_BUS_STOP
@ FACIL_BUS_STOP
Station with bus stops.
Definition: station_type.h:54
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:88
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:1685
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:154
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:20
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:101
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:323
StationViewWindow::sortings
CargoSortType sortings[NUM_COLUMNS]
Sort types of the different 'columns'.
Definition: station_gui.cpp:1303
CargoDataEntry::GetNumChildren
uint GetNumChildren() const
Get the number of children for this entry.
Definition: station_gui.cpp:987
TILE_AREA_LOOP
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition: tilearea_type.h:232
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:622
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
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
CargoPacket::SourceStation
StationID SourceStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:158
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:1829
StationCoverageType
StationCoverageType
Types of cargo to display for station coverage.
Definition: station_gui.h:19
StationViewWindow::SetDisplayedRow
void SetDisplayedRow(const CargoDataEntry *data)
Mark a specific row, characterized by its CargoDataEntry, as expanded.
Definition: station_gui.cpp:1652
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:1357
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:1244
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:273
CompanyStationsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:670
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:848
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:98
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
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:1896
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
GetProductionAroundTiles
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
Get the cargo types being produced around the tile (in a rectangle).
Definition: station_cmd.cpp:506
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:208
SB
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
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
CMD_RENAME_STATION
@ CMD_RENAME_STATION
rename a station
Definition: command_type.h:248
StationViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:1417
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:18
GoodsEntry::node
NodeID node
ID of node in link graph referring to this goods entry.
Definition: station_base.h:258
CargoSortType
CargoSortType
Definition: station_gui.cpp:862
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
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:157
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
_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:464
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:16
CargoWidgets
static NWidgetBase * CargoWidgets(int *biggest_index)
Make a horizontal row of cargo buttons, starting at widget WID_STL_CARGOSTART.
Definition: station_gui.cpp:723
CompanyStationsWindow::StationTypeSorter
static bool StationTypeSorter(const Station *const &a, const Station *const &b)
Sort stations by their type.
Definition: station_gui.cpp:266
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
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:1576
SelectStationWindow
Window for selecting stations/waypoints to (distant) join to.
Definition: station_gui.cpp:2269
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:393
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:338
_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:1141
CargoDataEntry::Retrieve
CargoDataEntry * Retrieve(CargoID cargo) const
Retrieve a child for the given cargo.
Definition: station_gui.cpp:956
Airport::flags
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:308
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:313
CargoDataEntry::station
StationID station
ID of the station this entry is associated with.
Definition: station_gui.cpp:1027
StationViewWindow::groupings
Grouping groupings[NUM_COLUMNS]
Grouping modes for the different columns.
Definition: station_gui.cpp:1311
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:1489
CargoPacket::Count
uint16 Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:99
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:978
WID_SV_LOCATION
@ WID_SV_LOCATION
'Location' button.
Definition: station_widget.h:23
TileAndStation::tile
TileIndex tile
TileIndex.
Definition: station_gui.cpp:2152
StationViewWindow::MODE_WAITING
@ MODE_WAITING
Show cargo waiting at the station.
Definition: station_gui.cpp:1279
CargoDataEntry::Remove
void Remove(StationID station)
Remove a child associated with the given station.
Definition: station_gui.cpp:924
GoodsEntry::rating
byte rating
Station rating for this cargo.
Definition: station_base.h:235
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:867
GameSettings::linkgraph
LinkGraphSettings linkgraph
settings for link graph calculations
Definition: settings_type.h:574
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:301
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:507
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:982
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:488
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:540
CompanyStationsWindow::StationWaitingTotalSorter
static bool StationWaitingTotalSorter(const Station *const &a, const Station *const &b)
Sort stations by their waiting cargo.
Definition: station_gui.cpp:272
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:313
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:114
GetCommandFlags
CommandFlags GetCommandFlags(uint32 cmd)
Definition: command.cpp:393
GoodsEntry::link_graph
LinkGraphID link_graph
Link graph this station belongs to.
Definition: station_base.h:257
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:2383
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:218
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
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:183
CompanyStationsWindow::SortStationsList
void SortStationsList()
Sort the stations list.
Definition: station_gui.cpp:328
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
_sorted_standard_cargo_specs_size
uint8 _sorted_standard_cargo_specs_size
Number of standard cargo specifications stored in the _sorted_cargo_specs array.
Definition: cargotype.cpp:133
StationViewWindow::_group_names
static const StringID _group_names[]
Names of the grouping options in the dropdown.
Definition: station_gui.cpp:1295
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:57
ShowSelectStationIfNeeded
void ShowSelectStationIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the station selection window when needed.
Definition: station_gui.cpp:2466
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:837
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:176
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:19
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:516
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:87
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:54
WID_STL_SORTDROPBTN
@ WID_STL_SORTDROPBTN
Dropdown button.
Definition: station_widget.h:53
SelectStationWindow::select_station_cmd
CommandContainer select_station_cmd
Command to build new station.
Definition: station_gui.cpp:2270
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:22
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:103
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:224
CargoDataEntry::SetTransfers
void SetTransfers(bool value)
Set the transfers state.
Definition: station_gui.cpp:1007
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:170
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1008
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:235
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:378
ST_STATION_STRING
@ ST_STATION_STRING
by station name
Definition: station_gui.cpp:865
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
StationViewWindow::Invalidation
Invalidation
Type of data invalidation.
Definition: station_gui.cpp:1260
StationViewWindow::displayed_rows
CargoDataVector displayed_rows
Parent entry of currently displayed rows (including collapsed ones).
Definition: station_gui.cpp:1315
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
NWidgetCore::SetDataTip
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:892
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:525
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:185
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:463
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:1142
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:945
CargoDataEntry::Clear
void Clear()
Delete all subentries, reset count and num_children and adapt parent's count.
Definition: station_gui.cpp:1087
CargoDataEntry::GetStation
StationID GetStation() const
Get the station ID for this entry.
Definition: station_gui.cpp:967
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
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:1249
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:259
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1123
StationViewWindow::sort_orders
SortOrder sort_orders[NUM_COLUMNS]
Sort order (ascending/descending) for the 'columns'.
Definition: station_gui.cpp:1306
SCT_NON_PASSENGERS_ONLY
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition: station_gui.h:21
geometry_func.hpp
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
SelectStationWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: station_gui.cpp:2315
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:956
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:152
TileAndStation::station
StationID station
StationID.
Definition: station_gui.cpp:2153
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:494
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:51
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:168
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:64
GoodsEntry::GES_ACCEPTANCE
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
Definition: station_base.h:177
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:640
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
GetAcceptanceAroundTiles
CargoArray GetAcceptanceAroundTiles(TileIndex 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:545
StationViewWindow::Mode
Mode
Display mode of the cargo view.
Definition: station_gui.cpp:1278
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:70
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
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:2484
company_func.h
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3522
CargoDataEntry::HasTransfers
bool HasTransfers() const
Has this entry transfers.
Definition: station_gui.cpp:1002
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:74
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:538
StationViewWindow::GR_NEXT
@ GR_NEXT
Group by next station ("via").
Definition: station_gui.cpp:1270
StationJoinerNeeded
static bool StationJoinerNeeded(const CommandContainer &cmd, TileArea ta)
Check whether we need to show the station selection window.
Definition: station_gui.cpp:2417
StationViewWindow::ALH_RATING
@ ALH_RATING
Height of the cargo ratings view.
Definition: station_gui.cpp:1290
StationSettings::adjacent_stations
bool adjacent_stations
allow stations to be built directly adjacent to other stations
Definition: settings_type.h:537
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:893
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
CommandFlagsToDCFlags
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:58
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:464
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:69
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:369
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:320
SelectStationWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:2375
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:42
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:1986
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:656
StationViewWindow::SelectSortOrder
void SelectSortOrder(SortOrder order)
Select a new sort order for the cargo view.
Definition: station_gui.cpp:1994
StationViewWindow::SelectGroupBy
void SelectGroupBy(int index)
Select a new grouping mode for the cargo view.
Definition: station_gui.cpp:2037
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:1034
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:186
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:1285
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
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:2295
CargoDataEntry::parent
CargoDataEntry * parent
the parent of this entry.
Definition: station_gui.cpp:1025
ST_AS_GROUPING
@ ST_AS_GROUPING
by the same principle the entries are being grouped
Definition: station_gui.cpp:863
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:1308
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:643
CargoSorter
Definition: station_gui.cpp:870
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:992
CargoDataEntry::Remove
void Remove(CargoID cargo)
Remove a child associated with the given cargo.
Definition: station_gui.cpp:934
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:1272
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:277
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
ShowSelectWaypointIfNeeded
void ShowSelectWaypointIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the waypoint selection window when needed.
Definition: station_gui.cpp:2476
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
ST_COUNT
@ ST_COUNT
by amount of cargo
Definition: station_gui.cpp:864
CompanyStationsWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: station_gui.cpp:662
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:484
StationViewWindow::rating_lines
int rating_lines
Number of lines in the cargo ratings view.
Definition: station_gui.cpp:1284
_viewport_highlight_station
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
Definition: viewport.cpp:985
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:2336
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
StationViewWindow::expanded_rows
CargoDataEntry expanded_rows
Parent entry of currently expanded rows.
Definition: station_gui.cpp:1313
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:55
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:554
CompanyStationsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: station_gui.cpp:436
StationViewWindow::Grouping
Grouping
Type of grouping used in each of the "columns".
Definition: station_gui.cpp:1268
CompanyStationsWindow::StationNameSorter
static bool StationNameSorter(const Station *const &a, const Station *const &b)
Sort stations by their name.
Definition: station_gui.cpp:258
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:225
CompanyStationsWindow::StationRatingMinSorter
static bool StationRatingMinSorter(const Station *const &a, const Station *const &b)
Sort stations by their rating.
Definition: station_gui.cpp:313
WID_SV_SCROLLBAR
@ WID_SV_SCROLLBAR
Scrollbar.
Definition: station_widget.h:21
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:68
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:292
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:148
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
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:1523
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:475
TileAndStation
Struct containing TileIndex and StationID.
Definition: station_gui.cpp:2151
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:319
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:2209
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:182
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:295
WD_PAR_VSEP_WIDE
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:138
SelectStationWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: station_gui.cpp:2357
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:3421
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:815
PC_GREEN
static const uint8 PC_GREEN
Green palette colour.
Definition: gfx_func.h:223
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:454
station_gui.h
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
FOR_EACH_SET_BIT
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
Definition: bitmath_func.hpp:361
_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:650
CargoDataEntry::Begin
CargoDataSet::iterator Begin() const
Get an iterator pointing to the begin of the set of children.
Definition: station_gui.cpp:992
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:581
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:517
CargoDataEntry::transfers
bool transfers
If there are transfers for this cargo.
Definition: station_gui.cpp:1030
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:974
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:151
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
CargoDataEntry::IncrementSize
void IncrementSize()
Increment.
Definition: station_gui.cpp:1151
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
CargoDataEntry::End
CargoDataSet::iterator End() const
Get an iterator pointing to the end of the set of children.
Definition: station_gui.cpp:997
WID_SV_RENAME
@ WID_SV_RENAME
'Rename' button.
Definition: station_widget.h:25