private void ApplyFilters() { if (BeatmapDetailsLoader.instance.IsLoading) { Logger.log.Warn("Tried to apply filters while loading beatmap details (this should never happen?)"); return; } if (!Tweaks.SongBrowserTweaks.Initialized) { Logger.log.Debug($"Applying filter, starting with {_beatmapDetails.Count} songs"); } List <BeatmapDetails> filteredLevels = null; bool hasApplied; if (!Tweaks.SongBrowserTweaks.Initialized) { filteredLevels = new List <BeatmapDetails>(_beatmapDetails.Values); hasApplied = FilterList.ApplyFilter(ref filteredLevels); Logger.log.Debug($"Filter completed, {filteredLevels.Count} songs left"); } else { foreach (var filter in FilterList.ActiveFilters) { filter.ApplyStagingValues(); } hasApplied = FilterList.AnyApplied; } RefreshUI(); if (hasApplied) { if (Tweaks.SongBrowserTweaks.ModLoaded && Tweaks.SongBrowserTweaks.Initialized) { _filterMainViewController.ShowInfoText("Filter applied"); } else { _filterMainViewController.ShowInfoText($"{filteredLevels.Count} out of {_beatmapDetails.Count} songs found"); // SongBrowser will create its own BeatmapLevelPack when it gets our filtered levels via: // ProcessSongList() -> CustomFilterHandler() -> ApplyFiltersForSongBrowser() -> ApplyFilters() // filters are applied once this flow coordinator is dismissed FilterApplied?.Invoke(_beatmapDetails.Where(x => filteredLevels.Contains(x.Value)).Select(x => x.Key).ToArray()); } } else { // default values were applied (no filtering or undo filtering) FiltersUnapplied?.Invoke(); } }
/// <summary> /// Unapply filters and refresh the UI. /// </summary> /// <param name="sendEvent">Invoke the FiltersUnapplied event.</param> public void UnapplyFilters(bool sendEvent = true) { foreach (var filter in FilterList.ActiveFilters) { filter.ApplyDefaultValues(); } RefreshUI(); if (sendEvent) { FiltersUnapplied?.Invoke(); } }