mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
Change: Hide unused cargos from vehicle cargo filter. (#11533)
The list of used cargo types is updated when the list is invalidated.
This commit is contained in:
parent
9a92e02fa7
commit
7ba89b946e
@ -424,7 +424,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GL_FILTER_BY_CARGO:
|
case WID_GL_FILTER_BY_CARGO:
|
||||||
size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width);
|
size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GL_MANAGE_VEHICLES_DROPDOWN: {
|
case WID_GL_MANAGE_VEHICLES_DROPDOWN: {
|
||||||
@ -665,7 +665,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
|
case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
|
||||||
ShowDropDownList(this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
|
ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_GL_ALL_VEHICLES: // All vehicles button
|
case WID_GL_ALL_VEHICLES: // All vehicles button
|
||||||
|
@ -191,6 +191,14 @@ void BaseVehicleListWindow::BuildVehicleList()
|
|||||||
|
|
||||||
GenerateVehicleSortList(&this->vehicles, this->vli);
|
GenerateVehicleSortList(&this->vehicles, this->vli);
|
||||||
|
|
||||||
|
CargoTypes used = 0;
|
||||||
|
for (const Vehicle *v : this->vehicles) {
|
||||||
|
for (const Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||||
|
if (u->cargo_cap > 0) SetBit(used, u->cargo_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->used_cargoes = used;
|
||||||
|
|
||||||
if (this->grouping == GB_NONE) {
|
if (this->grouping == GB_NONE) {
|
||||||
uint max_unitnumber = 0;
|
uint max_unitnumber = 0;
|
||||||
for (auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) {
|
for (auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) {
|
||||||
@ -371,7 +379,12 @@ StringID BaseVehicleListWindow::GetCargoFilterLabel(CargoID cid) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DropDownList BaseVehicleListWindow::BuildCargoDropDownList() const
|
/**
|
||||||
|
* Build drop down list for cargo filter selection.
|
||||||
|
* @param full If true, build list with all cargo types, instead of only used cargo types.
|
||||||
|
* @return Drop down list for cargo filter.
|
||||||
|
*/
|
||||||
|
DropDownList BaseVehicleListWindow::BuildCargoDropDownList(bool full) const
|
||||||
{
|
{
|
||||||
DropDownList list;
|
DropDownList list;
|
||||||
|
|
||||||
@ -385,7 +398,8 @@ DropDownList BaseVehicleListWindow::BuildCargoDropDownList() const
|
|||||||
/* Add cargos */
|
/* Add cargos */
|
||||||
Dimension d = GetLargestCargoIconSize();
|
Dimension d = GetLargestCargoIconSize();
|
||||||
for (const CargoSpec *cs : _sorted_cargo_specs) {
|
for (const CargoSpec *cs : _sorted_cargo_specs) {
|
||||||
list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false));
|
if (!full && !HasBit(this->used_cargoes, cs->Index())) continue;
|
||||||
|
list.push_back(std::make_unique<DropDownListIconItem>(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index(), false, !HasBit(this->used_cargoes, cs->Index())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@ -1877,7 +1891,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_VL_FILTER_BY_CARGO:
|
case WID_VL_FILTER_BY_CARGO:
|
||||||
size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width);
|
size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_VL_MANAGE_VEHICLES_DROPDOWN: {
|
case WID_VL_MANAGE_VEHICLES_DROPDOWN: {
|
||||||
@ -2007,7 +2021,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case WID_VL_FILTER_BY_CARGO: // Cargo filter dropdown
|
case WID_VL_FILTER_BY_CARGO: // Cargo filter dropdown
|
||||||
ShowDropDownList(this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
|
ShowDropDownList(this, this->BuildCargoDropDownList(false), this->cargo_filter_criteria, widget);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_VL_LIST: { // Matrix to show vehicles
|
case WID_VL_LIST: { // Matrix to show vehicles
|
||||||
|
@ -90,6 +90,7 @@ struct BaseVehicleListWindow : public Window {
|
|||||||
VehicleID vehicle_sel; ///< Selected vehicle
|
VehicleID vehicle_sel; ///< Selected vehicle
|
||||||
CargoID cargo_filter_criteria; ///< Selected cargo filter index
|
CargoID cargo_filter_criteria; ///< Selected cargo filter index
|
||||||
uint order_arrow_width; ///< Width of the arrow in the small order list.
|
uint order_arrow_width; ///< Width of the arrow in the small order list.
|
||||||
|
CargoTypes used_cargoes;
|
||||||
|
|
||||||
typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction;
|
typedef GUIVehicleGroupList::SortFunction VehicleGroupSortFunction;
|
||||||
typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction;
|
typedef GUIVehicleList::SortFunction VehicleIndividualSortFunction;
|
||||||
@ -124,7 +125,7 @@ struct BaseVehicleListWindow : public Window {
|
|||||||
void SetCargoFilterArray();
|
void SetCargoFilterArray();
|
||||||
void FilterVehicleList();
|
void FilterVehicleList();
|
||||||
StringID GetCargoFilterLabel(CargoID cid) const;
|
StringID GetCargoFilterLabel(CargoID cid) const;
|
||||||
DropDownList BuildCargoDropDownList() const;
|
DropDownList BuildCargoDropDownList(bool full) const;
|
||||||
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create);
|
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create);
|
||||||
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create);
|
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user