1
0
Fork 0

Fix #14361: Removing a badge filter did not clear it. (#14379)

pull/13565/merge
Peter Nelson 2025-06-23 08:24:03 +01:00 committed by GitHub
parent c15568be5f
commit 8901f9adca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 12 deletions

View File

@ -1896,7 +1896,7 @@ struct BuildVehicleWindow : Window {
break; break;
case WID_BV_CONFIGURE_BADGES: { case WID_BV_CONFIGURE_BADGES: {
bool reopen = HandleBadgeConfigurationDropDownClick(static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type), BADGE_COLUMNS, index, click_result); bool reopen = HandleBadgeConfigurationDropDownClick(static_cast<GrfSpecFeature>(GSF_TRAINS + this->vehicle_type), BADGE_COLUMNS, index, click_result, this->badge_filter_choices);
this->ReInit(); this->ReInit();
@ -1905,6 +1905,10 @@ struct BuildVehicleWindow : Window {
} else { } else {
this->CloseChildWindows(WC_DROPDOWN_MENU); this->CloseChildWindows(WC_DROPDOWN_MENU);
} }
/* We need to refresh if a filter is removed. */
this->eng_list.ForceRebuild();
this->SetDirty();
break; break;
} }

View File

@ -365,14 +365,17 @@ DropDownList BuildBadgeClassConfigurationList(const GUIBadgeClasses &gui_classes
* @param class_badge Class badge. * @param class_badge Class badge.
* @param click Dropdown click reuslt. * @param click Dropdown click reuslt.
*/ */
static void BadgeClassToggleVisibility(GrfSpecFeature feature, Badge &class_badge, int click_result) static void BadgeClassToggleVisibility(GrfSpecFeature feature, Badge &class_badge, int click_result, BadgeFilterChoices &choices)
{ {
auto config = GetBadgeClassConfiguration(feature); auto config = GetBadgeClassConfiguration(feature);
auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label); auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
if (it == std::end(config)) return; if (it == std::end(config)) return;
if (click_result == BADGE_CLICK_TOGGLE_ICON) it->show_icon = !it->show_icon; if (click_result == BADGE_CLICK_TOGGLE_ICON) it->show_icon = !it->show_icon;
if (click_result == BADGE_CLICK_TOGGLE_FILTER) it->show_filter = !it->show_filter; if (click_result == BADGE_CLICK_TOGGLE_FILTER) {
it->show_filter = !it->show_filter;
if (!it->show_filter) ResetBadgeFilter(choices, class_badge.class_index);
}
} }
/** /**
@ -442,7 +445,7 @@ static void BadgeClassMoveNext(GrfSpecFeature feature, Badge &class_badge, uint
* @param click_result Dropdown click result. * @param click_result Dropdown click result.
* @return true iff the caller should reinitialise their widgets. * @return true iff the caller should reinitialise their widgets.
*/ */
bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result) bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices)
{ {
if (result == INT_MAX) { if (result == INT_MAX) {
ResetBadgeClassConfiguration(feature); ResetBadgeClassConfiguration(feature);
@ -461,7 +464,7 @@ bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns,
break; break;
case BADGE_CLICK_TOGGLE_ICON: case BADGE_CLICK_TOGGLE_ICON:
case BADGE_CLICK_TOGGLE_FILTER: case BADGE_CLICK_TOGGLE_FILTER:
BadgeClassToggleVisibility(feature, *class_badge, click_result); BadgeClassToggleVisibility(feature, *class_badge, click_result, choices);
break; break;
default: default:
break; break;

View File

@ -54,7 +54,7 @@ std::unique_ptr<DropDownListItem> MakeDropDownListBadgeItem(const std::shared_pt
std::unique_ptr<DropDownListItem> MakeDropDownListBadgeIconItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked = false, bool shaded = false); std::unique_ptr<DropDownListItem> MakeDropDownListBadgeIconItem(const std::shared_ptr<GUIBadgeClasses> &gui_classes, std::span<const BadgeID> badges, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, const Dimension &dim, SpriteID sprite, PaletteID palette, std::string &&str, int value, bool masked = false, bool shaded = false);
DropDownList BuildBadgeClassConfigurationList(const class GUIBadgeClasses &badge_class, uint columns, std::span<const StringID> column_separators); DropDownList BuildBadgeClassConfigurationList(const class GUIBadgeClasses &badge_class, uint columns, std::span<const StringID> column_separators);
bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result); bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices);
std::pair<WidgetID, WidgetID> AddBadgeDropdownFilters(NWidgetContainer &container, WidgetID widget, Colours colour, GrfSpecFeature feature); std::pair<WidgetID, WidgetID> AddBadgeDropdownFilters(NWidgetContainer &container, WidgetID widget, Colours colour, GrfSpecFeature feature);

View File

@ -442,7 +442,7 @@ void PickerWindow::OnDropdownSelect(WidgetID widget, int index, int click_result
{ {
switch (widget) { switch (widget) {
case WID_PW_CONFIGURE_BADGES: { case WID_PW_CONFIGURE_BADGES: {
bool reopen = HandleBadgeConfigurationDropDownClick(this->callbacks.GetFeature(), 1, index, click_result); bool reopen = HandleBadgeConfigurationDropDownClick(this->callbacks.GetFeature(), 1, index, click_result, this->badge_filter_choices);
this->ReInit(); this->ReInit();
@ -451,6 +451,9 @@ void PickerWindow::OnDropdownSelect(WidgetID widget, int index, int click_result
} else { } else {
this->CloseChildWindows(WC_DROPDOWN_MENU); this->CloseChildWindows(WC_DROPDOWN_MENU);
} }
/* We need to refresh if a filter is removed. */
this->InvalidateData({PickerInvalidation::Type, PickerInvalidation::Filter});
break; break;
} }
@ -461,9 +464,7 @@ void PickerWindow::OnDropdownSelect(WidgetID widget, int index, int click_result
} else { } else {
SetBadgeFilter(this->badge_filter_choices, BadgeID(index)); SetBadgeFilter(this->badge_filter_choices, BadgeID(index));
} }
this->type_string_filter.bdf.emplace(this->badge_filter_choices); this->InvalidateData({PickerInvalidation::Type, PickerInvalidation::Filter});
this->types.SetFilterState(!type_string_filter.IsEmpty() || type_string_filter.bdf.has_value());
this->InvalidateData(PickerInvalidation::Type);
} }
break; break;
} }
@ -474,6 +475,16 @@ void PickerWindow::OnInvalidateData(int data, bool gui_scope)
if (!gui_scope) return; if (!gui_scope) return;
PickerInvalidations pi(data); PickerInvalidations pi(data);
if (pi.Test(PickerInvalidation::Filter)) {
if (this->badge_filter_choices.empty()) {
this->type_string_filter.bdf.reset();
} else {
this->type_string_filter.bdf.emplace(this->badge_filter_choices);
}
this->types.SetFilterState(!type_string_filter.IsEmpty() || type_string_filter.bdf.has_value());
}
if (pi.Test(PickerInvalidation::Class)) this->classes.ForceRebuild(); if (pi.Test(PickerInvalidation::Class)) this->classes.ForceRebuild();
if (pi.Test(PickerInvalidation::Type)) this->types.ForceRebuild(); if (pi.Test(PickerInvalidation::Type)) this->types.ForceRebuild();
@ -526,8 +537,7 @@ void PickerWindow::OnEditboxChanged(WidgetID wid)
} else { } else {
this->type_string_filter.btf.reset(); this->type_string_filter.btf.reset();
} }
this->types.SetFilterState(!type_string_filter.IsEmpty() || type_string_filter.bdf.has_value()); this->InvalidateData({PickerInvalidation::Type, PickerInvalidation::Filter});
this->InvalidateData(PickerInvalidation::Type);
break; break;
default: default:

View File

@ -165,6 +165,7 @@ public:
Type, ///< Refresh the type list. Type, ///< Refresh the type list.
Position, ///< Update scroll positions. Position, ///< Update scroll positions.
Validate, ///< Validate selected item. Validate, ///< Validate selected item.
Filter, ///< Update filter state.
}; };
using PickerInvalidations = EnumBitSet<PickerInvalidation, uint8_t>; using PickerInvalidations = EnumBitSet<PickerInvalidation, uint8_t>;