40#include "table/strings.h"
50 static bool IsAcceptableWaypointTile(
TileIndex) {
return false; }
51 static constexpr bool IsWaypoint() {
return false; }
54template <
bool ROAD, TileType TILE_TYPE>
61 static bool IsAcceptableWaypointTile(
TileIndex tile) {
return IsTileType(tile, TILE_TYPE); }
62 static constexpr bool IsWaypoint() {
return true; }
80 CargoTypes cargo_mask = 0;
95 default: NOT_REACHED();
97 if (cargoes[i] >= (supplies ? 1U : 8U))
SetBit(cargo_mask, i);
101 return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
113 SetViewportCatchmentSpecializedStation<typename T::StationType>(
nullptr,
true);
122 typename T::StationType *st = T::StationType::GetByTile(location.
tile);
123 if (st !=
nullptr && T::IsValidBaseStation(st)) {
124 SetViewportCatchmentSpecializedStation<typename T::StationType>(st,
true);
134 int max_c = T::IsWaypoint() && !T::IsAcceptableWaypointTile(location.
tile) ? 0 : 1;
137 typename T::StationType *adjacent =
nullptr;
142 typename T::StationType *st = T::StationType::GetByTile(tile);
143 if (st ==
nullptr || !T::IsValidBaseStation(st))
continue;
144 if (adjacent !=
nullptr && st != adjacent) {
152 SetViewportCatchmentSpecializedStation<typename T::StationType>(adjacent,
true);
163 static bool _last_ctrl_pressed;
169 if (_thd.
dirty & 1) {
174 FindStationsAroundSelection<StationTypeFilter>();
180void CheckRedrawWaypointCoverage()
183 static bool _last_ctrl_pressed;
189 if (_thd.
dirty & 1) {
193 FindStationsAroundSelection<T>();
198void CheckRedrawRailWaypointCoverage(
const Window *)
200 CheckRedrawWaypointCoverage<RailWaypointTypeFilter>();
203void CheckRedrawRoadWaypointCoverage(
const Window *)
205 CheckRedrawWaypointCoverage<RoadWaypointTypeFilter>();
222 static const uint units_full = 576;
223 static const uint rating_full = 224;
229 int width = right - left;
230 int colour = cs->rating_colour;
232 uint w = std::min(amount + 5, units_full) * width / units_full;
238 GfxFillRect(left, y, left + w - 1, y + height, colour);
244 GfxFillRect(left, y + height - rest, left + padding - 1, y + height, colour);
251 y += height + padding + 1;
253 w = std::min<uint>(rating, rating_full) * (width - padding - padding) / rating_full;
281 static inline const StringID sorter_names[] = {
289 static const std::initializer_list<GUIStationList::SortFunction * const> sorter_funcs;
295 bool filter_expanded;
310 this->stations.clear();
311 this->stations_per_cargo_type.fill(0);
312 this->stations_per_cargo_type_no_rating = 0;
315 if ((this->filter.facilities & st->facilities) != 0) {
320 if (st->goods[j].HasRating()) this->stations_per_cargo_type[j]++;
323 if (st->goods[j].HasRating()) {
325 if (
HasBit(this->filter.cargoes, j)) {
326 this->stations.push_back(st);
333 if (this->filter.include_no_rating) this->stations.push_back(st);
334 this->stations_per_cargo_type_no_rating++;
342 this->vscroll->
SetCount(this->stations.size());
414 if (!this->stations.
Sort())
return;
424 this->filter = CompanyStationsWindow::initial_state;
427 this->stations.
SetListing(this->filter.last_sorting);
428 this->stations.
SetSortFuncs(CompanyStationsWindow::sorter_funcs);
438 if (this->filter.cargoes == ALL_CARGOTYPES) this->filter.cargoes =
_cargo_mask;
440 for (uint i = 0; i < 5; i++) {
450 this->filter.last_sorting = this->stations.
GetListing();
451 CompanyStationsWindow::initial_state = this->filter;
460 d.height += padding.height;
467 d.width += padding.width;
468 d.height += padding.height;
475 size.height = padding.height + 5 *
resize.height;
478 this->rating_width = 0;
483 this->rating_width = this->rating_width * 16 / 10;
514 for (
auto it = first; it !=
last; ++it) {
537 if (x <
tr.left)
break;
542 if (x >
tr.right)
break;
546 tr.top += line_height;
549 if (this->vscroll->
GetCount() == 0) {
566 if (this->filter.cargoes == 0) {
570 }
else if (
CountBits(this->filter.cargoes) == 1 && !this->filter.include_no_rating) {
585 list.push_back(MakeDropDownListDividerItem());
598 count = this->stations_per_cargo_type[cs->Index()];
602 list.push_back(std::make_unique<DropDownListCargoItem>(
HasBit(this->filter.cargoes, cs->Index()), fmt::format(
"{}", count),
d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(),
false, count == 0));
607 if (list.size() > 2) list.push_back(MakeDropDownListDividerItem());
619 if (it == this->stations.end())
return;
672 this->filter_expanded =
false;
673 ShowDropDownList(
this, this->BuildCargoDropDownList(this->filter_expanded), -1, widget, 0,
false,
true);
681 if (this->stations.
SortType() != index) {
698 this->filter.cargoes = 1ULL << index;
699 this->filter.include_no_rating =
false;
703 this->filter.include_no_rating = !this->filter.include_no_rating;
705 this->filter.include_no_rating =
true;
706 this->filter.cargoes = 0;
710 this->filter.include_no_rating =
true;
712 this->filter_expanded =
true;
713 ReplaceDropDownList(
this, this->BuildCargoDropDownList(this->filter_expanded));
722 if (
_ctrl_pressed) ReplaceDropDownList(
this, this->BuildCargoDropDownList(this->filter_expanded));
733 Debug(
misc, 3,
"Periodic rebuild station list company {}", this->window_number);
760const std::initializer_list<GUIStationList::SortFunction * const> CompanyStationsWindow::sorter_funcs = {
763 &StationWaitingTotalSorter,
764 &StationWaitingAvailableSorter,
765 &StationRatingMaxSorter,
766 &StationRatingMinSorter
769static constexpr NWidgetPart _nested_company_stations_widgets[] = {
783 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_STL_FACILALL),
SetAspect(WidgetDimensions::ASPECT_VEHICLE_ICON),
SetDataTip(STR_ABBREV_ALL, STR_STATION_LIST_SELECT_ALL_FACILITIES),
SetTextStyle(TC_BLACK,
FS_SMALL),
SetFill(0, 1),
794 NWidget(
WWT_PANEL, COLOUR_GREY,
WID_STL_LIST),
SetMinimalSize(346, 125),
SetResize(1, 10),
SetDataTip(0x0, STR_STATION_LIST_TOOLTIP),
SetScrollbar(
WID_STL_SCROLLBAR),
EndContainer(),
803 WDP_AUTO,
"list_stations", 358, 162,
806 _nested_company_stations_widgets
818 AllocateWindowDescFront<CompanyStationsWindow>(_company_stations_desc, company);
821static constexpr NWidgetPart _nested_station_view_widgets[] = {
833 NWidget(
WWT_DROPDOWN, COLOUR_GREY,
WID_SV_GROUP_BY),
SetMinimalSize(168, 12),
SetResize(1, 0),
SetFill(0, 1),
SetDataTip(0x0, STR_TOOLTIP_GROUP_ORDER),
837 NWidget(
WWT_DROPDOWN, COLOUR_GREY,
WID_SV_SORT_BY),
SetMinimalSize(168, 12),
SetResize(1, 0),
SetFill(0, 1),
SetDataTip(0x0, STR_TOOLTIP_SORT_CRITERIA),
846 SetDataTip(STR_STATION_VIEW_RATINGS_BUTTON, STR_STATION_VIEW_RATINGS_TOOLTIP),
848 SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP),
849 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_SV_CATCHMENT),
SetMinimalSize(45, 12),
SetResize(1, 0),
SetFill(1, 1),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
870 uint num = std::min<uint>((waiting + (width / 2)) / width, (right - left) / width);
871 if (num == 0)
return;
908 bool SortId(Tid st1, Tid st2)
const;
910 bool SortStation (StationID st1, StationID st2)
const;
913typedef std::set<CargoDataEntry *, CargoSorter> CargoDataSet;
932 return this->InsertOrRetrieve<StationID>(
station);
942 return this->InsertOrRetrieve<CargoID>(
cargo);
1065CargoDataEntry::CargoDataEntry() :
1067 station(INVALID_STATION),
1078 children(new CargoDataSet)
1081CargoDataEntry::CargoDataEntry(StationID station, uint count,
CargoDataEntry *parent) :
1086 children(new CargoDataSet)
1089CargoDataEntry::CargoDataEntry(StationID station) :
1097CargoDataEntry::CargoDataEntry(
CargoID cargo) :
1105CargoDataEntry::~CargoDataEntry()
1136 CargoDataSet::iterator i = this->
children->find(child);
1153 CargoDataSet::iterator i = this->
children->find(&tmp);
1171 this->count +=
count;
1184void CargoDataEntry::Resort(
CargoSortType type, SortOrder order)
1186 CargoDataSet *new_subs =
new CargoDataSet(this->
children->begin(), this->children->end(),
CargoSorter(type, order));
1203 switch (this->type) {
1209 return this->SortCount(cd1, cd2);
1218bool CargoSorter::SortId(Tid st1, Tid st2)
const
1220 return (this->order == SO_ASCENDING) ? st1 < st2 : st2 < st1;
1229 }
else if (this->order == SO_ASCENDING) {
1236bool CargoSorter::SortStation(StationID st1, StationID st2)
const
1239 return Station::IsValidID(st2) ? this->order == SO_ASCENDING : this->SortId(st1, st2);
1241 return order == SO_DESCENDING;
1246 return this->SortId(st1, st2);
1248 return (this->order == SO_ASCENDING) ? res < 0 : res > 0;
1280 typedef std::vector<RowDisplay> CargoDataVector;
1371 this->sort_orders[0] = SO_ASCENDING;
1399 if (count == 0)
return;
1438 size.height = 4 *
resize.height + padding.height;
1483 const Rect r =
wid->GetCurrentRect();
1486 if (lines > this->accepts_lines) {
1487 this->accepts_lines = lines;
1493 if (lines > this->rating_lines) {
1494 this->rating_lines = lines;
1538 StationID from = it.first;
1541 for (
const auto &
flow_it : *it.second.GetShares()) {
1542 StationID via =
flow_it.second;
1544 if (via == this->window_number) {
1570 const FlowStat::SharesMap *shares =
map_it->second.GetShares();
1572 for (FlowStat::SharesMap::const_iterator i = shares->begin(); i != shares->end(); ++i) {
1573 tmp.InsertOrRetrieve(i->second)->Update(i->first -
prev_count);
1578 if (
tmp.GetCount() == 0) {
1583 for (CargoDataSet::iterator i =
tmp.Begin(); i !=
tmp.End() &&
sum_estimated < count; ++i) {
1586 if (estimate == 0) estimate = 1;
1619 for (FlowStatMap::const_iterator it = flows.begin(); it != flows.end(); ++it) {
1620 StationID from = it->first;
1622 const FlowStat::SharesMap *shares = it->second.GetShares();
1623 for (FlowStat::SharesMap::const_iterator
flow_it = shares->begin();
flow_it != shares->end(); ++
flow_it) {
1644 StationID next = it.GetKey();
1648 this->
ShowCargo(cargo, i,
cp->GetFirstStation(), next, INVALID_STATION,
cp->Count());
1654 this->
ShowCargo(cargo, i,
cp->GetFirstStation(), next, INVALID_STATION,
cp->Count());
1658 uint remaining =
cp->Count();
1690 if (this->cached_destinations.
Retrieve(i) ==
nullptr) {
1708 std::list<StationID> stations;
1710 if (
parent->GetParent() ==
nullptr) {
1716 while (
parent->GetParent()->GetParent() !=
nullptr) {
1717 stations.push_back(
parent->GetStation());
1723 while (!stations.empty()) {
1724 filter = filter->
Retrieve(stations.back());
1725 stations.pop_back();
1728 this->displayed_rows.push_back(
RowDisplay(filter, next));
1741 if (station == this->window_number) {
1743 }
else if (station == INVALID_STATION) {
1745 }
else if (station == NEW_STATION) {
1763 for (
int i =
column - 1; i > 0; --i) {
1765 if (
parent->GetStation() == station) {
1775 CargoDataSet::iterator begin =
cd->Begin();
1776 CargoDataSet::iterator end =
cd->End();
1777 if (begin != end && ++(
cd->Begin()) == end && (*(begin))->GetStation() == station) {
1806 for (CargoDataSet::iterator i =
entry->Begin(); i !=
entry->End(); ++i) {
1813 if (pos > -
maxrows && pos <= 0) {
1824 StationID station =
cd->GetStation();
1852 const char *
sym =
nullptr;
1853 if (
cd->GetNumChildren() > 0) {
1934 if (filter->
Retrieve(next) !=
nullptr) {
1947 if (
row < 0 || (uint)
row >= this->displayed_rows.size())
return;
1949 this->scroll_to_row =
row;
1952 if (display.
filter == &
this->expanded_rows) {
2031 this->
SelectSortOrder(this->sort_orders[1] == SO_ASCENDING ? SO_DESCENDING : SO_ASCENDING);
2045 this->sort_orders[1] = this->sort_orders[2] = this->sort_orders[3] = order;
2088 this->grouping_index = index;
2137 if (!str.has_value())
return;
2165 WDP_AUTO,
"view_station", 249, 117,
2168 _nested_station_view_widgets
2178 AllocateWindowDescFront<StationViewWindow>(_station_view_desc, station);
2187static std::vector<TileAndStation> _deleted_stations_nearby;
2188static std::vector<StationID> _stations_nearby_list;
2203 for (
auto it = _deleted_stations_nearby.begin(); it != _deleted_stations_nearby.end(); ) {
2204 if (it->tile == tile) {
2205 _stations_nearby_list.push_back(it->station);
2206 it = _deleted_stations_nearby.erase(it);
2218 if (!T::IsValidID(sid))
return false;
2221 if (st->
owner !=
_local_company || std::ranges::find(_stations_nearby_list, sid) != _stations_nearby_list.end())
return false;
2223 if (st->
rect.BeforeAddRect(ctx->
tile, ctx->
w, ctx->
h, StationRect::ADD_TEST).
Succeeded()) {
2224 _stations_nearby_list.push_back(sid);
2244 _stations_nearby_list.clear();
2245 _stations_nearby_list.push_back(NEW_STATION);
2246 _deleted_stations_nearby.clear();
2255 if (T::IsValidBaseStation(st) && !st->IsInUse() && st->owner ==
_local_company) {
2258 _deleted_stations_nearby.push_back({st->xy, st->index});
2263 AddNearbyStation<T>(st->xy, &ctx);
2281static constexpr NWidgetPart _nested_select_station_widgets[] = {
2302 StationPickerCmdProc select_station_proc;
2308 select_station_proc(std::
move(proc)),
2330 if (widget != WID_JS_PANEL)
return;
2334 for (
const auto &station : _stations_nearby_list) {
2335 if (station == NEW_STATION)
continue;
2344 d.width += padding.width;
2345 d.height += padding.height;
2351 if (widget != WID_JS_PANEL)
return;
2356 if (*it == NEW_STATION) {
2370 if (widget != WID_JS_PANEL)
return;
2373 if (it == _stations_nearby_list.end())
return;
2376 this->select_station_proc(
false, *it);
2384 if (_thd.
dirty & 2) {
2404 this->vscroll->
SetCount(_stations_nearby_list.size());
2410 if (widget != WID_JS_PANEL) {
2417 const typename T::StationType *st = it == _stations_nearby_list.end() || *it == NEW_STATION ?
nullptr : T::StationType::Get(*it);
2423 WDP_AUTO,
"build_station_join", 200, 180,
2426 _nested_select_station_widgets
2446 if (selection_window !=
nullptr) {
2448 selection_window->
Close();
2456 if (!proc(
true, INVALID_STATION))
return false;
2458 return FindStationsNearby<T>(ta,
false) ==
nullptr;
2470 if (StationJoinerNeeded<T>(ta, proc)) {
2474 proc(
false, INVALID_STATION);
2485 ShowSelectBaseStationIfNeeded<StationTypeFilter>(ta, std::move(proc));
2495 ShowSelectBaseStationIfNeeded<RailWaypointTypeFilter>(ta, std::move(proc));
2505 ShowSelectBaseStationIfNeeded<RoadWaypointTypeFilter>(ta, std::move(proc));
static const uint64_t AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
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.
Types/functions related to cargoes.
bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
@ CC_PASSENGERS
Passengers.
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 * InsertOrRetrieve(CargoID cargo)
Insert a new child or retrieve an existing child using a cargo ID as ID.
uint num_children
the number of subentries belonging to this entry.
CargoDataEntry * Retrieve(StationID station) const
Retrieve a child for the given station.
uint GetCount() const
Get the cargo count for this entry.
CargoID GetCargo() const
Get the cargo ID for this entry.
CargoDataEntry * Retrieve(CargoID cargo) const
Retrieve a child for the given cargo.
CargoDataEntry * GetParent() const
Get the parent entry for this entry.
StationID station
ID of the station this entry is associated with.
CargoDataSet * children
the children of this entry.
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.
void Remove(CargoID cargo)
Remove a child associated with the given cargo.
CargoID cargo
ID of the cargo this entry is associated with.
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 * 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.
CargoDataEntry * InsertOrRetrieve(StationID station)
Insert a new child or retrieve an existing child using a station ID as ID.
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Tcont::const_iterator ConstIterator
The const iterator for our container.
bool Succeeded() const
Did this command succeed?
The list of stations per company.
static bool StationRatingMaxSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their rating.
std::array< uint16_t, NUM_CARGO > stations_per_cargo_type
Number of stations with a rating for each cargo type.
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.
void SortStationsList()
Sort the stations list.
static bool StationRatingMinSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their rating.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
static bool StationWaitingAvailableSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their available waiting cargo.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPaint() override
The window must be repainted.
static bool StationNameSorter(const Station *const &a, const Station *const &b, const CargoTypes &)
Sort stations by their name.
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 &)
Sort stations by their type.
void OnGameTick() override
Called once per (game) tick.
static bool StationWaitingTotalSorter(const Station *const &a, const Station *const &b, const CargoTypes &cargo_filter)
Sort stations by their waiting cargo.
void BuildStationsList(const Owner owner)
(Re)Build station list
uint16_t stations_per_cargo_type_no_rating
Number of stations without a rating.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Drop down checkmark component.
Drop down string 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.
void SetListing(Listing l)
Import sort conditions.
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.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
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.
CargoList that is used for stations.
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
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.
Owner
Enum for all companies/owners.
@ OWNER_NONE
The tile has no ownership.
int DivideApprox(int a, int b)
Deterministic approximate division.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
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.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
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.
bool _ctrl_pressed
Is Ctrl pressed?
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
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.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ SA_CENTER
Center both horizontally and vertically.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
@ DT_MANUAL
Manual distribution. No link graph calculations are run.
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
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(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static constexpr CargoID CF_NO_RATING
Show items with no rating (station list)
static constexpr CargoID CF_EXPAND_LIST
Expand list to show all items (station list)
static constexpr CargoID CF_SELECT_ALL
Select all items (station list)
TextColour GetContrastColour(uint8_t background, uint8_t threshold)
Determine a contrasty text colour for a coloured background.
static const uint8_t PC_GREEN
Green palette colour.
static const uint8_t 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.
ClientSettings _settings_client
The current settings for this game.
Base types for having sorted lists in GUIs.
Base classes/functions for stations.
CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
Get the acceptance of cargoes around the tile in 1/8.
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.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int y)
Draws icons of waiting cargo in the StationView window.
static bool AddNearbyStation(TileIndex tile, void *user_data)
Add station on this tile to _stations_nearby_list if it's fully within the station spread.
static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, uint8_t rating)
Draw small boxes of cargo amount and ratings data at the given coordinates.
@ 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...
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
static const BaseStation * FindStationsNearby(TileArea ta, bool distant_join)
Circulate around the to-be-built station to find stations we could join.
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.
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc)
Check whether we need to show the station selection window.
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.
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
@ SCT_ALL
Draw all cargoes.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
@ FACIL_DOCK
Station with a dock.
@ FACIL_BUS_STOP
Station with bus stops.
@ FACIL_AIRPORT
Station with an airport.
@ FACIL_TRUCK_STOP
Station with truck stops.
@ FACIL_TRAIN
Station with train station.
@ FACIL_NONE
The station has no facilities at all.
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
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.
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Base class for all station-ish types.
StationFacility facilities
The facilities that this station has.
TileIndex xy
Base tile of the station.
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.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Class for storing amounts of cargo.
Container for cargo from the same location and time.
Specification of a cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
StringID abbrev
Two letter abbreviation for this cargo type.
SpriteID GetCargoIcon() const
Get sprite for showing cargo of this type.
StringID name
Name of this type of cargo.
bool IsValid() const
Tests for validity of this cargospec.
GUISettings gui
settings related to the GUI
CargoTypes cargoes
bitmap of cargo types to include
bool include_no_rating
Whether we should include stations with no cargo rating.
uint8_t facilities
types of stations of interest
Dimensions (a width and height) of a rectangle in 2D.
bool persistent_buildingtools
keep the building tools active after usage
uint8_t station_gui_group_order
the order of grouping cargo entries in the station gui
uint8_t station_gui_sort_order
the sort order of entries in the station gui - ascending or descending
bool station_show_coverage
whether to highlight coverage area
uint8_t station_gui_sort_by
sort cargo entries in the station gui by station name or amount
StationSettings station
settings related to station management
LinkGraphSettings linkgraph
settings for link graph calculations
Stores station stats for a single cargo.
FlowStatMap flows
Planned flows through this station.
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.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
LinkGraphID link_graph
Link graph this station belongs to.
uint8_t rating
Station rating for this cargo.
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 MP_VOID.
static debug_inline uint Size()
Get the size of the map.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Represents the covered area of e.g.
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Titem * Get(size_t index)
Returns Titem with given index.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
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.
uint step_height
Step-size of height resize changes.
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.
Iterable ensemble of each set bit in a value.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static Waypoint * Get(size_t index)
Gets station with given index.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
static Waypoint * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
uint8_t station_spread
amount a station may spread
bool distant_join_stations
allow to join non-adjacent stations
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.
CargoID next_cargo
ID of the cargo belonging to the entry actually displayed if it's cargo.
CargoDataEntry * filter
Parent of the cargo entry belonging to the row.
void HandleCargoWaitingClick(int row)
Handle a click on a specific row in the cargo view.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
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 SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
void EstimateDestinations(CargoID cargo, StationID source, StationID next, uint count, CargoDataEntry *dest)
Estimate the amounts of cargo per final destination for a given cargo, source station and next hop an...
void SelectSortBy(int index)
Select a new sort criterium for the cargo view.
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.
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 SetDisplayedRow(const CargoDataEntry *data)
Mark a specific row, characterized by its CargoDataEntry, as expanded.
void BuildFlowList(CargoID i, const FlowStatMap &flows, CargoDataEntry *cargo)
Build up the cargo view for PLANNED mode and a specific cargo.
StringID SearchNonStop(CargoDataEntry *cd, StationID station, int column)
Determine if we need to show the special "non-stop" string.
void RecalcDestinations(CargoID i)
Rebuild the cache for estimated destinations which is used to quickly show the "destination" entries ...
CargoSortType sortings[NUM_COLUMNS]
Sort types of the different 'columns'.
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.
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").
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.
void BuildCargoList(CargoDataEntry *cargo, const Station *st)
Build up the cargo view for all cargoes.
int DrawEntries(CargoDataEntry *entry, const Rect &r, int pos, int maxrows, int column, CargoID cargo=INVALID_CARGO)
Draw the given cargo entries in the station GUI.
uint expand_shrink_width
The width allocated to the expand/shrink 'button'.
void ShowCargo(CargoDataEntry *data, CargoID cargo, StationID source, StationID next, StationID dest, uint count)
Show a certain cargo entry characterized by source/next/dest station, cargo ID and amount of cargo at...
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.
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.
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.
void BuildCargoList(CargoID i, const StationCargoList &packets, CargoDataEntry *cargo)
Build up the cargo view for WAITING mode and a specific cargo.
StringID GetEntryString(StationID station, StringID here, StringID other_station, StringID any)
Select the correct string for an entry referring to the specified station.
SortOrder sort_orders[NUM_COLUMNS]
Sort order (ascending/descending) for the 'columns'.
void SelectGroupBy(int index)
Select a new grouping mode for the cargo view.
Grouping groupings[NUM_COLUMNS]
Grouping modes for the different columns.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
int DrawAcceptedCargo(const Rect &r) const
Draw accepted cargo in the WID_SV_ACCEPT_RATING_LIST widget.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Airport airport
Tile area the airport covers.
Struct containing TileIndex and StationID.
StationID station
StationID.
HighLightStyle drawstyle
Lower bits 0-3 are reserved for detailed highlight information.
uint8_t dirty
Whether the build station window needs to redraw due to the changed selection.
Point size
Size, in tile "units", of the white/red selection area.
Point pos
Location, in tile "units", of the northern tile of the selected area.
bool freeze
Freeze highlight in place.
CompanyID exclusivity
which company has exclusivity
uint8_t exclusive_counter
months till the exclusivity expires
The information about a vehicle list.
Representation of a waypoint.
High level window description.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
Window * parent
Parent window.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool IsShaded() const
Is window shaded currently?
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int width
width of the window (number of pixels to the right in x direction)
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
static const uint TILE_SIZE
Tile size in world coordinates.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_STATION
A tile of a station.
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, ...)
Functions related to the vehicle's GUIs.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
Functions and type for generating vehicle lists.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
const Station * _viewport_highlight_station
Currently selected station for coverage area highlight.
Functions related to (drawing on) viewports.
@ WPF_ROAD
This is a road waypoint.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Window functions not directly related to making/drawing windows.
@ SBS_DOWN
Sort ascending.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ 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_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.