diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 2e47a80a2f..45f8277429 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -79,6 +79,8 @@ static constexpr NWidgetPart _nested_build_vehicle_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER), SetResize(1, 0), SetFill(1, 0), SetPadding(2), SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), EndContainer(), + NWidget(NWID_VERTICAL, NWidContainerFlag{}, WID_BV_BADGE_FILTER), + EndContainer(), EndContainer(), /* Vehicle list. */ NWidget(NWID_HORIZONTAL), @@ -1159,6 +1161,9 @@ struct BuildVehicleWindow : Window { StringFilter string_filter{}; ///< Filter for vehicle name QueryString vehicle_editbox; ///< Filter editbox + std::pair badge_filters{}; ///< First and last widgets IDs of badge filters. + BadgeFilterChoices badge_filter_choices{}; + void SetBuyVehicleText() { NWidgetCore *widget = this->GetWidget(WID_BV_BUILD); @@ -1314,6 +1319,12 @@ struct BuildVehicleWindow : Window { { this->badge_classes = GUIBadgeClasses(static_cast(GSF_TRAINS + this->vehicle_type)); this->SetCargoFilterArray(); + + auto container = this->GetWidget(WID_BV_BADGE_FILTER); + this->badge_filters = AddBadgeDropdownFilters(*container, WID_BV_BADGE_FILTER, COLOUR_GREY, static_cast(GSF_TRAINS + this->vehicle_type)); + + this->widget_lookup.clear(); + this->nested_root->FillWidgetLookup(this->widget_lookup); } /** Filter the engine list against the currently selected cargo filter */ @@ -1361,6 +1372,7 @@ struct BuildVehicleWindow : Window { list.clear(); BadgeTextFilter btf(this->string_filter, GSF_TRAINS); + BadgeDropdownFilter bdf(this->badge_filter_choices); /* Make list of all available train engines and wagons. * Also check to see if the previously selected engine is still available, @@ -1377,6 +1389,8 @@ struct BuildVehicleWindow : Window { /* Filter now! So num_engines and num_wagons is valid */ if (!FilterSingleEngine(eid)) continue; + if (!bdf.Filter(e->badges)) continue; + /* Filter by name or NewGRF extra text */ if (!FilterByText(e) && !btf.Filter(e->badges)) continue; @@ -1672,6 +1686,7 @@ struct BuildVehicleWindow : Window { break; case WID_BV_CONFIGURE_BADGES: + if (this->badge_classes.GetClasses().empty()) break; ShowDropDownList(this, this->BuildBadgeConfigurationList(), -1, widget, 0, false, true); break; @@ -1695,6 +1710,12 @@ struct BuildVehicleWindow : Window { } break; } + + default: + if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) { + ShowDropDownList(this, this->GetWidget(widget)->GetDropDownList(), -1, widget, 0, false); + } + break; } } @@ -1745,6 +1766,10 @@ struct BuildVehicleWindow : Window { } default: + if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) { + return this->GetWidget(widget)->GetStringParameter(this->badge_filter_choices); + } + return this->Window::GetWidgetString(widget, stringid); } } @@ -1887,6 +1912,18 @@ struct BuildVehicleWindow : Window { } break; } + + default: + if (IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) { + if (index < 0) { + ResetBadgeFilter(this->badge_filter_choices, this->GetWidget(widget)->GetBadgeClassID()); + } else { + SetBadgeFilter(this->badge_filter_choices, BadgeID(index)); + } + this->eng_list.ForceRebuild(); + this->SetDirty(); + } + break; } this->SetDirty(); } diff --git a/src/widgets/build_vehicle_widget.h b/src/widgets/build_vehicle_widget.h index 79c5decb4b..5969449f09 100644 --- a/src/widgets/build_vehicle_widget.h +++ b/src/widgets/build_vehicle_widget.h @@ -26,6 +26,7 @@ enum BuildVehicleWidgets : WidgetID { WID_BV_BUILD_SEL, ///< Build button. WID_BV_RENAME, ///< Rename button. WID_BV_CONFIGURE_BADGES, ///< Button to configure badges. + WID_BV_BADGE_FILTER, ///< Container for dropdown badge filters. }; #endif /* WIDGETS_BUILD_VEHICLE_WIDGET_H */