OpenTTD Source  14.0-beta1
station_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "debug.h"
12 #include "gui.h"
13 #include "textbuf_gui.h"
14 #include "company_func.h"
15 #include "command_func.h"
16 #include "vehicle_gui.h"
17 #include "cargotype.h"
18 #include "station_gui.h"
19 #include "strings_func.h"
20 #include "string_func.h"
21 #include "window_func.h"
22 #include "viewport_func.h"
23 #include "widgets/dropdown_func.h"
24 #include "station_base.h"
25 #include "waypoint_base.h"
26 #include "tilehighlight_func.h"
27 #include "company_base.h"
28 #include "sortlist_type.h"
29 #include "core/geometry_func.hpp"
30 #include "vehiclelist.h"
31 #include "town.h"
32 #include "linkgraph/linkgraph.h"
33 #include "zoom_func.h"
34 #include "station_cmd.h"
35 
36 #include "widgets/station_widget.h"
37 
38 #include "table/strings.h"
39 
40 #include "safeguards.h"
41 
52 int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
53 {
54  TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
55  CargoTypes cargo_mask = 0;
56  if (_thd.drawstyle == HT_RECT && tile < Map::Size()) {
57  CargoArray cargoes;
58  if (supplies) {
59  cargoes = GetProductionAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
60  } else {
61  cargoes = GetAcceptanceAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
62  }
63 
64  /* Convert cargo counts to a set of cargo bits, and draw the result. */
65  for (CargoID i = 0; i < NUM_CARGO; i++) {
66  switch (sct) {
67  case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
68  case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
69  case SCT_ALL: break;
70  default: NOT_REACHED();
71  }
72  if (cargoes[i] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, i);
73  }
74  }
75  SetDParam(0, cargo_mask);
76  return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
77 }
78 
83 template <typename T>
85 {
86  /* With distant join we don't know which station will be selected, so don't show any */
87  if (_ctrl_pressed) {
88  SetViewportCatchmentSpecializedStation<T>(nullptr, true);
89  return;
90  }
91 
92  /* Tile area for TileHighlightData */
93  TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1);
94 
95  /* Extended area by one tile */
96  uint x = TileX(location.tile);
97  uint y = TileY(location.tile);
98 
99  /* Waypoints can only be built on existing rail tiles, so don't extend area if not highlighting a rail tile. */
100  int max_c = T::EXPECTED_FACIL == FACIL_WAYPOINT && !IsTileType(location.tile, MP_RAILWAY) ? 0 : 1;
101  TileArea ta(TileXY(std::max<int>(0, x - max_c), std::max<int>(0, y - max_c)), TileXY(std::min<int>(Map::MaxX(), x + location.w + max_c), std::min<int>(Map::MaxY(), y + location.h + max_c)));
102 
103  T *adjacent = nullptr;
104 
105  /* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
106  for (TileIndex tile : ta) {
107  if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) {
108  T *st = T::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  SetViewportCatchmentSpecializedStation<T>(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 
140  FindStationsAroundSelection<Station>();
141  }
142  }
143 }
144 
145 void CheckRedrawWaypointCoverage(const Window *)
146 {
147  /* Test if ctrl state changed */
148  static bool _last_ctrl_pressed;
149  if (_ctrl_pressed != _last_ctrl_pressed) {
150  _thd.dirty = 0xff;
151  _last_ctrl_pressed = _ctrl_pressed;
152  }
153 
154  if (_thd.dirty & 1) {
155  _thd.dirty &= ~1;
156 
157  if (_thd.drawstyle == HT_RECT) {
158  FindStationsAroundSelection<Waypoint>();
159  }
160  }
161 }
162 
175 static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating)
176 {
177  static const uint units_full = 576;
178  static const uint rating_full = 224;
179 
180  const CargoSpec *cs = CargoSpec::Get(type);
181  if (!cs->IsValid()) return;
182 
183  int padding = ScaleGUITrad(1);
184  int width = right - left;
185  int colour = cs->rating_colour;
186  TextColour tc = GetContrastColour(colour);
187  uint w = std::min(amount + 5, units_full) * width / units_full;
188 
189  int height = GetCharacterHeight(FS_SMALL) + padding - 1;
190 
191  if (amount > 30) {
192  /* Draw total cargo (limited) on station */
193  GfxFillRect(left, y, left + w - 1, y + height, colour);
194  } else {
195  /* Draw a (scaled) one pixel-wide bar of additional cargo meter, useful
196  * for stations with only a small amount (<=30) */
197  uint rest = ScaleGUITrad(amount) / 5;
198  if (rest != 0) {
199  GfxFillRect(left, y + height - rest, left + padding - 1, y + height, colour);
200  }
201  }
202 
203  DrawString(left + padding, right, y, cs->abbrev, tc, SA_CENTER, false, FS_SMALL);
204 
205  /* Draw green/red ratings bar (fits under the waiting bar) */
206  y += height + padding + 1;
207  GfxFillRect(left + padding, y, right - padding - 1, y + padding - 1, PC_RED);
208  w = std::min<uint>(rating, rating_full) * (width - padding - padding) / rating_full;
209  if (w != 0) GfxFillRect(left + padding, y, left + w - 1, y + padding - 1, PC_GREEN);
210 }
211 
213 
218 {
219 protected:
220  /* Runtime saved values */
221  struct FilterState {
222  Listing last_sorting;
223  byte facilities;
225  CargoTypes cargoes;
226  };
227 
228  static inline FilterState initial_state = {
229  {false, 0},
231  true,
232  ALL_CARGOTYPES,
233  };
234 
235  /* Constants for sorting stations */
236  static const StringID sorter_names[];
237  static GUIStationList::SortFunction * const sorter_funcs[];
238 
239  FilterState filter;
240  GUIStationList stations{filter.cargoes};
241  Scrollbar *vscroll;
242  uint rating_width;
243 
250  {
251  if (!this->stations.NeedRebuild()) return;
252 
253  Debug(misc, 3, "Building station list for company {}", owner);
254 
255  this->stations.clear();
256 
257  for (const Station *st : Station::Iterate()) {
258  if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
259  if (this->filter.facilities & st->facilities) { // only stations with selected facilities
260  int num_waiting_cargo = 0;
261  for (CargoID j = 0; j < NUM_CARGO; j++) {
262  if (st->goods[j].HasRating()) {
263  num_waiting_cargo++; // count number of waiting cargo
264  if (HasBit(this->filter.cargoes, j)) {
265  this->stations.push_back(st);
266  break;
267  }
268  }
269  }
270  /* stations without waiting cargo */
271  if (num_waiting_cargo == 0 && this->filter.include_empty) {
272  this->stations.push_back(st);
273  }
274  }
275  }
276  }
277 
278  this->stations.shrink_to_fit();
279  this->stations.RebuildDone();
280 
281  this->vscroll->SetCount(this->stations.size()); // Update the scrollbar
282  }
283 
285  static bool StationNameSorter(const Station * const &a, const Station * const &b, const CargoTypes &)
286  {
287  int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
288  if (r == 0) return a->index < b->index;
289  return r < 0;
290  }
291 
293  static bool StationTypeSorter(const Station * const &a, const Station * const &b, const CargoTypes &)
294  {
295  return a->facilities < b->facilities;
296  }
297 
299  static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
300  {
301  int diff = 0;
302 
303  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
304  diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount();
305  }
306 
307  return diff < 0;
308  }
309 
311  static bool StationWaitingAvailableSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
312  {
313  int diff = 0;
314 
315  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
316  diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
317  }
318 
319  return diff < 0;
320  }
321 
323  static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
324  {
325  byte maxr1 = 0;
326  byte maxr2 = 0;
327 
328  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
329  if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating);
330  if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating);
331  }
332 
333  return maxr1 < maxr2;
334  }
335 
337  static bool StationRatingMinSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
338  {
339  byte minr1 = 255;
340  byte minr2 = 255;
341 
342  for (CargoID j : SetCargoBitIterator(cargo_filter)) {
343  if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating);
344  if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating);
345  }
346 
347  return minr1 > minr2;
348  }
349 
352  {
353  if (!this->stations.Sort()) return;
354 
355  /* Set the modified widget dirty */
357  }
358 
359 public:
361  {
362  /* Load initial filter state. */
363  this->filter = CompanyStationsWindow::initial_state;
364  if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes = _cargo_mask;
365 
366  this->stations.SetListing(this->filter.last_sorting);
367  this->stations.SetSortFuncs(CompanyStationsWindow::sorter_funcs);
368  this->stations.ForceRebuild();
369  this->stations.NeedResort();
370  this->SortStationsList();
371 
372  this->CreateNestedTree();
373  this->vscroll = this->GetScrollbar(WID_STL_SCROLLBAR);
374  this->FinishInitNested(window_number);
375  this->owner = (Owner)this->window_number;
376 
377  uint8_t index = 0;
378  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
379  if (HasBit(this->filter.cargoes, cs->Index())) {
380  this->LowerWidget(WID_STL_CARGOSTART + index);
381  }
382  index++;
383  }
384 
385  if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes = _cargo_mask;
386 
387  for (uint i = 0; i < 5; i++) {
388  if (HasBit(this->filter.facilities, i)) this->LowerWidget(i + WID_STL_TRAIN);
389  }
390  this->SetWidgetLoweredState(WID_STL_NOCARGOWAITING, this->filter.include_empty);
391 
392  this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
393  }
394 
396  {
397  /* Save filter state. */
398  this->filter.last_sorting = this->stations.GetListing();
399  CompanyStationsWindow::initial_state = this->filter;
400  }
401 
402  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
403  {
404  switch (widget) {
405  case WID_STL_SORTBY: {
406  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
407  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
408  d.height += padding.height;
409  *size = maxdim(*size, d);
410  break;
411  }
412 
413  case WID_STL_SORTDROPBTN: {
414  Dimension d = {0, 0};
415  for (int i = 0; CompanyStationsWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
416  d = maxdim(d, GetStringBoundingBox(CompanyStationsWindow::sorter_names[i]));
417  }
418  d.width += padding.width;
419  d.height += padding.height;
420  *size = maxdim(*size, d);
421  break;
422  }
423 
424  case WID_STL_LIST:
426  size->height = padding.height + 5 * resize->height;
427 
428  /* Determine appropriate width for mini station rating graph */
429  this->rating_width = 0;
430  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
431  this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev, FS_SMALL).width);
432  }
433  /* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
434  this->rating_width = this->rating_width * 16 / 10;
435  break;
436 
437  default:
438  if (widget >= WID_STL_CARGOSTART) {
440  d.width += padding.width + 2;
441  d.height += padding.height;
442  *size = maxdim(*size, d);
443  }
444  break;
445  }
446  }
447 
448  void OnPaint() override
449  {
450  this->BuildStationsList((Owner)this->window_number);
451  this->SortStationsList();
452 
453  this->DrawWidgets();
454  }
455 
456  void DrawWidget(const Rect &r, WidgetID widget) const override
457  {
458  switch (widget) {
459  case WID_STL_SORTBY:
460  /* draw arrow pointing up/down for ascending/descending sorting */
462  break;
463 
464  case WID_STL_LIST: {
465  bool rtl = _current_text_dir == TD_RTL;
466  size_t max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size());
467  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
468  uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
469  /* Spacing between station name and first rating graph. */
470  int text_spacing = WidgetDimensions::scaled.hsep_wide;
471  /* Spacing between additional rating graphs. */
472  int rating_spacing = WidgetDimensions::scaled.hsep_normal;
473 
474  for (size_t i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner
475  const Station *st = this->stations[i];
476  assert(st->xy != INVALID_TILE);
477 
478  /* Do not do the complex check HasStationInUse here, it may be even false
479  * when the order had been removed and the station list hasn't been removed yet */
480  assert(st->owner == owner || st->owner == OWNER_NONE);
481 
482  SetDParam(0, st->index);
483  SetDParam(1, st->facilities);
484  int x = DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, STR_STATION_LIST_STATION);
485  x += rtl ? -text_spacing : text_spacing;
486 
487  /* show cargo waiting and station ratings */
488  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
489  CargoID cid = cs->Index();
490  if (st->goods[cid].HasRating()) {
491  /* For RTL we work in exactly the opposite direction. So
492  * decrement the space needed first, then draw to the left
493  * instead of drawing to the left and then incrementing
494  * the space. */
495  if (rtl) {
496  x -= rating_width + rating_spacing;
497  if (x < tr.left) break;
498  }
499  StationsWndShowStationRating(x, x + rating_width, tr.top, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
500  if (!rtl) {
501  x += rating_width + rating_spacing;
502  if (x > tr.right) break;
503  }
504  }
505  }
506  tr.top += line_height;
507  }
508 
509  if (this->vscroll->GetCount() == 0) { // company has no stations
510  DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, STR_STATION_LIST_NONE);
511  return;
512  }
513  break;
514  }
515 
516  default:
517  if (widget >= WID_STL_CARGOSTART) {
518  Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
519  const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
520  GfxFillRect(br, cs->rating_colour);
521  TextColour tc = GetContrastColour(cs->rating_colour);
522  DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), cs->abbrev, tc, SA_HOR_CENTER, false, FS_SMALL);
523  }
524  break;
525  }
526  }
527 
528  void SetStringParameters(WidgetID widget) const override
529  {
530  if (widget == WID_STL_CAPTION) {
531  SetDParam(0, this->window_number);
532  SetDParam(1, this->vscroll->GetCount());
533  }
534  }
535 
536  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
537  {
538  switch (widget) {
539  case WID_STL_LIST: {
540  auto it = this->vscroll->GetScrolledItemFromWidget(this->stations, pt.y, this, WID_STL_LIST);
541  if (it == this->stations.end()) return; // click out of list bound
542 
543  const Station *st = *it;
544  /* do not check HasStationInUse - it is slow and may be invalid */
545  assert(st->owner == (Owner)this->window_number || st->owner == OWNER_NONE);
546 
547  if (_ctrl_pressed) {
549  } else {
551  }
552  break;
553  }
554 
555  case WID_STL_TRAIN:
556  case WID_STL_TRUCK:
557  case WID_STL_BUS:
558  case WID_STL_AIRPLANE:
559  case WID_STL_SHIP:
560  if (_ctrl_pressed) {
561  ToggleBit(this->filter.facilities, widget - WID_STL_TRAIN);
562  this->ToggleWidgetLoweredState(widget);
563  } else {
564  for (uint i : SetBitIterator(this->filter.facilities)) {
565  this->RaiseWidget(i + WID_STL_TRAIN);
566  }
567  this->filter.facilities = 1 << (widget - WID_STL_TRAIN);
568  this->LowerWidget(widget);
569  }
570  this->stations.ForceRebuild();
571  this->SetDirty();
572  break;
573 
574  case WID_STL_FACILALL:
575  for (WidgetID i = WID_STL_TRAIN; i <= WID_STL_SHIP; i++) {
576  this->LowerWidget(i);
577  }
578 
579  this->filter.facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
580  this->stations.ForceRebuild();
581  this->SetDirty();
582  break;
583 
584  case WID_STL_CARGOALL: {
585  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
586  this->LowerWidget(WID_STL_CARGOSTART + i);
587  }
589 
590  this->filter.cargoes = _cargo_mask;
591  this->filter.include_empty = true;
592  this->stations.ForceRebuild();
593  this->SetDirty();
594  break;
595  }
596 
597  case WID_STL_SORTBY: // flip sorting method asc/desc
598  this->stations.ToggleSortOrder();
599  this->SetDirty();
600  break;
601 
602  case WID_STL_SORTDROPBTN: // select sorting criteria dropdown menu
603  ShowDropDownMenu(this, this->sorter_names, this->stations.SortType(), WID_STL_SORTDROPBTN, 0, 0);
604  break;
605 
607  if (_ctrl_pressed) {
608  this->filter.include_empty = !this->filter.include_empty;
610  } else {
611  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
612  this->RaiseWidget(WID_STL_CARGOSTART + i);
613  }
614 
615  this->filter.cargoes = 0;
616  this->filter.include_empty = true;
617 
619  }
620  this->stations.ForceRebuild();
621  this->SetDirty();
622  break;
623 
624  default:
625  if (widget >= WID_STL_CARGOSTART) { // change cargo_filter
626  /* Determine the selected cargo type */
627  const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
628 
629  if (_ctrl_pressed) {
630  ToggleBit(this->filter.cargoes, cs->Index());
631  this->ToggleWidgetLoweredState(widget);
632  } else {
633  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
634  this->RaiseWidget(WID_STL_CARGOSTART + i);
635  }
637 
638  this->filter.cargoes = 0;
639  this->filter.include_empty = false;
640 
641  SetBit(this->filter.cargoes, cs->Index());
642  this->LowerWidget(widget);
643  }
644  this->stations.ForceRebuild();
645  this->SetDirty();
646  }
647  break;
648  }
649  }
650 
651  void OnDropdownSelect(WidgetID widget, int index) override
652  {
653  if (widget == WID_STL_SORTDROPBTN) {
654  if (this->stations.SortType() != index) {
655  this->stations.SetSortType(index);
656 
657  /* Display the current sort variant */
658  this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = CompanyStationsWindow::sorter_names[this->stations.SortType()];
659 
660  this->SetDirty();
661  }
662  }
663  }
664 
665  void OnGameTick() override
666  {
667  if (this->stations.NeedResort()) {
668  Debug(misc, 3, "Periodic rebuild station list company {}", this->window_number);
669  this->SetDirty();
670  }
671  }
672 
673  void OnResize() override
674  {
675  this->vscroll->SetCapacityFromWidget(this, WID_STL_LIST, WidgetDimensions::scaled.framerect.Vertical());
676  }
677 
683  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
684  {
685  if (data == 0) {
686  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
687  this->stations.ForceRebuild();
688  } else {
689  this->stations.ForceResort();
690  }
691  }
692 };
693 
694 /* Available station sorting functions */
695 GUIStationList::SortFunction * const CompanyStationsWindow::sorter_funcs[] = {
696  &StationNameSorter,
697  &StationTypeSorter,
698  &StationWaitingTotalSorter,
699  &StationWaitingAvailableSorter,
700  &StationRatingMaxSorter,
701  &StationRatingMinSorter
702 };
703 
704 /* Names of the sorting functions */
705 const StringID CompanyStationsWindow::sorter_names[] = {
706  STR_SORT_BY_NAME,
707  STR_SORT_BY_FACILITY,
708  STR_SORT_BY_WAITING_TOTAL,
709  STR_SORT_BY_WAITING_AVAILABLE,
710  STR_SORT_BY_RATING_MAX,
711  STR_SORT_BY_RATING_MIN,
713 };
714 
719 static std::unique_ptr<NWidgetBase> CargoWidgets()
720 {
721  auto container = std::make_unique<NWidgetHorizontal>();
722 
723  for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
724  auto panel = std::make_unique<NWidgetBackground>(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
725  panel->SetMinimalSize(14, 0);
726  panel->SetMinimalTextLines(1, 0, FS_NORMAL);
727  panel->SetResize(0, 0);
728  panel->SetFill(0, 1);
729  panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
730  container->Add(std::move(panel));
731  }
732  return container;
733 }
734 
735 static constexpr NWidgetPart _nested_company_stations_widgets[] = {
737  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
738  NWidget(WWT_CAPTION, COLOUR_GREY, WID_STL_CAPTION), SetDataTip(STR_STATION_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
739  NWidget(WWT_SHADEBOX, COLOUR_GREY),
740  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
741  NWidget(WWT_STICKYBOX, COLOUR_GREY),
742  EndContainer(),
744  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRAIN), SetMinimalSize(14, 0), SetDataTip(STR_TRAIN, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
745  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_TRUCK), SetMinimalSize(14, 0), SetDataTip(STR_LORRY, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
746  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_BUS), SetMinimalSize(14, 0), SetDataTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
747  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_SHIP), SetMinimalSize(14, 0), SetDataTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
748  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_AIRPLANE), SetMinimalSize(14, 0), SetDataTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE), SetFill(0, 1),
749  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_FACILALL), SetMinimalSize(14, 0), SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES), SetTextStyle(TC_BLACK, FS_SMALL), SetFill(0, 1),
750  NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
752  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_STL_NOCARGOWAITING), SetMinimalSize(14, 0), SetDataTip(STR_ABBREV_NONE, STR_STATION_LIST_NO_WAITING_CARGO), SetTextStyle(TC_BLACK, FS_SMALL), SetFill(0, 1),
753  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_CARGOALL), SetMinimalSize(14, 0), SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_TYPES), SetTextStyle(TC_BLACK, FS_SMALL), SetFill(0, 1),
754  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
755  EndContainer(),
757  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_SORTBY), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
758  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_STL_SORTDROPBTN), SetMinimalSize(163, 12), SetDataTip(STR_SORT_BY_NAME, STR_TOOLTIP_SORT_CRITERIA), // widget_data gets overwritten.
759  NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
760  EndContainer(),
762  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(),
765  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
766  EndContainer(),
767  EndContainer(),
768 };
769 
770 static WindowDesc _company_stations_desc(__FILE__, __LINE__,
771  WDP_AUTO, "list_stations", 358, 162,
773  0,
774  std::begin(_nested_company_stations_widgets), std::end(_nested_company_stations_widgets)
775 );
776 
783 {
784  if (!Company::IsValidID(company)) return;
785 
786  AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
787 }
788 
789 static constexpr NWidgetPart _nested_station_view_widgets[] = {
791  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
792  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
793  NWidget(WWT_CAPTION, COLOUR_GREY, WID_SV_CAPTION), SetDataTip(STR_STATION_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
794  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_STATION_VIEW_CENTER_TOOLTIP),
795  NWidget(WWT_SHADEBOX, COLOUR_GREY),
796  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
797  NWidget(WWT_STICKYBOX, COLOUR_GREY),
798  EndContainer(),
800  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_GROUP), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_STATION_VIEW_GROUP, 0x0),
801  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_GROUP_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
802  EndContainer(),
804  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SORT_ORDER), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
805  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_SORT_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
806  EndContainer(),
810  EndContainer(),
813  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ACCEPTS_RATINGS), SetMinimalSize(46, 12), SetResize(1, 0), SetFill(1, 1),
814  SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
815  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
816  SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
817  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
818  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
819  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
820  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
821  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_PLANES), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
822  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
823  EndContainer(),
824 };
825 
835 static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int y)
836 {
837  int width = ScaleSpriteTrad(10);
838  uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow
839  if (num == 0) return;
840 
841  SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon();
842 
843  int x = _current_text_dir == TD_RTL ? left : right - num * width;
844  do {
845  DrawSprite(sprite, PAL_NONE, x, y);
846  x += width;
847  } while (--num);
848 }
849 
850 enum SortOrder {
851  SO_DESCENDING,
852  SO_ASCENDING
853 };
854 
855 class CargoDataEntry;
856 
857 enum class CargoSortType : byte {
858  AsGrouping,
859  Count,
860  StationString,
861  StationID,
862  CargoID,
863 };
864 
865 class CargoSorter {
866 public:
867  CargoSorter(CargoSortType t = CargoSortType::StationID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
868  CargoSortType GetSortType() {return this->type;}
869  bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
870 
871 private:
872  CargoSortType type;
873  SortOrder order;
874 
875  template<class Tid>
876  bool SortId(Tid st1, Tid st2) const;
877  bool SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
878  bool SortStation (StationID st1, StationID st2) const;
879 };
880 
881 typedef std::set<CargoDataEntry *, CargoSorter> CargoDataSet;
882 
889 public:
890  CargoDataEntry();
891  ~CargoDataEntry();
892 
899  {
900  return this->InsertOrRetrieve<StationID>(station);
901  }
902 
909  {
910  return this->InsertOrRetrieve<CargoID>(cargo);
911  }
912 
913  void Update(uint count);
914 
919  void Remove(StationID station)
920  {
922  this->Remove(&t);
923  }
924 
930  {
932  this->Remove(&t);
933  }
934 
940  CargoDataEntry *Retrieve(StationID station) const
941  {
943  return this->Retrieve(this->children->find(&t));
944  }
945 
952  {
954  return this->Retrieve(this->children->find(&t));
955  }
956 
957  void Resort(CargoSortType type, SortOrder order);
958 
962  StationID GetStation() const { return this->station; }
963 
967  CargoID GetCargo() const { return this->cargo; }
968 
972  uint GetCount() const { return this->count; }
973 
977  CargoDataEntry *GetParent() const { return this->parent; }
978 
982  uint GetNumChildren() const { return this->num_children; }
983 
987  CargoDataSet::iterator Begin() const { return this->children->begin(); }
988 
992  CargoDataSet::iterator End() const { return this->children->end(); }
993 
997  bool HasTransfers() const { return this->transfers; }
998 
1002  void SetTransfers(bool value) { this->transfers = value; }
1003 
1004  void Clear();
1005 private:
1006 
1007  CargoDataEntry(StationID st, uint c, CargoDataEntry *p);
1008  CargoDataEntry(CargoID car, uint c, CargoDataEntry *p);
1009  CargoDataEntry(StationID st);
1010  CargoDataEntry(CargoID car);
1011 
1012  CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
1013 
1014  template<class Tid>
1016 
1017  void Remove(CargoDataEntry *comp);
1018  void IncrementSize();
1019 
1021  const union {
1022  StationID station;
1023  struct {
1025  bool transfers;
1026  };
1027  };
1029  uint count;
1030  CargoDataSet *children;
1031 };
1032 
1033 CargoDataEntry::CargoDataEntry() :
1034  parent(nullptr),
1035  station(INVALID_STATION),
1036  num_children(0),
1037  count(0),
1038  children(new CargoDataSet(CargoSorter(CargoSortType::CargoID)))
1039 {}
1040 
1041 CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
1042  parent(parent),
1043  cargo(cargo),
1044  num_children(0),
1045  count(count),
1046  children(new CargoDataSet)
1047 {}
1048 
1049 CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
1050  parent(parent),
1051  station(station),
1052  num_children(0),
1053  count(count),
1054  children(new CargoDataSet)
1055 {}
1056 
1057 CargoDataEntry::CargoDataEntry(StationID station) :
1058  parent(nullptr),
1059  station(station),
1060  num_children(0),
1061  count(0),
1062  children(nullptr)
1063 {}
1064 
1065 CargoDataEntry::CargoDataEntry(CargoID cargo) :
1066  parent(nullptr),
1067  cargo(cargo),
1068  num_children(0),
1069  count(0),
1070  children(nullptr)
1071 {}
1072 
1073 CargoDataEntry::~CargoDataEntry()
1074 {
1075  this->Clear();
1076  delete this->children;
1077 }
1078 
1083 {
1084  if (this->children != nullptr) {
1085  for (auto &it : *this->children) {
1086  assert(it != this);
1087  delete it;
1088  }
1089  this->children->clear();
1090  }
1091  if (this->parent != nullptr) this->parent->count -= this->count;
1092  this->count = 0;
1093  this->num_children = 0;
1094 }
1095 
1103 {
1104  CargoDataSet::iterator i = this->children->find(child);
1105  if (i != this->children->end()) {
1106  delete *i;
1107  this->children->erase(i);
1108  }
1109 }
1110 
1117 template<class Tid>
1119 {
1120  CargoDataEntry tmp(child_id);
1121  CargoDataSet::iterator i = this->children->find(&tmp);
1122  if (i == this->children->end()) {
1123  IncrementSize();
1124  return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first);
1125  } else {
1126  CargoDataEntry *ret = *i;
1127  assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
1128  return ret;
1129  }
1130 }
1131 
1137 void CargoDataEntry::Update(uint count)
1138 {
1139  this->count += count;
1140  if (this->parent != nullptr) this->parent->Update(count);
1141 }
1142 
1147 {
1148  ++this->num_children;
1149  if (this->parent != nullptr) this->parent->IncrementSize();
1150 }
1151 
1152 void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
1153 {
1154  CargoDataSet *new_subs = new CargoDataSet(this->children->begin(), this->children->end(), CargoSorter(type, order));
1155  delete this->children;
1156  this->children = new_subs;
1157 }
1158 
1159 CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
1160 {
1161  if (i == this->children->end()) {
1162  return nullptr;
1163  } else {
1164  assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
1165  return *i;
1166  }
1167 }
1168 
1169 bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1170 {
1171  switch (this->type) {
1173  return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation());
1175  return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo());
1176  case CargoSortType::Count:
1177  return this->SortCount(cd1, cd2);
1179  return this->SortStation(cd1->GetStation(), cd2->GetStation());
1180  default:
1181  NOT_REACHED();
1182  }
1183 }
1184 
1185 template<class Tid>
1186 bool CargoSorter::SortId(Tid st1, Tid st2) const
1187 {
1188  return (this->order == SO_ASCENDING) ? st1 < st2 : st2 < st1;
1189 }
1190 
1191 bool CargoSorter::SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1192 {
1193  uint c1 = cd1->GetCount();
1194  uint c2 = cd2->GetCount();
1195  if (c1 == c2) {
1196  return this->SortStation(cd1->GetStation(), cd2->GetStation());
1197  } else if (this->order == SO_ASCENDING) {
1198  return c1 < c2;
1199  } else {
1200  return c2 < c1;
1201  }
1202 }
1203 
1204 bool CargoSorter::SortStation(StationID st1, StationID st2) const
1205 {
1206  if (!Station::IsValidID(st1)) {
1207  return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
1208  } else if (!Station::IsValidID(st2)) {
1209  return order == SO_DESCENDING;
1210  }
1211 
1212  int res = StrNaturalCompare(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
1213  if (res == 0) {
1214  return this->SortId(st1, st2);
1215  } else {
1216  return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
1217  }
1218 }
1219 
1223 struct StationViewWindow : public Window {
1227  struct RowDisplay {
1228  RowDisplay(CargoDataEntry *f, StationID n) : filter(f), next_station(n) {}
1230 
1235  union {
1239  StationID next_station;
1240 
1245  };
1246  };
1247 
1248  typedef std::vector<RowDisplay> CargoDataVector;
1249 
1250  static const int NUM_COLUMNS = 4;
1251 
1256  INV_FLOWS = 0x100,
1257  INV_CARGO = 0x200
1258  };
1259 
1263  enum Grouping {
1268  };
1269 
1273  enum Mode {
1276  };
1277 
1281  Scrollbar *vscroll;
1282 
1285  ALH_RATING = 13,
1287  };
1288 
1289  static const StringID _sort_names[];
1290  static const StringID _group_names[];
1291 
1299 
1302 
1307 
1310  CargoDataVector displayed_rows;
1311 
1313  scroll_to_row(INT_MAX), grouping_index(0)
1314  {
1315  this->rating_lines = ALH_RATING;
1316  this->accepts_lines = ALH_ACCEPTS;
1317 
1318  this->CreateNestedTree();
1319  this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
1320  /* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
1321  this->FinishInitNested(window_number);
1322 
1323  this->groupings[0] = GR_CARGO;
1324  this->sortings[0] = CargoSortType::AsGrouping;
1327  this->sort_orders[0] = SO_ASCENDING;
1329  this->owner = Station::Get(window_number)->owner;
1330  }
1331 
1332  void Close([[maybe_unused]] int data = 0) override
1333  {
1334  CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false);
1335  CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false);
1336  CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false);
1337  CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false);
1338 
1339  SetViewportCatchmentStation(Station::Get(this->window_number), false);
1340  this->Window::Close();
1341  }
1342 
1353  void ShowCargo(CargoDataEntry *data, CargoID cargo, StationID source, StationID next, StationID dest, uint count)
1354  {
1355  if (count == 0) return;
1356  bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1357  const CargoDataEntry *expand = &this->expanded_rows;
1358  for (int i = 0; i < NUM_COLUMNS && expand != nullptr; ++i) {
1359  switch (groupings[i]) {
1360  case GR_CARGO:
1361  assert(i == 0);
1362  data = data->InsertOrRetrieve(cargo);
1363  data->SetTransfers(source != this->window_number);
1364  expand = expand->Retrieve(cargo);
1365  break;
1366  case GR_SOURCE:
1367  if (auto_distributed || source != this->window_number) {
1368  data = data->InsertOrRetrieve(source);
1369  expand = expand->Retrieve(source);
1370  }
1371  break;
1372  case GR_NEXT:
1373  if (auto_distributed) {
1374  data = data->InsertOrRetrieve(next);
1375  expand = expand->Retrieve(next);
1376  }
1377  break;
1378  case GR_DESTINATION:
1379  if (auto_distributed) {
1380  data = data->InsertOrRetrieve(dest);
1381  expand = expand->Retrieve(dest);
1382  }
1383  break;
1384  }
1385  }
1386  data->Update(count);
1387  }
1388 
1389  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1390  {
1391  switch (widget) {
1392  case WID_SV_WAITING:
1393  resize->height = GetCharacterHeight(FS_NORMAL);
1394  size->height = 4 * resize->height + padding.height;
1395  this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width);
1396  break;
1397 
1399  size->height = ((this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) ? this->accepts_lines : this->rating_lines) * GetCharacterHeight(FS_NORMAL) + padding.height;
1400  break;
1401 
1402  case WID_SV_CLOSE_AIRPORT:
1403  if (!(Station::Get(this->window_number)->facilities & FACIL_AIRPORT)) {
1404  /* Hide 'Close Airport' button if no airport present. */
1405  size->width = 0;
1406  resize->width = 0;
1407  fill->width = 0;
1408  }
1409  break;
1410  }
1411  }
1412 
1413  void OnPaint() override
1414  {
1415  const Station *st = Station::Get(this->window_number);
1416  CargoDataEntry cargo;
1417  BuildCargoList(&cargo, st);
1418 
1419  this->vscroll->SetCount(cargo.GetNumChildren()); // update scrollbar
1420 
1421  /* disable some buttons */
1427  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
1429 
1430  extern const Station *_viewport_highlight_station;
1432  this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st);
1433 
1434  this->DrawWidgets();
1435 
1436  if (!this->IsShaded()) {
1437  /* Draw 'accepted cargo' or 'cargo ratings'. */
1438  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SV_ACCEPT_RATING_LIST);
1439  const Rect r = wid->GetCurrentRect();
1440  if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1441  int lines = this->DrawAcceptedCargo(r);
1442  if (lines > this->accepts_lines) { // Resize the widget, and perform re-initialization of the window.
1443  this->accepts_lines = lines;
1444  this->ReInit();
1445  return;
1446  }
1447  } else {
1448  int lines = this->DrawCargoRatings(r);
1449  if (lines > this->rating_lines) { // Resize the widget, and perform re-initialization of the window.
1450  this->rating_lines = lines;
1451  this->ReInit();
1452  return;
1453  }
1454  }
1455 
1456  /* Draw arrow pointing up/down for ascending/descending sorting */
1457  this->DrawSortButtonState(WID_SV_SORT_ORDER, sort_orders[1] == SO_ASCENDING ? SBS_UP : SBS_DOWN);
1458 
1459  int pos = this->vscroll->GetPosition();
1460 
1461  int maxrows = this->vscroll->GetCapacity();
1462 
1463  displayed_rows.clear();
1464 
1465  /* Draw waiting cargo. */
1466  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SV_WAITING);
1467  Rect waiting_rect = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
1468  this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0);
1469  scroll_to_row = INT_MAX;
1470  }
1471  }
1472 
1473  void SetStringParameters(WidgetID widget) const override
1474  {
1475  if (widget == WID_SV_CAPTION) {
1476  const Station *st = Station::Get(this->window_number);
1477  SetDParam(0, st->index);
1478  SetDParam(1, st->facilities);
1479  }
1480  }
1481 
1488  {
1489  const Station *st = Station::Get(this->window_number);
1491  cargo_entry->Clear();
1492 
1493  for (const auto &it : st->goods[i].flows) {
1494  StationID from = it.first;
1495  CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from);
1496  uint32_t prev_count = 0;
1497  for (const auto &flow_it : *it.second.GetShares()) {
1498  StationID via = flow_it.second;
1499  CargoDataEntry *via_entry = source_entry->InsertOrRetrieve(via);
1500  if (via == this->window_number) {
1501  via_entry->InsertOrRetrieve(via)->Update(flow_it.first - prev_count);
1502  } else {
1503  EstimateDestinations(i, from, via, flow_it.first - prev_count, via_entry);
1504  }
1505  prev_count = flow_it.first;
1506  }
1507  }
1508  }
1509 
1519  void EstimateDestinations(CargoID cargo, StationID source, StationID next, uint count, CargoDataEntry *dest)
1520  {
1521  if (Station::IsValidID(next) && Station::IsValidID(source)) {
1522  CargoDataEntry tmp;
1523  const FlowStatMap &flowmap = Station::Get(next)->goods[cargo].flows;
1524  FlowStatMap::const_iterator map_it = flowmap.find(source);
1525  if (map_it != flowmap.end()) {
1526  const FlowStat::SharesMap *shares = map_it->second.GetShares();
1527  uint32_t prev_count = 0;
1528  for (FlowStat::SharesMap::const_iterator i = shares->begin(); i != shares->end(); ++i) {
1529  tmp.InsertOrRetrieve(i->second)->Update(i->first - prev_count);
1530  prev_count = i->first;
1531  }
1532  }
1533 
1534  if (tmp.GetCount() == 0) {
1535  dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1536  } else {
1537  uint sum_estimated = 0;
1538  while (sum_estimated < count) {
1539  for (CargoDataSet::iterator i = tmp.Begin(); i != tmp.End() && sum_estimated < count; ++i) {
1540  CargoDataEntry *child = *i;
1541  uint estimate = DivideApprox(child->GetCount() * count, tmp.GetCount());
1542  if (estimate == 0) estimate = 1;
1543 
1544  sum_estimated += estimate;
1545  if (sum_estimated > count) {
1546  estimate -= sum_estimated - count;
1547  sum_estimated = count;
1548  }
1549 
1550  if (estimate > 0) {
1551  if (child->GetStation() == next) {
1552  dest->InsertOrRetrieve(next)->Update(estimate);
1553  } else {
1554  EstimateDestinations(cargo, source, child->GetStation(), estimate, dest);
1555  }
1556  }
1557  }
1558 
1559  }
1560  }
1561  } else {
1562  dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1563  }
1564  }
1565 
1572  void BuildFlowList(CargoID i, const FlowStatMap &flows, CargoDataEntry *cargo)
1573  {
1574  const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1575  for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1576  StationID from = it->first;
1577  const CargoDataEntry *source_entry = source_dest->Retrieve(from);
1578  const FlowStat::SharesMap *shares = it->second.GetShares();
1579  for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1580  const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second);
1581  for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1582  CargoDataEntry *dest_entry = *dest_it;
1583  ShowCargo(cargo, i, from, flow_it->second, dest_entry->GetStation(), dest_entry->GetCount());
1584  }
1585  }
1586  }
1587  }
1588 
1595  void BuildCargoList(CargoID i, const StationCargoList &packets, CargoDataEntry *cargo)
1596  {
1597  const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1598  for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) {
1599  const CargoPacket *cp = *it;
1600  StationID next = it.GetKey();
1601 
1602  const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation());
1603  if (source_entry == nullptr) {
1604  this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count());
1605  continue;
1606  }
1607 
1608  const CargoDataEntry *via_entry = source_entry->Retrieve(next);
1609  if (via_entry == nullptr) {
1610  this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count());
1611  continue;
1612  }
1613 
1614  uint remaining = cp->Count();
1615  for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End();) {
1616  CargoDataEntry *dest_entry = *dest_it;
1617 
1618  /* Advance iterator here instead of in the for statement to test whether this is the last entry */
1619  ++dest_it;
1620 
1621  uint val;
1622  if (dest_it == via_entry->End()) {
1623  /* Allocate all remaining waiting cargo to the last destination to avoid
1624  * waiting cargo being "lost", and the displayed total waiting cargo
1625  * not matching GoodsEntry::TotalCount() */
1626  val = remaining;
1627  } else {
1628  val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount()));
1629  remaining -= val;
1630  }
1631  this->ShowCargo(cargo, i, cp->GetFirstStation(), next, dest_entry->GetStation(), val);
1632  }
1633  }
1634  this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
1635  }
1636 
1642  void BuildCargoList(CargoDataEntry *cargo, const Station *st)
1643  {
1644  for (CargoID i = 0; i < NUM_CARGO; i++) {
1645 
1646  if (this->cached_destinations.Retrieve(i) == nullptr) {
1647  this->RecalcDestinations(i);
1648  }
1649 
1650  if (this->current_mode == MODE_WAITING) {
1651  this->BuildCargoList(i, st->goods[i].cargo, cargo);
1652  } else {
1653  this->BuildFlowList(i, st->goods[i].flows, cargo);
1654  }
1655  }
1656  }
1657 
1663  {
1664  std::list<StationID> stations;
1665  const CargoDataEntry *parent = data->GetParent();
1666  if (parent->GetParent() == nullptr) {
1667  this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, data->GetCargo()));
1668  return;
1669  }
1670 
1671  StationID next = data->GetStation();
1672  while (parent->GetParent()->GetParent() != nullptr) {
1673  stations.push_back(parent->GetStation());
1674  parent = parent->GetParent();
1675  }
1676 
1677  CargoID cargo = parent->GetCargo();
1678  CargoDataEntry *filter = this->expanded_rows.Retrieve(cargo);
1679  while (!stations.empty()) {
1680  filter = filter->Retrieve(stations.back());
1681  stations.pop_back();
1682  }
1683 
1684  this->displayed_rows.push_back(RowDisplay(filter, next));
1685  }
1686 
1695  StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any)
1696  {
1697  if (station == this->window_number) {
1698  return here;
1699  } else if (station == INVALID_STATION) {
1700  return any;
1701  } else if (station == NEW_STATION) {
1702  return STR_STATION_VIEW_RESERVED;
1703  } else {
1704  SetDParam(2, station);
1705  return other_station;
1706  }
1707  }
1708 
1716  StringID SearchNonStop(CargoDataEntry *cd, StationID station, int column)
1717  {
1718  CargoDataEntry *parent = cd->GetParent();
1719  for (int i = column - 1; i > 0; --i) {
1720  if (this->groupings[i] == GR_DESTINATION) {
1721  if (parent->GetStation() == station) {
1722  return STR_STATION_VIEW_NONSTOP;
1723  } else {
1724  return STR_STATION_VIEW_VIA;
1725  }
1726  }
1727  parent = parent->GetParent();
1728  }
1729 
1730  if (this->groupings[column + 1] == GR_DESTINATION) {
1731  CargoDataSet::iterator begin = cd->Begin();
1732  CargoDataSet::iterator end = cd->End();
1733  if (begin != end && ++(cd->Begin()) == end && (*(begin))->GetStation() == station) {
1734  return STR_STATION_VIEW_NONSTOP;
1735  } else {
1736  return STR_STATION_VIEW_VIA;
1737  }
1738  }
1739 
1740  return STR_STATION_VIEW_VIA;
1741  }
1742 
1753  int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo = INVALID_CARGO)
1754  {
1755  if (this->sortings[column] == CargoSortType::AsGrouping) {
1756  if (this->groupings[column] != GR_CARGO) {
1757  entry->Resort(CargoSortType::StationString, this->sort_orders[column]);
1758  }
1759  } else {
1760  entry->Resort(CargoSortType::Count, this->sort_orders[column]);
1761  }
1762  for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) {
1763  CargoDataEntry *cd = *i;
1764 
1765  Grouping grouping = this->groupings[column];
1766  if (grouping == GR_CARGO) cargo = cd->GetCargo();
1767  bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1768 
1769  if (pos > -maxrows && pos <= 0) {
1770  StringID str = STR_EMPTY;
1771  int y = r.top - pos * GetCharacterHeight(FS_NORMAL);
1772  SetDParam(0, cargo);
1773  SetDParam(1, cd->GetCount());
1774 
1775  if (this->groupings[column] == GR_CARGO) {
1776  str = STR_STATION_VIEW_WAITING_CARGO;
1777  DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + this->expand_shrink_width, r.right - this->expand_shrink_width, y);
1778  } else {
1779  if (!auto_distributed) grouping = GR_SOURCE;
1780  StationID station = cd->GetStation();
1781 
1782  switch (grouping) {
1783  case GR_SOURCE:
1784  str = this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
1785  break;
1786  case GR_NEXT:
1787  str = this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
1788  if (str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
1789  break;
1790  case GR_DESTINATION:
1791  str = this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
1792  break;
1793  default:
1794  NOT_REACHED();
1795  }
1796  if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
1797  ScrollMainWindowToTile(Station::Get(station)->xy);
1798  }
1799  }
1800 
1801  bool rtl = _current_text_dir == TD_RTL;
1802  Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl);
1803  Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl);
1804 
1805  DrawString(text.left, text.right, y, str);
1806 
1807  if (column < NUM_COLUMNS - 1) {
1808  const char *sym = nullptr;
1809  if (cd->GetNumChildren() > 0) {
1810  sym = "-";
1811  } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
1812  sym = "+";
1813  } else {
1814  /* Only draw '+' if there is something to be shown. */
1815  const StationCargoList &list = Station::Get(this->window_number)->goods[cargo].cargo;
1816  if (grouping == GR_CARGO && (list.ReservedCount() > 0 || cd->HasTransfers())) {
1817  sym = "+";
1818  }
1819  }
1820  if (sym != nullptr) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW);
1821  }
1822  this->SetDisplayedRow(cd);
1823  }
1824  --pos;
1825  if (auto_distributed || column == 0) {
1826  pos = this->DrawEntries(cd, r, pos, maxrows, column + 1, cargo);
1827  }
1828  }
1829  return pos;
1830  }
1831 
1837  int DrawAcceptedCargo(const Rect &r) const
1838  {
1839  const Station *st = Station::Get(this->window_number);
1840  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1841 
1842  SetDParam(0, GetAcceptanceMask(st));
1843  int bottom = DrawStringMultiLine(tr.left, tr.right, tr.top, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO);
1845  }
1846 
1852  int DrawCargoRatings(const Rect &r) const
1853  {
1854  const Station *st = Station::Get(this->window_number);
1855  bool rtl = _current_text_dir == TD_RTL;
1856  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1857 
1858  if (st->town->exclusive_counter > 0) {
1859  SetDParam(0, st->town->exclusivity);
1860  tr.top = DrawStringMultiLine(tr, st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY);
1862  }
1863 
1864  DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_VIEW_SUPPLY_RATINGS_TITLE_MINUTE : STR_STATION_VIEW_SUPPLY_RATINGS_TITLE_MONTH);
1865  tr.top += GetCharacterHeight(FS_NORMAL);
1866 
1867  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1868  const GoodsEntry *ge = &st->goods[cs->Index()];
1869  if (!ge->HasRating()) continue;
1870 
1871  const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph);
1872  SetDParam(0, cs->name);
1873  SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].supply) : 0);
1874  SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
1875  SetDParam(3, ToPercent8(ge->rating));
1876  DrawString(tr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), STR_STATION_VIEW_CARGO_SUPPLY_RATING);
1877  tr.top += GetCharacterHeight(FS_NORMAL);
1878  }
1880  }
1881 
1887  template<class Tid>
1888  void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
1889  {
1890  if (filter->Retrieve(next) != nullptr) {
1891  filter->Remove(next);
1892  } else {
1893  filter->InsertOrRetrieve(next);
1894  }
1895  }
1896 
1902  {
1903  if (row < 0 || (uint)row >= this->displayed_rows.size()) return;
1904  if (_ctrl_pressed) {
1905  this->scroll_to_row = row;
1906  } else {
1907  RowDisplay &display = this->displayed_rows[row];
1908  if (display.filter == &this->expanded_rows) {
1909  this->HandleCargoWaitingClick<CargoID>(display.filter, display.next_cargo);
1910  } else {
1911  this->HandleCargoWaitingClick<StationID>(display.filter, display.next_station);
1912  }
1913  }
1915  }
1916 
1917  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1918  {
1919  switch (widget) {
1920  case WID_SV_WAITING:
1921  this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WidgetDimensions::scaled.framerect.top) - this->vscroll->GetPosition());
1922  break;
1923 
1924  case WID_SV_CATCHMENT:
1926  break;
1927 
1928  case WID_SV_LOCATION:
1929  if (_ctrl_pressed) {
1930  ShowExtraViewportWindow(Station::Get(this->window_number)->xy);
1931  } else {
1932  ScrollMainWindowToTile(Station::Get(this->window_number)->xy);
1933  }
1934  break;
1935 
1936  case WID_SV_ACCEPTS_RATINGS: {
1937  /* Swap between 'accepts' and 'ratings' view. */
1938  int height_change;
1939  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS);
1940  if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1941  nwi->SetDataTip(STR_STATION_VIEW_ACCEPTS_BUTTON, STR_STATION_VIEW_ACCEPTS_TOOLTIP); // Switch to accepts view.
1942  height_change = this->rating_lines - this->accepts_lines;
1943  } else {
1944  nwi->SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP); // Switch to ratings view.
1945  height_change = this->accepts_lines - this->rating_lines;
1946  }
1947  this->ReInit(0, height_change * GetCharacterHeight(FS_NORMAL));
1948  break;
1949  }
1950 
1951  case WID_SV_RENAME:
1952  SetDParam(0, this->window_number);
1953  ShowQueryString(STR_STATION_NAME, STR_STATION_VIEW_RENAME_STATION_CAPTION, MAX_LENGTH_STATION_NAME_CHARS,
1955  break;
1956 
1957  case WID_SV_CLOSE_AIRPORT:
1958  Command<CMD_OPEN_CLOSE_AIRPORT>::Post(this->window_number);
1959  break;
1960 
1961  case WID_SV_TRAINS: // Show list of scheduled trains to this station
1962  case WID_SV_ROADVEHS: // Show list of scheduled road-vehicles to this station
1963  case WID_SV_SHIPS: // Show list of scheduled ships to this station
1964  case WID_SV_PLANES: { // Show list of scheduled aircraft to this station
1965  Owner owner = Station::Get(this->window_number)->owner;
1966  ShowVehicleListWindow(owner, (VehicleType)(widget - WID_SV_TRAINS), (StationID)this->window_number);
1967  break;
1968  }
1969 
1970  case WID_SV_SORT_BY: {
1971  /* The initial selection is composed of current mode and
1972  * sorting criteria for columns 1, 2, and 3. Column 0 is always
1973  * sorted by cargo ID. The others can theoretically be sorted
1974  * by different things but there is no UI for that. */
1976  this->current_mode * 2 + (this->sortings[1] == CargoSortType::Count ? 1 : 0),
1977  WID_SV_SORT_BY, 0, 0);
1978  break;
1979  }
1980 
1981  case WID_SV_GROUP_BY: {
1982  ShowDropDownMenu(this, _group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
1983  break;
1984  }
1985 
1986  case WID_SV_SORT_ORDER: { // flip sorting method asc/desc
1987  this->SelectSortOrder(this->sort_orders[1] == SO_ASCENDING ? SO_DESCENDING : SO_ASCENDING);
1988  this->SetTimeout();
1990  break;
1991  }
1992  }
1993  }
1994 
1999  void SelectSortOrder(SortOrder order)
2000  {
2001  this->sort_orders[1] = this->sort_orders[2] = this->sort_orders[3] = order;
2002  _settings_client.gui.station_gui_sort_order = this->sort_orders[1];
2003  this->SetDirty();
2004  }
2005 
2010  void SelectSortBy(int index)
2011  {
2013  switch (_sort_names[index]) {
2014  case STR_STATION_VIEW_WAITING_STATION:
2015  this->current_mode = MODE_WAITING;
2016  this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
2017  break;
2018  case STR_STATION_VIEW_WAITING_AMOUNT:
2019  this->current_mode = MODE_WAITING;
2020  this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
2021  break;
2022  case STR_STATION_VIEW_PLANNED_STATION:
2023  this->current_mode = MODE_PLANNED;
2024  this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
2025  break;
2026  case STR_STATION_VIEW_PLANNED_AMOUNT:
2027  this->current_mode = MODE_PLANNED;
2028  this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
2029  break;
2030  default:
2031  NOT_REACHED();
2032  }
2033  /* Display the current sort variant */
2034  this->GetWidget<NWidgetCore>(WID_SV_SORT_BY)->widget_data = _sort_names[index];
2035  this->SetDirty();
2036  }
2037 
2042  void SelectGroupBy(int index)
2043  {
2044  this->grouping_index = index;
2046  this->GetWidget<NWidgetCore>(WID_SV_GROUP_BY)->widget_data = _group_names[index];
2047  switch (_group_names[index]) {
2048  case STR_STATION_VIEW_GROUP_S_V_D:
2049  this->groupings[1] = GR_SOURCE;
2050  this->groupings[2] = GR_NEXT;
2051  this->groupings[3] = GR_DESTINATION;
2052  break;
2053  case STR_STATION_VIEW_GROUP_S_D_V:
2054  this->groupings[1] = GR_SOURCE;
2055  this->groupings[2] = GR_DESTINATION;
2056  this->groupings[3] = GR_NEXT;
2057  break;
2058  case STR_STATION_VIEW_GROUP_V_S_D:
2059  this->groupings[1] = GR_NEXT;
2060  this->groupings[2] = GR_SOURCE;
2061  this->groupings[3] = GR_DESTINATION;
2062  break;
2063  case STR_STATION_VIEW_GROUP_V_D_S:
2064  this->groupings[1] = GR_NEXT;
2065  this->groupings[2] = GR_DESTINATION;
2066  this->groupings[3] = GR_SOURCE;
2067  break;
2068  case STR_STATION_VIEW_GROUP_D_S_V:
2069  this->groupings[1] = GR_DESTINATION;
2070  this->groupings[2] = GR_SOURCE;
2071  this->groupings[3] = GR_NEXT;
2072  break;
2073  case STR_STATION_VIEW_GROUP_D_V_S:
2074  this->groupings[1] = GR_DESTINATION;
2075  this->groupings[2] = GR_NEXT;
2076  this->groupings[3] = GR_SOURCE;
2077  break;
2078  }
2079  this->SetDirty();
2080  }
2081 
2082  void OnDropdownSelect(WidgetID widget, int index) override
2083  {
2084  if (widget == WID_SV_SORT_BY) {
2085  this->SelectSortBy(index);
2086  } else {
2087  this->SelectGroupBy(index);
2088  }
2089  }
2090 
2091  void OnQueryTextFinished(char *str) override
2092  {
2093  if (str == nullptr) return;
2094 
2095  Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, str);
2096  }
2097 
2098  void OnResize() override
2099  {
2100  this->vscroll->SetCapacityFromWidget(this, WID_SV_WAITING, WidgetDimensions::scaled.framerect.Vertical());
2101  }
2102 
2108  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2109  {
2110  if (gui_scope) {
2111  if (data >= 0 && data < NUM_CARGO) {
2112  this->cached_destinations.Remove((CargoID)data);
2113  } else {
2114  this->ReInit();
2115  }
2116  }
2117  }
2118 };
2119 
2121  STR_STATION_VIEW_WAITING_STATION,
2122  STR_STATION_VIEW_WAITING_AMOUNT,
2123  STR_STATION_VIEW_PLANNED_STATION,
2124  STR_STATION_VIEW_PLANNED_AMOUNT,
2126 };
2127 
2129  STR_STATION_VIEW_GROUP_S_V_D,
2130  STR_STATION_VIEW_GROUP_S_D_V,
2131  STR_STATION_VIEW_GROUP_V_S_D,
2132  STR_STATION_VIEW_GROUP_V_D_S,
2133  STR_STATION_VIEW_GROUP_D_S_V,
2134  STR_STATION_VIEW_GROUP_D_V_S,
2136 };
2137 
2138 static WindowDesc _station_view_desc(__FILE__, __LINE__,
2139  WDP_AUTO, "view_station", 249, 117,
2141  0,
2142  std::begin(_nested_station_view_widgets), std::end(_nested_station_view_widgets)
2143 );
2144 
2150 void ShowStationViewWindow(StationID station)
2151 {
2152  AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
2153 }
2154 
2158  StationID station;
2159 };
2160 
2161 static std::vector<TileAndStation> _deleted_stations_nearby;
2162 static std::vector<StationID> _stations_nearby_list;
2163 
2171 template <class T>
2172 static bool AddNearbyStation(TileIndex tile, void *user_data)
2173 {
2174  TileArea *ctx = (TileArea *)user_data;
2175 
2176  /* First check if there were deleted stations here */
2177  for (auto it = _deleted_stations_nearby.begin(); it != _deleted_stations_nearby.end(); /* nothing */) {
2178  if (it->tile == tile) {
2179  _stations_nearby_list.push_back(it->station);
2180  it = _deleted_stations_nearby.erase(it);
2181  } else {
2182  ++it;
2183  }
2184  }
2185 
2186  /* Check if own station and if we stay within station spread */
2187  if (!IsTileType(tile, MP_STATION)) return false;
2188 
2189  StationID sid = GetStationIndex(tile);
2190 
2191  /* This station is (likely) a waypoint */
2192  if (!T::IsValidID(sid)) return false;
2193 
2194  T *st = T::Get(sid);
2195  if (st->owner != _local_company || std::find(_stations_nearby_list.begin(), _stations_nearby_list.end(), sid) != _stations_nearby_list.end()) return false;
2196 
2197  if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
2198  _stations_nearby_list.push_back(sid);
2199  }
2200 
2201  return false; // We want to include *all* nearby stations
2202 }
2203 
2213 template <class T>
2214 static const T *FindStationsNearby(TileArea ta, bool distant_join)
2215 {
2216  TileArea ctx = ta;
2217 
2218  _stations_nearby_list.clear();
2219  _stations_nearby_list.push_back(NEW_STATION);
2220  _deleted_stations_nearby.clear();
2221 
2222  /* Check the inside, to return, if we sit on another station */
2223  for (TileIndex t : ta) {
2224  if (t < Map::Size() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
2225  }
2226 
2227  /* Look for deleted stations */
2228  for (const BaseStation *st : BaseStation::Iterate()) {
2229  if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
2230  /* Include only within station spread (yes, it is strictly less than) */
2231  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) {
2232  _deleted_stations_nearby.push_back({st->xy, st->index});
2233 
2234  /* Add the station when it's within where we're going to build */
2235  if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
2236  IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
2237  AddNearbyStation<T>(st->xy, &ctx);
2238  }
2239  }
2240  }
2241  }
2242 
2243  /* Only search tiles where we have a chance to stay within the station spread.
2244  * The complete check needs to be done in the callback as we don't know the
2245  * extent of the found station, yet. */
2246  if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return nullptr;
2247  uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1;
2248 
2249  TileIndex tile = TileAddByDir(ctx.tile, DIR_N);
2250  CircularTileSearch(&tile, max_dist, ta.w, ta.h, AddNearbyStation<T>, &ctx);
2251 
2252  return nullptr;
2253 }
2254 
2255 static constexpr NWidgetPart _nested_select_station_widgets[] = {
2257  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
2258  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_JS_CAPTION), SetDataTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2259  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
2260  EndContainer(),
2262  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_JS_PANEL), SetResize(1, 0), SetScrollbar(WID_JS_SCROLLBAR), EndContainer(),
2264  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_JS_SCROLLBAR),
2265  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
2266  EndContainer(),
2267  EndContainer(),
2268 };
2269 
2274 template <class T>
2276  StationPickerCmdProc select_station_proc;
2278  Scrollbar *vscroll;
2279 
2280  SelectStationWindow(WindowDesc *desc, TileArea ta, StationPickerCmdProc&& proc) :
2281  Window(desc),
2282  select_station_proc(std::move(proc)),
2283  area(ta)
2284  {
2285  this->CreateNestedTree();
2286  this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR);
2287  this->GetWidget<NWidgetCore>(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION;
2288  this->FinishInitNested(0);
2289  this->OnInvalidateData(0);
2290 
2291  _thd.freeze = true;
2292  }
2293 
2294  void Close([[maybe_unused]] int data = 0) override
2295  {
2296  SetViewportCatchmentSpecializedStation<T>(nullptr, true);
2297 
2298  _thd.freeze = false;
2299  this->Window::Close();
2300  }
2301 
2302  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2303  {
2304  if (widget != WID_JS_PANEL) return;
2305 
2306  /* Determine the widest string */
2307  Dimension d = GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2308  for (const auto &station : _stations_nearby_list) {
2309  if (station == NEW_STATION) continue;
2310  const T *st = T::Get(station);
2311  SetDParam(0, st->index);
2312  SetDParam(1, st->facilities);
2313  d = maxdim(d, GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION));
2314  }
2315 
2316  resize->height = d.height;
2317  d.height *= 5;
2318  d.width += padding.width;
2319  d.height += padding.height;
2320  *size = d;
2321  }
2322 
2323  void DrawWidget(const Rect &r, WidgetID widget) const override
2324  {
2325  if (widget != WID_JS_PANEL) return;
2326 
2327  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
2328  for (uint i = this->vscroll->GetPosition(); i < _stations_nearby_list.size(); ++i, tr.top += this->resize.step_height) {
2329  if (_stations_nearby_list[i] == NEW_STATION) {
2330  DrawString(tr, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2331  } else {
2332  const T *st = T::Get(_stations_nearby_list[i]);
2333  SetDParam(0, st->index);
2334  SetDParam(1, st->facilities);
2335  DrawString(tr, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION);
2336  }
2337  }
2338 
2339  }
2340 
2341  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2342  {
2343  if (widget != WID_JS_PANEL) return;
2344 
2345  auto it = this->vscroll->GetScrolledItemFromWidget(_stations_nearby_list, pt.y, this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.top);
2346  if (it == _stations_nearby_list.end()) return;
2347 
2348  /* Execute stored Command */
2349  this->select_station_proc(false, *it);
2350 
2351  /* Close Window; this might cause double frees! */
2353  }
2354 
2355  void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
2356  {
2357  if (_thd.dirty & 2) {
2358  _thd.dirty &= ~2;
2359  this->SetDirty();
2360  }
2361  }
2362 
2363  void OnResize() override
2364  {
2365  this->vscroll->SetCapacityFromWidget(this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.Vertical());
2366  }
2367 
2373  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2374  {
2375  if (!gui_scope) return;
2376  FindStationsNearby<T>(this->area, true);
2377  this->vscroll->SetCount(_stations_nearby_list.size());
2378  this->SetDirty();
2379  }
2380 
2381  void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
2382  {
2383  if (widget != WID_JS_PANEL) {
2384  SetViewportCatchmentSpecializedStation<T>(nullptr, true);
2385  return;
2386  }
2387 
2388  /* Show coverage area of station under cursor */
2389  auto it = this->vscroll->GetScrolledItemFromWidget(_stations_nearby_list, pt.y, this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.top);
2390  const T *st = it == _stations_nearby_list.end() || *it == NEW_STATION ? nullptr : T::Get(*it);
2391  SetViewportCatchmentSpecializedStation<T>(st, true);
2392  }
2393 };
2394 
2395 static WindowDesc _select_station_desc(__FILE__, __LINE__,
2396  WDP_AUTO, "build_station_join", 200, 180,
2399  std::begin(_nested_select_station_widgets), std::end(_nested_select_station_widgets)
2400 );
2401 
2402 
2410 template <class T>
2411 static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
2412 {
2413  /* Only show selection if distant join is enabled in the settings */
2414  if (!_settings_game.station.distant_join_stations) return false;
2415 
2416  /* If a window is already opened and we didn't ctrl-click,
2417  * return true (i.e. just flash the old window) */
2418  Window *selection_window = FindWindowById(WC_SELECT_STATION, 0);
2419  if (selection_window != nullptr) {
2420  /* Abort current distant-join and start new one */
2421  selection_window->Close();
2423  }
2424 
2425  /* only show the popup, if we press ctrl */
2426  if (!_ctrl_pressed) return false;
2427 
2428  /* Now check if we could build there */
2429  if (!proc(true, INVALID_STATION)) return false;
2430 
2431  /* Test for adjacent station or station below selection.
2432  * If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
2433  * but join the other station immediately. */
2434  const T *st = FindStationsNearby<T>(ta, false);
2435  return st == nullptr && (_settings_game.station.adjacent_stations || std::any_of(std::begin(_stations_nearby_list), std::end(_stations_nearby_list), [](StationID s) { return s != NEW_STATION; }));
2436 }
2437 
2444 template <class T>
2445 void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc&& proc)
2446 {
2447  if (StationJoinerNeeded<T>(ta, proc)) {
2449  new SelectStationWindow<T>(&_select_station_desc, ta, std::move(proc));
2450  } else {
2451  proc(false, INVALID_STATION);
2452  }
2453 }
2454 
2460 void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
2461 {
2462  ShowSelectBaseStationIfNeeded<Station>(ta, std::move(proc));
2463 }
2464 
2470 void ShowSelectWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
2471 {
2472  ShowSelectBaseStationIfNeeded<Waypoint>(ta, std::move(proc));
2473 }
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:1304
StationJoinerNeeded
static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
Check whether we need to show the station selection window.
Definition: station_gui.cpp:2411
StationViewWindow::HandleCargoWaitingClick
void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
Expand or collapse a specific row.
Definition: station_gui.cpp:1888
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
CargoWidgets
static std::unique_ptr< NWidgetBase > CargoWidgets()
Make a horizontal row of cargo buttons, starting at widget WID_STL_CARGOSTART.
Definition: station_gui.cpp:719
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
ToPercent8
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
Definition: math_func.hpp:295
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:355
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
StationViewWindow
The StationView window.
Definition: station_gui.cpp:1223
CargoList< StationCargoList, StationCargoPacketMap >::ConstIterator
StationCargoPacketMap ::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:290
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:314
AIRPORT_CLOSED_block
static const uint64_t AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
Definition: airport.h:128
WID_SV_ACCEPT_RATING_LIST
@ WID_SV_ACCEPT_RATING_LIST
List of accepted cargoes / rating of cargoes.
Definition: station_widget.h:22
TileHighlightData::size
Point size
Size, in tile "units", of the white/red selection area.
Definition: tilehighlight_type.h:48
Airport::flags
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:293
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:471
GoodsEntry::rating
uint8_t rating
Station rating for this cargo.
Definition: station_base.h:226
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
GUISettings::station_gui_sort_order
uint8_t station_gui_sort_order
the sort order of entries in the station gui - ascending or descending
Definition: settings_type.h:209
GUISettings::station_show_coverage
bool station_show_coverage
whether to highlight coverage area
Definition: settings_type.h:189
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
vehicle_gui.h
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:630
StationViewWindow::ALH_ACCEPTS
@ ALH_ACCEPTS
Height of the accepted cargo view.
Definition: station_gui.cpp:1286
UpdateTileSelection
void UpdateTileSelection()
Updates tile highlighting for all cases.
Definition: viewport.cpp:2596
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:37
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
StationViewWindow::RowDisplay::filter
CargoDataEntry * filter
Parent of the cargo entry belonging to the row.
Definition: station_gui.cpp:1234
GetAcceptanceAroundTiles
CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
Get the acceptance of cargoes around the tile in 1/8.
Definition: station_cmd.cpp:581
WID_STL_LIST
@ WID_STL_LIST
The main panel, list of stations.
Definition: station_widget.h:38
CompanyStationsWindow::FilterState::cargoes
CargoTypes cargoes
bitmap of cargo types to include
Definition: station_gui.cpp:225
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
Pool::PoolItem<&_link_graph_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
dropdown_func.h
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:28
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:898
NWidgetCore::SetDataTip
void SetDataTip(uint32_t widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:1094
GUISettings::station_gui_group_order
uint8_t station_gui_group_order
the order of grouping cargo entries in the station gui
Definition: settings_type.h:207
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:297
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:161
company_base.h
StationViewWindow::INV_FLOWS
@ INV_FLOWS
The planned flows have been recalculated and everything has to be updated.
Definition: station_gui.cpp:1256
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:329
CargoDataEntry::cargo
CargoID cargo
ID of the cargo this entry is associated with.
Definition: station_gui.cpp:1024
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:73
CompanyStationsWindow
The list of stations per company.
Definition: station_gui.cpp:217
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:249
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Station
Station data structure.
Definition: station_base.h:442
CheckRedrawStationCoverage
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Definition: station_gui.cpp:126
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WID_SV_WAITING
@ WID_SV_WAITING
List of waiting cargo.
Definition: station_widget.h:20
GUIList< const Station *, const CargoTypes & >
CargoSortType
CargoSortType
Definition: station_gui.cpp:857
WID_STL_AIRPLANE
@ WID_STL_AIRPLANE
'AIRPLANE' button - list only facilities where is an airport.
Definition: station_widget.h:45
SelectStationWindow::OnRealtimeTick
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
Called periodically.
Definition: station_gui.cpp:2355
SelectStationWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2363
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
vehiclelist.h
WID_SV_PLANES
@ WID_SV_PLANES
List of scheduled planes button.
Definition: station_widget.h:30
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
WID_STL_TRUCK
@ WID_STL_TRUCK
'TRUCK' button - list only facilities where is a truck stop.
Definition: station_widget.h:43
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:134
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
GetAcceptanceMask
CargoTypes GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
Definition: station_cmd.cpp:497
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:97
CompanyStationsWindow::StationWaitingTotalSorter
static bool StationWaitingTotalSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their waiting cargo.
Definition: station_gui.cpp:299
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
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:1309
StationViewWindow::RowDisplay
A row being displayed in the cargo view (as opposed to being "hidden" behind a plus sign).
Definition: station_gui.cpp:1227
WID_SV_SORT_BY
@ WID_SV_SORT_BY
'Sort by' button
Definition: station_widget.h:19
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
CargoDataEntry::GetCargo
CargoID GetCargo() const
Get the cargo ID for this entry.
Definition: station_gui.cpp:967
StationViewWindow::SelectSortBy
void SelectSortBy(int index)
Select a new sort criterium for the cargo view.
Definition: station_gui.cpp:2010
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:529
FindStationsAroundSelection
void FindStationsAroundSelection()
Find stations adjacent to the current tile highlight area, so that existing coverage area can be draw...
Definition: station_gui.cpp:84
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:1595
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:835
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:124
zoom_func.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2334
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:15
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:585
StationViewWindow::BuildCargoList
void BuildCargoList(CargoDataEntry *cargo, const Station *st)
Build up the cargo view for all cargoes.
Definition: station_gui.cpp:1642
StationViewWindow::DrawCargoRatings
int DrawCargoRatings(const Rect &r) const
Draw cargo ratings in the WID_SV_ACCEPT_RATING_LIST widget.
Definition: station_gui.cpp:1852
ShowCompanyStations
void ShowCompanyStations(CompanyID company)
Opens window with list of company's stations.
Definition: station_gui.cpp:782
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:2172
CeilDiv
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:320
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:71
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:250
CargoDataEntry::GetCount
uint GetCount() const
Get the cargo count for this entry.
Definition: station_gui.cpp:972
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
town.h
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
WC_STATION_VIEW
@ WC_STATION_VIEW
Station view; Window numbers:
Definition: window_type.h:345
CargoSpec::GetCargoIcon
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
Definition: cargotype.cpp:147
StationViewWindow::_sort_names
static const StringID _sort_names[]
Names of the sorting options in the dropdown.
Definition: station_gui.cpp:1289
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:53
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1279
CompanyStationsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:448
StationViewWindow::GR_DESTINATION
@ GR_DESTINATION
Group by estimated final destination ("to").
Definition: station_gui.cpp:1266
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:1716
SelectStationWindow::area
TileArea area
Location of new station.
Definition: station_gui.cpp:2277
CompanyStationsWindow::StationTypeSorter
static bool StationTypeSorter(const Station *const &a, const Station *const &b, const CargoTypes &)
Sort stations by their type.
Definition: station_gui.cpp:293
WID_SV_RENAME
@ WID_SV_RENAME
'Rename' button.
Definition: station_widget.h:25
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:74
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:1278
StationViewWindow::MODE_PLANNED
@ MODE_PLANNED
Show cargo planned to pass through the station.
Definition: station_gui.cpp:1275
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
CargoDataEntry::children
CargoDataSet * children
the children of this entry.
Definition: station_gui.cpp:1030
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition: tilearea_type.h:21
StationViewWindow::GR_SOURCE
@ GR_SOURCE
Group by source of cargo ("from").
Definition: station_gui.cpp:1264
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
StationViewWindow::AcceptListHeight
AcceptListHeight
Height of the WID_SV_ACCEPT_RATING_LIST widget for different views.
Definition: station_gui.cpp:1284
ShowStationViewWindow
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
Definition: station_gui.cpp:2150
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:607
textbuf_gui.h
StationViewWindow::INV_CARGO
@ INV_CARGO
Some cargo has been added or removed.
Definition: station_gui.cpp:1257
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:702
WID_STL_CAPTION
@ WID_STL_CAPTION
Caption of the window.
Definition: station_widget.h:37
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:908
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:310
WID_SV_CAPTION
@ WID_SV_CAPTION
Caption of the window.
Definition: station_widget.h:15
StationViewWindow::current_mode
Mode current_mode
Currently selected display mode of cargo view.
Definition: station_gui.cpp:1305
StationViewWindow::NUM_COLUMNS
static const int NUM_COLUMNS
Number of "columns" in the cargo view: cargo, from, via, to.
Definition: station_gui.cpp:1250
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
CargoPacket::GetFirstStation
StationID GetFirstStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:218
StationViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2098
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:210
CargoDataEntry::num_children
uint num_children
the number of subentries belonging to this entry.
Definition: station_gui.cpp:1028
CargoSortType::StationID
@ StationID
by station id
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
FACIL_BUS_STOP
@ FACIL_BUS_STOP
Station with bus stops.
Definition: station_type.h:54
GetProductionAroundTiles
CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
Get the cargo types being produced around the tile (in a rectangle).
Definition: station_cmd.cpp:543
_sorted_standard_cargo_specs
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:162
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:252
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:105
PC_GREEN
static const uint8_t PC_GREEN
Green palette colour.
Definition: palette_func.h:72
CompanyStationsWindow::StationNameSorter
static bool StationNameSorter(const Station *const &a, const Station *const &b, const CargoTypes &)
Sort stations by their name.
Definition: station_gui.cpp:285
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:1695
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
CompanyStationsWindow::StationRatingMinSorter
static bool StationRatingMinSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their rating.
Definition: station_gui.cpp:337
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:220
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
SCT_PASSENGERS_ONLY
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
Definition: station_gui.h:21
WID_STL_SHIP
@ WID_STL_SHIP
'SHIP' button - list only facilities where is a dock.
Definition: station_widget.h:46
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
StationViewWindow::sortings
CargoSortType sortings[NUM_COLUMNS]
Sort types of the different 'columns'.
Definition: station_gui.cpp:1298
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
WID_SV_LOCATION
@ WID_SV_LOCATION
'Location' button.
Definition: station_widget.h:23
CargoDataEntry::GetNumChildren
uint GetNumChildren() const
Get the number of children for this entry.
Definition: station_gui.cpp:982
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:260
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
CompanyStationsWindow::FilterState
Definition: station_gui.cpp:221
SelectStationWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:2373
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
StationViewWindow::DrawAcceptedCargo
int DrawAcceptedCargo(const Rect &r) const
Draw accepted cargo in the WID_SV_ACCEPT_RATING_LIST widget.
Definition: station_gui.cpp:1837
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
StationCoverageType
StationCoverageType
Types of cargo to display for station coverage.
Definition: station_gui.h:20
StationViewWindow::SetDisplayedRow
void SetDisplayedRow(const CargoDataEntry *data)
Mark a specific row, characterized by its CargoDataEntry, as expanded.
Definition: station_gui.cpp:1662
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:1353
WID_SV_ROADVEHS
@ WID_SV_ROADVEHS
List of scheduled road vehs button.
Definition: station_widget.h:28
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:1239
GoodsEntry::HasRating
bool HasRating() const
Does this cargo have a rating at this station?
Definition: station_base.h:258
CompanyStationsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:673
CargoSpec::IsValid
bool IsValid() const
Tests for validity of this cargospec.
Definition: cargotype.h:115
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
GUIList< const Station *, const CargoTypes & >::SortFunction
std::conditional_t< std::is_same_v< const CargoTypes &, std::nullptr_t >, bool(const const Station * &, const const Station * &), bool(const const Station * &, const const Station * &, const const CargoTypes &)> SortFunction
Signature of sort function.
Definition: sortlist_type.h:49
StationViewWindow::HandleCargoWaitingClick
void HandleCargoWaitingClick(int row)
Handle a click on a specific row in the cargo view.
Definition: station_gui.cpp:1901
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
StationViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:1413
CompanyStationsWindow::StationRatingMaxSorter
static bool StationRatingMaxSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their rating.
Definition: station_gui.cpp:323
GoodsEntry::node
NodeID node
ID of node in link graph referring to this goods entry.
Definition: station_base.h:214
station_cmd.h
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:175
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition: sortlist_type.h:254
_cargo_mask
CargoTypes _cargo_mask
Bitmask of cargo types available.
Definition: cargotype.cpp:31
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:456
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
ShowSelectStationIfNeeded
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
Definition: station_gui.cpp:2460
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
WID_STL_SCROLLBAR
@ WID_STL_SCROLLBAR
Scrollbar next to the main panel.
Definition: station_widget.h:39
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
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:1572
SelectStationWindow
Window for selecting stations/waypoints to (distant) join to.
Definition: station_gui.cpp:2275
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:244
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
safeguards.h
CargoSortType::Count
@ Count
by amount of cargo
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:1083
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition: window_gui.h:460
CargoDataEntry::Retrieve
CargoDataEntry * Retrieve(CargoID cargo) const
Retrieve a child for the given cargo.
Definition: station_gui.cpp:951
ShowSelectWaypointIfNeeded
void ShowSelectWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the waypoint selection window when needed.
Definition: station_gui.cpp:2470
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:320
CargoDataEntry::station
StationID station
ID of the station this entry is associated with.
Definition: station_gui.cpp:1022
StationViewWindow::groupings
Grouping groupings[NUM_COLUMNS]
Grouping modes for the different columns.
Definition: station_gui.cpp:1306
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:1487
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
CompanyStationsWindow::StationWaitingAvailableSorter
static bool StationWaitingAvailableSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their available waiting cargo.
Definition: station_gui.cpp:311
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
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:1007
TileAndStation::tile
TileIndex tile
TileIndex.
Definition: station_gui.cpp:2157
StationViewWindow::MODE_WAITING
@ MODE_WAITING
Show cargo waiting at the station.
Definition: station_gui.cpp:1274
CargoDataEntry::Remove
void Remove(StationID station)
Remove a child associated with the given station.
Definition: station_gui.cpp:919
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
GameSettings::linkgraph
LinkGraphSettings linkgraph
settings for link graph calculations
Definition: settings_type.h:629
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:308
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:588
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
CargoDataEntry::GetParent
CargoDataEntry * GetParent() const
Get the parent entry for this entry.
Definition: station_gui.cpp:977
DivideApprox
int DivideApprox(int a, int b)
Deterministic approximate division.
Definition: math_func.cpp:22
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition: widget_type.h:845
CompanyStationsWindow::FilterState::include_empty
bool include_empty
whether we should include stations without waiting cargo
Definition: station_gui.cpp:224
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:386
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:595
WID_SV_TRAINS
@ WID_SV_TRAINS
List of scheduled trains button.
Definition: station_widget.h:27
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
TileAddByDir
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition: map_func.h:592
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:113
GoodsEntry::link_graph
LinkGraphID link_graph
Link graph this station belongs to.
Definition: station_base.h:215
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
WID_SV_ACCEPTS_RATINGS
@ WID_SV_ACCEPTS_RATINGS
'Accepts' / 'Ratings' button.
Definition: station_widget.h:24
WID_STL_SORTBY
@ WID_STL_SORTBY
'Sort by' button - reverse sort direction.
Definition: station_widget.h:52
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:25
viewport_func.h
CompanyStationsWindow::SortStationsList
void SortStationsList()
Sort the stations list.
Definition: station_gui.cpp:351
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
StationViewWindow::_group_names
static const StringID _group_names[]
Names of the grouping options in the dropdown.
Definition: station_gui.cpp:1290
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
FACIL_WAYPOINT
@ FACIL_WAYPOINT
Station is a waypoint.
Definition: station_type.h:57
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2260
DistanceMax
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition: map.cpp:191
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
StationCargoList::ReservedCount
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Definition: cargopacket.h:597
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
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
WID_SV_SCROLLBAR
@ WID_SV_SCROLLBAR
Scrollbar.
Definition: station_widget.h:21
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:52
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
string_func.h
SCT_ALL
@ SCT_ALL
Draw all cargoes.
Definition: station_gui.h:23
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:491
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
CargoDataEntry::SetTransfers
void SetTransfers(bool value)
Set the transfers state.
Definition: station_gui.cpp:1002
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:775
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:166
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:242
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:384
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:306
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
WID_SV_GROUP_BY
@ WID_SV_GROUP_BY
'Group by' button
Definition: station_widget.h:17
StationViewWindow::Invalidation
Invalidation
Type of data invalidation.
Definition: station_gui.cpp:1255
StationViewWindow::displayed_rows
CargoDataVector displayed_rows
Parent entry of currently displayed rows (including collapsed ones).
Definition: station_gui.cpp:1310
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:556
WID_SV_SORT_ORDER
@ WID_SV_SORT_ORDER
'Sort order' button
Definition: station_widget.h:18
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:1137
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:137
CargoDataEntry::Retrieve
CargoDataEntry * Retrieve(StationID station) const
Retrieve a child for the given station.
Definition: station_gui.cpp:940
CargoDataEntry::Clear
void Clear()
Delete all subentries, reset count and num_children and adapt parent's count.
Definition: station_gui.cpp:1082
CargoDataEntry::GetStation
StationID GetStation() const
Get the station ID for this entry.
Definition: station_gui.cpp:962
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
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:1244
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:211
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
StationViewWindow::sort_orders
SortOrder sort_orders[NUM_COLUMNS]
Sort order (ascending/descending) for the 'columns'.
Definition: station_gui.cpp:1301
SCT_NON_PASSENGERS_ONLY
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition: station_gui.h:22
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
CargoSortType::StationString
@ StationString
by station name
geometry_func.hpp
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
WID_STL_CARGOALL
@ WID_STL_CARGOALL
'ALL' button - list all stations.
Definition: station_widget.h:50
WID_STL_BUS
@ WID_STL_BUS
'BUS' button - list only facilities where is a bus stop.
Definition: station_widget.h:44
FlowStatMap
Flow descriptions by origin stations.
Definition: station_base.h:148
TileAndStation::station
StationID station
StationID.
Definition: station_gui.cpp:2158
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
waypoint_base.h
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
cargotype.h
linkgraph.h
StationViewWindow::Mode
Mode
Display mode of the cargo view.
Definition: station_gui.cpp:1273
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:88
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
WID_SV_CATCHMENT
@ WID_SV_CATCHMENT
Toggle catchment area highlight.
Definition: station_widget.h:31
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:64
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:2619
company_func.h
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3603
WID_SV_SHIPS
@ WID_SV_SHIPS
List of scheduled ships button.
Definition: station_widget.h:29
CargoDataEntry::HasTransfers
bool HasTransfers() const
Has this entry transfers.
Definition: station_gui.cpp:997
CargoSpec::abbrev
StringID abbrev
Two letter abbreviation for this cargo type.
Definition: cargotype.h:92
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:480
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition: tilearea_type.h:20
Window::RaiseWidget
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition: window_gui.h:469
CargoSortType::CargoID
@ CargoID
by cargo id
CompanyStationsWindow::FilterState::facilities
byte facilities
types of stations of interest
Definition: station_gui.cpp:223
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition: settings_type.h:593
StationViewWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:2108
WID_SV_GROUP
@ WID_SV_GROUP
label for "group by"
Definition: station_widget.h:16
StationViewWindow::GR_NEXT
@ GR_NEXT
Group by next station ("via").
Definition: station_gui.cpp:1265
CommandHelper
Definition: command_func.h:93
StationViewWindow::ALH_RATING
@ ALH_RATING
Height of the cargo ratings view.
Definition: station_gui.cpp:1285
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
StationSettings::adjacent_stations
bool adjacent_stations
allow stations to be built directly adjacent to other stations
Definition: settings_type.h:592
window_func.h
WID_STL_SORTDROPBTN
@ WID_STL_SORTDROPBTN
Dropdown button.
Definition: station_widget.h:53
CargoDataEntry
A cargo data entry representing one possible row in the station view window's top part.
Definition: station_gui.cpp:888
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:40
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:295
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
StationViewWindow::SelectSortOrder
void SelectSortOrder(SortOrder order)
Select a new sort order for the cargo view.
Definition: station_gui.cpp:1999
StationViewWindow::SelectGroupBy
void SelectGroupBy(int index)
Select a new grouping mode for the cargo view.
Definition: station_gui.cpp:2042
CargoDataEntry::count
uint count
sum of counts of all children or amount of cargo for this entry.
Definition: station_gui.cpp:1029
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CargoSortType::AsGrouping
@ AsGrouping
by the same principle the entries are being grouped
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
StationViewWindow::accepts_lines
int accepts_lines
Number of lines in the accepted cargo view.
Definition: station_gui.cpp:1280
CargoDataEntry::parent
CargoDataEntry * parent
the parent of this entry.
Definition: station_gui.cpp:1020
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:1303
CargoSorter
Definition: station_gui.cpp:865
TileVirtXY
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:416
WID_SV_CLOSE_AIRPORT
@ WID_SV_CLOSE_AIRPORT
'Close airport' button.
Definition: station_widget.h:26
CargoDataEntry::Remove
void Remove(CargoID cargo)
Remove a child associated with the given cargo.
Definition: station_gui.cpp:929
CargoPacket::Count
uint16_t Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:158
gui.h
BaseStation::IsInUse
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
Definition: base_station_base.h:182
StationViewWindow::GR_CARGO
@ GR_CARGO
Group by cargo type.
Definition: station_gui.cpp:1267
Window
Data structure for an opened window.
Definition: window_gui.h:267
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
CompanyStationsWindow::OnGameTick
void OnGameTick() override
Called once per (game) tick.
Definition: station_gui.cpp:665
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
StationViewWindow::rating_lines
int rating_lines
Number of lines in the cargo ratings view.
Definition: station_gui.cpp:1279
_viewport_highlight_station
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
Definition: viewport.cpp:1002
PC_RED
static const uint8_t PC_RED
Red palette colour.
Definition: palette_func.h:62
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
StationViewWindow::expanded_rows
CargoDataEntry expanded_rows
Parent entry of currently expanded rows.
Definition: station_gui.cpp:1308
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:55
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:68
StationViewWindow::Grouping
Grouping
Type of grouping used in each of the "columns".
Definition: station_gui.cpp:1263
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
WID_STL_NOCARGOWAITING
@ WID_STL_NOCARGOWAITING
'NO' button - list stations where no cargo is waiting.
Definition: station_widget.h:49
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:1519
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
IsCargoInClass
bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:222
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:450
WID_STL_FACILALL
@ WID_STL_FACILALL
'ALL' button - list all facilities.
Definition: station_widget.h:47
TileAndStation
Struct containing TileIndex and StationID.
Definition: station_gui.cpp:2156
Town::exclusivity
CompanyID exclusivity
which company has exclusivity
Definition: town.h:71
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
WID_STL_TRAIN
@ WID_STL_TRAIN
'TRAIN' button - list only facilities where is a railroad station.
Definition: station_widget.h:42
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:326
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:2214
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:302
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
station_gui.h
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
Town::exclusive_counter
uint8_t exclusive_counter
months till the exclusivity expires
Definition: town.h:72
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
GetContrastColour
TextColour GetContrastColour(uint8_t background, uint8_t threshold)
Determine a contrasty text colour for a coloured background.
Definition: palette.cpp:289
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1120
TileHighlightData::freeze
bool freeze
Freeze highlight in place.
Definition: tilehighlight_type.h:53
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
GUISettings::station_gui_sort_by
uint8_t station_gui_sort_by
sort cargo entries in the station gui by station name or amount
Definition: settings_type.h:208
CargoDataEntry::Begin
CargoDataSet::iterator Begin() const
Get an iterator pointing to the begin of the set of children.
Definition: station_gui.cpp:987
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
station_widget.h
debug.h
LinkGraph::Monthly
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
Definition: linkgraph.h:249
CargoDataEntry::transfers
bool transfers
If there are transfers for this cargo.
Definition: station_gui.cpp:1025
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
CompanyStationsWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: station_gui.cpp:683
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:190
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:151
StationViewWindow::DrawEntries
int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo=INVALID_CARGO)
Draw the given cargo entries in the station GUI.
Definition: station_gui.cpp:1753
ShowSelectBaseStationIfNeeded
void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc &&proc)
Show the station selection window when needed.
Definition: station_gui.cpp:2445
CargoDataEntry::IncrementSize
void IncrementSize()
Increment.
Definition: station_gui.cpp:1146
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
CargoDataEntry::End
CargoDataSet::iterator End() const
Get an iterator pointing to the end of the set of children.
Definition: station_gui.cpp:992
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103