OpenTTD Source 20260512-master-g20b387b91f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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 "dropdown_type.h"
24#include "dropdown_func.h"
25#include "station_base.h"
26#include "waypoint_base.h"
27#include "tilehighlight_func.h"
28#include "company_base.h"
29#include "sortlist_type.h"
31#include "vehiclelist.h"
32#include "sound_func.h"
33#include "town.h"
34#include "linkgraph/linkgraph.h"
35#include "zoom_func.h"
36#include "station_cmd.h"
37
39#include "widgets/misc_widget.h"
40
41#include "table/strings.h"
42
44
45#include "safeguards.h"
46
48{
49 using StationType = Station;
50
51 static bool IsValidID(StationID id) { return Station::IsValidID(id); }
52 static bool IsValidBaseStation(const BaseStation *st) { return Station::IsExpected(st); }
53 static bool IsAcceptableWaypointTile(TileIndex) { return false; }
54 static constexpr bool IsWaypoint() { return false; }
55};
56
57template <bool ROAD, TileType TILE_TYPE>
59{
60 using StationType = Waypoint;
61
62 static bool IsValidID(StationID id) { return Waypoint::IsValidID(id) && HasBit(Waypoint::Get(id)->waypoint_flags, WPF_ROAD) == ROAD; }
63 static bool IsValidBaseStation(const BaseStation *st) { return Waypoint::IsExpected(st) && HasBit(Waypoint::From(st)->waypoint_flags, WPF_ROAD) == ROAD; }
64 static bool IsAcceptableWaypointTile(TileIndex tile) { return IsTileType(tile, TILE_TYPE); }
65 static constexpr bool IsWaypoint() { return true; }
66};
67using RailWaypointTypeFilter = GenericWaypointTypeFilter<false, TileType::Railway>;
68using RoadWaypointTypeFilter = GenericWaypointTypeFilter<true, TileType::Road>;
69
78int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
79{
80 TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
81 CargoTypes cargo_mask{};
82 if (_thd.drawstyle == HT_RECT && tile < Map::Size()) {
83 CargoArray cargoes;
84 if (supplies) {
85 cargoes = GetProductionAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
86 } else {
87 cargoes = GetAcceptanceAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad).first;
88 }
89
90 /* Convert cargo counts to a set of cargo bits, and draw the result. */
91 for (CargoType cargo{}; cargo < NUM_CARGO; ++cargo) {
92 switch (sct) {
93 case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(cargo, CargoClass::Passengers)) continue; break;
94 case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(cargo, CargoClass::Passengers)) continue; break;
95 case SCT_ALL: break;
96 default: NOT_REACHED();
97 }
98 if (cargoes[cargo] >= (supplies ? 1U : 8U)) cargo_mask.Set(cargo);
99 }
100 }
101 return DrawStringMultiLine(r, GetString(supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO, cargo_mask));
102}
103
108template <typename T>
110{
111 /* With distant join we don't know which station will be selected, so don't show any */
112 if (_ctrl_pressed) {
113 SetViewportCatchmentSpecializedStation<typename T::StationType>(nullptr, true);
114 return;
115 }
116
117 /* Tile area for TileHighlightData */
118 TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1);
119
120 /* If the current tile is already a station, then it must be the nearest station. */
121 if (IsTileType(location.tile, TileType::Station) && GetTileOwner(location.tile) == _local_company) {
122 typename T::StationType *st = T::StationType::GetByTile(location.tile);
123 if (st != nullptr && T::IsValidBaseStation(st)) {
124 SetViewportCatchmentSpecializedStation<typename T::StationType>(st, true);
125 return;
126 }
127 }
128
129 /* Extended area by one tile */
130 uint x = TileX(location.tile);
131 uint y = TileY(location.tile);
132
133 /* Waypoints can only be built on existing rail/road tiles, so don't extend area if not highlighting a rail tile. */
134 int max_c = T::IsWaypoint() && !T::IsAcceptableWaypointTile(location.tile) ? 0 : 1;
135 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)));
136
137 typename T::StationType *adjacent = nullptr;
138
139 /* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
140 for (TileIndex tile : ta) {
142 typename T::StationType *st = T::StationType::GetByTile(tile);
143 if (st == nullptr || !T::IsValidBaseStation(st)) continue;
144 if (adjacent != nullptr && st != adjacent) {
145 /* Multiple nearby, distant join is required. */
146 adjacent = nullptr;
147 break;
148 }
149 adjacent = st;
150 }
151 }
152 SetViewportCatchmentSpecializedStation<typename T::StationType>(adjacent, true);
153}
154
161{
162 /* Test if ctrl state changed */
163 static bool _last_ctrl_pressed;
164 if (_ctrl_pressed != _last_ctrl_pressed) {
165 _thd.dirty = 0xff;
166 _last_ctrl_pressed = _ctrl_pressed;
167 }
168
169 if (_thd.dirty & 1) {
170 _thd.dirty &= ~1;
171 w->SetDirty();
172
173 if (_settings_client.gui.station_show_coverage && _thd.drawstyle == HT_RECT) {
175 }
176 }
177}
178
179template <typename T>
180void CheckRedrawWaypointCoverage()
181{
182 /* Test if ctrl state changed */
183 static bool _last_ctrl_pressed;
184 if (_ctrl_pressed != _last_ctrl_pressed) {
185 _thd.dirty = 0xff;
186 _last_ctrl_pressed = _ctrl_pressed;
187 }
188
189 if (_thd.dirty & 1) {
190 _thd.dirty &= ~1;
191
192 if (_thd.drawstyle == HT_RECT) {
194 }
195 }
196}
197
198void CheckRedrawRailWaypointCoverage(const Window *)
199{
200 CheckRedrawWaypointCoverage<RailWaypointTypeFilter>();
201}
202
203void CheckRedrawRoadWaypointCoverage(const Window *)
204{
205 CheckRedrawWaypointCoverage<RoadWaypointTypeFilter>();
206}
207
220static void StationsWndShowStationRating(int left, int right, int y, CargoType cargo, uint amount, uint8_t rating)
221{
222 static const uint units_full = 576;
223 static const uint rating_full = 224;
224
225 const CargoSpec *cs = CargoSpec::Get(cargo);
226 if (!cs->IsValid()) return;
227
228 int padding = ScaleGUITrad(1);
229 int width = right - left;
230 PixelColour colour = cs->rating_colour;
231 TextColour tc = GetContrastColour(colour);
232 uint w = std::min(amount + 5, units_full) * width / units_full;
233
234 int height = GetCharacterHeight(FontSize::Small) + padding - 1;
235
236 if (amount > 30) {
237 /* Draw total cargo (limited) on station */
238 GfxFillRect(left, y, left + w - 1, y + height, colour);
239 } else {
240 /* Draw a (scaled) one pixel-wide bar of additional cargo meter, useful
241 * for stations with only a small amount (<=30) */
242 uint rest = ScaleGUITrad(amount) / 5;
243 if (rest != 0) {
244 GfxFillRect(left, y + height - rest, left + padding - 1, y + height, colour);
245 }
246 }
247
248 DrawString(left + padding, right, y, cs->abbrev, tc, SA_CENTER, false, FontSize::Small);
249
250 /* Draw green/red ratings bar (fits under the waiting bar) */
251 y += height + padding + 1;
252 GfxFillRect(left + padding, y, right - padding - 1, y + padding - 1, PC_RED);
253 w = std::min<uint>(rating, rating_full) * (width - padding - padding) / rating_full;
254 if (w != 0) GfxFillRect(left + padding, y, left + w - 1, y + padding - 1, PC_GREEN);
255}
256
258
262class CompanyStationsWindow : public Window
263{
264protected:
266 struct FilterState {
267 Listing last_sorting;
268 StationFacilities facilities;
270 CargoTypes cargoes;
271 };
272
273 static inline FilterState initial_state = {
274 {false, 0},
276 true,
277 ALL_CARGOTYPES,
278 };
279
281 static inline const StringID sorter_names[] = {
282 STR_SORT_BY_NAME,
283 STR_SORT_BY_FACILITY,
284 STR_SORT_BY_WAITING_TOTAL,
285 STR_SORT_BY_WAITING_AVAILABLE,
286 STR_SORT_BY_RATING_MAX,
287 STR_SORT_BY_RATING_MIN,
288 };
289 static const std::initializer_list<GUIStationList::SortFunction * const> sorter_funcs;
290
291 FilterState filter{};
292 GUIStationList stations{filter.cargoes};
293 Scrollbar *vscroll = nullptr;
294 uint rating_width = 0;
295 bool filter_expanded = false;
296 std::array<uint16_t, NUM_CARGO> stations_per_cargo_type{};
298
304 void BuildStationsList(const Owner owner)
305 {
306 if (!this->stations.NeedRebuild()) return;
307
308 Debug(misc, 3, "Building station list for company {}", owner);
309
310 this->stations.clear();
311 this->stations_per_cargo_type.fill(0);
312 this->stations_per_cargo_type_no_rating = 0;
313
314 for (const Station *st : Station::Iterate()) {
315 if (this->filter.facilities.Any(st->facilities)) { // only stations with selected facilities
316 if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
317 bool has_rating = false;
318 /* Add to the station/cargo counts. */
319 for (CargoType cargo{}; cargo < NUM_CARGO; ++cargo) {
320 if (st->goods[cargo].HasRating()) this->stations_per_cargo_type[cargo]++;
321 }
322 for (CargoType cargo{}; cargo < NUM_CARGO; ++cargo) {
323 if (st->goods[cargo].HasRating()) {
324 has_rating = true;
325 if (this->filter.cargoes.Test(cargo)) {
326 this->stations.push_back(st);
327 break;
328 }
329 }
330 }
331 /* Stations with no cargo rating. */
332 if (!has_rating) {
333 if (this->filter.include_no_rating) this->stations.push_back(st);
334 this->stations_per_cargo_type_no_rating++;
335 }
336 }
337 }
338 }
339
340 this->stations.RebuildDone();
341
342 this->vscroll->SetCount(this->stations.size()); // Update the scrollbar
343 }
344
346 static bool StationNameSorter(const Station * const &a, const Station * const &b, [[maybe_unused]] const CargoTypes &filter)
347 {
348 int r = StrNaturalCompare(a->GetCachedName(), b->GetCachedName()); // Sort by name (natural sorting).
349 if (r == 0) return a->index < b->index;
350 return r < 0;
351 }
352
354 static bool StationTypeSorter(const Station * const &a, const Station * const &b, [[maybe_unused]] const CargoTypes &filter)
355 {
356 return a->facilities < b->facilities;
357 }
358
360 static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b, const CargoTypes &filter)
361 {
362 int diff = 0;
363
364 for (CargoType cargo : filter) {
365 diff += a->goods[cargo].TotalCount() - b->goods[cargo].TotalCount();
366 }
367
368 return diff < 0;
369 }
370
372 static bool StationWaitingAvailableSorter(const Station * const &a, const Station * const &b, const CargoTypes &filter)
373 {
374 int diff = 0;
375
376 for (CargoType cargo : filter) {
377 diff += a->goods[cargo].AvailableCount() - b->goods[cargo].AvailableCount();
378 }
379
380 return diff < 0;
381 }
382
384 static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b, const CargoTypes &filter)
385 {
386 uint8_t maxr1 = 0;
387 uint8_t maxr2 = 0;
388
389 for (CargoType cargo : filter) {
390 if (a->goods[cargo].HasRating()) maxr1 = std::max(maxr1, a->goods[cargo].rating);
391 if (b->goods[cargo].HasRating()) maxr2 = std::max(maxr2, b->goods[cargo].rating);
392 }
393
394 return maxr1 < maxr2;
395 }
396
398 static bool StationRatingMinSorter(const Station * const &a, const Station * const &b, const CargoTypes &filter)
399 {
400 uint8_t minr1 = 255;
401 uint8_t minr2 = 255;
402
403 for (CargoType cargo : filter) {
404 if (a->goods[cargo].HasRating()) minr1 = std::min(minr1, a->goods[cargo].rating);
405 if (b->goods[cargo].HasRating()) minr2 = std::min(minr2, b->goods[cargo].rating);
406 }
407
408 return minr1 > minr2;
409 }
410
413 {
414 if (!this->stations.Sort()) return;
415
416 /* Set the modified widget dirty */
418 }
419
420public:
422 {
423 /* Load initial filter state. */
424 this->filter = CompanyStationsWindow::initial_state;
425 if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes = _cargo_mask;
426
427 this->stations.SetListing(this->filter.last_sorting);
428 this->stations.SetSortFuncs(CompanyStationsWindow::sorter_funcs);
429 this->stations.ForceRebuild();
430 this->stations.NeedResort();
431 this->SortStationsList();
432
433 this->CreateNestedTree();
434 this->vscroll = this->GetScrollbar(WID_STL_SCROLLBAR);
435 this->FinishInitNested(window_number);
436 this->owner = this->window_number;
437
438 if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes = _cargo_mask;
439
440 for (StationFacility facil : this->filter.facilities) {
441 this->LowerWidget(WID_STL_TRAIN + to_underlying(facil));
442 }
443
444 this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->SetString(CompanyStationsWindow::sorter_names[this->stations.SortType()]);
445 }
446
449 {
450 /* Save filter state. */
451 this->filter.last_sorting = this->stations.GetListing();
452 CompanyStationsWindow::initial_state = this->filter;
453 }
454
455 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
456 {
457 switch (widget) {
458 case WID_STL_SORTBY: {
460 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
461 d.height += padding.height;
462 size = maxdim(size, d);
463 break;
464 }
465
466 case WID_STL_SORTDROPBTN: {
468 d.width += padding.width;
469 d.height += padding.height;
470 size = maxdim(size, d);
471 break;
472 }
473
474 case WID_STL_LIST:
476 size.height = padding.height + 5 * resize.height;
477
478 /* Determine appropriate width for mini station rating graph */
479 this->rating_width = 0;
480 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
481 this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev, FontSize::Small).width);
482 }
483 /* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
484 this->rating_width = this->rating_width * 16 / 10;
485 break;
486 }
487 }
488
489 void OnPaint() override
490 {
491 this->BuildStationsList(this->window_number);
492 this->SortStationsList();
493
494 this->DrawWidgets();
495 }
496
497 void DrawWidget(const Rect &r, WidgetID widget) const override
498 {
499 switch (widget) {
500 case WID_STL_SORTBY:
501 /* draw arrow pointing up/down for ascending/descending sorting */
503 break;
504
505 case WID_STL_LIST: {
506 bool rtl = _current_text_dir == TD_RTL;
507 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
508 uint line_height = this->GetWidget<NWidgetBase>(widget)->resize_y;
509 /* Spacing between station name and first rating graph. */
510 int text_spacing = WidgetDimensions::scaled.hsep_wide;
511 /* Spacing between additional rating graphs. */
512 int rating_spacing = WidgetDimensions::scaled.hsep_normal;
513
514 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->stations);
515 for (auto it = first; it != last; ++it) {
516 const Station *st = *it;
517 assert(st->xy != INVALID_TILE);
518
519 /* Do not do the complex check HasStationInUse here, it may be even false
520 * when the order had been removed and the station list hasn't been removed yet */
521 assert(st->owner == owner || st->owner == OWNER_NONE);
522
523 int x = DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FontSize::Normal)) / 2, GetString(STR_STATION_LIST_STATION, st->index, st->facilities));
524 x += rtl ? -text_spacing : text_spacing;
525
526 /* show cargo waiting and station ratings */
527 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
528 CargoType cargo_type = cs->Index();
529 if (st->goods[cargo_type].HasRating()) {
530 /* For RTL we work in exactly the opposite direction. So
531 * decrement the space needed first, then draw to the left
532 * instead of drawing to the left and then incrementing
533 * the space. */
534 if (rtl) {
535 x -= rating_width + rating_spacing;
536 if (x < tr.left) break;
537 }
538 StationsWndShowStationRating(x, x + rating_width, tr.top, cargo_type, st->goods[cargo_type].TotalCount(), st->goods[cargo_type].rating);
539 if (!rtl) {
540 x += rating_width + rating_spacing;
541 if (x > tr.right) break;
542 }
543 }
544 }
545 tr.top += line_height;
546 }
547
548 if (this->vscroll->GetCount() == 0) { // company has no stations
549 DrawString(tr.left, tr.right, tr.top + (line_height - GetCharacterHeight(FontSize::Normal)) / 2, STR_STATION_LIST_NONE);
550 return;
551 }
552 break;
553 }
554 }
555 }
556
557 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
558 {
559 if (widget == WID_STL_CAPTION) {
560 return GetString(STR_STATION_LIST_CAPTION, this->window_number, this->vscroll->GetCount());
561 }
562
563 if (widget == WID_STL_CARGODROPDOWN) {
564 if (this->filter.cargoes.None()) return GetString(this->filter.include_no_rating ? STR_STATION_LIST_CARGO_FILTER_ONLY_NO_RATING : STR_STATION_LIST_CARGO_FILTER_NO_CARGO_TYPES);
565 if (this->filter.cargoes == _cargo_mask) return GetString(this->filter.include_no_rating ? STR_STATION_LIST_CARGO_FILTER_ALL_AND_NO_RATING : STR_CARGO_TYPE_FILTER_ALL);
566 if (this->filter.cargoes.Count() == 1 && !this->filter.include_no_rating) return GetString(CargoSpec::Get(*this->filter.cargoes.begin())->name);
567 return GetString(STR_STATION_LIST_CARGO_FILTER_MULTIPLE);
568 }
569
570 return this->Window::GetWidgetString(widget, stringid);
571 }
572
573 DropDownList BuildCargoDropDownList(bool expanded) const
574 {
575 /* Define a custom item consisting of check mark, count string, icon and name string. */
577
578 DropDownList list;
579 list.push_back(MakeDropDownListStringItem(STR_STATION_LIST_CARGO_FILTER_SELECT_ALL, CargoFilterCriteria::CF_SELECT_ALL));
580 list.push_back(MakeDropDownListDividerItem());
581
582 bool any_hidden = false;
583
584 uint16_t count = this->stations_per_cargo_type_no_rating;
585 if (count == 0 && !expanded) {
586 any_hidden = true;
587 } else {
588 list.push_back(std::make_unique<DropDownString<DropDownListCheckedItem, FontSize::Small, true>>(fmt::format("{}", count), 0, this->filter.include_no_rating, GetString(STR_STATION_LIST_CARGO_FILTER_NO_RATING), CargoFilterCriteria::CF_NO_RATING, false, count == 0));
589 }
590
591 Dimension d = GetLargestCargoIconSize();
592 for (const CargoSpec *cs : _sorted_cargo_specs) {
593 count = this->stations_per_cargo_type[cs->Index()];
594 if (count == 0 && !expanded) {
595 any_hidden = true;
596 } else {
597 list.push_back(std::make_unique<DropDownListCargoItem>(this->filter.cargoes.Test(cs->Index()), fmt::format("{}", count), d, cs->GetCargoIcon(), PAL_NONE, GetString(cs->name), cs->Index(), false, count == 0));
598 }
599 }
600
601 if (!expanded && any_hidden) {
602 if (list.size() > 2) list.push_back(MakeDropDownListDividerItem());
603 list.push_back(MakeDropDownListStringItem(STR_STATION_LIST_CARGO_FILTER_EXPAND, CargoFilterCriteria::CF_EXPAND_LIST));
604 }
605
606 return list;
607 }
608
609 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
610 {
611 switch (widget) {
612 case WID_STL_LIST: {
613 auto it = this->vscroll->GetScrolledItemFromWidget(this->stations, pt.y, this, WID_STL_LIST, WidgetDimensions::scaled.framerect.top);
614 if (it == this->stations.end()) return; // click out of list bound
615
616 const Station *st = *it;
617 /* do not check HasStationInUse - it is slow and may be invalid */
618 assert(st->owner == this->window_number || st->owner == OWNER_NONE);
619
620 if (_ctrl_pressed) {
622 } else {
624 }
625 break;
626 }
627
628 case WID_STL_TRAIN:
629 case WID_STL_TRUCK:
630 case WID_STL_BUS:
631 case WID_STL_AIRPLANE:
632 case WID_STL_SHIP:
633 if (_ctrl_pressed) {
634 this->filter.facilities.Flip(static_cast<StationFacility>(widget - WID_STL_TRAIN));
635 this->ToggleWidgetLoweredState(widget);
636 } else {
637 for (StationFacility facil : this->filter.facilities) {
639 }
640 this->filter.facilities = static_cast<StationFacility>(widget - WID_STL_TRAIN);
641 this->LowerWidget(widget);
642 }
643 this->stations.ForceRebuild();
644 this->SetDirty();
645 SndClickBeep();
646 break;
647
648 case WID_STL_FACILALL:
649 for (WidgetID i = WID_STL_TRAIN; i <= WID_STL_SHIP; i++) {
650 this->LowerWidget(i);
651 }
652
654 this->stations.ForceRebuild();
655 this->SetDirty();
656 break;
657
658 case WID_STL_SORTBY: // flip sorting method asc/desc
659 this->stations.ToggleSortOrder();
660 this->SetDirty();
661 break;
662
663 case WID_STL_SORTDROPBTN: // select sorting criteria dropdown menu
665 break;
666
668 static std::string cargo_filter;
669 this->filter_expanded = false;
670 ShowDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded), -1, widget, 0, {DropDownOption::Persist, DropDownOption::Filterable}, &cargo_filter);
671 break;
672 }
673 }
674 }
675
676 void OnDropdownSelect(WidgetID widget, int index, int) override
677 {
678 if (widget == WID_STL_SORTDROPBTN) {
679 if (this->stations.SortType() != index) {
680 this->stations.SetSortType(index);
681
682 /* Display the current sort variant */
684
685 this->SetDirty();
686 }
687 }
688
689 if (widget == WID_STL_CARGODROPDOWN) {
690 FilterState oldstate = this->filter;
691
692 if (index >= 0 && index < NUM_CARGO) {
693 if (_ctrl_pressed) {
694 this->filter.cargoes.Flip(static_cast<CargoType>(index));
695 } else {
696 this->filter.cargoes = static_cast<CargoType>(index);
697 this->filter.include_no_rating = false;
698 }
699 } else if (index == CargoFilterCriteria::CF_NO_RATING) {
700 if (_ctrl_pressed) {
701 this->filter.include_no_rating = !this->filter.include_no_rating;
702 } else {
703 this->filter.include_no_rating = true;
704 this->filter.cargoes.Reset();
705 }
706 } else if (index == CargoFilterCriteria::CF_SELECT_ALL) {
707 this->filter.cargoes = _cargo_mask;
708 this->filter.include_no_rating = true;
709 } else if (index == CargoFilterCriteria::CF_EXPAND_LIST) {
710 this->filter_expanded = true;
711 ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
712 return;
713 }
714
715 if (oldstate.cargoes != this->filter.cargoes || oldstate.include_no_rating != this->filter.include_no_rating) {
716 this->stations.ForceRebuild();
717 this->SetDirty();
718
719 /* Only refresh the list if it's changed. */
720 if (_ctrl_pressed) ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
721 }
722
723 /* Always close the list if ctrl is not pressed. */
725 }
726 }
727
728 void OnGameTick() override
729 {
730 if (this->stations.NeedResort()) {
731 Debug(misc, 3, "Periodic rebuild station list company {}", static_cast<int>(this->window_number));
732 this->SetDirty();
733 }
734 }
735
736 void OnResize() override
737 {
738 this->vscroll->SetCapacityFromWidget(this, WID_STL_LIST, WidgetDimensions::scaled.framerect.Vertical());
739 }
740
746 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
747 {
748 if (data == 0) {
749 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
750 this->stations.ForceRebuild();
751 } else {
752 this->stations.ForceResort();
753 }
754 }
755};
756
757/* Available station sorting functions */
758const std::initializer_list<GUIStationList::SortFunction * const> CompanyStationsWindow::sorter_funcs = {
765};
766
767static constexpr std::initializer_list<NWidgetPart> _nested_company_stations_widgets = {
774 EndContainer(),
776 NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_TRAIN), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_TRAIN, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
777 NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_TRUCK), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_LORRY, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
778 NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_BUS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_BUS, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
779 NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_SHIP), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_SHIP, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
780 NWidget(WWT_TEXTBTN, Colours::Grey, WID_STL_AIRPLANE), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_PLANE, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP), SetFill(0, 1),
781 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_STL_FACILALL), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetStringTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES_TOOLTIP), SetTextStyle(TC_BLACK, FontSize::Small), SetFill(0, 1),
783 NWidget(WWT_DROPDOWN, Colours::Grey, WID_STL_CARGODROPDOWN), SetFill(1, 0), SetToolTip(STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE_TOOLTIP),
785 EndContainer(),
787 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_STL_SORTBY), SetMinimalSize(81, 12), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
788 NWidget(WWT_DROPDOWN, Colours::Grey, WID_STL_SORTDROPBTN), SetMinimalSize(163, 12), SetStringTip(STR_SORT_BY_NAME, STR_TOOLTIP_SORT_CRITERIA), // widget_data gets overwritten.
790 EndContainer(),
796 EndContainer(),
797 EndContainer(),
798};
799
802 WindowPosition::Automatic, "list_stations", 358, 162,
804 {},
805 _nested_company_stations_widgets
806);
807
813void ShowCompanyStations(CompanyID company)
814{
815 if (!Company::IsValidID(company)) return;
816
818}
819
820static constexpr std::initializer_list<NWidgetPart> _nested_station_view_widgets = {
823 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_SV_RENAME), SetAspect(WidgetDimensions::ASPECT_RENAME), SetSpriteTip(SPR_RENAME, STR_STATION_VIEW_EDIT_TOOLTIP),
825 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_SV_LOCATION), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetSpriteTip(SPR_GOTO_LOCATION, STR_STATION_VIEW_CENTER_TOOLTIP),
829 EndContainer(),
831 NWidget(WWT_TEXTBTN, Colours::Grey, WID_SV_GROUP), SetMinimalSize(81, 12), SetFill(1, 1), SetStringTip(STR_STATION_VIEW_GROUP),
832 NWidget(WWT_DROPDOWN, Colours::Grey, WID_SV_GROUP_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetToolTip(STR_TOOLTIP_GROUP_ORDER),
833 EndContainer(),
835 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SV_SORT_ORDER), SetMinimalSize(81, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
836 NWidget(WWT_DROPDOWN, Colours::Grey, WID_SV_SORT_BY), SetMinimalSize(168, 12), SetResize(1, 0), SetFill(0, 1), SetToolTip(STR_TOOLTIP_SORT_CRITERIA),
837 EndContainer(),
841 EndContainer(),
845 SetStringTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
848 SetStringTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
849 EndContainer(),
850 NWidget(WWT_TEXTBTN, Colours::Grey, WID_SV_CATCHMENT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetStringTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
851 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SV_TRAINS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), SetStringTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP),
852 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SV_ROADVEHS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), SetStringTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP),
853 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SV_SHIPS), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), SetStringTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP),
854 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SV_PLANES), SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON), SetFill(0, 1), SetStringTip(STR_PLANE, STR_STATION_VIEW_SCHEDULED_AIRCRAFT_TOOLTIP),
856 EndContainer(),
857};
858
859enum SortOrder : uint8_t {
860 SO_DESCENDING,
861 SO_ASCENDING
862};
863
864class CargoDataEntry;
865
874
875class CargoSorter {
876public:
877 using is_transparent = void;
878 CargoSorter(CargoSortType t = CargoSortType::StationID, SortOrder o = SO_ASCENDING) : type(t), order(o) {}
879 CargoSortType GetSortType() {return this->type;}
880 bool operator()(const CargoDataEntry &cd1, const CargoDataEntry &cd2) const;
881 bool operator()(const CargoDataEntry &cd1, const std::unique_ptr<CargoDataEntry> &cd2) const { return this->operator()(cd1, *cd2); }
882 bool operator()(const std::unique_ptr<CargoDataEntry> &cd1, const CargoDataEntry &cd2) const { return this->operator()(*cd1, cd2); }
883 bool operator()(const std::unique_ptr<CargoDataEntry> &cd1, const std::unique_ptr<CargoDataEntry> &cd2) const { return this->operator()(*cd1, *cd2); }
884
885private:
886 CargoSortType type;
887 SortOrder order;
888
889 template <class Tid>
890 bool SortId(Tid st1, Tid st2) const;
891 bool SortCount(const CargoDataEntry &cd1, const CargoDataEntry &cd2) const;
892 bool SortStation(StationID st1, StationID st2) const;
893};
894
895typedef std::set<std::unique_ptr<CargoDataEntry>, CargoSorter> CargoDataSet;
896
902class CargoDataEntry {
903public:
904 CargoDataEntry();
906
912 CargoDataEntry &InsertOrRetrieve(StationID station)
913 {
914 return this->InsertOrRetrieve<StationID>(station);
915 }
916
923 {
924 return this->InsertOrRetrieve<CargoType>(cargo);
925 }
926
927 void Update(uint count);
928
933 void Remove(StationID station)
934 {
935 CargoDataEntry t(station);
936 this->Remove(t);
937 }
938
944 {
945 CargoDataEntry t(cargo);
946 this->Remove(t);
947 }
948
954 CargoDataEntry *Retrieve(StationID station) const
955 {
956 CargoDataEntry t(station);
957 return this->Retrieve(this->children->find(t));
958 }
959
965 CargoDataEntry *Retrieve(CargoType cargo) const
966 {
967 CargoDataEntry t(cargo);
968 return this->Retrieve(this->children->find(t));
969 }
970
971 void Resort(CargoSortType type, SortOrder order);
972
977 StationID GetStation() const { return this->station; }
978
983 CargoType GetCargo() const { return this->cargo; }
984
989 uint GetCount() const { return this->count; }
990
995 CargoDataEntry *GetParent() const { return this->parent; }
996
1001 uint GetNumChildren() const { return this->num_children; }
1002
1007 CargoDataSet::iterator Begin() const { return this->children->begin(); }
1008
1013 CargoDataSet::iterator End() const { return this->children->end(); }
1014
1019 bool HasTransfers() const { return this->transfers; }
1020
1025 void SetTransfers(bool value) { this->transfers = value; }
1026
1027 void Clear();
1028
1031 CargoDataEntry(StationID station);
1033
1034private:
1035 CargoDataEntry *Retrieve(CargoDataSet::iterator i) const;
1036
1037 template <class Tid>
1039
1040 void Remove(CargoDataEntry &entry);
1041 void IncrementSize();
1042
1043 CargoDataEntry *parent;
1044 const union {
1045 StationID station;
1046 struct {
1049 };
1050 };
1052 uint count;
1053 std::unique_ptr<CargoDataSet> children;
1054};
1055
1056CargoDataEntry::CargoDataEntry() :
1057 parent(nullptr),
1058 station(StationID::Invalid()),
1059 num_children(0),
1060 count(0),
1061 children(std::make_unique<CargoDataSet>(CargoSorter(CargoSortType::CargoType)))
1062{}
1063
1064CargoDataEntry::CargoDataEntry(CargoType cargo, uint count, CargoDataEntry *parent) :
1065 parent(parent),
1066 cargo(cargo),
1067 num_children(0),
1068 count(count),
1069 children(std::make_unique<CargoDataSet>())
1070{}
1071
1072CargoDataEntry::CargoDataEntry(StationID station, uint count, CargoDataEntry *parent) :
1073 parent(parent),
1074 station(station),
1075 num_children(0),
1076 count(count),
1077 children(std::make_unique<CargoDataSet>())
1078{}
1079
1080CargoDataEntry::CargoDataEntry(StationID station) :
1081 parent(nullptr),
1082 station(station),
1083 num_children(0),
1084 count(0),
1085 children(nullptr)
1086{}
1087
1088CargoDataEntry::CargoDataEntry(CargoType cargo) :
1089 parent(nullptr),
1090 cargo(cargo),
1091 num_children(0),
1092 count(0),
1093 children(nullptr)
1094{}
1095
1098{
1099 this->Clear();
1100}
1101
1106{
1107 if (this->children != nullptr) this->children->clear();
1108 if (this->parent != nullptr) this->parent->count -= this->count;
1109 this->count = 0;
1110 this->num_children = 0;
1111}
1112
1119void CargoDataEntry::Remove(CargoDataEntry &entry)
1120{
1121 CargoDataSet::iterator i = this->children->find(entry);
1122 if (i != this->children->end()) this->children->erase(i);
1123}
1124
1131template <class Tid>
1132CargoDataEntry &CargoDataEntry::InsertOrRetrieve(Tid child_id)
1133{
1134 CargoDataEntry tmp(child_id);
1135 CargoDataSet::iterator i = this->children->find(tmp);
1136 if (i == this->children->end()) {
1137 IncrementSize();
1138 return **(this->children->insert(std::make_unique<CargoDataEntry>(child_id, 0, this)).first);
1139 } else {
1140 assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
1141 return **i;
1142 }
1143}
1144
1151{
1152 this->count += count;
1153 if (this->parent != nullptr) this->parent->Update(count);
1154}
1155
1160{
1161 ++this->num_children;
1162 if (this->parent != nullptr) this->parent->IncrementSize();
1163}
1164
1165void CargoDataEntry::Resort(CargoSortType type, SortOrder order)
1166{
1167 auto new_children = std::make_unique<CargoDataSet>(CargoSorter(type, order));
1168 new_children->merge(*this->children);
1169 this->children = std::move(new_children);
1170}
1171
1172CargoDataEntry *CargoDataEntry::Retrieve(CargoDataSet::iterator i) const
1173{
1174 if (i == this->children->end()) {
1175 return nullptr;
1176 } else {
1177 assert(this->children->value_comp().GetSortType() != CargoSortType::Count);
1178 return i->get();
1179 }
1180}
1181
1182bool CargoSorter::operator()(const CargoDataEntry &cd1, const CargoDataEntry &cd2) const
1183{
1184 switch (this->type) {
1186 return this->SortId<StationID>(cd1.GetStation(), cd2.GetStation());
1188 return this->SortId<CargoType>(cd1.GetCargo(), cd2.GetCargo());
1190 return this->SortCount(cd1, cd2);
1192 return this->SortStation(cd1.GetStation(), cd2.GetStation());
1193 default:
1194 NOT_REACHED();
1195 }
1196}
1197
1198template <class Tid>
1199bool CargoSorter::SortId(Tid st1, Tid st2) const
1200{
1201 return (this->order == SO_ASCENDING) ? st1 < st2 : st2 < st1;
1202}
1203
1204bool CargoSorter::SortCount(const CargoDataEntry &cd1, const CargoDataEntry &cd2) const
1205{
1206 uint c1 = cd1.GetCount();
1207 uint c2 = cd2.GetCount();
1208 if (c1 == c2) {
1209 return this->SortStation(cd1.GetStation(), cd2.GetStation());
1210 } else if (this->order == SO_ASCENDING) {
1211 return c1 < c2;
1212 } else {
1213 return c2 < c1;
1214 }
1215}
1216
1217bool CargoSorter::SortStation(StationID st1, StationID st2) const
1218{
1219 if (!Station::IsValidID(st1)) {
1220 return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
1221 } else if (!Station::IsValidID(st2)) {
1222 return order == SO_DESCENDING;
1223 }
1224
1225 int res = StrNaturalCompare(Station::Get(st1)->GetCachedName(), Station::Get(st2)->GetCachedName()); // Sort by name (natural sorting).
1226 if (res == 0) {
1227 return this->SortId(st1, st2);
1228 } else {
1229 return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
1230 }
1231}
1232
1236struct StationViewWindow : public Window {
1240 struct RowDisplay {
1241 RowDisplay(CargoDataEntry *f, StationID n) : filter(f), next_station(n) {}
1242 RowDisplay(CargoDataEntry *f, CargoType n) : filter(f), next_cargo(n) {}
1243
1248 union {
1252 StationID next_station;
1253
1258 };
1259 };
1260
1261 typedef std::vector<RowDisplay> CargoDataVector;
1262
1263 static const int NUM_COLUMNS = 4;
1264
1268 enum Invalidation : uint16_t {
1269 INV_FLOWS = 0x100,
1270 INV_CARGO = 0x200
1271 };
1272
1282
1286 enum Mode : uint8_t {
1289 };
1290
1294 int line_height = 0;
1296 Scrollbar *vscroll = nullptr;
1297
1298 /* Height of the #WID_SV_ACCEPT_RATING_LIST widget for different views. */
1299 static constexpr uint RATING_LINES = 13;
1300 static constexpr uint ACCEPTS_LINES = 3;
1301
1303 static inline const StringID sort_names[] = {
1304 STR_STATION_VIEW_WAITING_STATION,
1305 STR_STATION_VIEW_WAITING_AMOUNT,
1306 STR_STATION_VIEW_PLANNED_STATION,
1307 STR_STATION_VIEW_PLANNED_AMOUNT,
1308 };
1309
1310 static inline const StringID group_names[] = {
1311 STR_STATION_VIEW_GROUP_S_V_D,
1312 STR_STATION_VIEW_GROUP_S_D_V,
1313 STR_STATION_VIEW_GROUP_V_S_D,
1314 STR_STATION_VIEW_GROUP_V_D_S,
1315 STR_STATION_VIEW_GROUP_D_S_V,
1316 STR_STATION_VIEW_GROUP_D_V_S,
1317 };
1318
1325 std::array<CargoSortType, NUM_COLUMNS> sortings{};
1326
1328 std::array<SortOrder, NUM_COLUMNS> sort_orders{};
1329
1330 int scroll_to_row = INT_MAX;
1333 std::array<Grouping, NUM_COLUMNS> groupings;
1334
1337 CargoDataVector displayed_rows{};
1338
1340 {
1341 this->CreateNestedTree();
1343 this->vscroll = this->GetScrollbar(WID_SV_SCROLLBAR);
1344 /* Nested widget tree creation is done in two steps to ensure that this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS) exists in UpdateWidgetSize(). */
1345 this->FinishInitNested(window_number);
1346
1347 this->groupings[0] = GR_CARGO;
1348 this->sortings[0] = CargoSortType::AsGrouping;
1349 this->SelectGroupBy(_settings_client.gui.station_gui_group_order);
1350 this->SelectSortBy(_settings_client.gui.station_gui_sort_by);
1351 this->sort_orders[0] = SO_ASCENDING;
1352 this->SelectSortOrder((SortOrder)_settings_client.gui.station_gui_sort_order);
1353 this->owner = Station::Get(window_number)->owner;
1354 }
1355
1356 void OnInit() override
1357 {
1358 this->cargo_icon_size = GetLargestCargoIconSize();
1359 this->line_height = std::max<int>(GetCharacterHeight(FontSize::Normal), this->cargo_icon_size.height);
1360 this->expand_shrink_width = std::max(GetCharacterWidth(FontSize::Normal, '-'), GetCharacterWidth(FontSize::Normal, '+'));
1361 }
1362
1363 void Close([[maybe_unused]] int data = 0) override
1364 {
1365 CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Train, this->owner, this->window_number).ToWindowNumber(), false);
1366 CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Road, this->owner, this->window_number).ToWindowNumber(), false);
1367 CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Ship, this->owner, this->window_number).ToWindowNumber(), false);
1368 CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VehicleType::Aircraft, this->owner, this->window_number).ToWindowNumber(), false);
1369
1370 SetViewportCatchmentStation(Station::Get(this->window_number), false);
1371 this->Window::Close();
1372 }
1373
1384 void ShowCargo(CargoDataEntry *data, CargoType cargo, StationID source, StationID next, StationID dest, uint count)
1385 {
1386 if (count == 0) return;
1387 bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DistributionType::Manual;
1388 const CargoDataEntry *expand = &this->expanded_rows;
1389 for (int i = 0; i < NUM_COLUMNS && expand != nullptr; ++i) {
1390 switch (groupings[i]) {
1391 case GR_CARGO:
1392 assert(i == 0);
1393 data = &data->InsertOrRetrieve(cargo);
1394 data->SetTransfers(source != this->window_number);
1395 expand = expand->Retrieve(cargo);
1396 break;
1397 case GR_SOURCE:
1398 if (auto_distributed || source != this->window_number) {
1399 data = &data->InsertOrRetrieve(source);
1400 expand = expand->Retrieve(source);
1401 }
1402 break;
1403 case GR_NEXT:
1404 if (auto_distributed) {
1405 data = &data->InsertOrRetrieve(next);
1406 expand = expand->Retrieve(next);
1407 }
1408 break;
1409 case GR_DESTINATION:
1410 if (auto_distributed) {
1411 data = &data->InsertOrRetrieve(dest);
1412 expand = expand->Retrieve(dest);
1413 }
1414 break;
1415 }
1416 }
1417 data->Update(count);
1418 }
1419
1420 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1421 {
1422 switch (widget) {
1423 case WID_SV_WAITING:
1424 fill.height = resize.height = this->line_height;
1425 size.height = 4 * resize.height + padding.height;
1426 break;
1427
1429 size.height = ((this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->GetString() == STR_STATION_VIEW_RATINGS_BUTTON) ? this->accepts_lines : this->rating_lines) * GetCharacterHeight(FontSize::Normal) + padding.height;
1430 break;
1431 }
1432 }
1433
1434 void OnPaint() override
1435 {
1436 const Station *st = Station::Get(this->window_number);
1437 CargoDataEntry cargo;
1438 BuildCargoList(&cargo, st);
1439
1440 this->vscroll->SetCount(cargo.GetNumChildren()); // update scrollbar
1441
1442 /* disable some buttons */
1448 this->SetWidgetDisabledState(WID_SV_CLOSE_AIRPORT, !st->facilities.Test(StationFacility::Airport) || st->owner != _local_company || st->owner == OWNER_NONE); // Also consider SE, where _local_company == OWNER_NONE
1450
1454
1455 this->DrawWidgets();
1456
1457 if (!this->IsShaded()) {
1458 /* Draw 'accepted cargo' or 'cargo ratings'. */
1460 const Rect r = wid->GetCurrentRect();
1461 if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->GetString() == STR_STATION_VIEW_RATINGS_BUTTON) {
1462 int lines = this->DrawAcceptedCargo(r);
1463 if (lines > this->accepts_lines) { // Resize the widget, and perform re-initialization of the window.
1464 this->accepts_lines = lines;
1465 this->ReInit();
1466 return;
1467 }
1468 } else {
1469 int lines = this->DrawCargoRatings(r);
1470 if (lines > this->rating_lines) { // Resize the widget, and perform re-initialization of the window.
1471 this->rating_lines = lines;
1472 this->ReInit();
1473 return;
1474 }
1475 }
1476
1477 /* Draw arrow pointing up/down for ascending/descending sorting */
1478 this->DrawSortButtonState(WID_SV_SORT_ORDER, sort_orders[1] == SO_ASCENDING ? SBS_UP : SBS_DOWN);
1479
1480 int pos = this->vscroll->GetPosition();
1481
1482 int maxrows = this->vscroll->GetCapacity();
1483
1484 displayed_rows.clear();
1485
1486 /* Draw waiting cargo. */
1488 Rect waiting_rect = nwi->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
1489 this->DrawEntries(cargo, waiting_rect, pos, maxrows, 0);
1490 scroll_to_row = INT_MAX;
1491 }
1492 }
1493
1494 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1495 {
1496 if (widget == WID_SV_CAPTION) {
1497 const Station *st = Station::Get(this->window_number);
1498 return GetString(STR_STATION_VIEW_CAPTION, st->index, st->facilities);
1499 }
1500
1501 return this->Window::GetWidgetString(widget, stringid);
1502 }
1503
1510 {
1511 const Station *st = Station::Get(this->window_number);
1512 CargoDataEntry &entry = cached_destinations.InsertOrRetrieve(cargo);
1513 entry.Clear();
1514
1515 if (!st->goods[cargo].HasData()) return;
1516
1517 for (const auto &it : st->goods[cargo].GetData().flows) {
1518 StationID from = it.first;
1519 CargoDataEntry &source_entry = entry.InsertOrRetrieve(from);
1520 uint32_t prev_count = 0;
1521 for (const auto &flow_it : *it.second.GetShares()) {
1522 StationID via = flow_it.second;
1523 CargoDataEntry &via_entry = source_entry.InsertOrRetrieve(via);
1524 if (via == this->window_number) {
1525 via_entry.InsertOrRetrieve(via).Update(flow_it.first - prev_count);
1526 } else {
1527 EstimateDestinations(cargo, from, via, flow_it.first - prev_count, via_entry);
1528 }
1529 prev_count = flow_it.first;
1530 }
1531 }
1532 }
1533
1543 void EstimateDestinations(CargoType cargo, StationID source, StationID next, uint count, CargoDataEntry &dest)
1544 {
1545 if (Station::IsValidID(next) && Station::IsValidID(source)) {
1546 GoodsEntry &ge = Station::Get(next)->goods[cargo];
1547 if (!ge.HasData()) return;
1548
1549 CargoDataEntry tmp;
1550 const FlowStatMap &flowmap = ge.GetData().flows;
1551 FlowStatMap::const_iterator map_it = flowmap.find(source);
1552 if (map_it != flowmap.end()) {
1553 const FlowStat::SharesMap *shares = map_it->second.GetShares();
1554 uint32_t prev_count = 0;
1555 for (FlowStat::SharesMap::const_iterator i = shares->begin(); i != shares->end(); ++i) {
1556 tmp.InsertOrRetrieve(i->second).Update(i->first - prev_count);
1557 prev_count = i->first;
1558 }
1559 }
1560
1561 if (tmp.GetCount() == 0) {
1562 dest.InsertOrRetrieve(StationID::Invalid()).Update(count);
1563 } else {
1564 uint sum_estimated = 0;
1565 while (sum_estimated < count) {
1566 for (CargoDataSet::iterator i = tmp.Begin(); i != tmp.End() && sum_estimated < count; ++i) {
1567 CargoDataEntry &child = **i;
1568 uint estimate = DivideApprox(child.GetCount() * count, tmp.GetCount());
1569 if (estimate == 0) estimate = 1;
1570
1571 sum_estimated += estimate;
1572 if (sum_estimated > count) {
1573 estimate -= sum_estimated - count;
1574 sum_estimated = count;
1575 }
1576
1577 if (estimate > 0) {
1578 if (child.GetStation() == next) {
1579 dest.InsertOrRetrieve(next).Update(estimate);
1580 } else {
1581 EstimateDestinations(cargo, source, child.GetStation(), estimate, dest);
1582 }
1583 }
1584 }
1585
1586 }
1587 }
1588 } else {
1589 dest.InsertOrRetrieve(StationID::Invalid()).Update(count);
1590 }
1591 }
1592
1599 void BuildFlowList(CargoType cargo, const FlowStatMap &flows, CargoDataEntry *entry)
1600 {
1601 const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(cargo);
1602 for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1603 StationID from = it->first;
1604 const CargoDataEntry *source_entry = source_dest->Retrieve(from);
1605 const FlowStat::SharesMap *shares = it->second.GetShares();
1606 for (FlowStat::SharesMap::const_iterator flow_it = shares->begin(); flow_it != shares->end(); ++flow_it) {
1607 const CargoDataEntry *via_entry = source_entry->Retrieve(flow_it->second);
1608 for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End(); ++dest_it) {
1609 CargoDataEntry &dest_entry = **dest_it;
1610 ShowCargo(entry, cargo, from, flow_it->second, dest_entry.GetStation(), dest_entry.GetCount());
1611 }
1612 }
1613 }
1614 }
1615
1622 void BuildCargoList(CargoType cargo, const StationCargoList &packets, CargoDataEntry *entry)
1623 {
1624 const CargoDataEntry *source_dest = this->cached_destinations.Retrieve(cargo);
1625 for (StationCargoList::ConstIterator it = packets.Packets()->begin(); it != packets.Packets()->end(); it++) {
1626 const CargoPacket *cp = *it;
1627 StationID next = it.GetKey();
1628
1629 const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation());
1630 if (source_entry == nullptr) {
1631 this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count());
1632 continue;
1633 }
1634
1635 const CargoDataEntry *via_entry = source_entry->Retrieve(next);
1636 if (via_entry == nullptr) {
1637 this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count());
1638 continue;
1639 }
1640
1641 uint remaining = cp->Count();
1642 for (CargoDataSet::iterator dest_it = via_entry->Begin(); dest_it != via_entry->End();) {
1643 CargoDataEntry &dest_entry = **dest_it;
1644
1645 /* Advance iterator here instead of in the for statement to test whether this is the last entry */
1646 ++dest_it;
1647
1648 uint val;
1649 if (dest_it == via_entry->End()) {
1650 /* Allocate all remaining waiting cargo to the last destination to avoid
1651 * waiting cargo being "lost", and the displayed total waiting cargo
1652 * not matching GoodsEntry::TotalCount() */
1653 val = remaining;
1654 } else {
1655 val = std::min<uint>(remaining, DivideApprox(cp->Count() * dest_entry.GetCount(), via_entry->GetCount()));
1656 remaining -= val;
1657 }
1658 this->ShowCargo(entry, cargo, cp->GetFirstStation(), next, dest_entry.GetStation(), val);
1659 }
1660 }
1661 this->ShowCargo(entry, cargo, NEW_STATION, NEW_STATION, NEW_STATION, packets.ReservedCount());
1662 }
1663
1669 void BuildCargoList(CargoDataEntry *entry, const Station *st)
1670 {
1671 for (CargoType cargo{}; cargo < NUM_CARGO; ++cargo) {
1672
1673 if (this->cached_destinations.Retrieve(cargo) == nullptr) {
1674 this->RecalcDestinations(cargo);
1675 }
1676
1677 const GoodsEntry &ge = st->goods[cargo];
1678 if (!ge.HasData()) continue;
1679
1680 if (this->current_mode == MODE_WAITING) {
1681 this->BuildCargoList(cargo, ge.GetData().cargo, entry);
1682 } else {
1683 this->BuildFlowList(cargo, ge.GetData().flows, entry);
1684 }
1685 }
1686 }
1687
1693 {
1694 std::list<StationID> stations;
1695 const CargoDataEntry *parent = entry.GetParent();
1696 if (parent->GetParent() == nullptr) {
1697 this->displayed_rows.push_back(RowDisplay(&this->expanded_rows, entry.GetCargo()));
1698 return;
1699 }
1700
1701 StationID next = entry.GetStation();
1702 while (parent->GetParent()->GetParent() != nullptr) {
1703 stations.push_back(parent->GetStation());
1704 parent = parent->GetParent();
1705 }
1706
1707 CargoType cargo = parent->GetCargo();
1708 CargoDataEntry *filter = this->expanded_rows.Retrieve(cargo);
1709 while (!stations.empty()) {
1710 filter = filter->Retrieve(stations.back());
1711 stations.pop_back();
1712 }
1713
1714 this->displayed_rows.push_back(RowDisplay(filter, next));
1715 }
1716
1725 StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any) const
1726 {
1727 if (station == this->window_number) {
1728 return here;
1729 } else if (station == StationID::Invalid()) {
1730 return any;
1731 } else if (station == NEW_STATION) {
1732 return STR_STATION_VIEW_RESERVED;
1733 } else {
1734 return other_station;
1735 }
1736 }
1737
1738 StringID GetGroupingString(Grouping grouping, StationID station) const
1739 {
1740 switch (grouping) {
1741 case GR_SOURCE: return this->GetEntryString(station, STR_STATION_VIEW_FROM_HERE, STR_STATION_VIEW_FROM, STR_STATION_VIEW_FROM_ANY);
1742 case GR_NEXT: return this->GetEntryString(station, STR_STATION_VIEW_VIA_HERE, STR_STATION_VIEW_VIA, STR_STATION_VIEW_VIA_ANY);
1743 case GR_DESTINATION: return this->GetEntryString(station, STR_STATION_VIEW_TO_HERE, STR_STATION_VIEW_TO, STR_STATION_VIEW_TO_ANY);
1744 default: NOT_REACHED();
1745 }
1746 }
1747
1755 StringID SearchNonStop(CargoDataEntry &cd, StationID station, int column)
1756 {
1757 assert(column < NUM_COLUMNS);
1759 for (int i = column - 1; i > 0; --i) {
1760 if (this->groupings[i] == GR_DESTINATION) {
1761 if (parent->GetStation() == station) {
1762 return STR_STATION_VIEW_NONSTOP;
1763 } else {
1764 return STR_STATION_VIEW_VIA;
1765 }
1766 }
1767 parent = parent->GetParent();
1768 }
1769
1770 if (column < NUM_COLUMNS - 1 && this->groupings[column + 1] == GR_DESTINATION) {
1771 CargoDataSet::iterator begin = cd.Begin();
1772 CargoDataSet::iterator end = cd.End();
1773 if (begin != end && ++(cd.Begin()) == end && (*(begin))->GetStation() == station) {
1774 return STR_STATION_VIEW_NONSTOP;
1775 } else {
1776 return STR_STATION_VIEW_VIA;
1777 }
1778 }
1779
1780 return STR_STATION_VIEW_VIA;
1781 }
1782
1789 void DrawCargoIcons(CargoType cargo, uint waiting, const Rect &r) const
1790 {
1791 int width = ScaleSpriteTrad(10);
1792 uint num = std::min<uint>((waiting + (width / 2)) / width, r.Width() / width); // maximum is width / 10 icons so it won't overflow
1793 if (num == 0) return;
1794
1795 SpriteID sprite = CargoSpec::Get(cargo)->GetCargoIcon();
1796
1797 int x = _current_text_dir == TD_RTL ? r.left : r.right - num * width;
1798 int y = CentreBounds(r.top, r.bottom, this->cargo_icon_size.height);
1799 do {
1800 DrawSprite(sprite, PAL_NONE, x, y);
1801 x += width;
1802 } while (--num);
1803 }
1804
1815 int DrawEntries(CargoDataEntry &entry, const Rect &r, int pos, int maxrows, int column, CargoType cargo = INVALID_CARGO)
1816 {
1817 assert(column < NUM_COLUMNS);
1818 if (this->sortings[column] == CargoSortType::AsGrouping) {
1819 if (this->groupings[column] != GR_CARGO) {
1820 entry.Resort(CargoSortType::StationString, this->sort_orders[column]);
1821 }
1822 } else {
1823 entry.Resort(CargoSortType::Count, this->sort_orders[column]);
1824 }
1825 int text_y_offset = (this->line_height - GetCharacterHeight(FontSize::Normal)) / 2;
1826 for (CargoDataSet::iterator i = entry.Begin(); i != entry.End(); ++i) {
1827 CargoDataEntry &cd = **i;
1828
1829 Grouping grouping = this->groupings[column];
1830 if (grouping == GR_CARGO) cargo = cd.GetCargo();
1831 bool auto_distributed = _settings_game.linkgraph.GetDistributionType(cargo) != DistributionType::Manual;
1832
1833 if (pos > -maxrows && pos <= 0) {
1834 StringID str = STR_EMPTY;
1835 StationID station = StationID::Invalid();
1836 int y = r.top - pos * this->line_height;
1837 if (this->groupings[column] == GR_CARGO) {
1838 str = STR_STATION_VIEW_WAITING_CARGO;
1839 this->DrawCargoIcons(cd.GetCargo(), cd.GetCount(), Rect(r.left + this->expand_shrink_width, y, r.right - this->expand_shrink_width, y + this->line_height - 1));
1840 } else {
1841 if (!auto_distributed) grouping = GR_SOURCE;
1842 station = cd.GetStation();
1843 str = this->GetGroupingString(grouping, station);
1844 if (grouping == GR_NEXT && str == STR_STATION_VIEW_VIA) str = this->SearchNonStop(cd, station, column);
1845
1846 if (pos == -this->scroll_to_row && Station::IsValidID(station)) {
1848 }
1849 }
1850
1851 bool rtl = _current_text_dir == TD_RTL;
1852 Rect text = r.Indent(column * WidgetDimensions::scaled.hsep_indent, rtl).Indent(this->expand_shrink_width, !rtl);
1853 Rect shrink = r.WithWidth(this->expand_shrink_width, !rtl);
1854
1855 DrawString(text.left, text.right, y + text_y_offset, GetString(str, cargo, cd.GetCount(), station));
1856
1857 if (column < NUM_COLUMNS - 1) {
1858 std::string_view sym;
1859 if (cd.GetNumChildren() > 0) {
1860 sym = "-";
1861 } else if (auto_distributed && str != STR_STATION_VIEW_RESERVED) {
1862 sym = "+";
1863 } else {
1864 /* Only draw '+' if there is something to be shown. */
1865 const GoodsEntry &ge = Station::Get(this->window_number)->goods[cargo];
1866 if (ge.HasData()) {
1867 const StationCargoList &cargo_list = ge.GetData().cargo;
1868 if (grouping == GR_CARGO && (cargo_list.ReservedCount() > 0 || cd.HasTransfers())) {
1869 sym = "+";
1870 }
1871 }
1872 }
1873 if (!sym.empty()) DrawString(shrink.left, shrink.right, y + text_y_offset, sym, TC_YELLOW);
1874 }
1875 this->SetDisplayedRow(cd);
1876 }
1877 --pos;
1878 if ((auto_distributed || column == 0) && column < NUM_COLUMNS - 1) {
1879 pos = this->DrawEntries(cd, r, pos, maxrows, column + 1, cargo);
1880 }
1881 }
1882 return pos;
1883 }
1884
1890 int DrawAcceptedCargo(const Rect &r) const
1891 {
1892 const Station *st = Station::Get(this->window_number);
1893 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1894
1895 int bottom = DrawStringMultiLine(tr.left, tr.right, tr.top, INT32_MAX, GetString(STR_STATION_VIEW_ACCEPTS_CARGO, GetAcceptanceMask(st)));
1896 return CeilDiv(bottom - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FontSize::Normal));
1897 }
1898
1904 int DrawCargoRatings(const Rect &r) const
1905 {
1906 const Station *st = Station::Get(this->window_number);
1907 bool rtl = _current_text_dir == TD_RTL;
1908 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
1909
1910 if (st->town->exclusive_counter > 0) {
1911 tr.top = DrawStringMultiLine(tr, GetString(st->town->exclusivity == st->owner ? STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF : STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY, st->town->exclusivity));
1912 tr.top += WidgetDimensions::scaled.vsep_wide;
1913 }
1914
1915 DrawString(tr, TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_VIEW_SUPPLY_RATINGS_TITLE_MINUTE : STR_STATION_VIEW_SUPPLY_RATINGS_TITLE_MONTH);
1917
1918 for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1919 const GoodsEntry *ge = &st->goods[cs->Index()];
1920 if (!ge->HasRating()) continue;
1921
1923 DrawString(tr.Indent(WidgetDimensions::scaled.hsep_indent, rtl),
1924 GetString(STR_STATION_VIEW_CARGO_SUPPLY_RATING,
1925 cs->name,
1926 lg != nullptr ? lg->Monthly((*lg)[ge->node].supply) : 0,
1927 STR_CARGO_RATING_APPALLING + (ge->rating >> 5),
1928 ToPercent8(ge->rating)));
1930 }
1931 return CeilDiv(tr.top - r.top - WidgetDimensions::scaled.framerect.top, GetCharacterHeight(FontSize::Normal));
1932 }
1933
1939 template <class Tid>
1941 {
1942 if (filter->Retrieve(next) != nullptr) {
1943 filter->Remove(next);
1944 } else {
1945 filter->InsertOrRetrieve(next);
1946 }
1947 }
1948
1954 {
1955 if (row < 0 || (uint)row >= this->displayed_rows.size()) return;
1956 if (_ctrl_pressed) {
1957 this->scroll_to_row = row;
1958 } else {
1959 RowDisplay &display = this->displayed_rows[row];
1960 if (display.filter == &this->expanded_rows) {
1962 } else {
1964 }
1965 }
1968 }
1969
1970 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1971 {
1973
1974 switch (widget) {
1975 case WID_SV_WAITING:
1976 this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WidgetDimensions::scaled.framerect.top) - this->vscroll->GetPosition());
1977 break;
1978
1979 case WID_SV_CATCHMENT:
1981
1982 if (w != nullptr && this->IsWidgetLowered(WID_SV_CATCHMENT)) {
1985 }
1986 break;
1987
1988 case WID_SV_LOCATION:
1989 if (_ctrl_pressed) {
1990 ShowExtraViewportWindow(Station::Get(this->window_number)->xy);
1991 } else {
1992 ScrollMainWindowToTile(Station::Get(this->window_number)->xy);
1993 }
1994 break;
1995
1997 /* Swap between 'accepts' and 'ratings' view. */
1998 int height_change;
2000 if (this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->GetString() == STR_STATION_VIEW_RATINGS_BUTTON) {
2001 nwi->SetStringTip(STR_STATION_VIEW_ACCEPTS_BUTTON, STR_STATION_VIEW_ACCEPTS_TOOLTIP); // Switch to accepts view.
2002 height_change = this->rating_lines - this->accepts_lines;
2003 } else {
2004 nwi->SetStringTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP); // Switch to ratings view.
2005 height_change = this->accepts_lines - this->rating_lines;
2006 }
2007 this->ReInit(0, height_change * GetCharacterHeight(FontSize::Normal));
2008 break;
2009 }
2010
2011 case WID_SV_RENAME:
2012 ShowQueryString(GetString(STR_STATION_NAME, this->window_number), STR_STATION_VIEW_EDIT_STATION_SIGN, MAX_LENGTH_STATION_NAME_CHARS,
2014 break;
2015
2017 Command<Commands::OpenCloseAirport>::Post(this->window_number);
2018 break;
2019
2020 case WID_SV_TRAINS: // Show list of scheduled trains to this station
2021 case WID_SV_ROADVEHS: // Show list of scheduled road-vehicles to this station
2022 case WID_SV_SHIPS: // Show list of scheduled ships to this station
2023 case WID_SV_PLANES: { // Show list of scheduled aircraft to this station
2024 Owner owner = Station::Get(this->window_number)->owner;
2025 ShowVehicleListWindow(owner, (VehicleType)(widget - WID_SV_TRAINS), static_cast<StationID>(this->window_number));
2026 break;
2027 }
2028
2029 case WID_SV_SORT_BY: {
2030 /* The initial selection is composed of current mode and
2031 * sorting criteria for columns 1, 2, and 3. Column 0 is always
2032 * sorted by cargo type. The others can theoretically be sorted
2033 * by different things but there is no UI for that. */
2035 this->current_mode * 2 + (this->sortings[1] == CargoSortType::Count ? 1 : 0),
2036 WID_SV_SORT_BY, 0, 0);
2037 break;
2038 }
2039
2040 case WID_SV_GROUP_BY: {
2041 ShowDropDownMenu(this, StationViewWindow::group_names, this->grouping_index, WID_SV_GROUP_BY, 0, 0);
2042 break;
2043 }
2044
2045 case WID_SV_SORT_ORDER: { // flip sorting method asc/desc
2046 this->SelectSortOrder(this->sort_orders[1] == SO_ASCENDING ? SO_DESCENDING : SO_ASCENDING);
2047 this->SetTimeout();
2049 break;
2050 }
2051 }
2052 }
2053
2058 void SelectSortOrder(SortOrder order)
2059 {
2060 this->sort_orders[1] = this->sort_orders[2] = this->sort_orders[3] = order;
2061 _settings_client.gui.station_gui_sort_order = this->sort_orders[1];
2062 this->SetDirty();
2063 }
2064
2069 void SelectSortBy(int index)
2070 {
2071 _settings_client.gui.station_gui_sort_by = index;
2072 switch (StationViewWindow::sort_names[index]) {
2073 case STR_STATION_VIEW_WAITING_STATION:
2074 this->current_mode = MODE_WAITING;
2075 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
2076 break;
2077 case STR_STATION_VIEW_WAITING_AMOUNT:
2078 this->current_mode = MODE_WAITING;
2079 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
2080 break;
2081 case STR_STATION_VIEW_PLANNED_STATION:
2082 this->current_mode = MODE_PLANNED;
2083 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::AsGrouping;
2084 break;
2085 case STR_STATION_VIEW_PLANNED_AMOUNT:
2086 this->current_mode = MODE_PLANNED;
2087 this->sortings[1] = this->sortings[2] = this->sortings[3] = CargoSortType::Count;
2088 break;
2089 default:
2090 NOT_REACHED();
2091 }
2092 /* Display the current sort variant */
2094 this->SetDirty();
2095 }
2096
2101 void SelectGroupBy(int index)
2102 {
2103 this->grouping_index = index;
2104 _settings_client.gui.station_gui_group_order = index;
2106 switch (StationViewWindow::group_names[index]) {
2107 case STR_STATION_VIEW_GROUP_S_V_D:
2108 this->groupings[1] = GR_SOURCE;
2109 this->groupings[2] = GR_NEXT;
2110 this->groupings[3] = GR_DESTINATION;
2111 break;
2112 case STR_STATION_VIEW_GROUP_S_D_V:
2113 this->groupings[1] = GR_SOURCE;
2114 this->groupings[2] = GR_DESTINATION;
2115 this->groupings[3] = GR_NEXT;
2116 break;
2117 case STR_STATION_VIEW_GROUP_V_S_D:
2118 this->groupings[1] = GR_NEXT;
2119 this->groupings[2] = GR_SOURCE;
2120 this->groupings[3] = GR_DESTINATION;
2121 break;
2122 case STR_STATION_VIEW_GROUP_V_D_S:
2123 this->groupings[1] = GR_NEXT;
2124 this->groupings[2] = GR_DESTINATION;
2125 this->groupings[3] = GR_SOURCE;
2126 break;
2127 case STR_STATION_VIEW_GROUP_D_S_V:
2128 this->groupings[1] = GR_DESTINATION;
2129 this->groupings[2] = GR_SOURCE;
2130 this->groupings[3] = GR_NEXT;
2131 break;
2132 case STR_STATION_VIEW_GROUP_D_V_S:
2133 this->groupings[1] = GR_DESTINATION;
2134 this->groupings[2] = GR_NEXT;
2135 this->groupings[3] = GR_SOURCE;
2136 break;
2137 }
2138 this->SetDirty();
2139 }
2140
2141 void OnDropdownSelect(WidgetID widget, int index, int) override
2142 {
2143 if (widget == WID_SV_SORT_BY) {
2144 this->SelectSortBy(index);
2145 } else {
2146 this->SelectGroupBy(index);
2147 }
2148 }
2149
2150 void OnQueryTextFinished(std::optional<std::string> str) override
2151 {
2152 if (!str.has_value()) return;
2153
2154 Command<Commands::RenameStation>::Post(STR_ERROR_CAN_T_RENAME_STATION, this->window_number, *str);
2155 }
2156
2157 void OnResize() override
2158 {
2159 this->vscroll->SetCapacityFromWidget(this, WID_SV_WAITING, WidgetDimensions::scaled.framerect.Vertical());
2160 }
2161
2167 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2168 {
2169 if (gui_scope) {
2170 if (data >= 0 && data < NUM_CARGO) {
2171 this->cached_destinations.Remove((CargoType)data);
2172 } else {
2173 this->ReInit();
2174 }
2175 }
2176 }
2177};
2178
2181 WindowPosition::Automatic, "view_station", 249, 117,
2183 {},
2184 _nested_station_view_widgets
2185);
2186
2196
2202
2203static std::vector<TileAndStation> _deleted_stations_nearby;
2204static std::vector<StationID> _stations_nearby_list;
2205
2213template <class T>
2214static void AddNearbyStation(TileIndex tile, TileArea *ctx)
2215{
2216 /* First check if there were deleted stations here */
2217 for (auto it = _deleted_stations_nearby.begin(); it != _deleted_stations_nearby.end(); /* nothing */) {
2218 if (it->tile == tile) {
2219 _stations_nearby_list.push_back(it->station);
2220 it = _deleted_stations_nearby.erase(it);
2221 } else {
2222 ++it;
2223 }
2224 }
2225
2226 /* Check if own station and if we stay within station spread */
2227 if (!IsTileType(tile, TileType::Station)) return;
2228
2229 StationID sid = GetStationIndex(tile);
2230
2231 /* This station is (likely) a waypoint */
2232 if (!T::IsValidID(sid)) return;
2233
2234 BaseStation *st = BaseStation::Get(sid);
2235 if (st->owner != _local_company || std::ranges::find(_stations_nearby_list, sid) != _stations_nearby_list.end()) return;
2236
2237 if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) {
2238 _stations_nearby_list.push_back(sid);
2239 }
2240}
2241
2251template <class T>
2252static void FindStationsNearby(TileArea ta, bool distant_join)
2253{
2254 TileArea ctx = ta;
2255
2256 _stations_nearby_list.clear();
2257 _stations_nearby_list.push_back(NEW_STATION);
2258 _deleted_stations_nearby.clear();
2259
2260 /* Look for deleted stations */
2261 for (const BaseStation *st : BaseStation::Iterate()) {
2262 if (T::IsValidBaseStation(st) && !st->IsInUse() && st->owner == _local_company) {
2263 /* Include only within station spread (yes, it is strictly less than) */
2264 if (std::max(DistanceMax(ta.tile, st->xy), DistanceMax(TileAddXY(ta.tile, ta.w - 1, ta.h - 1), st->xy)) < _settings_game.station.station_spread) {
2265 _deleted_stations_nearby.emplace_back(st->xy, st->index);
2266
2267 /* Add the station when it's within where we're going to build */
2268 if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
2269 IsInsideBS(TileY(st->xy), TileY(ctx.tile), ctx.h)) {
2270 AddNearbyStation<T>(st->xy, &ctx);
2271 }
2272 }
2273 }
2274 }
2275
2276 /* Add stations that are within station tile area. Stations do not have to occupy all tiles */
2277 for (auto t : ta) {
2278 AddNearbyStation<T>(t, &ctx);
2279 }
2280
2281 /* Only search tiles where we have a chance to stay within the station spread.
2282 * The complete check needs to be done in the callback as we don't know the
2283 * extent of the found station, yet. */
2284 if (distant_join && std::min(ta.w, ta.h) >= _settings_game.station.station_spread) return;
2285 uint max_dist = distant_join ? _settings_game.station.station_spread - std::min(ta.w, ta.h) : 1;
2286
2287 for (auto tile : SpiralTileSequence(TileAddByDir(ctx.tile, DIR_N), max_dist, ta.w, ta.h)) {
2288 AddNearbyStation<T>(tile, &ctx);
2289 }
2290}
2291
2292static constexpr std::initializer_list<NWidgetPart> _nested_select_station_widgets = {
2295 NWidget(WWT_CAPTION, Colours::DarkGreen, WID_JS_CAPTION), SetStringTip(STR_JOIN_STATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2297 EndContainer(),
2303 EndContainer(),
2304 EndContainer(),
2305};
2306
2311template <class T>
2312struct SelectStationWindow : Window {
2313 StationPickerCmdProc select_station_proc{};
2315 Scrollbar *vscroll = nullptr;
2316
2317 SelectStationWindow(WindowDesc &desc, TileArea ta, StationPickerCmdProc&& proc) :
2318 Window(desc),
2319 select_station_proc(std::move(proc)),
2320 area(ta)
2321 {
2322 this->CreateNestedTree();
2323 this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR);
2324 this->GetWidget<NWidgetCore>(WID_JS_CAPTION)->SetString(T::IsWaypoint() ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION);
2325 this->FinishInitNested(0);
2326 this->OnInvalidateData(0);
2327
2328 _thd.freeze = true;
2329 }
2330
2331 void Close([[maybe_unused]] int data = 0) override
2332 {
2333 SetViewportCatchmentSpecializedStation<typename T::StationType>(nullptr, true);
2334
2335 _thd.freeze = false;
2336 this->Window::Close();
2337 }
2338
2339 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2340 {
2341 if (widget != WID_JS_PANEL) return;
2342
2343 /* Determine the widest string */
2344 Dimension d = GetStringBoundingBox(T::IsWaypoint() ? STR_JOIN_WAYPOINT_CREATE_SPLIT_WAYPOINT : STR_JOIN_STATION_CREATE_SPLIT_STATION);
2345 for (const auto &station : _stations_nearby_list) {
2346 if (station == NEW_STATION) continue;
2347 const BaseStation *st = BaseStation::Get(station);
2348 d = maxdim(d, GetStringBoundingBox(T::IsWaypoint()
2349 ? GetString(STR_STATION_LIST_WAYPOINT, st->index)
2350 : GetString(STR_STATION_LIST_STATION, st->index, st->facilities)));
2351 }
2352
2353 fill.height = resize.height = d.height;
2354 d.height *= 5;
2355 d.width += padding.width;
2356 d.height += padding.height;
2357 size = d;
2358 }
2359
2360 void DrawWidget(const Rect &r, WidgetID widget) const override
2361 {
2362 if (widget != WID_JS_PANEL) return;
2363
2364 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
2365 auto [first, last] = this->vscroll->GetVisibleRangeIterators(_stations_nearby_list);
2366 for (auto it = first; it != last; ++it, tr.top += this->resize.step_height) {
2367 if (*it == NEW_STATION) {
2368 DrawString(tr, T::IsWaypoint() ? STR_JOIN_WAYPOINT_CREATE_SPLIT_WAYPOINT : STR_JOIN_STATION_CREATE_SPLIT_STATION);
2369 } else {
2370 const BaseStation *st = BaseStation::Get(*it);
2371 DrawString(tr, T::IsWaypoint()
2372 ? GetString(STR_STATION_LIST_WAYPOINT, st->index)
2373 : GetString(STR_STATION_LIST_STATION, st->index, st->facilities));
2374 }
2375 }
2376
2377 }
2378
2379 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2380 {
2381 if (widget != WID_JS_PANEL) return;
2382
2383 auto it = this->vscroll->GetScrolledItemFromWidget(_stations_nearby_list, pt.y, this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.top);
2384 if (it == _stations_nearby_list.end()) return;
2385
2386 /* Execute stored Command */
2387 this->select_station_proc(false, *it);
2388
2389 /* Close Window; this might cause double frees! */
2391 }
2392
2393 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
2394 {
2395 if (_thd.dirty & 2) {
2396 _thd.dirty &= ~2;
2397 this->SetDirty();
2398 }
2399 }
2400
2401 void OnResize() override
2402 {
2403 this->vscroll->SetCapacityFromWidget(this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.Vertical());
2404 }
2405
2411 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2412 {
2413 if (!gui_scope) return;
2414 FindStationsNearby<T>(this->area, true);
2415 this->vscroll->SetCount(_stations_nearby_list.size());
2416 this->SetDirty();
2417 }
2418
2419 void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
2420 {
2421 if (widget != WID_JS_PANEL) {
2422 SetViewportCatchmentSpecializedStation<typename T::StationType>(nullptr, true);
2423 return;
2424 }
2425
2426 /* Show coverage area of station under cursor */
2427 auto it = this->vscroll->GetScrolledItemFromWidget(_stations_nearby_list, pt.y, this, WID_JS_PANEL, WidgetDimensions::scaled.framerect.top);
2428 const typename T::StationType *st = it == _stations_nearby_list.end() || *it == NEW_STATION ? nullptr : T::StationType::Get(*it);
2429 SetViewportCatchmentSpecializedStation<typename T::StationType>(st, true);
2430 }
2431};
2432
2435 WindowPosition::Automatic, "build_station_join", 200, 180,
2438 _nested_select_station_widgets
2439);
2440
2441
2447static bool StationJoinerNeeded(const StationPickerCmdProc &proc)
2448{
2449 /* Only show selection if distant join is enabled in the settings */
2450 if (!_settings_game.station.distant_join_stations) return false;
2451
2452 /* If a window is already opened and we didn't ctrl-click,
2453 * return true (i.e. just flash the old window) */
2454 Window *selection_window = FindWindowById(WC_SELECT_STATION, 0);
2455 if (selection_window != nullptr) {
2456 /* Abort current distant-join and start new one */
2457 selection_window->Close();
2459 }
2460
2461 /* only show the popup, if we press ctrl */
2462 if (!_ctrl_pressed) return false;
2463
2464 /* Now check if we could build there */
2465 return proc(true, StationID::Invalid());
2466}
2467
2474template <class T>
2475void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc&& proc)
2476{
2477 if (StationJoinerNeeded(proc)) {
2478 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
2479 FindStationsNearby<T>(ta, false);
2480 new SelectStationWindow<T>(_select_station_desc, ta, std::move(proc));
2481 } else {
2482 proc(false, StationID::Invalid());
2483 }
2484}
2485
2491void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
2492{
2494}
2495
2501void ShowSelectRailWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
2502{
2504}
2505
2511void ShowSelectRoadWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
2512{
2514}
@ AirportClosed
Dummy block for indicating a closed airport.
Definition airport.h:130
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:75
CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
CargoTypes _cargo_mask
Bitmask of cargo types available.
Definition cargotype.cpp:30
Types/functions related to cargoes.
@ Passengers
Passengers.
Definition cargotype.h:51
@ Invalid
Invalid town production effect.
Definition cargotype.h:46
bool IsCargoInClass(CargoType cargo, CargoClasses cc)
Does cargo c have cargo class cc?
Definition cargotype.h:236
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool None() const
Test if none of the values are set.
constexpr Timpl & Set()
Set all bits.
A cargo data entry representing one possible row in the station view window's top part.
uint count
sum of counts of all children or amount of cargo for this entry.
void Clear()
Delete all subentries, reset count and num_children and adapt parent's count.
StationID GetStation() const
Get the station ID for this entry.
void IncrementSize()
Increment.
void SetTransfers(bool value)
Set the transfers state.
~CargoDataEntry()
Remove ourselves from our parent.
CargoType GetCargo() const
Get the cargo type for this entry.
uint num_children
the number of subentries belonging to this entry.
void Remove(CargoType cargo)
Remove a child associated with the given cargo.
CargoDataEntry * Retrieve(StationID station) const
Retrieve a child for the given station.
uint GetCount() const
Get the cargo count for this entry.
CargoDataEntry * GetParent() const
Get the parent entry for this entry.
StationID station
ID of the station this entry is associated with.
CargoType cargo
ID of the cargo this entry is associated with.
CargoDataEntry & InsertOrRetrieve(StationID station)
Insert a new child or retrieve an existing child using a station ID as ID.
CargoDataEntry & InsertOrRetrieve(CargoType cargo)
Insert a new child or retrieve an existing child using a cargo type as ID.
CargoDataSet::iterator End() const
Get an iterator pointing to the end of the set of children.
void Update(uint count)
Update the count for this entry and propagate the change to the parent entry if there is one.
std::unique_ptr< CargoDataSet > children
the children of this entry.
bool transfers
If there are transfers for this cargo.
CargoDataSet::iterator Begin() const
Get an iterator pointing to the begin of the set of children.
bool HasTransfers() const
Has this entry transfers.
CargoDataEntry * Retrieve(CargoType cargo) const
Retrieve a child for the given cargo.
CargoDataEntry * parent
the parent of this entry.
void Remove(StationID station)
Remove a child associated with the given station.
uint GetNumChildren() const
Get the number of children for this entry.
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
StationCargoPacketMap::const_iterator ConstIterator
bool Succeeded() const
Did this command succeed?
The list of stations per company.
std::array< uint16_t, NUM_CARGO > stations_per_cargo_type
Number of stations with a rating for each cargo type.
static bool StationNameSorter(const Station *const &a, const Station *const &b, const CargoTypes &filter)
Sort stations by their name.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnResize() override
Called after the window got resized.
static bool StationWaitingAvailableSorter(const Station *const &a, const Station *const &b, const CargoTypes &filter)
Sort stations by their available waiting cargo.
void SortStationsList()
Sort the stations list.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static const StringID sorter_names[]
Strings describing how stations are sorted.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static bool StationRatingMaxSorter(const Station *const &a, const Station *const &b, const CargoTypes &filter)
Sort stations by their rating.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnPaint() override
The window must be repainted.
static bool StationWaitingTotalSorter(const Station *const &a, const Station *const &b, const CargoTypes &filter)
Sort stations by their waiting cargo.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static bool StationTypeSorter(const Station *const &a, const Station *const &b, const CargoTypes &filter)
Sort stations by their type.
void OnGameTick() override
Called once per (game) tick.
~CompanyStationsWindow() override
Save the last sorting state.
void BuildStationsList(const Owner owner)
(Re)Build station list
static const std::initializer_list< GUIStationList::SortFunction *const > sorter_funcs
Functions to sort stations.
uint16_t stations_per_cargo_type_no_rating
Number of stations without a rating.
static bool StationRatingMinSorter(const Station *const &a, const Station *const &b, const CargoTypes &filter)
Sort stations by their rating.
Drop down checkmark component.
Flow descriptions by origin stations.
List template of 'things' T to sort in a GUI.
void RebuildDone()
Notify the sortlist that the rebuild is done.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
A connected component of a link graph.
Definition linkgraph.h:37
uint Monthly(uint base) const
Scale a value to its monthly equivalent, based on last compression.
Definition linkgraph.h:253
Baseclass for nested widgets.
Base class for a 'real' widget.
void SetString(StringID string)
Set string of the nested widget.
Definition widget.cpp:1185
void SetStringTip(StringID string, StringID tool_tip)
Set string and tool tip of the nested widget.
Definition widget.cpp:1195
Scrollbar data structure.
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
void SetCount(size_t num)
Sets the number of elements in the list.
auto 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.
size_type 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:2458
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:2532
size_type GetCount() const
Gets the number of elements in the list.
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
size_type GetPosition() const
Gets the position of the first visible element in the list.
Generate TileIndices around a center tile or tile area, with increasing distance.
CargoList that is used for stations.
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
@ DIR_N
North.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:629
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
Definition dropdown.cpp:36
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:587
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ Persist
Set if this dropdown should stay open after an option is selected.
@ Filterable
Set if the dropdown is filterable.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:900
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:939
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:669
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
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:1038
uint8_t GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
Definition gfx.cpp:1278
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:788
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:116
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Small
Index of the small font in the font tables.
Definition gfx_type.h:250
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ DarkGreen
Dark green.
Definition gfx_type.h:292
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:980
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Declaration of link graph classes used for cargo distribution.
@ Manual
Manual distribution. No link graph calculations are run.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition map.cpp:201
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:474
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:407
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
Definition map_func.h:603
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:376
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
int DivideApprox(int a, int b)
Deterministic approximate division.
Definition math_func.cpp:22
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.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr uint ToPercent8(uint i)
Converts a "fract" value 0..255 to "percent" value 0..100.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Types related to the misc widgets.
@ WID_QS_MOVE
Move button.
Definition misc_widget.h:39
static constexpr CargoType CF_EXPAND_LIST
Expand list to show all items (station list).
Definition cargo_type.h:102
static constexpr CargoType CF_NO_RATING
Show items with no rating (station list).
Definition cargo_type.h:100
static constexpr CargoType CF_SELECT_ALL
Select all items (station list).
Definition cargo_type.h:101
TextColour GetContrastColour(PixelColour background, uint8_t threshold)
Determine a contrasty text colour for a coloured background.
Definition palette.cpp:366
static constexpr PixelColour PC_GREEN
Green palette colour.
static constexpr PixelColour PC_RED
Red palette colour.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
Base types for having sorted lists in GUIs.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
Base classes/functions for stations.
std::pair< CargoArray, CargoTypes > GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad)
Get the acceptance of cargoes around the tile in 1/8.
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
CargoTypes GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
Get the cargo types being produced around the tile (in a rectangle).
Command definitions related to stations.
static WindowDesc _station_view_desc(WindowPosition::Automatic, "view_station", 249, 117, WC_STATION_VIEW, WC_NONE, {}, _nested_station_view_widgets)
Window definition for the station view window.
static void StationsWndShowStationRating(int left, int right, int y, CargoType cargo, uint amount, uint8_t rating)
Draw small boxes of cargo amount and ratings data at the given coordinates.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
static WindowDesc _select_station_desc(WindowPosition::Automatic, "build_station_join", 200, 180, WC_SELECT_STATION, WC_NONE, WindowDefaultFlag::Construction, _nested_select_station_widgets)
Window definition for the station selection window for (distant) joining.
CargoSortType
Ways of sorting cargo in the UI.
@ StationID
by station id
@ CargoType
by cargo type
@ AsGrouping
by the same principle the entries are being grouped
@ StationString
by station name
@ Count
by amount of cargo
void ShowSelectRailWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the rail waypoint selection window when needed.
void FindStationsAroundSelection()
Find stations adjacent to the current tile highlight area, so that existing coverage area can be draw...
static bool StationJoinerNeeded(const StationPickerCmdProc &proc)
Check whether we need to show the station selection window.
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s).
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
static WindowDesc _company_stations_desc(WindowPosition::Automatic, "list_stations", 358, 162, WC_STATION_LIST, WC_NONE, {}, _nested_company_stations_widgets)
Window definition for the company stations window.
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
void ShowCompanyStations(CompanyID company)
Opens window with list of company's stations.
void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc &&proc)
Show the station selection window when needed.
static void FindStationsNearby(TileArea ta, bool distant_join)
Circulate around the to-be-built station to find stations we could join.
static void AddNearbyStation(TileIndex tile, TileArea *ctx)
Add station on this tile to _stations_nearby_list if it's fully within the station spread.
void ShowSelectRoadWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the road waypoint selection window when needed.
Contains enums and function declarations connected with stations GUI.
StationCoverageType
Types of cargo to display for station coverage.
Definition station_gui.h:21
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition station_gui.h:23
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
Definition station_gui.h:22
@ SCT_ALL
Draw all cargoes.
Definition station_gui.h:24
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
StationFacility
The facilities a station might be having.
@ Dock
Station with a dock.
@ TruckStop
Station with truck stops.
@ Train
Station with train station.
@ Airport
Station with an airport.
@ BusStop
Station with bus stops.
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
Types related to the station widgets.
@ WID_JS_CAPTION
Caption of the window.
@ WID_JS_PANEL
Main panel.
@ WID_JS_SCROLLBAR
Scrollbar of the panel.
@ WID_SV_CLOSE_AIRPORT
'Close airport' button.
@ WID_SV_SORT_ORDER
'Sort order' button
@ WID_SV_CATCHMENT
Toggle catchment area highlight.
@ WID_SV_ROADVEHS
List of scheduled road vehs button.
@ WID_SV_SCROLLBAR
Scrollbar.
@ WID_SV_CAPTION
Caption of the window.
@ WID_SV_GROUP
label for "group by"
@ WID_SV_RENAME
'Rename' button.
@ WID_SV_SORT_BY
'Sort by' button
@ WID_SV_GROUP_BY
'Group by' button
@ WID_SV_PLANES
List of scheduled planes button.
@ WID_SV_ACCEPT_RATING_LIST
List of accepted cargoes / rating of cargoes.
@ WID_SV_WAITING
List of waiting cargo.
@ WID_SV_SHIPS
List of scheduled ships button.
@ WID_SV_LOCATION
'Location' button.
@ WID_SV_TRAINS
List of scheduled trains button.
@ WID_SV_ACCEPTS_RATINGS
'Accepts' / 'Ratings' button.
@ WID_SV_CLOSE_AIRPORT_SEL
Container for 'close airport' button, which can be hidden.
@ WID_STL_CAPTION
Caption of the window.
@ WID_STL_TRUCK
'TRUCK' button - list only facilities where is a truck stop.
@ WID_STL_SCROLLBAR
Scrollbar next to the main panel.
@ WID_STL_SORTDROPBTN
Dropdown button.
@ WID_STL_SORTBY
'Sort by' button - reverse sort direction.
@ WID_STL_TRAIN
'TRAIN' button - list only facilities where is a railroad station.
@ WID_STL_BUS
'BUS' button - list only facilities where is a bus stop.
@ WID_STL_FACILALL
'ALL' button - list all facilities.
@ WID_STL_LIST
The main panel, list of stations.
@ WID_STL_SHIP
'SHIP' button - list only facilities where is a dock.
@ WID_STL_CARGODROPDOWN
Cargo type dropdown list.
@ WID_STL_AIRPLANE
'AIRPLANE' button - list only facilities where is an airport.
Definition of base types and functions in a cross-platform compatible way.
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:429
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
AirportBlocks blocks
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Base class for all station-ish types.
TileIndex xy
Base tile of the station.
StationFacilities facilities
The facilities that this station has.
Owner owner
The owner of this station.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Town * town
The town this station is associated with.
Class for storing amounts of cargo.
Definition cargo_type.h:117
Container for cargo from the same location and time.
Definition cargopacket.h:41
uint16_t Count() const
Gets the number of 'items' in this packet.
StationID GetFirstStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Specification of a cargo type.
Definition cargotype.h:75
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:139
StringID abbrev
Two letter abbreviation for this cargo type.
Definition cargotype.h:96
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
bool IsValid() const
Tests for validity of this cargospec.
Definition cargotype.h:119
CargoTypes cargoes
bitmap of cargo types to include
StationFacilities facilities
types of stations of interest
bool include_no_rating
Whether we should include stations with no cargo rating.
Dimensions (a width and height) of a rectangle in 2D.
FlowStatMap flows
Planned flows through this station.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Stores station stats for a single cargo.
bool HasRating() const
Does this cargo have a rating at this station?
NodeID node
ID of node in link graph referring to this goods entry.
const GoodsEntryData & GetData() const
Get optional cargo packet/flow data.
LinkGraphID link_graph
Link graph this station belongs to.
uint8_t rating
Station rating for this cargo.
bool HasData() const
Test if this goods entry has optional cargo packet/flow data.
Data structure describing how to show the list (what sort direction and criteria).
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
Definition map_func.h:298
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Definition map_func.h:289
static uint Size()
Get the size of the map.
Definition map_func.h:280
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
Colour for pixel/line drawing.
Definition gfx_type.h:414
static Pool::IterateWrapper< BaseStation > Iterate(size_t from=0)
static BaseStation * Get(auto index)
static LinkGraph * GetIfValid(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Window for selecting stations/waypoints to (distant) join to.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnResize() override
Called after the window got resized.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnMouseOver(Point pt, WidgetID widget) override
The mouse is currently moving over the window or has just moved outside of the window.
TileArea area
Location of new station.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static bool IsExpected(const BaseStation *st)
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
static Waypoint * Get(auto index)
static Waypoint * From(BaseStation *st)
A row being displayed in the cargo view (as opposed to being "hidden" behind a plus sign).
StationID next_station
ID of the station belonging to the entry actually displayed if it's to/from/via.
CargoDataEntry * filter
Parent of the cargo entry belonging to the row.
CargoType next_cargo
ID of the cargo belonging to the entry actually displayed if it's cargo.
The StationView window.
void HandleCargoWaitingClick(int row)
Handle a click on a specific row in the cargo view.
int DrawEntries(CargoDataEntry &entry, const Rect &r, int pos, int maxrows, int column, CargoType cargo=INVALID_CARGO)
Draw the given cargo entries in the station GUI.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Mode
Display mode of the cargo view.
@ MODE_PLANNED
Show cargo planned to pass through the station.
@ MODE_WAITING
Show cargo waiting at the station.
std::array< Grouping, NUM_COLUMNS > groupings
Grouping modes for the different columns.
void EstimateDestinations(CargoType 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...
void SelectSortBy(int index)
Select a new sort criterium for the cargo view.
void OnResize() override
Called after the window got resized.
StringID SearchNonStop(CargoDataEntry &cd, StationID station, int column)
Determine if we need to show the special "non-stop" string.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Grouping
Type of grouping used in each of the "columns".
@ GR_SOURCE
Group by source of cargo ("from").
@ GR_NEXT
Group by next station ("via").
@ GR_CARGO
Group by cargo type.
@ GR_DESTINATION
Group by estimated final destination ("to").
void BuildCargoList(CargoType cargo, const StationCargoList &packets, CargoDataEntry *entry)
Build up the cargo view for WAITING mode and a specific cargo.
int DrawCargoRatings(const Rect &r) const
Draw cargo ratings in the WID_SV_ACCEPT_RATING_LIST widget.
static const int NUM_COLUMNS
Number of "columns" in the cargo view: cargo, from, via, to.
void OnInit() override
Notification that the nested widget tree gets initialized.
void RecalcDestinations(CargoType cargo)
Rebuild the cache for estimated destinations which is used to quickly show the "destination" entries ...
int line_height
Height of a cargo line.
Dimension cargo_icon_size
Size of largest cargo icon.
Invalidation
Type of data invalidation.
@ INV_FLOWS
The planned flows have been recalculated and everything has to be updated.
@ INV_CARGO
Some cargo has been added or removed.
void BuildCargoList(CargoDataEntry *entry, const Station *st)
Build up the cargo view for all cargoes.
void SelectSortOrder(SortOrder order)
Select a new sort order for the cargo view.
CargoDataEntry expanded_rows
Parent entry of currently expanded rows.
void OnPaint() override
The window must be repainted.
static constexpr uint RATING_LINES
Height in lines of the cargo ratings view.
CargoDataVector displayed_rows
Parent entry of currently displayed rows (including collapsed ones).
static const StringID group_names[]
Names of the grouping options in the dropdown.
int grouping_index
Currently selected entry in the grouping drop down.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static constexpr uint ACCEPTS_LINES
Height in lines of the accepted cargo view.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any) const
Select the correct string for an entry referring to the specified station.
std::array< CargoSortType, NUM_COLUMNS > sortings
Sort types of the different 'columns'.
void SetDisplayedRow(const CargoDataEntry &entry)
Mark a specific row, characterized by its CargoDataEntry, as expanded.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
std::array< SortOrder, NUM_COLUMNS > sort_orders
Sort order (ascending/descending) for the 'columns'.
uint expand_shrink_width
The width allocated to the expand/shrink 'button'.
void HandleCargoWaitingClick(CargoDataEntry *filter, Tid next)
Expand or collapse a specific row.
int rating_lines
Number of lines in the cargo ratings view.
static const StringID sort_names[]
Names of the sorting options in the dropdown.
void DrawCargoIcons(CargoType cargo, uint waiting, const Rect &r) const
Draw icons of waiting cargo.
CargoDataEntry cached_destinations
Cache for the flows passing through this station.
int scroll_to_row
If set, scroll the main viewport to the station pointed to by this row.
Mode current_mode
Currently selected display mode of cargo view.
int accepts_lines
Number of lines in the accepted cargo view.
void BuildFlowList(CargoType cargo, const FlowStatMap &flows, CargoDataEntry *entry)
Build up the cargo view for PLANNED mode and a specific cargo.
void SelectGroupBy(int index)
Select a new grouping mode for the cargo view.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
int DrawAcceptedCargo(const Rect &r) const
Draw accepted cargo in the WID_SV_ACCEPT_RATING_LIST widget.
void ShowCargo(CargoDataEntry *data, CargoType cargo, StationID source, StationID next, StationID dest, uint count)
Show a certain cargo entry characterized by source/next/dest station, cargo type and amount of cargo ...
Station data structure.
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
Airport airport
Tile area the airport covers.
Struct containing TileIndex and StationID.
TileIndex tile
TileIndex.
StationID station
StationID.
CompanyID exclusivity
which company has exclusivity
Definition town.h:86
uint8_t exclusive_counter
months till the exclusivity expires
Definition town.h:87
The information about a vehicle list.
Definition vehiclelist.h:32
Representation of a waypoint.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:992
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1117
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:835
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1822
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:786
Window * parent
Parent window.
Definition window_gui.h:329
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:570
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:518
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:818
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1089
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1812
WindowClass window_class
Window class.
Definition window_gui.h:302
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:317
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:563
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:356
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1846
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:990
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:327
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:451
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
Stuff related to the text buffer GUI.
@ EnableMove
enable the 'Move' button
Definition textbuf_gui.h:22
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Definition textbuf_gui.h:20
@ LengthIsInChars
the length of the string is counted in characters
Definition textbuf_gui.h:21
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
@ Station
A tile of a station or airport.
Definition tile_type.h:54
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void UpdateTileSelection()
Updates tile highlighting for all cases.
@ HT_RECT
rectangle (stations, depots, ...)
Base of the town class.
Functions related to the vehicle's GUIs.
VehicleType
Available vehicle types.
@ Ship
Ship vehicle type.
@ Aircraft
Aircraft vehicle type.
@ Road
Road vehicle type.
@ Train
Train vehicle type.
Functions and type for generating vehicle lists.
@ VL_STATION_LIST
Index is the station.
Definition vehiclelist.h:25
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
void SetViewportStationRect(const Station *st, bool sel)
Select or deselect station for rectangle area highlight.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
void SetViewportWaypointRect(const Waypoint *wp, bool sel)
Select or deselect waypoint for rectangle area highlight.
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
Functions related to (drawing on) viewports.
Base of waypoints.
@ WPF_ROAD
This is a road waypoint.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
@ EqualSize
Containers should keep all their (resizing) children equally large.
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:1209
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1181
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1166
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:153
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:219
@ SBS_UP
Sort descending.
Definition window_gui.h:220
@ Automatic
Find a place automatically.
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:21
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:51
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_STATION_VIEW
Station view; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107