mirror of https://github.com/OpenTTD/OpenTTD
Add: Badge dropdown filters to build vehicle window.
parent
25f1c97bea
commit
7b60e5ccad
|
@ -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<WidgetID, WidgetID> badge_filters{}; ///< First and last widgets IDs of badge filters.
|
||||
BadgeFilterChoices badge_filter_choices{};
|
||||
|
||||
void SetBuyVehicleText()
|
||||
{
|
||||
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
|
||||
|
@ -1314,6 +1319,12 @@ struct BuildVehicleWindow : Window {
|
|||
{
|
||||
this->badge_classes = GUIBadgeClasses(static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type));
|
||||
this->SetCargoFilterArray();
|
||||
|
||||
auto container = this->GetWidget<NWidgetContainer>(WID_BV_BADGE_FILTER);
|
||||
this->badge_filters = AddBadgeDropdownFilters(*container, WID_BV_BADGE_FILTER, COLOUR_GREY, static_cast<GrfSpecFeature>(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<NWidgetBadgeFilter>(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<NWidgetBadgeFilter>(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<NWidgetBadgeFilter>(widget)->GetBadgeClassID());
|
||||
} else {
|
||||
SetBadgeFilter(this->badge_filter_choices, BadgeID(index));
|
||||
}
|
||||
this->eng_list.ForceRebuild();
|
||||
this->SetDirty();
|
||||
}
|
||||
break;
|
||||
}
|
||||
this->SetDirty();
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue