From e517e556201212d6e705ae2571ce51823b56a493 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 25 Nov 2023 21:22:09 +0000 Subject: [PATCH] Change: Include count of stations per cargo type in station cargo filter. Cargo types with no stations are shaded to make the list clearer. --- src/station_gui.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/station_gui.cpp b/src/station_gui.cpp index e580caa927..e45a998afe 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -240,6 +240,8 @@ protected: GUIStationList stations{filter.cargoes}; Scrollbar *vscroll; uint rating_width; + std::array stations_per_cargo_type; ///< Number of stations with a rating for each cargo type. + uint16_t stations_per_cargo_type_no_rating; ///< Number of stations without a rating. /** * (Re)Build station list @@ -253,11 +255,17 @@ protected: Debug(misc, 3, "Building station list for company {}", owner); this->stations.clear(); + this->stations_per_cargo_type.fill(0); + this->stations_per_cargo_type_no_rating = 0; for (const Station *st : Station::Iterate()) { if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) { if (this->filter.facilities & st->facilities) { // only stations with selected facilities bool has_rating = false; + /* Add to the station/cargo counts. */ + for (CargoID j = 0; j < NUM_CARGO; j++) { + if (st->goods[j].HasRating()) this->stations_per_cargo_type[j]++; + } for (CargoID j = 0; j < NUM_CARGO; j++) { if (st->goods[j].HasRating()) { has_rating = true; @@ -268,8 +276,9 @@ protected: } } /* Stations with no cargo rating. */ - if (!has_rating && this->filter.include_no_rating) { - this->stations.push_back(st); + if (!has_rating) { + if (this->filter.include_no_rating) this->stations.push_back(st); + this->stations_per_cargo_type_no_rating++; } } } @@ -519,15 +528,20 @@ public: DropDownList BuildCargoDropDownList() const { - /* Define a custom item consisting of check mark, icon and string. */ - using DropDownListCargoItem = DropDownCheck; + /* Define a custom item consisting of check mark, count string, icon and name string. */ + using DropDownListCargoItem = DropDownCheck>; DropDownList list; list.push_back(std::make_unique(STR_STATION_LIST_CARGO_FILTER_SELECT_ALL, CargoFilterCriteria::CF_SELECT_ALL)); list.push_back(std::make_unique(-1)); - list.push_back(std::make_unique(this->filter.include_no_rating, STR_STATION_LIST_CARGO_FILTER_NO_RATING, CargoFilterCriteria::CF_NO_RATING)); + + uint16_t count = this->stations_per_cargo_type_no_rating; + list.push_back(std::make_unique>(fmt::format("{}", count), this->filter.include_no_rating, STR_STATION_LIST_CARGO_FILTER_NO_RATING, CargoFilterCriteria::CF_NO_RATING, false, count == 0)); + + Dimension d = GetLargestCargoIconSize(); for (const CargoSpec *cs : _sorted_cargo_specs) { - list.push_back(std::make_unique(HasBit(this->filter.cargoes, cs->Index()), cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index())); + count = this->stations_per_cargo_type[cs->Index()]; + list.push_back(std::make_unique(HasBit(this->filter.cargoes, cs->Index()), fmt::format("{}", count), d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false, count == 0)); } return list;