mirror of https://github.com/OpenTTD/OpenTTD
Fix: also apply cargo filters on shared groups in vehicle listing (#11294)
parent
8d90448153
commit
39ef4b503f
|
@ -199,8 +199,6 @@ void BaseVehicleListWindow::BuildVehicleList()
|
||||||
max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
|
max_unitnumber = std::max<uint>(max_unitnumber, (*it)->unitnumber);
|
||||||
}
|
}
|
||||||
this->unitnumber_digits = CountDigitsForAllocatingSpace(max_unitnumber);
|
this->unitnumber_digits = CountDigitsForAllocatingSpace(max_unitnumber);
|
||||||
|
|
||||||
this->FilterVehicleList();
|
|
||||||
} else {
|
} else {
|
||||||
/* Sort by the primary vehicle; we just want all vehicles that share the same orders to form a contiguous range. */
|
/* Sort by the primary vehicle; we just want all vehicles that share the same orders to form a contiguous range. */
|
||||||
std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](const Vehicle * const &u, const Vehicle * const &v) {
|
std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](const Vehicle * const &u, const Vehicle * const &v) {
|
||||||
|
@ -224,22 +222,21 @@ void BaseVehicleListWindow::BuildVehicleList()
|
||||||
|
|
||||||
this->unitnumber_digits = CountDigitsForAllocatingSpace(max_num_vehicles);
|
this->unitnumber_digits = CountDigitsForAllocatingSpace(max_num_vehicles);
|
||||||
}
|
}
|
||||||
|
this->FilterVehicleList();
|
||||||
|
|
||||||
this->vehgroups.RebuildDone();
|
this->vehgroups.RebuildDone();
|
||||||
this->vscroll->SetCount(this->vehgroups.size());
|
this->vscroll->SetCount(this->vehgroups.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Cargo filter functions */
|
|
||||||
/**
|
/**
|
||||||
* Check whether a vehicle can carry a specific cargo.
|
* Check whether a single vehicle should pass the filter.
|
||||||
* @param vehgroup The vehicle group which contains the vehicle to be checked
|
*
|
||||||
* @param cid The cargo what we are looking for
|
* @param v The vehicle to check.
|
||||||
* @return Whether the vehicle can carry the specified cargo or not
|
* @param cid The cargo to filter for.
|
||||||
|
* @return true iff the vehicle carries the cargo.
|
||||||
*/
|
*/
|
||||||
static bool CDECL CargoFilter(const GUIVehicleGroup *vehgroup, const CargoID cid)
|
static bool CargoFilterSingle(const Vehicle *v, const CargoID cid)
|
||||||
{
|
{
|
||||||
const Vehicle *v = (*vehgroup).GetSingleVehicle();
|
|
||||||
if (cid == BaseVehicleListWindow::CF_ANY) {
|
if (cid == BaseVehicleListWindow::CF_ANY) {
|
||||||
return true;
|
return true;
|
||||||
} else if (cid == BaseVehicleListWindow::CF_NONE) {
|
} else if (cid == BaseVehicleListWindow::CF_NONE) {
|
||||||
|
@ -271,6 +268,25 @@ static bool CDECL CargoFilter(const GUIVehicleGroup *vehgroup, const CargoID cid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a vehicle can carry a specific cargo.
|
||||||
|
*
|
||||||
|
* @param vehgroup The vehicle group which contains the vehicle to be checked
|
||||||
|
* @param cid The cargo what we are looking for
|
||||||
|
* @return Whether the vehicle can carry the specified cargo or not
|
||||||
|
*/
|
||||||
|
static bool CargoFilter(const GUIVehicleGroup *vehgroup, const CargoID cid)
|
||||||
|
{
|
||||||
|
auto it = vehgroup->vehicles_begin;
|
||||||
|
|
||||||
|
/* Check if any vehicle in the group matches; if so, the whole group does. */
|
||||||
|
for (; it != vehgroup->vehicles_end; it++) {
|
||||||
|
if (CargoFilterSingle(*it, cid)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static GUIVehicleGroupList::FilterFunction * const _filter_funcs[] = {
|
static GUIVehicleGroupList::FilterFunction * const _filter_funcs[] = {
|
||||||
&CargoFilter,
|
&CargoFilter,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue