diff --git a/Knossos.NET/ViewModels/ModListViewModel.cs b/Knossos.NET/ViewModels/ModListViewModel.cs index 0b89db47..b07b3f61 100644 --- a/Knossos.NET/ViewModels/ModListViewModel.cs +++ b/Knossos.NET/ViewModels/ModListViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; @@ -41,6 +42,15 @@ internal string Search } } + [ObservableProperty] + internal String sortString = String.Empty; + + [ObservableProperty] + internal String filterString = String.Empty; + + [ObservableProperty] + internal bool filtersEnabled = false; + //The actual collection were the mods are private ObservableList Mods = new ObservableList(); //A hook for the UI, do not access directly @@ -74,12 +84,19 @@ public void RemoveTagFilter(int tagIndex) { MainWindowViewModel.Instance.tagFilter.Remove(tags[tagIndex]); } + + if (MainWindowViewModel.Instance.tagFilter.Count < 1) { + FiltersEnabled = false; + } + ApplyFilters(); } } private void ApplyFilters() { + BuildFilterString(); + Parallel.ForEach(Mods, new ParallelOptions { MaxDegreeOfParallelism = 4 }, card => { bool visibility = true; @@ -109,6 +126,45 @@ private void ApplyFilters() }); } + private void BuildFilterString(){ + if (MainWindowViewModel.Instance == null){ + FilterString = ""; + FiltersEnabled = false; + return; + } + + int externalCount = MainWindowViewModel.Instance.tagFilter.Count; + + if (externalCount == 0 ){ + FilterString = ""; + FiltersEnabled = false; + return; + } + + int count = 0; + FilterString = "Filtering for "; + TextInfo myTI = new CultureInfo("en-US", false).TextInfo; + + foreach (var filter in MainWindowViewModel.Instance.tagFilter) { + if (count > 3){ + FilterString += " and ..."; + break; + // easiest case, this handles a filter list of one and the start of all other cases + } else if (count == 0){ + FilterString += myTI.ToTitleCase(filter.Replace("_", " ")); + // Last case except for 0 will always have an and + } else if (count == externalCount - 1){ + FilterString += " and " + myTI.ToTitleCase(filter.Replace("_", " "));; // No Oxford commas here! + // Other cases will always have a comma + } else { + FilterString += ", " + myTI.ToTitleCase(filter.Replace("_", " "));; + } + + FiltersEnabled = true; + count++; + } + } + /// /// /// @@ -125,6 +181,9 @@ public void OpenTab() ApplyFilters(); } } + + SortString = "Sorted by " + Search; + BuildFilterString(); } public void CloseTab() @@ -206,6 +265,7 @@ internal void ChangeSort(object sort) Knossos.globalSettings.sortType = newSort; Mods.Sort(); //It will use ModCardViewModel.CompareTo() } + SortString = "Sorted by " + newSort; LoadingAnimation.Animate = 0; Sorting = false; } diff --git a/Knossos.NET/ViewModels/NebulaModListViewModel.cs b/Knossos.NET/ViewModels/NebulaModListViewModel.cs index 10484e7f..74dd4f53 100644 --- a/Knossos.NET/ViewModels/NebulaModListViewModel.cs +++ b/Knossos.NET/ViewModels/NebulaModListViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -63,6 +64,15 @@ internal string Search } } + [ObservableProperty] + internal String sortString = String.Empty; + + [ObservableProperty] + internal String filterString = String.Empty; + + [ObservableProperty] + internal bool filtersEnabled = false; + private ModSortType localSort = ModSortType.name; //The actual collection were the mods are private ObservableList Mods = new ObservableList(); @@ -97,12 +107,19 @@ public void RemoveTagFilter(int tagIndex) { MainWindowViewModel.Instance.tagFilter.Remove(tags[tagIndex]); } + + if (MainWindowViewModel.Instance.tagFilter.Count < 1) { + FiltersEnabled = false; + } + ApplyFilters(); } } private void ApplyFilters() { + BuildFilterString(); + Parallel.ForEach(Mods, new ParallelOptions { MaxDegreeOfParallelism = 4 }, card => { bool visibility = true; @@ -132,6 +149,45 @@ private void ApplyFilters() }); } + private void BuildFilterString(){ + if (MainWindowViewModel.Instance == null){ + FilterString = ""; + FiltersEnabled = false; + return; + } + + int externalCount = MainWindowViewModel.Instance.tagFilter.Count; + + if (externalCount == 0 ){ + FilterString = ""; + FiltersEnabled = false; + return; + } + + int count = 0; + FilterString = "Filtering for "; + TextInfo myTI = new CultureInfo("en-US", false).TextInfo; + + foreach (var filter in MainWindowViewModel.Instance.tagFilter) { + if (count > 3){ + FilterString += " and ..."; + break; + // easiest case, this handles a filter list of one and the start of all other cases + } else if (count == 0){ + FilterString += myTI.ToTitleCase(filter.Replace("_", " ")); + // Last case except for 0 will always have an and + } else if (count == externalCount - 1){ + FilterString += " and " + myTI.ToTitleCase(filter.Replace("_", " "));; // No Oxford commas here! + // Other cases will always have a comma + } else { + FilterString += ", " + myTI.ToTitleCase(filter.Replace("_", " "));; + } + + FiltersEnabled = true; + count++; + } + } + /// /// Open the tab code /// @@ -157,6 +213,8 @@ public void OpenTab() } ChangeSort(Knossos.globalSettings.sortType); + BuildFilterString(); + Parallel.ForEach(Mods, new ParallelOptions { MaxDegreeOfParallelism = 4 }, async card => { await card.LoadImage(); @@ -263,12 +321,15 @@ internal void ChangeSort(object sort) { newSort = (ModSortType)Enum.Parse(typeof(ModSortType), (string)sort); } + if (newSort != localSort) { localSort = newSort; Knossos.globalSettings.sortType = newSort; Mods.Sort(); //It will use NebulaModCardViewModel.CompareTo() } + + SortString = "Sorted by " + newSort; } /// diff --git a/Knossos.NET/Views/ModListView.axaml b/Knossos.NET/Views/ModListView.axaml index 67a2a342..6ffae928 100644 --- a/Knossos.NET/Views/ModListView.axaml +++ b/Knossos.NET/Views/ModListView.axaml @@ -15,7 +15,7 @@ - + + + + + + + +