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

@@ -424,7 +424,7 @@ public:
break;
case WID_GL_FILTER_BY_CARGO:
size->width = GetStringListWidth(this->cargo_filter_texts) + padding.width;
size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width);
break;
case WID_GL_MANAGE_VEHICLES_DROPDOWN: {
@@ -470,7 +470,7 @@ public:
{
switch (widget) {
case WID_GL_FILTER_BY_CARGO:
SetDParam(0, this->cargo_filter_texts[this->cargo_filter_criteria]);
SetDParam(0, this->GetCargoFilterLabel(this->cargo_filter_criteria));
break;
case WID_GL_AVAILABLE_VEHICLES:
@@ -549,9 +549,6 @@ public:
/* Set text of "sort by" dropdown widget. */
this->GetWidget<NWidgetCore>(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()];
/* Set text of filter by cargo dropdown */
this->GetWidget<NWidgetCore>(WID_GL_FILTER_BY_CARGO)->widget_data = this->cargo_filter_texts[this->cargo_filter_criteria];
this->DrawWidgets();
}
@@ -668,7 +665,7 @@ public:
return;
case WID_GL_FILTER_BY_CARGO: // Select filtering criteria dropdown menu
ShowDropDownMenu(this, this->cargo_filter_texts, this->cargo_filter_criteria, WID_GL_FILTER_BY_CARGO, 0, 0);
ShowDropDownList(this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
break;
case WID_GL_ALL_VEHICLES: // All vehicles button