mirror of https://github.com/OpenTTD/OpenTTD
Change: Limit cargo types in station cargo filter, with "More..." option to show all.
parent
e517e55620
commit
2c78146da5
|
@ -96,8 +96,9 @@ namespace CargoFilterCriteria {
|
|||
static constexpr CargoID CF_ENGINES = NUM_CARGO + 2; ///< Show only engines (for rail vehicles only)
|
||||
static constexpr CargoID CF_FREIGHT = NUM_CARGO + 3; ///< Show only vehicles which carry any freight (non-passenger) cargo
|
||||
|
||||
static constexpr CargoID CF_NO_RATING = NUM_CARGO + 4; ///< Show items with no rating (station list)
|
||||
static constexpr CargoID CF_SELECT_ALL = NUM_CARGO + 5; ///< Select all items (station list)
|
||||
static constexpr CargoID CF_NO_RATING = NUM_CARGO + 4; ///< Show items with no rating (station list)
|
||||
static constexpr CargoID CF_SELECT_ALL = NUM_CARGO + 5; ///< Select all items (station list)
|
||||
static constexpr CargoID CF_EXPAND_LIST = NUM_CARGO + 6; ///< Expand list to show all items (station list)
|
||||
};
|
||||
|
||||
/** Test whether cargo type is not CT_INVALID */
|
||||
|
|
|
@ -3750,6 +3750,7 @@ STR_STATION_LIST_CARGO_FILTER_NO_CARGO_TYPES :No cargo types
|
|||
STR_STATION_LIST_CARGO_FILTER_ONLY_NO_RATING :Only no cargo rating
|
||||
STR_STATION_LIST_CARGO_FILTER_SELECT_ALL :Select all and no rating
|
||||
STR_STATION_LIST_CARGO_FILTER_NO_RATING :No cargo rating
|
||||
STR_STATION_LIST_CARGO_FILTER_EXPAND :Show more...
|
||||
|
||||
# Station view window
|
||||
STR_STATION_VIEW_CAPTION :{WHITE}{STATION} {STATION_FEATURES}
|
||||
|
|
|
@ -240,6 +240,7 @@ protected:
|
|||
GUIStationList stations{filter.cargoes};
|
||||
Scrollbar *vscroll;
|
||||
uint rating_width;
|
||||
bool filter_expanded;
|
||||
std::array<uint16_t, NUM_CARGO> 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.
|
||||
|
||||
|
@ -526,7 +527,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
DropDownList BuildCargoDropDownList() const
|
||||
DropDownList BuildCargoDropDownList(bool expanded) const
|
||||
{
|
||||
/* Define a custom item consisting of check mark, count string, icon and name string. */
|
||||
using DropDownListCargoItem = DropDownCheck<DropDownString<DropDownListIconItem, FS_SMALL, true>>;
|
||||
|
@ -535,13 +536,28 @@ public:
|
|||
list.push_back(std::make_unique<DropDownListStringItem>(STR_STATION_LIST_CARGO_FILTER_SELECT_ALL, CargoFilterCriteria::CF_SELECT_ALL));
|
||||
list.push_back(std::make_unique<DropDownListDividerItem>(-1));
|
||||
|
||||
bool any_hidden = false;
|
||||
|
||||
uint16_t count = this->stations_per_cargo_type_no_rating;
|
||||
list.push_back(std::make_unique<DropDownString<DropDownListCheckedItem, FS_SMALL, true>>(fmt::format("{}", count), this->filter.include_no_rating, STR_STATION_LIST_CARGO_FILTER_NO_RATING, CargoFilterCriteria::CF_NO_RATING, false, count == 0));
|
||||
if (count == 0 && !expanded) {
|
||||
any_hidden = true;
|
||||
} else {
|
||||
list.push_back(std::make_unique<DropDownString<DropDownListCheckedItem, FS_SMALL, true>>(fmt::format("{}", count), this->filter.include_no_rating, STR_STATION_LIST_CARGO_FILTER_NO_RATING, CargoFilterCriteria::CF_NO_RATING, false, count == 0));
|
||||
}
|
||||
|
||||
Dimension d = GetLargestCargoIconSize();
|
||||
for (const CargoSpec *cs : _sorted_cargo_specs) {
|
||||
count = this->stations_per_cargo_type[cs->Index()];
|
||||
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));
|
||||
if (count == 0 && !expanded) {
|
||||
any_hidden = true;
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
if (!expanded && any_hidden) {
|
||||
if (list.size() > 2) list.push_back(std::make_unique<DropDownListDividerItem>(-1));
|
||||
list.push_back(std::make_unique<DropDownListStringItem>(STR_STATION_LIST_CARGO_FILTER_EXPAND, CargoFilterCriteria::CF_EXPAND_LIST));
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@ -605,8 +621,8 @@ public:
|
|||
break;
|
||||
|
||||
case WID_STL_CARGODROPDOWN:
|
||||
/* Multiple-choice list should not have a default row selected, so use a non-present value. */
|
||||
ShowDropDownList(this, this->BuildCargoDropDownList(), -1, widget, 0, false, true);
|
||||
this->filter_expanded = false;
|
||||
ShowDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded), -1, widget, 0, false, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -644,6 +660,10 @@ public:
|
|||
} else if (index == CargoFilterCriteria::CF_SELECT_ALL) {
|
||||
this->filter.cargoes = _cargo_mask;
|
||||
this->filter.include_no_rating = true;
|
||||
} else if (index == CargoFilterCriteria::CF_EXPAND_LIST) {
|
||||
this->filter_expanded = true;
|
||||
ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldstate.cargoes != this->filter.cargoes || oldstate.include_no_rating != this->filter.include_no_rating) {
|
||||
|
@ -651,7 +671,7 @@ public:
|
|||
this->SetDirty();
|
||||
|
||||
/* Only refresh the list if it's changed. */
|
||||
if (_ctrl_pressed) ReplaceDropDownList(this, this->BuildCargoDropDownList());
|
||||
if (_ctrl_pressed) ReplaceDropDownList(this, this->BuildCargoDropDownList(this->filter_expanded));
|
||||
}
|
||||
|
||||
/* Always close the list if ctrl is not pressed. */
|
||||
|
|
Loading…
Reference in New Issue