Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Knossos.NET/ViewModels/ModListViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
Expand Down Expand Up @@ -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<ModCardViewModel> Mods = new ObservableList<ModCardViewModel>();
//A hook for the UI, do not access directly
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}
}

/// <summary>
///
/// </summary>
Expand All @@ -125,6 +181,9 @@ public void OpenTab()
ApplyFilters();
}
}

SortString = "Sorted by " + Search;
BuildFilterString();
}

public void CloseTab()
Expand Down Expand Up @@ -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;
}
Expand Down
61 changes: 61 additions & 0 deletions Knossos.NET/ViewModels/NebulaModListViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -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<NebulaModCardViewModel> Mods = new ObservableList<NebulaModCardViewModel>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}
}

/// <summary>
/// Open the tab code
/// </summary>
Expand All @@ -157,6 +213,8 @@ public void OpenTab()
}

ChangeSort(Knossos.globalSettings.sortType);
BuildFilterString();

Parallel.ForEach(Mods, new ParallelOptions { MaxDegreeOfParallelism = 4 }, async card =>
{
await card.LoadImage();
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion Knossos.NET/Views/ModListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Grid RowDefinitions="Auto,*">
<Grid Grid.Row="0">
<WrapPanel Margin="10" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left">
<Button Name="FilterFlyout" ToolTip.Tip="Sort by" Margin="0,0,5,0" HorizontalAlignment="Right">
<Button Name="FilterFlyout" ToolTip.Tip="Sort by and filters" Margin="0,0,5,0" HorizontalAlignment="Right">
<PathIcon Height="30" Width="30" Data="{StaticResource FilterRegular}"/>
<Button.Flyout>
<Flyout Flyout.FlyoutPresenterClasses="filterFlyout" Placement="BottomEdgeAlignedLeft">
Expand Down Expand Up @@ -47,6 +47,12 @@
</Button.Flyout>
</Button>
<TextBox VerticalContentAlignment="Center" Text="{Binding Search}" FontSize="16" Width="300"></TextBox>
<StackPanel Margin="10,0,0,0">
<Label Content="{Binding SortString}" FontSize="12">
</Label>
<Label Content="{Binding FilterString}" IsEnabled="{Binding FiltersEnabled}" FontSize="12">
</Label>
</StackPanel>
</WrapPanel>
<WrapPanel Margin="10" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right">
<Button ToolTip.Tip="View Color Codes" HorizontalAlignment="Right">
Expand Down
8 changes: 7 additions & 1 deletion Knossos.NET/Views/NebulaModListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Grid RowDefinitions="Auto,*">
<Grid Grid.Row="0">
<WrapPanel Margin="10" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left">
<Button Name="FilterFlyout" ToolTip.Tip="Sort by" Margin="0,0,5,0" HorizontalAlignment="Right">
<Button Name="FilterFlyout" ToolTip.Tip="Sort by and filters" Margin="0,0,5,0" HorizontalAlignment="Right">
<PathIcon Height="30" Width="30" Data="{StaticResource FilterRegular}"/>
<Button.Flyout>
<Flyout Flyout.FlyoutPresenterClasses="filterFlyout" Placement="BottomEdgeAlignedLeft">
Expand Down Expand Up @@ -47,6 +47,12 @@
</Button.Flyout>
</Button>
<TextBox VerticalContentAlignment="Center" Text="{Binding Search}" FontSize="16" Width="300"></TextBox>
<StackPanel Margin="10,0,0,0">
<Label Content="{Binding SortString}" FontSize="12">
</Label>
<Label Content="{Binding FilterString}" IsEnabled="{Binding FiltersEnabled}" FontSize="12">
</Label>
</StackPanel>
</WrapPanel>
<WrapPanel Margin="10" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right">
<Button Command="{Binding ReloadRepoCommand}" ToolTip.Tip="Refresh">
Expand Down