OpenTTD Source: src/station_gui.cpp Source File

OpenTTD Source 14.1

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>
84 void FindStationsAroundSelection()
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
126 void CheckRedrawStationCoverage(const Window *w)
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
139 if (_settings_client.gui.station_show_coverage && _thd.drawstyle == HT_RECT) {
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
212 typedef GUIList<const Station*, const CargoTypes &> GUIStationList;
213
217 class CompanyStationsWindow : public Window
218 {
219 protected:
220 /* Runtime saved values */
221 struct FilterState {
222 Listing last_sorting;
223 byte facilities;
224 bool include_no_rating;
225 CargoTypes cargoes;
226 };
227
228 static inline FilterState initial_state = {
229 {false, 0},
230 FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK,
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 bool filter_expanded;
244 std::array<uint16_t, NUM_CARGO> stations_per_cargo_type;
245 uint16_t stations_per_cargo_type_no_rating;
246
252 void BuildStationsList(const Owner owner)
253 {
254 if (!this->stations.NeedRebuild()) return;
255
256 Debug(misc, 3, "Building station list for company {}", owner);
257
258 this->stations.clear();
259 this->stations_per_cargo_type.fill(0);
260 this->stations_per_cargo_type_no_rating = 0;
261
262 for (const Station *st : Station::Iterate()) {
263 if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
264 if (this->filter.facilities & st->facilities) { // only stations with selected facilities
265 bool has_rating = false;
266 /* Add to the station/cargo counts. */
267 for (CargoID j = 0; j < NUM_CARGO; j++) {
268 if (st->goods[j].HasRating()) this->stations_per_cargo_type[j]++;
269 }
270 for (CargoID j = 0; j < NUM_CARGO; j++) {
271 if (st->goods[j].HasRating()) {
272 has_rating = true;
273 if (HasBit(this->filter.cargoes, j)) {
274 this->stations.push_back(st);
275 break;
276 }
277 }
278 }
279 /* Stations with no cargo rating. */
280 if (!has_rating) {
281 if (this->filter.include_no_rating) this->stations.push_back(st);
282 this->stations_per_cargo_type_no_rating++;
283 }
284 }
285 }
286 }
287
288 this->stations.shrink_to_fit();
289 this->stations.RebuildDone();
290
291 this->vscroll->SetCount(this->stations.size()); // Update the scrollbar
292 }
293
295 static bool StationNameSorter(const Station * const &a, const Station * const &b, const CargoTypes &)
296 {
297 int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
298 if (r == 0) return a->index < b->index;
299 return r < 0;
300 }
301
303 static bool StationTypeSorter(const Station * const &a, const Station * const &b, const CargoTypes &)
304 {
305 return a->facilities < b->facilities;
306 }
307
309 static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
310 {
311 int diff = 0;
312
313 for (CargoID j : SetCargoBitIterator(cargo_filter)) {
314 diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount();
315 }
316
317 return diff < 0;
318 }
319
321 static bool StationWaitingAvailableSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
322 {
323 int diff = 0;
324
325 for (CargoID j : SetCargoBitIterator(cargo_filter)) {
326 diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
327 }
328
329 return diff < 0;
330 }
331
333 static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
334 {
335 byte maxr1 = 0;
336 byte maxr2 = 0;
337
338 for (CargoID j : SetCargoBitIterator(cargo_filter)) {
339 if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating);
340 if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating);
341 }
342
343 return maxr1 < maxr2;
344 }
345
347 static bool StationRatingMinSorter(const Station * const &a, const Station * const &b, const CargoTypes &cargo_filter)
348 {
349 byte minr1 = 255;
350 byte minr2 = 255;
351
352 for (CargoID j : SetCargoBitIterator(cargo_filter)) {
353 if (a->goods[j].HasRating()) minr1 = std::min(minr1, a->goods[j].rating);
354 if (b->goods[j].HasRating()) minr2 = std::min(minr2, b->goods[j].rating);
355 }
356
357 return minr1 > minr2;
358 }
359
361 void SortStationsList()
362 {
363 if (!this->stations.Sort()) return;
364
365 /* Set the modified widget dirty */
366 this->SetWidgetDirty(WID_STL_LIST);
367 }
368
369 public:
370 CompanyStationsWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
371 {
372 /* Load initial filter state. */
373 this->filter = CompanyStationsWindow::initial_state;
374 if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes = _cargo_mask;
375
376 this->stations.SetListing(this->filter.last_sorting);
377 this->stations.SetSortFuncs(CompanyStationsWindow::sorter_funcs);
378 this->stations.ForceRebuild();
379 this->stations.NeedResort();
380 this->SortStationsList();
381
382 this->CreateNestedTree();
383 this->vscroll = this->GetScrollbar(WID_STL_SCROLLBAR);
384 this->FinishInitNested(window_number);
385 this->owner = (Owner)this->window_number;
386
387 if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes = _cargo_mask;
388
389 for (uint i = 0; i < 5; i++) {
390 if (HasBit(this->filter.facilities, i)) this->LowerWidget(i + WID_STL_TRAIN);
391 }
392
393 this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
394 }
395
396 ~CompanyStationsWindow()
397 {
398 /* Save filter state. */
399 this->filter.last_sorting = this->stations.GetListing();
400 CompanyStationsWindow::initial_state = this->filter;
401 }
402
403 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
404 {
405 switch (widget) {
406 case WID_STL_SORTBY: {
407 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
408 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
409 d.height += padding.height;
410 *size = maxdim(*size, d);
411 break;
412 }
413
414 case WID_STL_SORTDROPBTN: {
415 Dimension d = {0, 0};
416 for (int i = 0; CompanyStationsWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
417 d = maxdim(d, GetStringBoundingBox(CompanyStationsWindow::sorter_names[i]));
418 }
419 d.width += padding.width;
420 d.height += padding.height;
421 *size = maxdim(*size, d);
422 break;
423 }
424
425 case WID_STL_LIST:
426 resize->height = std::max(GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_SMALL) + ScaleGUITrad(3));
427 size->height = padding.height + 5 * resize->height;
428
429 /* Determine appropriate width for mini station rating graph */
430 this->rating_width = 0;
431 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
432 this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev, FS_SMALL).width);
433 }
434 /* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
435 this->rating_width = this->rating_width * 16 / 10;
436 break;
437 }
438 }
439
440 void OnPaint() override
441 {
442 this->BuildStationsList((Owner)this->window_number);
443 this->SortStationsList();
444
445 this->DrawWidgets();
446 }
447
448 void DrawWidget(const Rect &r, WidgetID widget) const override
449 {
450 switch (widget) {
451 case WID_STL_SORTBY:
452 /* draw arrow pointing up/down for ascending/descending sorting */
453 this->DrawSortButtonState(WID_STL_SORTBY, this->stations.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
454 break;
455
456 case WID_STL_LIST: {
457 bool rtl = _current_text_dir == TD_RTL;
458 size_t max = std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size());
459 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
460 uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
461 /* Spacing between station name and first rating graph. */
462 int text_spacing = WidgetDimensions::scaled.hsep_wide;
463 /* Spacing between additional rating graphs. */
464 int rating_spacing = WidgetDimensions::scaled.hsep_normal;
465
466 for (size_t i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner
467 const Station *st = this->stations[i];
468 assert(st->xy != INVALID_TILE);
469
470 /* Do not do the complex check HasStationInUse here, it may be even false
471 * when the order had been removed and the station list hasn't been removed yet */
472 assert(st->owner == owner || st->owner == OWNER_NONE);
473
474 SetDParam(0, st->index);
475 SetDParam(1, st->facilities);
476 int x = DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, STR_STATION_LIST_STATION);
477 x += rtl ? -text_spacing : text_spacing;
478
479 /* show cargo waiting and station ratings */
480 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
481 CargoID cid = cs->Index();
482 if (st->goods[cid].HasRating()) {
483 /* For RTL we work in exactly the opposite direction. So
484 * decrement the space needed first, then draw to the left
485 * instead of drawing to the left and then incrementing
486 * the space. */
487 if (rtl) {
488 x -= rating_width + rating_spacing;
489 if (x < tr.left) break;
490 }
491 StationsWndShowStationRating(x, x + rating_width, tr.top, cid, st->goods[cid].cargo.TotalCount(), st->goods[cid].rating);
492 if (!rtl) {
493 x += rating_width + rating_spacing;
494 if (x > tr.right) break;
495 }
496 }
497 }
498 tr.top += line_height;
499 }
500
501 if (this->vscroll->GetCount() == 0) { // company has no stations
502 DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FS_NORMAL)) / 2, STR_STATION_LIST_NONE);
503 return;
504 }
505 break;
506 }
507 }
508 }
509
510 void SetStringParameters(WidgetID widget) const override
511 {
512 if (widget == WID_STL_CAPTION) {
513 SetDParam(0, this->window_number);
514 SetDParam(1, this->vscroll->GetCount());
515 }
516
517 if (widget == WID_STL_CARGODROPDOWN) {
518 if (this->filter.cargoes == 0) {
519 SetDParam(0, this->filter.include_no_rating ? STR_STATION_LIST_CARGO_FILTER_ONLY_NO_RATING : STR_STATION_LIST_CARGO_FILTER_NO_CARGO_TYPES);
520 } else if (this->filter.cargoes == _cargo_mask) {
521 SetDParam(0, this->filter.include_no_rating ? STR_STATION_LIST_CARGO_FILTER_ALL_AND_NO_RATING : STR_CARGO_TYPE_FILTER_ALL);
522 } else if (CountBits(this->filter.cargoes) == 1 && !this->filter.include_no_rating) {
523 SetDParam(0, CargoSpec::Get(FindFirstBit(this->filter.cargoes))->name);
524 } else {
525 SetDParam(0, STR_STATION_LIST_CARGO_FILTER_MULTIPLE);
526 }
527 }
528 }
529
530 DropDownList BuildCargoDropDownList(bool expanded) const
531 {
532 /* Define a custom item consisting of check mark, count string, icon and name string. */
533 using DropDownListCargoItem = DropDownCheck<DropDownString<DropDownListIconItem, FS_SMALL, true>>;
534
535 DropDownList list;
536 list.push_back(std::make_unique<DropDownListStringItem>(STR_STATION_LIST_CARGO_FILTER_SELECT_ALL, CargoFilterCriteria::CF_SELECT_ALL));
537 list.push_back(std::make_unique<DropDownListDividerItem>(-1));
538
539 bool any_hidden = false;
540
541 uint16_t count = this->stations_per_cargo_type_no_rating;
542 if (count == 0 && !expanded) {
543 any_hidden = true;
544 } else {
545 list.push_back(std::make_unique<DropDownString<DropDownListCheckedItem, FS_SMALL, true>>(fmt::format("{}", count), this->filter.include_no_rating, STR_STATION_LIST_CARGO_FILTER_NO_RATING, CargoFilterCriteria::CF_NO_RATING, false, count == 0));
546 }
547
548 Dimension d = GetLargestCargoIconSize();
549 for (const CargoSpec *cs : _sorted_cargo_specs) {
550 count = this->stations_per_cargo_type[cs->Index()];
551 if (count == 0 && !expanded) {
552 any_hidden = true;
553 } else {
554 list.push_back(std::make_unique<DropDownListCargoItem>(HasBit(this->filter.cargoes, cs->Index()), fmt::format("{}", count), d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false, count == 0));
555 }
556 }
557
558 if (!expanded && any_hidden) {
559 if (list.size() > 2) list.push_back(std::make_unique<DropDownListDividerItem>(-1));
560 list.push_back(std::make_unique<DropDownListStringItem>(STR_STATION_LIST_CARGO_FILTER_EXPAND, CargoFilterCriteria::CF_EXPAND_LIST));
561 }
562
563 return list;
564 }
565
566 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
567 {
568 switch (widget) {
569 case WID_STL_LIST: {
570 auto it = this->vscroll->GetScrolledItemFromWidget(this->stations, pt.y, this, WID_STL_LIST);
571 if (it == this->stations.end()) return; // click out of list bound
572
573 const Station *st = *it;
574 /* do not check HasStationInUse - it is slow and may be invalid */
575 assert(st->owner == (Owner)this->window_number || st->owner == OWNER_NONE);
576
577 if (_ctrl_pressed) {
578 ShowExtraViewportWindow(st->xy);
579 } else {
580 ScrollMainWindowToTile(st->xy);
581 }
582 break;
583 }
584
585 case WID_STL_TRAIN:
586 case WID_STL_TRUCK:
587 case WID_STL_BUS:
588 case WID_STL_AIRPLANE:
589 case WID_STL_SHIP:
590 if (_ctrl_pressed) {
591 ToggleBit(this->filter.facilities, widget - WID_STL_TRAIN);
592 this->ToggleWidgetLoweredState(widget);
593 } else {
594 for (uint i : SetBitIterator(this->filter.facilities)) {
595 this->RaiseWidget(i + WID_STL_TRAIN);
596 }
597 this->filter.facilities = 1 << (widget - WID_STL_TRAIN);
598 this->LowerWidget(widget);
599 }
600 this->stations.ForceRebuild();
601 this->SetDirty();
602 break;
603
604 case WID_STL_FACILALL:
605 for (WidgetID i = WID_STL_TRAIN; i <= WID_STL_SHIP; i++) {
606 this->LowerWidget(i);
607 }
608
609 this->filter.facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
610 this->stations.ForceRebuild();
611 this->SetDirty();
612 break;
613
614 case WID_STL_SORTBY: // flip sorting method asc/desc
615 this->stations.ToggleSortOrder();
616 this->SetDirty();
617 break;
618
619 case WID_STL_SORTDROPBTN: // select sorting criteria dropdown menu
620 ShowDropDownMenu(this, this->sorter_names, this->stations.SortType(), WID_STL_SORTDROPBTN, 0, 0);
621 break;
622
623 case WID_STL_CARGODROPDOWN:
624 this->filter_expanded = false;
625 ShowDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded), -1, widget, 0, false, true);
626 break;
627 }
628 }
629
630 void OnDropdownSelect(int widget, int index) override
631 {
632 if (widget == WID_STL_SORTDROPBTN) {
633 if (this->stations.SortType() != index) {
634 this->stations.SetSortType(index);
635
636 /* Display the current sort variant */
637 this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
638
639 this->SetDirty();
640 }
641 }
642
643 if (widget == WID_STL_CARGODROPDOWN) {
644 FilterState oldstate = this->filter;
645
646 if (index >= 0 && index < NUM_CARGO) {
647 if (_ctrl_pressed) {
648 ToggleBit(this->filter.cargoes, index);
649 } else {
650 this->filter.cargoes = 1ULL << index;
651 this->filter.include_no_rating = false;
652 }
653 } else if (index == CargoFilterCriteria::CF_NO_RATING) {
654 if (_ctrl_pressed) {
655 this->filter.include_no_rating = !this->filter.include_no_rating;
656 } else {
657 this->filter.include_no_rating = true;
658 this->filter.cargoes = 0;
659 }
660 } else if (index == CargoFilterCriteria::CF_SELECT_ALL) {
661 this->filter.cargoes = _cargo_mask;
662 this->filter.include_no_rating = true;
663 } else if (index == CargoFilterCriteria::CF_EXPAND_LIST) {
664 this->filter_expanded = true;
665 ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
666 return;
667 }
668
669 if (oldstate.cargoes != this->filter.cargoes || oldstate.include_no_rating != this->filter.include_no_rating) {
670 this->stations.ForceRebuild();
671 this->SetDirty();
672
673 /* Only refresh the list if it's changed. */
674 if (_ctrl_pressed) ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
675 }
676
677 /* Always close the list if ctrl is not pressed. */
678 if (!_ctrl_pressed) this->CloseChildWindows(WC_DROPDOWN_MENU);
679 }
680 }
681
682 void OnGameTick() override
683 {
684 if (this->stations.NeedResort()) {
685 Debug(misc, 3, "Periodic rebuild station list company {}", this->window_number);
686 this->SetDirty();
687 }
688 }
689
690 void OnResize() override
691 {
692 this->vscroll->SetCapacityFromWidget(this, WID_STL_LIST, WidgetDimensions::scaled.framerect.Vertical());
693 }
694
700 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
701 {
702 if (data == 0) {
703 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
704 this->stations.ForceRebuild();
705 } else {
706 this->stations.ForceResort();
707 }
708 }
709 };
710
711 /* Available station sorting functions */
712 GUIStationList::SortFunction * const CompanyStationsWindow::sorter_funcs[] = {
713 &StationNameSorter,
714 &StationTypeSorter,
715 &StationWaitingTotalSorter,
716 &StationWaitingAvailableSorter,
717 &StationRatingMaxSorter,
718 &StationRatingMinSorter
719 };
720
721 /* Names of the sorting functions */
722 const StringID CompanyStationsWindow::sorter_names[] = {
723 STR_SORT_BY_NAME,
724 STR_SORT_BY_FACILITY,
725 STR_SORT_BY_WAITING_TOTAL,
726 STR_SORT_BY_WAITING_AVAILABLE,
727 STR_SORT_BY_RATING_MAX,
728 STR_SORT_BY_RATING_MIN,
729 INVALID_STRING_ID
730 };
731
732 static constexpr NWidgetPart _nested_company_stations_widgets[] = {
733 NWidget(NWID_HORIZONTAL),
734 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
735 NWidget(WWT_CAPTION, COLOUR_GREY, WID_STL_CAPTION), SetDataTip(STR_STATION_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
736 NWidget(WWT_SHADEBOX, COLOUR_GREY),
737 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
738 NWidget(WWT_STICKYBOX, COLOUR_GREY),
739 EndContainer(),
740 NWidget(NWID_HORIZONTAL),
741 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),
742 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),
743 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),
744 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),
745 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),
746 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),
747 NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(5, 0), SetFill(0, 1), EndContainer(),
748 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_STL_CARGODROPDOWN), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE),
749 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
750 EndContainer(),
751 NWidget(NWID_HORIZONTAL),
752 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_STL_SORTBY), SetMinimalSize(81, 12), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
753 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_STL_SORTDROPBTN), SetMinimalSize(163, 12), SetDataTip(STR_SORT_BY_NAME, STR_TOOLTIP_SORT_CRITERIA), // widget_data gets overwritten.
754 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1), EndContainer(),
755 EndContainer(),
756 NWidget(NWID_HORIZONTAL),
757 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(),
758 NWidget(NWID_VERTICAL),
759 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_STL_SCROLLBAR),
760 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
761 EndContainer(),
762 EndContainer(),
763 };
764
765 static WindowDesc _company_stations_desc(__FILE__, __LINE__,
766 WDP_AUTO, "list_stations", 358, 162,
767 WC_STATION_LIST, WC_NONE,
768 0,
769 std::begin(_nested_company_stations_widgets), std::end(_nested_company_stations_widgets)
770 );
771
777 void ShowCompanyStations(CompanyID company)
778 {
779 if (!Company::IsValidID(company)) return;
780
781 AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
782 }
783
784 static constexpr NWidgetPart _nested_station_view_widgets[] = {
785 NWidget(NWID_HORIZONTAL),
786 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
787 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_RENAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_STATION_VIEW_RENAME_TOOLTIP),
788 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SV_CAPTION), SetDataTip(STR_STATION_VIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
789 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SV_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_STATION_VIEW_CENTER_TOOLTIP),
790 NWidget(WWT_SHADEBOX, COLOUR_GREY),
791 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
792 NWidget(WWT_STICKYBOX, COLOUR_GREY),
793 EndContainer(),
794 NWidget(NWID_HORIZONTAL),
795 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_GROUP), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_STATION_VIEW_GROUP, 0x0),
796 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_GROUP_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
797 EndContainer(),
798 NWidget(NWID_HORIZONTAL),
799 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SORT_ORDER), SetMinimalSize(81, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
800 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_SV_SORT_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
801 EndContainer(),
802 NWidget(NWID_HORIZONTAL),
803 NWidget(WWT_PANEL, COLOUR_GREY, WID_SV_WAITING), SetMinimalSize(237, 44), SetResize(1, 10), SetScrollbar(WID_SV_SCROLLBAR), EndContainer(),
804 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SV_SCROLLBAR),
805 EndContainer(),
806 NWidget(WWT_PANEL, COLOUR_GREY, WID_SV_ACCEPT_RATING_LIST), SetMinimalSize(249, 23), SetResize(1, 0), EndContainer(),
807 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
808 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ACCEPTS_RATINGS), SetMinimalSize(46, 12), SetResize(1, 0), SetFill(1, 1),
809 SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
810 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1),
811 SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
812 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
813 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
814 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
815 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
816 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_PLANES), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
817 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
818 EndContainer(),
819 };
820
830 static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int y)
831 {
832 int width = ScaleSpriteTrad(10);
833 uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow
834 if (num == 0) return;
835
836 SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon();
837
838 int x = _current_text_dir == TD_RTL ? left : right - num * width;
839 do {
840 DrawSprite(sprite, PAL_NONE, x, y);
841 x += width;
842 } while (--num);
843 }
844
845 enum SortOrder {
846 SO_DESCENDING,
847 SO_ASCENDING
848 };
849
850 class CargoDataEntry;
851
852 enum class CargoSortType : byte {
853 AsGrouping,
854 Count,
855 StationString,
856 StationID,
857 CargoID,
858 };
859
860 class CargoSorter {
861 public:
862 CargoSorter(CargoSortType t = CargoSortType::StationID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
863 CargoSortType GetSortType() {return this->type;}
864 bool operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
865
866 private:
867 CargoSortType type;
868 SortOrder order;
869
870 template<class Tid>
871 bool SortId(Tid st1, Tid st2) const;
872 bool SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const;
873 bool SortStation (StationID st1, StationID st2) const;
874 };
875
876 typedef std::set<CargoDataEntry *, CargoSorter> CargoDataSet;
877
883 class CargoDataEntry {
884 public:
885 CargoDataEntry();
886 ~CargoDataEntry();
887
893 CargoDataEntry *InsertOrRetrieve(StationID station)
894 {
895 return this->InsertOrRetrieve<StationID>(station);
896 }
897
903 CargoDataEntry *InsertOrRetrieve(CargoID cargo)
904 {
905 return this->InsertOrRetrieve<CargoID>(cargo);
906 }
907
908 void Update(uint count);
909
914 void Remove(StationID station)
915 {
916 CargoDataEntry t(station);
917 this->Remove(&t);
918 }
919
924 void Remove(CargoID cargo)
925 {
926 CargoDataEntry t(cargo);
927 this->Remove(&t);
928 }
929
935 CargoDataEntry *Retrieve(StationID station) const
936 {
937 CargoDataEntry t(station);
938 return this->Retrieve(this->children->find(&t));
939 }
940
946 CargoDataEntry *Retrieve(CargoID cargo) const
947 {
948 CargoDataEntry t(cargo);
949 return this->Retrieve(this->children->find(&t));
950 }
951
952 void Resort(CargoSortType type, SortOrder order);
953
957 StationID GetStation() const { return this->station; }
958
962 CargoID GetCargo() const { return this->cargo; }
963
967 uint GetCount() const { return this->count; }
968
972 CargoDataEntry *GetParent() const { return this->parent; }
973
977 uint GetNumChildren() const { return this->num_children; }
978
982 CargoDataSet::iterator Begin() const { return this->children->begin(); }
983
987 CargoDataSet::iterator End() const { return this->children->end(); }
988
992 bool HasTransfers() const { return this->transfers; }
993
997 void SetTransfers(bool value) { this->transfers = value; }
998
999 void Clear();
1000 private:
1001
1002 CargoDataEntry(StationID st, uint c, CargoDataEntry *p);
1003 CargoDataEntry(CargoID car, uint c, CargoDataEntry *p);
1004 CargoDataEntry(StationID st);
1005 CargoDataEntry(CargoID car);
1006
1007 CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
1008
1009 template<class Tid>
1010 CargoDataEntry *InsertOrRetrieve(Tid s);
1011
1012 void Remove(CargoDataEntry *comp);
1013 void IncrementSize();
1014
1015 CargoDataEntry *parent;
1016 const union {
1017 StationID station;
1018 struct {
1019 CargoID cargo;
1020 bool transfers;
1021 };
1022 };
1023 uint num_children;
1024 uint count;
1025 CargoDataSet *children;
1026 };
1027
1028 CargoDataEntry::CargoDataEntry() :
1029 parent(nullptr),
1030 station(INVALID_STATION),
1031 num_children(0),
1032 count(0),
1033 children(new CargoDataSet(CargoSorter(CargoSortType::CargoID)))
1034 {}
1035
1036 CargoDataEntry::CargoDataEntry(CargoID cargo, uint count, CargoDataEntry *parent) :
1037 parent(parent),
1038 cargo(cargo),
1039 num_children(0),
1040 count(count),
1041 children(new CargoDataSet)
1042 {}
1043
1044 CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
1045 parent(parent),
1046 station(station),
1047 num_children(0),
1048 count(count),
1049 children(new CargoDataSet)
1050 {}
1051
1052 CargoDataEntry::CargoDataEntry(StationID station) :
1053 parent(nullptr),
1054 station(station),
1055 num_children(0),
1056 count(0),
1057 children(nullptr)
1058 {}
1059
1060 CargoDataEntry::CargoDataEntry(CargoID cargo) :
1061 parent(nullptr),
1062 cargo(cargo),
1063 num_children(0),
1064 count(0),
1065 children(nullptr)
1066 {}
1067
1068 CargoDataEntry::~CargoDataEntry()
1069 {
1070 this->Clear();
1071 delete this->children;
1072 }
1073
1077 void CargoDataEntry::Clear()
1078 {
1079 if (this->children != nullptr) {
1080 for (auto &it : *this->children) {
1081 assert(it != this);
1082 delete it;
1083 }
1084 this->children->clear();
1085 }
1086 if (this->parent != nullptr) this->parent->count -= this->count;
1087 this->count = 0;
1088 this->num_children = 0;
1089 }
1090
1097 void CargoDataEntry::Remove(CargoDataEntry *child)
1098 {
1099 CargoDataSet::iterator i = this->children->find(child);
1100 if (i != this->children->end()) {
1101 delete *i;
1102 this->children->erase(i);
1103 }
1104 }
1105
1112 template<class Tid>
1113 CargoDataEntry *CargoDataEntry::InsertOrRetrieve(Tid child_id)
1114 {
1115 CargoDataEntry tmp(child_id);
1116 CargoDataSet::iterator i = this->children->find(&tmp);
1117 if (i == this->children->end()) {
1118 IncrementSize();
1119 return *(this->children->insert(new CargoDataEntry(child_id, 0, this)).first);
1120 } else {
1121 CargoDataEntry *ret = *i;
1122 assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
1123 return ret;
1124 }
1125 }
1126
1132 void CargoDataEntry::Update(uint count)
1133 {
1134 this->count += count;
1135 if (this->parent != nullptr) this->parent->Update(count);
1136 }
1137
1141 void CargoDataEntry::IncrementSize()
1142 {
1143 ++this->num_children;
1144 if (this->parent != nullptr) this->parent->IncrementSize();
1145 }
1146
1147 void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
1148 {
1149 CargoDataSet *new_subs = new CargoDataSet(this->children->begin(), this->children->end(), CargoSorter(type, order));
1150 delete this->children;
1151 this->children = new_subs;
1152 }
1153
1154 CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
1155 {
1156 if (i == this->children->end()) {
1157 return nullptr;
1158 } else {
1159 assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
1160 return *i;
1161 }
1162 }
1163
1164 bool CargoSorter::operator()(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1165 {
1166 switch (this->type) {
1167 case CargoSortType::StationID:
1168 return this->SortId<StationID>(cd1->GetStation(), cd2->GetStation());
1169 case CargoSortType::CargoID:
1170 return this->SortId<CargoID>(cd1->GetCargo(), cd2->GetCargo());
1171 case CargoSortType::Count:
1172 return this->SortCount(cd1, cd2);
1173 case CargoSortType::StationString:
1174 return this->SortStation(cd1->GetStation(), cd2->GetStation());
1175 default:
1176 NOT_REACHED();
1177 }
1178 }
1179
1180 template<class Tid>
1181 bool CargoSorter::SortId(Tid st1, Tid st2) const
1182 {
1183 return (this->order == SO_ASCENDING) ? st1 < st2 : st2 < st1;
1184 }
1185
1186 bool CargoSorter::SortCount(const CargoDataEntry *cd1, const CargoDataEntry *cd2) const
1187 {
1188 uint c1 = cd1->GetCount();
1189 uint c2 = cd2->GetCount();
1190 if (c1 == c2) {
1191 return this->SortStation(cd1->GetStation(), cd2->GetStation());
1192 } else if (this->order == SO_ASCENDING) {
1193 return c1 < c2;
1194 } else {
1195 return c2 < c1;
1196 }
1197 }
1198
1199 bool CargoSorter::SortStation(StationID st1, StationID st2) const
1200 {
1201 if (!Station::IsValidID(st1)) {
1202 return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
1203 } else if (!Station::IsValidID(st2)) {
1204 return order == SO_DESCENDING;
1205 }
1206
1207 int res = StrNaturalCompare(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
1208 if (res == 0) {
1209 return this->SortId(st1, st2);
1210 } else {
1211 return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
1212 }
1213 }
1214
1218 struct StationViewWindow : public Window {
1222 struct RowDisplay {
1223 RowDisplay(CargoDataEntry *f, StationID n) : filter(f), next_station(n) {}
1224 RowDisplay(CargoDataEntry *f, CargoID n) : filter(f), next_cargo(n) {}
1225
1229 CargoDataEntry *filter;
1230 union {
1234 StationID next_station;
1235
1239 CargoID next_cargo;
1240 };
1241 };
1242
1243 typedef std::vector<RowDisplay> CargoDataVector;
1244
1245 static const int NUM_COLUMNS = 4;
1246
1250 enum Invalidation {
1251 INV_FLOWS = 0x100,
1252 INV_CARGO = 0x200
1253 };
1254
1258 enum Grouping {
1259 GR_SOURCE,
1260 GR_NEXT,
1261 GR_DESTINATION,
1262 GR_CARGO,
1263 };
1264
1268 enum Mode {
1269 MODE_WAITING,
1270 MODE_PLANNED
1271 };
1272
1273 uint expand_shrink_width;
1274 int rating_lines;
1275 int accepts_lines;
1276 Scrollbar *vscroll;
1277
1279 enum AcceptListHeight {
1280 ALH_RATING = 13,
1281 ALH_ACCEPTS = 3,
1282 };
1283
1284 static const StringID _sort_names[];
1285 static const StringID _group_names[];
1286
1293 CargoSortType sortings[NUM_COLUMNS];
1294
1296 SortOrder sort_orders[NUM_COLUMNS];
1297
1298 int scroll_to_row;
1299 int grouping_index;
1300 Mode current_mode;
1301 Grouping groupings[NUM_COLUMNS];
1302
1303 CargoDataEntry expanded_rows;
1304 CargoDataEntry cached_destinations;
1305 CargoDataVector displayed_rows;
1306
1307 StationViewWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc),
1308 scroll_to_row(INT_MAX), grouping_index(0)
1309 {
1310 this->rating_lines = ALH_RATING;
1311 this->accepts_lines = ALH_ACCEPTS;
1312
1313 this->CreateNestedTree();
1314 this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
1315 /* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
1316 this->FinishInitNested(window_number);
1317
1318 this->groupings[0] = GR_CARGO;
1319 this->sortings[0] = CargoSortType::AsGrouping;
1320 this->SelectGroupBy(_settings_client.gui.station_gui_group_order);
1321 this->SelectSortBy(_settings_client.gui.station_gui_sort_by);
1322 this->sort_orders[0] = SO_ASCENDING;
1323 this->SelectSortOrder((SortOrder)_settings_client.gui.station_gui_sort_order);
1324 this->owner = Station::Get(window_number)->owner;
1325 }
1326
1327 void Close([[maybe_unused]] int data = 0) override
1328 {
1329 CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false);
1330 CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false);
1331 CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false);
1332 CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false);
1333
1334 SetViewportCatchmentStation(Station::Get(this->window_number), false);
1335 this->Window::Close();
1336 }
1337
1348 void ShowCargo(CargoDataEntry *data, CargoID cargo, StationID source, StationID next, StationID dest, uint count)
1349 {
1350 if (count == 0) return;
1351 bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1352 const CargoDataEntry *expand = &this->expanded_rows;
1353 for (int i = 0; i < NUM_COLUMNS && expand != nullptr; ++i) {
1354 switch (groupings[i]) {
1355 case GR_CARGO:
1356 assert(i == 0);
1357 data = data->InsertOrRetrieve(cargo);
1358 data->SetTransfers(source != this->window_number);
1359 expand = expand->Retrieve(cargo);
1360 break;
1361 case GR_SOURCE:
1362 if (auto_distributed || source != this->window_number) {
1363 data = data->InsertOrRetrieve(source);
1364 expand = expand->Retrieve(source);
1365 }
1366 break;
1367 case GR_NEXT:
1368 if (auto_distributed) {
1369 data = data->InsertOrRetrieve(next);
1370 expand = expand->Retrieve(next);
1371 }
1372 break;
1373 case GR_DESTINATION:
1374 if (auto_distributed) {
1375 data = data->InsertOrRetrieve(dest);
1376 expand = expand->Retrieve(dest);
1377 }
1378 break;
1379 }
1380 }
1381 data->Update(count);
1382 }
1383
1384 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1385 {
1386 switch (widget) {
1387 case WID_SV_WAITING:
1388 resize->height = GetCharacterHeight(FS_NORMAL);
1389 size->height = 4 * resize->height + padding.height;
1390 this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width);
1391 break;
1392
1393 case WID_SV_ACCEPT_RATING_LIST:
1394 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;
1395 break;
1396
1397 case WID_SV_CLOSE_AIRPORT:
1398 if (!(Station::Get(this->window_number)->facilities & FACIL_AIRPORT)) {
1399 /* Hide 'Close Airport' button if no airport present. */
1400 size->width = 0;
1401 resize->width = 0;
1402 fill->width = 0;
1403 }
1404 break;
1405 }
1406 }
1407
1408 void OnPaint() override
1409 {
1410 const Station *st = Station::Get(this->window_number);
1411 CargoDataEntry cargo;
1412 BuildCargoList(&cargo, st);
1413
1414 this->vscroll->SetCount(cargo.GetNumChildren()); // update scrollbar
1415
1416 /* disable some buttons */
1417 this->SetWidgetDisabledState(WID_SV_RENAME, st->owner != _local_company);
1418 this->SetWidgetDisabledState(WID_SV_TRAINS, !(st->facilities & FACIL_TRAIN));
1419 this->SetWidgetDisabledState(WID_SV_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
1420 this->SetWidgetDisabledState(WID_SV_SHIPS, !(st->facilities & FACIL_DOCK));
1421 this->SetWidgetDisabledState(WID_SV_PLANES, !(st->facilities & FACIL_AIRPORT));
1422 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
1423 this->SetWidgetLoweredState(WID_SV_CLOSE_AIRPORT, (st->facilities & FACIL_AIRPORT) && (st->airport.flags & AIRPORT_CLOSED_block) != 0);
1424
1425 extern const Station *_viewport_highlight_station;
1426 this->SetWidgetDisabledState(WID_SV_CATCHMENT, st->facilities == FACIL_NONE);
1427 this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st);
1428
1429 this->DrawWidgets();
1430
1431 if (!this->IsShaded()) {
1432 /* Draw 'accepted cargo' or 'cargo ratings'. */
1433 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SV_ACCEPT_RATING_LIST);
1434 const Rect r = wid->GetCurrentRect();
1435 if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1436 int lines = this->DrawAcceptedCargo(r);
1437 if (lines > this->accepts_lines) { // Resize the widget, and perform re-initialization of the window.
1438 this->accepts_lines = lines;
1439 this->ReInit();
1440 return;
1441 }
1442 } else {
1443 int lines = this->DrawCargoRatings(r);
1444 if (lines > this->rating_lines) { // Resize the widget, and perform re-initialization of the window.
1445 this->rating_lines = lines;
1446 this->ReInit();
1447 return;
1448 }
1449 }
1450
1451 /* Draw arrow pointing up/down for ascending/descending sorting */
1452 this->DrawSortButtonState(WID_SV_SORT_ORDER, sort_orders[1] == SO_ASCENDING ? SBS_UP : SBS_DOWN);
1453
1454 int pos = this->vscroll->GetPosition();
1455
1456 int maxrows = this->vscroll->GetCapacity();
1457
1458 displayed_rows.clear();
1459
1460 /* Draw waiting cargo. */
1461 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_SV_WAITING);
1462 Rect waiting_rect = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
1463 this->DrawEntries(&cargo, waiting_rect, pos, maxrows, 0);
1464 scroll_to_row = INT_MAX;
1465 }
1466 }
1467
1468 void SetStringParameters(WidgetID widget) const override
1469 {
1470 if (widget == WID_SV_CAPTION) {
1471 const Station *st = Station::Get(this->window_number);
1472 SetDParam(0, st->index);
1473 SetDParam(1, st->facilities);
1474 }
1475 }
1476
1482 void RecalcDestinations(CargoID i)
1483 {
1484 const Station *st = Station::Get(this->window_number);
1485 CargoDataEntry *cargo_entry = cached_destinations.InsertOrRetrieve(i);
1486 cargo_entry->Clear();
1487
1488 for (const auto &it : st->goods[i].flows) {
1489 StationID from = it.first;
1490 CargoDataEntry *source_entry = cargo_entry->InsertOrRetrieve(from);
1491 uint32_t prev_count = 0;
1492 for (const auto &flow_it : *it.second.GetShares()) {
1493 StationID via = flow_it.second;
1494 CargoDataEntry *via_entry = source_entry->InsertOrRetrieve(via);
1495 if (via == this->window_number) {
1496 via_entry->InsertOrRetrieve(via)->Update(flow_it.first - prev_count);
1497 } else {
1498 EstimateDestinations(i, from, via, flow_it.first - prev_count, via_entry);
1499 }
1500 prev_count = flow_it.first;
1501 }
1502 }
1503 }
1504
1514 void EstimateDestinations(CargoID cargo, StationID source, StationID next, uint count, CargoDataEntry *dest)
1515 {
1516 if (Station::IsValidID(next) && Station::IsValidID(source)) {
1517 CargoDataEntry tmp;
1518 const FlowStatMap &flowmap = Station::Get(next)->goods[cargo].flows;
1519 FlowStatMap::const_iterator map_it = flowmap.find(source);
1520 if (map_it != flowmap.end()) {
1521 const FlowStat::SharesMap *shares = map_it->second.GetShares();
1522 uint32_t prev_count = 0;
1523 for (FlowStat::SharesMap::const_iterator i = shares->begin(); i != shares->end(); ++i) {
1524 tmp.InsertOrRetrieve(i->second)->Update(i->first - prev_count);
1525 prev_count = i->first;
1526 }
1527 }
1528
1529 if (tmp.GetCount() == 0) {
1530 dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1531 } else {
1532 uint sum_estimated = 0;
1533 while (sum_estimated < count) {
1534 for (CargoDataSet::iterator i = tmp.Begin(); i != tmp.End() && sum_estimated < count; ++i) {
1535 CargoDataEntry *child = *i;
1536 uint estimate = DivideApprox(child->GetCount() * count, tmp.GetCount());
1537 if (estimate == 0) estimate = 1;
1538
1539 sum_estimated += estimate;
1540 if (sum_estimated > count) {
1541 estimate -= sum_estimated - count;
1542 sum_estimated = count;
1543 }
1544
1545 if (estimate > 0) {
1546 if (child->GetStation() == next) {
1547 dest->InsertOrRetrieve(next)->Update(estimate);
1548 } else {
1549 EstimateDestinations(cargo, source, child->GetStation(), estimate, dest);
1550 }
1551 }
1552 }
1553
1554 }
1555 }
1556 } else {
1557 dest->InsertOrRetrieve(INVALID_STATION)->Update(count);
1558 }
1559 }
1560
1567 void BuildFlowList(CargoID i, const FlowStatMap &flows, CargoDataEntry *cargo)
1568 {
1569 const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1570 for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1571 StationID from = it->first;
1572 const CargoDataEntry *source_entry = source_dest->Retrieve(from);
1573 const FlowStat::SharesMap *shares = it->second.GetShares();
1574 for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1575 const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second);
1576 for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1577 CargoDataEntry *dest_entry = *dest_it;
1578 ShowCargo(cargo, i, from, flow_it->second, dest_entry->GetStation(), dest_entry->GetCount());
1579 }
1580 }
1581 }
1582 }
1583
1590 void BuildCargoList(CargoID i, const StationCargoList &packets, CargoDataEntry *cargo)
1591 {
1592 const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(i);
1593 for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) {
1594 const CargoPacket *cp = *it;
1595 StationID next = it.GetKey();
1596
1597 const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation());
1598 if (source_entry == nullptr) {
1599 this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count());
1600 continue;
1601 }
1602
1603 const CargoDataEntry *via_entry = source_entry->Retrieve(next);
1604 if (via_entry == nullptr) {
1605 this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count());
1606 continue;
1607 }
1608
1609 uint remaining = cp->Count();
1610 for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End();) {
1611 CargoDataEntry *dest_entry = *dest_it;
1612
1613 /* Advance iterator here instead of in the for statement to test whether this is the last entry */
1614 ++dest_it;
1615
1616 uint val;
1617 if (dest_it == via_entry->End()) {
1618 /* Allocate all remaining waiting cargo to the last destination to avoid
1619 * waiting cargo being "lost", and the displayed total waiting cargo
1620 * not matching GoodsEntry::TotalCount() */
1621 val = remaining;
1622 } else {
1623 val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry->GetCount(), via_entry->GetCount()));
1624 remaining -= val;
1625 }
1626 this->ShowCargo(cargo, i, cp->GetFirstStation(), next, dest_entry->GetStation(), val);
1627 }
1628 }
1629 this->ShowCargo(cargo, i, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
1630 }
1631
1637 void BuildCargoList(CargoDataEntry *cargo, const Station *st)
1638 {
1639 for (CargoID i = 0; i < NUM_CARGO; i++) {
1640
1641 if (this->cached_destinations.Retrieve(i) == nullptr) {
1642 this->RecalcDestinations(i);
1643 }
1644
1645 if (this->current_mode == MODE_WAITING) {
1646 this->BuildCargoList(i, st->goods[i].cargo, cargo);
1647 } else {
1648 this->BuildFlowList(i, st->goods[i].flows, cargo);
1649 }
1650 }
1651 }
1652
1657 void SetDisplayedRow(const CargoDataEntry *data)
1658 {
1659 std::list<StationID> stations;
1660 const CargoDataEntry *parent = data->GetParent();
1661 if (parent->GetParent() == nullptr) {
1662 this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, data->GetCargo()));
1663 return;
1664 }
1665
1666 StationID next = data->GetStation();
1667 while (parent->GetParent()->GetParent() != nullptr) {
1668 stations.push_back(parent->GetStation());
1669 parent = parent->GetParent();
1670 }
1671
1672 CargoID cargo = parent->GetCargo();
1673 CargoDataEntry *filter = this->expanded_rows.Retrieve(cargo);
1674 while (!stations.empty()) {
1675 filter = filter->Retrieve(stations.back());
1676 stations.pop_back();
1677 }
1678
1679 this->displayed_rows.push_back(RowDisplay(filter, next));
1680 }
1681
1690 StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any)
1691 {
1692 if (station == this->window_number) {
1693 return here;
1694 } else if (station == INVALID_STATION) {
1695 return any;
1696 } else if (station == NEW_STATION) {
1697 return STR_STATION_VIEW_RESERVED;
1698 } else {
1699 SetDParam(2, station);
1700 return other_station;
1701 }
1702 }
1703
1711 StringID SearchNonStop(CargoDataEntry *cd, StationID station, int column)
1712 {
1713 CargoDataEntry *parent = cd->GetParent();
1714 for (int i = column - 1; i > 0; --i) {
1715 if (this->groupings[i] == GR_DESTINATION) {
1716 if (parent->GetStation() == station) {
1717 return STR_STATION_VIEW_NONSTOP;
1718 } else {
1719 return STR_STATION_VIEW_VIA;
1720 }
1721 }
1722 parent = parent->GetParent();
1723 }
1724
1725 if (this->groupings[column + 1] == GR_DESTINATION) {
1726 CargoDataSet::iterator begin = cd->Begin();
1727 CargoDataSet::iterator end = cd->End();
1728 if (begin != end && ++(cd->Begin()) == end && (*(begin))->GetStation() == station) {
1729 return STR_STATION_VIEW_NONSTOP;
1730 } else {
1731 return STR_STATION_VIEW_VIA;
1732 }
1733 }
1734
1735 return STR_STATION_VIEW_VIA;
1736 }
1737
1748 int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo = INVALID_CARGO)
1749 {
1750 if (this->sortings[column] == CargoSortType::AsGrouping) {
1751 if (this->groupings[column] != GR_CARGO) {
1752 entry->Resort(CargoSortType::StationString, this->sort_orders[column]);
1753 }
1754 } else {
1755 entry->Resort(CargoSortType::Count, this->sort_orders[column]);
1756 }
1757 for (CargoDataSet::iterator i = entry->Begin(); i != entry->End(); ++i) {
1758 CargoDataEntry *cd = *i;
1759
1760 Grouping grouping = this->groupings[column];
1761 if (grouping == GR_CARGO) cargo = cd->GetCargo();
1762 bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DT_MANUAL;
1763
1764 if (pos > -maxrows && pos <= 0) {
1765 StringID str = STR_EMPTY;
1766 int y = r.top - pos * GetCharacterHeight(FS_NORMAL);
1767 SetDParam(0, cargo);
1768 SetDParam(1, cd->GetCount());
1769
1770 if (this->groupings[column] == GR_CARGO) {
1771 str = STR_STATION_VIEW_WAITING_CARGO;
1772 DrawCargoIcons(cd->GetCargo(), cd->GetCount(), r.left + this->expand_shrink_width, r.right - this->expand_shrink_width, y);
1773 } else {
1774 if (!auto_distributed) grouping = GR_SOURCE;
1775 StationID station = cd->GetStation();
1776
1777 switch (grouping) {
1778 case GR_SOURCE:
1779 str = this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
1780 break;
1781 case GR_NEXT:
1782 str = this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
1783 if (str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
1784 break;
1785 case GR_DESTINATION:
1786 str = this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
1787 break;
1788 default:
1789 NOT_REACHED();
1790 }
1791 if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
1792 ScrollMainWindowToTile(Station::Get(station)->xy);
1793 }
1794 }
1795
1796 bool rtl = _current_text_dir == TD_RTL;
1797 Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl);
1798 Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl);
1799
1800 DrawString(text.left, text.right, y, str);
1801
1802 if (column < NUM_COLUMNS - 1) {
1803 const char *sym = nullptr;
1804 if (cd->GetNumChildren() > 0) {
1805 sym = "-";
1806 } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
1807 sym = "+";
1808 } else {
1809 /* Only draw '+' if there is something to be shown. */
1810 const StationCargoList &list = Station::Get(this->window_number)->goods[cargo].cargo;
1811 if (grouping == GR_CARGO && (list.ReservedCount() > 0 || cd->HasTransfers())) {
1812 sym = "+";
1813 }
1814 }
1815 if (sym != nullptr) DrawString(shrink.left, shrink.right, y, sym, TC_YELLOW);
1816 }
1817 this->SetDisplayedRow(cd);
1818 }
1819 --pos;
1820 if (auto_distributed || column == 0) {
1821 pos = this->DrawEntries(cd, r, pos, maxrows, column + 1, cargo);
1822 }
1823 }
1824 return pos;
1825 }
1826
1832 int DrawAcceptedCargo(const Rect &r) const
1833 {
1834 const Station *st = Station::Get(this->window_number);
1835 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1836
1837 SetDParam(0, GetAcceptanceMask(st));
1838 int bottom = DrawStringMultiLine(tr.left, tr.right, tr.top, INT32_MAX, STR_STATION_VIEW_ACCEPTS_CARGO);
1839 return CeilDiv(bottom - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FS_NORMAL));
1840 }
1841
1847 int DrawCargoRatings(const Rect &r) const
1848 {
1849 const Station *st = Station::Get(this->window_number);
1850 bool rtl = _current_text_dir == TD_RTL;
1851 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1852
1853 if (st->town->exclusive_counter > 0) {
1854 SetDParam(0, st->town->exclusivity);
1855 tr.top = DrawStringMultiLine(tr, st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY);
1856 tr.top += WidgetDimensions::scaled.vsep_wide;
1857 }
1858
1859 DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_VIEW_SUPPLY_RATINGS_TITLE_MINUTE : STR_STATION_VIEW_SUPPLY_RATINGS_TITLE_MONTH);
1860 tr.top += GetCharacterHeight(FS_NORMAL);
1861
1862 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1863 const GoodsEntry *ge = &st->goods[cs->Index()];
1864 if (!ge->HasRating()) continue;
1865
1866 const LinkGraph *lg = LinkGraph::GetIfValid(ge->link_graph);
1867 SetDParam(0, cs->name);
1868 SetDParam(1, lg != nullptr ? lg->Monthly((*lg)[ge->node].supply) : 0);
1869 SetDParam(2, STR_CARGO_RATING_APPALLING + (ge->rating >> 5));
1870 SetDParam(3, ToPercent8(ge->rating));
1871 DrawString(tr.Indent(WidgetDimensions::scaled.hsep_indent, rtl), STR_STATION_VIEW_CARGO_SUPPLY_RATING);
1872 tr.top += GetCharacterHeight(FS_NORMAL);
1873 }
1874 return CeilDiv(tr.top - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FS_NORMAL));
1875 }
1876
1882 template<class Tid>
1883 void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
1884 {
1885 if (filter->Retrieve(next) != nullptr) {
1886 filter->Remove(next);
1887 } else {
1888 filter->InsertOrRetrieve(next);
1889 }
1890 }
1891
1896 void HandleCargoWaitingClick(int row)
1897 {
1898 if (row < 0 || (uint)row >= this->displayed_rows.size()) return;
1899 if (_ctrl_pressed) {
1900 this->scroll_to_row = row;
1901 } else {
1902 RowDisplay &display = this->displayed_rows[row];
1903 if (display.filter == &this->expanded_rows) {
1904 this->HandleCargoWaitingClick<CargoID>(display.filter, display.next_cargo);
1905 } else {
1906 this->HandleCargoWaitingClick<StationID>(display.filter, display.next_station);
1907 }
1908 }
1909 this->SetWidgetDirty(WID_SV_WAITING);
1910 }
1911
1912 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1913 {
1914 switch (widget) {
1915 case WID_SV_WAITING:
1916 this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WidgetDimensions::scaled.framerect.top) - this->vscroll->GetPosition());
1917 break;
1918
1919 case WID_SV_CATCHMENT:
1920 SetViewportCatchmentStation(Station::Get(this->window_number), !this->IsWidgetLowered(WID_SV_CATCHMENT));
1921 break;
1922
1923 case WID_SV_LOCATION:
1924 if (_ctrl_pressed) {
1925 ShowExtraViewportWindow(Station::Get(this->window_number)->xy);
1926 } else {
1927 ScrollMainWindowToTile(Station::Get(this->window_number)->xy);
1928 }
1929 break;
1930
1931 case WID_SV_ACCEPTS_RATINGS: {
1932 /* Swap between 'accepts' and 'ratings' view. */
1933 int height_change;
1934 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS);
1935 if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) {
1936 nwi->SetDataTip(STR_STATION_VIEW_ACCEPTS_BUTTON, STR_STATION_VIEW_ACCEPTS_TOOLTIP); // Switch to accepts view.
1937 height_change = this->rating_lines - this->accepts_lines;
1938 } else {
1939 nwi->SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP); // Switch to ratings view.
1940 height_change = this->accepts_lines - this->rating_lines;
1941 }
1942 this->ReInit(0, height_change * GetCharacterHeight(FS_NORMAL));
1943 break;
1944 }
1945
1946 case WID_SV_RENAME:
1947 SetDParam(0, this->window_number);
1948 ShowQueryString(STR_STATION_NAME, STR_STATION_VIEW_RENAME_STATION_CAPTION, MAX_LENGTH_STATION_NAME_CHARS,
1949 this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
1950 break;
1951
1952 case WID_SV_CLOSE_AIRPORT:
1953 Command<CMD_OPEN_CLOSE_AIRPORT>::Post(this->window_number);
1954 break;
1955
1956 case WID_SV_TRAINS: // Show list of scheduled trains to this station
1957 case WID_SV_ROADVEHS: // Show list of scheduled road-vehicles to this station
1958 case WID_SV_SHIPS: // Show list of scheduled ships to this station
1959 case WID_SV_PLANES: { // Show list of scheduled aircraft to this station
1960 Owner owner = Station::Get(this->window_number)->owner;
1961 ShowVehicleListWindow(owner, (VehicleType)(widget - WID_SV_TRAINS), (StationID)this->window_number);
1962 break;
1963 }
1964
1965 case WID_SV_SORT_BY: {
1966 /* The initial selection is composed of current mode and
1967 * sorting criteria for columns 1, 2, and 3. Column 0 is always
1968 * sorted by cargo ID. The others can theoretically be sorted
1969 * by different things but there is no UI for that. */
1970 ShowDropDownMenu(this, _sort_names,
1971 this->current_mode * 2 + (this->sortings[1] == CargoSortType::Count ? 1 : 0),
1972 WID_SV_SORT_BY, 0, 0);
1973 break;
1974 }
1975
1976 case WID_SV_GROUP_BY: {
1977 ShowDropDownMenu(this, _group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
1978 break;
1979 }
1980
1981 case WID_SV_SORT_ORDER: { // flip sorting method asc/desc
1982 this->SelectSortOrder(this->sort_orders[1] == SO_ASCENDING ? SO_DESCENDING : SO_ASCENDING);
1983 this->SetTimeout();
1984 this->LowerWidget(WID_SV_SORT_ORDER);
1985 break;
1986 }
1987 }
1988 }
1989
1994 void SelectSortOrder(SortOrder order)
1995 {
1996 this->sort_orders[1] = this->sort_orders[2] = this->sort_orders[3] = order;
1997 _settings_client.gui.station_gui_sort_order = this->sort_orders[1];
1998 this->SetDirty();
1999 }
2000
2005 void SelectSortBy(int index)
2006 {
2007 _settings_client.gui.station_gui_sort_by = index;
2008 switch (_sort_names[index]) {
2009 case STR_STATION_VIEW_WAITING_STATION:
2010 this->current_mode = MODE_WAITING;
2011 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
2012 break;
2013 case STR_STATION_VIEW_WAITING_AMOUNT:
2014 this->current_mode = MODE_WAITING;
2015 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
2016 break;
2017 case STR_STATION_VIEW_PLANNED_STATION:
2018 this->current_mode = MODE_PLANNED;
2019 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
2020 break;
2021 case STR_STATION_VIEW_PLANNED_AMOUNT:
2022 this->current_mode = MODE_PLANNED;
2023 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
2024 break;
2025 default:
2026 NOT_REACHED();
2027 }
2028 /* Display the current sort variant */
2029 this->GetWidget<NWidgetCore>(WID_SV_SORT_BY)->widget_data = _sort_names[index];
2030 this->SetDirty();
2031 }
2032
2037 void SelectGroupBy(int index)
2038 {
2039 this->grouping_index = index;
2040 _settings_client.gui.station_gui_group_order = index;
2041 this->GetWidget<NWidgetCore>(WID_SV_GROUP_BY)->widget_data = _group_names[index];
2042 switch (_group_names[index]) {
2043 case STR_STATION_VIEW_GROUP_S_V_D:
2044 this->groupings[1] = GR_SOURCE;
2045 this->groupings[2] = GR_NEXT;
2046 this->groupings[3] = GR_DESTINATION;
2047 break;
2048 case STR_STATION_VIEW_GROUP_S_D_V:
2049 this->groupings[1] = GR_SOURCE;
2050 this->groupings[2] = GR_DESTINATION;
2051 this->groupings[3] = GR_NEXT;
2052 break;
2053 case STR_STATION_VIEW_GROUP_V_S_D:
2054 this->groupings[1] = GR_NEXT;
2055 this->groupings[2] = GR_SOURCE;
2056 this->groupings[3] = GR_DESTINATION;
2057 break;
2058 case STR_STATION_VIEW_GROUP_V_D_S:
2059 this->groupings[1] = GR_NEXT;
2060 this->groupings[2] = GR_DESTINATION;
2061 this->groupings[3] = GR_SOURCE;
2062 break;
2063 case STR_STATION_VIEW_GROUP_D_S_V:
2064 this->groupings[1] = GR_DESTINATION;
2065 this->groupings[2] = GR_SOURCE;
2066 this->groupings[3] = GR_NEXT;
2067 break;
2068 case STR_STATION_VIEW_GROUP_D_V_S:
2069 this->groupings[1] = GR_DESTINATION;
2070 this->groupings[2] = GR_NEXT;
2071 this->groupings[3] = GR_SOURCE;
2072 break;
2073 }
2074 this->SetDirty();
2075 }
2076
2077 void OnDropdownSelect(WidgetID widget, int index) override
2078 {
2079 if (widget == WID_SV_SORT_BY) {
2080 this->SelectSortBy(index);
2081 } else {
2082 this->SelectGroupBy(index);
2083 }
2084 }
2085
2086 void OnQueryTextFinished(char *str) override
2087 {
2088 if (str == nullptr) return;
2089
2090 Command<CMD_RENAME_STATION>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, str);
2091 }
2092
2093 void OnResize() override
2094 {
2095 this->vscroll->SetCapacityFromWidget(this, WID_SV_WAITING, WidgetDimensions::scaled.framerect.Vertical());
2096 }
2097
2103 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2104 {
2105 if (gui_scope) {
2106 if (data >= 0 && data < NUM_CARGO) {
2107 this->cached_destinations.Remove((CargoID)data);
2108 } else {
2109 this->ReInit();
2110 }
2111 }
2112 }
2113 };
2114
2115 const StringID StationViewWindow::_sort_names[] = {
2116 STR_STATION_VIEW_WAITING_STATION,
2117 STR_STATION_VIEW_WAITING_AMOUNT,
2118 STR_STATION_VIEW_PLANNED_STATION,
2119 STR_STATION_VIEW_PLANNED_AMOUNT,
2120 INVALID_STRING_ID
2121 };
2122
2123 const StringID StationViewWindow::_group_names[] = {
2124 STR_STATION_VIEW_GROUP_S_V_D,
2125 STR_STATION_VIEW_GROUP_S_D_V,
2126 STR_STATION_VIEW_GROUP_V_S_D,
2127 STR_STATION_VIEW_GROUP_V_D_S,
2128 STR_STATION_VIEW_GROUP_D_S_V,
2129 STR_STATION_VIEW_GROUP_D_V_S,
2130 INVALID_STRING_ID
2131 };
2132
2133 static WindowDesc _station_view_desc(__FILE__, __LINE__,
2134 WDP_AUTO, "view_station", 249, 117,
2135 WC_STATION_VIEW, WC_NONE,
2136 0,
2137 std::begin(_nested_station_view_widgets), std::end(_nested_station_view_widgets)
2138 );
2139
2145 void ShowStationViewWindow(StationID station)
2146 {
2147 AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
2148 }
2149
2151 struct TileAndStation {
2152 TileIndex tile;
2153 StationID station;
2154 };
2155
2156 static std::vector<TileAndStation> _deleted_stations_nearby;
2157 static std::vector<StationID> _stations_nearby_list;
2158
2166 template <class T>
2167 static bool AddNearbyStation(TileIndex tile, void *user_data)
2168 {
2169 TileArea *ctx = (TileArea *)user_data;
2170
2171 /* First check if there were deleted stations here */
2172 for (auto it = _deleted_stations_nearby.begin(); it != _deleted_stations_nearby.end(); /* nothing */) {
2173 if (it->tile == tile) {
2174 _stations_nearby_list.push_back(it->station);
2175 it = _deleted_stations_nearby.erase(it);
2176 } else {
2177 ++it;
2178 }
2179 }
2180
2181 /* Check if own station and if we stay within station spread */
2182 if (!IsTileType(tile, MP_STATION)) return false;
2183
2184 StationID sid = GetStationIndex(tile);
2185
2186 /* This station is (likely) a waypoint */
2187 if (!T::IsValidID(sid)) return false;
2188
2189 T *st = T::Get(sid);
2190 if (st->owner != _local_company || std::find(_stations_nearby_list.begin(), _stations_nearby_list.end(), sid) != _stations_nearby_list.end()) return false;
2191
2192 if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
2193 _stations_nearby_list.push_back(sid);
2194 }
2195
2196 return false; // We want to include *all* nearby stations
2197 }
2198
2208 template <class T>
2209 static const T *FindStationsNearby(TileArea ta, bool distant_join)
2210 {
2211 TileArea ctx = ta;
2212
2213 _stations_nearby_list.clear();
2214 _stations_nearby_list.push_back(NEW_STATION);
2215 _deleted_stations_nearby.clear();
2216
2217 /* Check the inside, to return, if we sit on another station */
2218 for (TileIndex t : ta) {
2219 if (t < Map::Size() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
2220 }
2221
2222 /* Look for deleted stations */
2223 for (const BaseStation *st : BaseStation::Iterate()) {
2224 if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
2225 /* Include only within station spread (yes, it is strictly less than) */
2226 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) {
2227 _deleted_stations_nearby.push_back({st->xy, st->index});
2228
2229 /* Add the station when it's within where we're going to build */
2230 if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
2231 IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
2232 AddNearbyStation<T>(st->xy, &ctx);
2233 }
2234 }
2235 }
2236 }
2237
2238 /* Only search tiles where we have a chance to stay within the station spread.
2239 * The complete check needs to be done in the callback as we don't know the
2240 * extent of the found station, yet. */
2241 if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return nullptr;
2242 uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1;
2243
2244 TileIndex tile = TileAddByDir(ctx.tile, DIR_N);
2245 CircularTileSearch(&tile, max_dist, ta.w, ta.h, AddNearbyStation<T>, &ctx);
2246
2247 return nullptr;
2248 }
2249
2250 static constexpr NWidgetPart _nested_select_station_widgets[] = {
2251 NWidget(NWID_HORIZONTAL),
2252 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
2253 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_JS_CAPTION), SetDataTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2254 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
2255 EndContainer(),
2256 NWidget(NWID_HORIZONTAL),
2257 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_JS_PANEL), SetResize(1, 0), SetScrollbar(WID_JS_SCROLLBAR), EndContainer(),
2258 NWidget(NWID_VERTICAL),
2259 NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_JS_SCROLLBAR),
2260 NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
2261 EndContainer(),
2262 EndContainer(),
2263 };
2264
2269 template <class T>
2270 struct SelectStationWindow : Window {
2271 StationPickerCmdProc select_station_proc;
2272 TileArea area;
2273 Scrollbar *vscroll;
2274
2275 SelectStationWindow(WindowDesc *desc, TileArea ta, StationPickerCmdProc&& proc) :
2276 Window(desc),
2277 select_station_proc(std::move(proc)),
2278 area(ta)
2279 {
2280 this->CreateNestedTree();
2281 this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR);
2282 this->GetWidget<NWidgetCore>(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION;
2283 this->FinishInitNested(0);
2284 this->OnInvalidateData(0);
2285
2286 _thd.freeze = true;
2287 }
2288
2289 void Close([[maybe_unused]] int data = 0) override
2290 {
2291 SetViewportCatchmentSpecializedStation<T>(nullptr, true);
2292
2293 _thd.freeze = false;
2294 this->Window::Close();
2295 }
2296
2297 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
2298 {
2299 if (widget != WID_JS_PANEL) return;
2300
2301 /* Determine the widest string */
2302 Dimension d = GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2303 for (const auto &station : _stations_nearby_list) {
2304 if (station == NEW_STATION) continue;
2305 const T *st = T::Get(station);
2306 SetDParam(0, st->index);
2307 SetDParam(1, st->facilities);
2308 d = maxdim(d, GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION));
2309 }
2310
2311 resize->height = d.height;
2312 d.height *= 5;
2313 d.width += padding.width;
2314 d.height += padding.height;
2315 *size = d;
2316 }
2317
2318 void DrawWidget(const Rect &r, WidgetID widget) const override
2319 {
2320 if (widget != WID_JS_PANEL) return;
2321
2322 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
2323 for (uint i = this->vscroll->GetPosition(); i < _stations_nearby_list.size(); ++i, tr.top += this->resize.step_height) {
2324 if (_stations_nearby_list[i] == NEW_STATION) {
2325 DrawString(tr, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
2326 } else {
2327 const T *st = T::Get(_stations_nearby_list[i]);
2328 SetDParam(0, st->index);
2329 SetDParam(1, st->facilities);
2330 DrawString(tr, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION);
2331 }
2332 }
2333
2334 }
2335
2336 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2337 {
2338 if (widget != WID_JS_PANEL) return;
2339
2340 auto it = this->vscroll->GetScrolledItemFromWidget(_stations_nearby_list, pt.y, this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.top);
2341 if (it == _stations_nearby_list.end()) return;
2342
2343 /* Execute stored Command */
2344 this->select_station_proc(false, *it);
2345
2346 /* Close Window; this might cause double frees! */
2347 CloseWindowById(WC_SELECT_STATION, 0);
2348 }
2349
2350 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
2351 {
2352 if (_thd.dirty & 2) {
2353 _thd.dirty &= ~2;
2354 this->SetDirty();
2355 }
2356 }
2357
2358 void OnResize() override
2359 {
2360 this->vscroll->SetCapacityFromWidget(this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.Vertical());
2361 }
2362
2368 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2369 {
2370 if (!gui_scope) return;
2371 FindStationsNearby<T>(this->area, true);
2372 this->vscroll->SetCount(_stations_nearby_list.size());
2373 this->SetDirty();
2374 }
2375
2376 void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
2377 {
2378 if (widget != WID_JS_PANEL) {
2379 SetViewportCatchmentSpecializedStation<T>(nullptr, true);
2380 return;
2381 }
2382
2383 /* Show coverage area of station under cursor */
2384 auto it = this->vscroll->GetScrolledItemFromWidget(_stations_nearby_list, pt.y, this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.top);
2385 const T *st = it == _stations_nearby_list.end() || *it == NEW_STATION ? nullptr : T::Get(*it);
2386 SetViewportCatchmentSpecializedStation<T>(st, true);
2387 }
2388 };
2389
2390 static WindowDesc _select_station_desc(__FILE__, __LINE__,
2391 WDP_AUTO, "build_station_join", 200, 180,
2392 WC_SELECT_STATION, WC_NONE,
2393 WDF_CONSTRUCTION,
2394 std::begin(_nested_select_station_widgets), std::end(_nested_select_station_widgets)
2395 );
2396
2397
2405 template <class T>
2406 static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
2407 {
2408 /* Only show selection if distant join is enabled in the settings */
2409 if (!_settings_game.station.distant_join_stations) return false;
2410
2411 /* If a window is already opened and we didn't ctrl-click,
2412 * return true (i.e. just flash the old window) */
2413 Window *selection_window = FindWindowById(WC_SELECT_STATION, 0);
2414 if (selection_window != nullptr) {
2415 /* Abort current distant-join and start new one */
2416 selection_window->Close();
2417 UpdateTileSelection();
2418 }
2419
2420 /* only show the popup, if we press ctrl */
2421 if (!_ctrl_pressed) return false;
2422
2423 /* Now check if we could build there */
2424 if (!proc(true, INVALID_STATION)) return false;
2425
2426 /* Test for adjacent station or station below selection.
2427 * If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
2428 * but join the other station immediately. */
2429 const T *st = FindStationsNearby<T>(ta, false);
2430 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; }));
2431 }
2432
2439 template <class T>
2440 void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc&& proc)
2441 {
2442 if (StationJoinerNeeded<T>(ta, proc)) {
2443 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
2444 new SelectStationWindow<T>(&_select_station_desc, ta, std::move(proc));
2445 } else {
2446 proc(false, INVALID_STATION);
2447 }
2448 }
2449
2455 void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
2456 {
2457 ShowSelectBaseStationIfNeeded<Station>(ta, std::move(proc));
2458 }
2459
2465 void ShowSelectWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
2466 {
2467 ShowSelectBaseStationIfNeeded<Waypoint>(ta, std::move(proc));
2468 }
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:1299
StationJoinerNeeded
static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
Check whether we need to show the station selection window.
Definition: station_gui.cpp:2406
StationViewWindow::HandleCargoWaitingClick
void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
Expand or collapse a specific row.
Definition: station_gui.cpp:1883
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:1143
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
CargoFilterCriteria::CF_SELECT_ALL
static constexpr CargoID CF_SELECT_ALL
Select all items (station list)
Definition: cargo_type.h:100
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
StationViewWindow
The StationView window.
Definition: station_gui.cpp:1218
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:629
StationViewWindow::ALH_ACCEPTS
@ ALH_ACCEPTS
Height of the accepted cargo view.
Definition: station_gui.cpp:1281
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:1229
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:350
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:893
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:168
company_base.h
StationViewWindow::INV_FLOWS
@ INV_FLOWS
The planned flows have been recalculated and everything has to be updated.
Definition: station_gui.cpp:1251
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:1019
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:252
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
CargoFilterCriteria::CF_EXPAND_LIST
static constexpr CargoID CF_EXPAND_LIST
Expand list to show all items (station list)
Definition: cargo_type.h:101
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:852
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:2350
SelectStationWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: station_gui.cpp:2358
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
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:210
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:238
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:131
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:114
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:309
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:1304
StationViewWindow::RowDisplay
A row being displayed in the cargo view (as opposed to being "hidden" behind a plus sign).
Definition: station_gui.cpp:1222
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:962
StationViewWindow::SelectSortBy
void SelectSortBy(int index)
Select a new sort criterium for the cargo view.
Definition: station_gui.cpp:2005
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
_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:1590
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:830
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:2341
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:1637
StationViewWindow::DrawCargoRatings
int DrawCargoRatings(const Rect &r) const
Draw cargo ratings in the WID_SV_ACCEPT_RATING_LIST widget.
Definition: station_gui.cpp:1847
ShowCompanyStations
void ShowCompanyStations(CompanyID company)
Opens window with list of company's stations.
Definition: station_gui.cpp:777
AddNearbyStation
static bool AddNearbyStation(TileIndex tile, void *user_data)
Add station on this tile to _stations_nearby_list if it's fully within the station spread.
Definition: station_gui.cpp:2167
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:68
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:967
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:154
StationViewWindow::_sort_names
static const StringID _sort_names[]
Names of the sorting options in the dropdown.
Definition: station_gui.cpp:1284
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:50
CompanyStationsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: station_gui.cpp:440
StationViewWindow::GR_DESTINATION
@ GR_DESTINATION
Group by estimated final destination ("to").
Definition: station_gui.cpp:1261
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:1711
SelectStationWindow::area
TileArea area
Location of new station.
Definition: station_gui.cpp:2272
CompanyStationsWindow::StationTypeSorter
static bool StationTypeSorter(const Station *const &a, const Station *const &b, const CargoTypes &)
Sort stations by their type.
Definition: station_gui.cpp:303
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:680
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:1273
StationViewWindow::MODE_PLANNED
@ MODE_PLANNED
Show cargo planned to pass through the station.
Definition: station_gui.cpp:1270
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
CargoDataEntry::children
CargoDataSet * children
the children of this entry.
Definition: station_gui.cpp:1025
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:1259
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:722
StationViewWindow::AcceptListHeight
AcceptListHeight
Height of the WID_SV_ACCEPT_RATING_LIST widget for different views.
Definition: station_gui.cpp:1279
CompanyStationsWindow::FilterState::include_no_rating
bool include_no_rating
Whether we should include stations with no cargo rating.
Definition: station_gui.cpp:224
ShowStationViewWindow
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
Definition: station_gui.cpp:2145
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:1252
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:704
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:903
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:1300
StationViewWindow::NUM_COLUMNS
static const int NUM_COLUMNS
Number of "columns" in the cargo view: cargo, from, via, to.
Definition: station_gui.cpp:1245
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:2093
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:1023
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:510
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:169
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
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:295
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:1690
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1088
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:347
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:1293
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:977
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:2368
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:1832
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
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:1657
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:1348
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:1234
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:690
CargoSpec::IsValid
bool IsValid() const
Tests for validity of this cargospec.
Definition: cargotype.h:112
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:1896
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:1408
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:333
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:713
ShowSelectStationIfNeeded
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
Definition: station_gui.cpp:2455
_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:1567
SelectStationWindow
Window for selecting stations/waypoints to (distant) join to.
Definition: station_gui.cpp:2270
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:1260
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:50
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:1087
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:946
ShowSelectWaypointIfNeeded
void ShowSelectWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the waypoint selection window when needed.
Definition: station_gui.cpp:2465
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:1017
StationViewWindow::groupings
Grouping groupings[NUM_COLUMNS]
Grouping modes for the different columns.
Definition: station_gui.cpp:1301
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:1482
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:321
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:1003
TileAndStation::tile
TileIndex tile
TileIndex.
Definition: station_gui.cpp:2152
StationViewWindow::MODE_WAITING
@ MODE_WAITING
Show cargo waiting at the station.
Definition: station_gui.cpp:1269
CargoDataEntry::Remove
void Remove(StationID station)
Remove a child associated with the given station.
Definition: station_gui.cpp:914
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
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:628
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
CargoDataEntry::GetParent
CargoDataEntry * GetParent() const
Get the parent entry for this entry.
Definition: station_gui.cpp:972
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:847
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:411
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:594
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
CountBits
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:243
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:49
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:361
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:1285
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:2267
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
CompanyStationsWindow::stations_per_cargo_type
std::array< uint16_t, NUM_CARGO > stations_per_cargo_type
Number of stations with a rating for each cargo type.
Definition: station_gui.cpp:244
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:997
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:771
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:388
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:1250
StationViewWindow::displayed_rows
CargoDataVector displayed_rows
Parent entry of currently displayed rows (including collapsed ones).
Definition: station_gui.cpp:1305
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:557
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:1132
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:935
CargoDataEntry::Clear
void Clear()
Delete all subentries, reset count and num_children and adapt parent's count.
Definition: station_gui.cpp:1077
CargoDataEntry::GetStation
StationID GetStation() const
Get the station ID for this entry.
Definition: station_gui.cpp:957
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition: window.cpp:1036
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:1239
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:1296
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_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:2153
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:762
waypoint_base.h
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
cargotype.h
linkgraph.h
CompanyStationsWindow::stations_per_cargo_type_no_rating
uint16_t stations_per_cargo_type_no_rating
Number of stations without a rating.
Definition: station_gui.cpp:245
StationViewWindow::Mode
Mode
Display mode of the cargo view.
Definition: station_gui.cpp:1268
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:85
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
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:374
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:2621
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:992
CargoSpec::abbrev
StringID abbrev
Two letter abbreviation for this cargo type.
Definition: cargotype.h:89
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:592
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:2103
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:1260
CommandHelper
Definition: command_func.h:93
StationViewWindow::ALH_RATING
@ ALH_RATING
Height of the cargo ratings view.
Definition: station_gui.cpp:1280
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:591
window_func.h
WID_STL_SORTDROPBTN
@ WID_STL_SORTDROPBTN
Dropdown button.
Definition: station_widget.h:50
CargoDataEntry
A cargo data entry representing one possible row in the station view window's top part.
Definition: station_gui.cpp:883
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:1099
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:1994
StationViewWindow::SelectGroupBy
void SelectGroupBy(int index)
Select a new grouping mode for the cargo view.
Definition: station_gui.cpp:2037
CargoDataEntry::count
uint count
sum of counts of all children or amount of cargo for this entry.
Definition: station_gui.cpp:1024
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:654
StationViewWindow::accepts_lines
int accepts_lines
Number of lines in the accepted cargo view.
Definition: station_gui.cpp:1275
CargoDataEntry::parent
CargoDataEntry * parent
the parent of this entry.
Definition: station_gui.cpp:1015
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:1298
CargoSorter
Definition: station_gui.cpp:860
DropDownCheck
Drop down checkmark component.
Definition: dropdown_type.h:178
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:924
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:1262
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:682
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:328
StationViewWindow::rating_lines
int rating_lines
Number of lines in the cargo ratings view.
Definition: station_gui.cpp:1274
_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:1303
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:74
StationViewWindow::Grouping
Grouping
Type of grouping used in each of the "columns".
Definition: station_gui.cpp:1258
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
CargoFilterCriteria::CF_NO_RATING
static constexpr CargoID CF_NO_RATING
Show items with no rating (station list)
Definition: cargo_type.h:99
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:1514
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:230
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
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
TileAndStation
Struct containing TileIndex and StationID.
Definition: station_gui.cpp:2151
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
DropDownString
Drop down string component.
Definition: dropdown_type.h:82
FindStationsNearby
static const T * FindStationsNearby(TileArea ta, bool distant_join)
Circulate around the to-be-built station to find stations we could join.
Definition: station_gui.cpp:2209
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
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:1122
TileHighlightData::freeze
bool freeze
Freeze highlight in place.
Definition: tilehighlight_type.h:53
GetLargestCargoIconSize
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
Definition: cargotype.cpp:124
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:848
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:982
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:635
station_widget.h
debug.h
WID_STL_CARGODROPDOWN
@ WID_STL_CARGODROPDOWN
Cargo type dropdown list.
Definition: station_widget.h:52
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:1020
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:700
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:1748
ShowSelectBaseStationIfNeeded
void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc &&proc)
Show the station selection window when needed.
Definition: station_gui.cpp:2440
CargoDataEntry::IncrementSize
void IncrementSize()
Increment.
Definition: station_gui.cpp:1141
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:987
FindFirstBit
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
Definition: bitmath_func.hpp:194
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