Codechange: Simplify cargo filter lists, building only when required.

Some cargo filter lists were built in advance, and used as lookups to test which cargo type to filter.

Instead, use the Cargo ID directly as the filter parameter, and build the lists only when the drop down list is used.
This commit is contained in:
Peter Nelson
2023-11-12 21:32:12 +00:00
committed by Peter Nelson
parent 08dfe35442
commit 7cfcf65f95
5 changed files with 133 additions and 138 deletions

View File

@@ -88,8 +88,6 @@ struct BaseVehicleListWindow : public Window {
Scrollbar *vscroll;
VehicleListIdentifier vli; ///< Identifier of the vehicle list we want to currently show.
VehicleID vehicle_sel; ///< Selected vehicle
CargoID cargo_filter[NUM_CARGO + 3]; ///< Available cargo filters; CargoID or CF_ANY or CF_FREIGHT or CF_NONE
StringID cargo_filter_texts[NUM_CARGO + 4]; ///< Texts for filter_cargo, terminated by INVALID_STRING_ID
byte cargo_filter_criteria; ///< Selected cargo filter index
uint order_arrow_width; ///< Width of the arrow in the small order list.
@@ -125,6 +123,8 @@ struct BaseVehicleListWindow : public Window {
void SetCargoFilterIndex(byte index);
void SetCargoFilterArray();
void FilterVehicleList();
StringID GetCargoFilterLabel(CargoID cid) const;
DropDownList BuildCargoDropDownList() const;
Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group, bool show_create);
DropDownList BuildActionDropdownList(bool show_autoreplace, bool show_group, bool show_create);