Skip to content

Commit

Permalink
Add mod search to the gallery, clean up later
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4wzified committed Nov 9, 2024
1 parent 71529b9 commit ecc7186
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 75 deletions.
69 changes: 21 additions & 48 deletions Wabbajack.App.Wpf/ViewModels/Gallery/BaseModListMetadataVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,37 @@
namespace Wabbajack;


public struct ModListTag
public struct ModListTag(string name)
{
public ModListTag(string name)
{
Name = name;
}
public string Name { get; } = name;
public override string ToString() => Name;
}

public string Name { get; }
public struct ModListMod(string name)
{
public string Name { get; } = name;
public override string ToString() => Name;
}

public class BaseModListMetadataVM : ViewModel
{
public ModlistMetadata Metadata { get; }

public AbsolutePath Location { get; }

public LoadingLock LoadingImageLock { get; } = new();

[Reactive]
public HashSet<ModListTag> ModListTagList { get; protected set; }

[Reactive]
public Percent ProgressPercent { get; protected set; }

[Reactive]
public bool IsBroken { get; protected set; }

[Reactive]
public ModListStatus Status { get; set; }

[Reactive]
public bool IsDownloading { get; protected set; }

[Reactive]
public string DownloadSizeText { get; protected set; }

[Reactive]
public string InstallSizeText { get; protected set; }

[Reactive]
public string TotalSizeRequirementText { get; protected set; }

[Reactive]
public string VersionText { get; protected set; }

[Reactive]
public bool ImageContainsTitle { get; protected set; }

[Reactive]
public GameMetaData GameMetaData { get; protected set; }

[Reactive]

public bool DisplayVersionOnlyInInstallerView { get; protected set; }

[Reactive]
public IErrorResponse Error { get; protected set; }
[Reactive] public HashSet<ModListTag> ModListTagList { get; protected set; }
[Reactive] public Percent ProgressPercent { get; protected set; }
[Reactive] public bool IsBroken { get; protected set; }
[Reactive] public ModListStatus Status { get; set; }
[Reactive] public bool IsDownloading { get; protected set; }
[Reactive] public string DownloadSizeText { get; protected set; }
[Reactive] public string InstallSizeText { get; protected set; }
[Reactive] public string TotalSizeRequirementText { get; protected set; }
[Reactive] public string VersionText { get; protected set; }
[Reactive] public bool ImageContainsTitle { get; protected set; }
[Reactive] public GameMetaData GameMetaData { get; protected set; }
[Reactive] public bool DisplayVersionOnlyInInstallerView { get; protected set; }

[Reactive] public IErrorResponse Error { get; protected set; }

protected ObservableAsPropertyHelper<BitmapImage> _Image { get; set; }
public BitmapImage Image => _Image.Value;
Expand Down
29 changes: 25 additions & 4 deletions Wabbajack.App.Wpf/ViewModels/Gallery/ModListGalleryVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;
using System.Windows.Input;
using DynamicData;
using DynamicData.Binding;
Expand Down Expand Up @@ -69,10 +70,14 @@ public GameTypeEntry(GameMetaData gameMetaData, int amount)
[Reactive] public double MinModlistSize { get; set; }
[Reactive] public double MaxModlistSize { get; set; }

[Reactive] public ObservableCollection<ModListTag> AllTags { get; set; }
[Reactive] public ObservableCollection<ModListTag> AllTags { get; set; } = new();
[Reactive] public ObservableCollection<ModListTag> HasTags { get; set; } = new();

[Reactive] public HashSet<string> AllModNames { get; set; } = new();


[Reactive] public HashSet<ModListMod> AllMods { get; set; } = new();
[Reactive] public ObservableCollection<ModListMod> AllModsOE { get; set; } = new();
[Reactive] public ObservableCollection<ModListMod> HasMods { get; set; } = new();
[Reactive] public Dictionary<string, HashSet<string>> ModsPerList { get; set; } = new();

[Reactive] public GalleryModListMetadataVM SmallestSizedModlist { get; set; }
[Reactive] public GalleryModListMetadataVM LargestSizedModlist { get; set; }
Expand Down Expand Up @@ -207,6 +212,17 @@ public ModListGalleryVM(ILogger<ModListGalleryVM> logger, Client wjClient, GameL
return item => filteredTags.All(tag => item.Metadata.Tags.Contains(tag.Name));
})
.StartWith(_ => true);

var includedModsFilter = this.ObservableForProperty(vm => vm.HasMods)
.Select(v => v.Value)
.Select<ObservableCollection<ModListMod>, Func<GalleryModListMetadataVM, bool>>(filteredMods =>
{
if(!filteredMods?.Any() ?? true) return _ => true;

return item =>
ModsPerList.TryGetValue(item.Metadata.Links.MachineURL, out var mods) && filteredMods.All(mod => mods.Contains(mod.Name));
})
.StartWith(_ => true);


var searchSorter = this.WhenValueChanged(vm => vm.Search)
Expand All @@ -225,6 +241,7 @@ public ModListGalleryVM(ILogger<ModListGalleryVM> logger, Client wjClient, GameL
.Filter(minModlistSizeFilter)
.Filter(maxModlistSizeFilter)
.Filter(includedTagsFilter)
.Filter(includedModsFilter)
.Sort(searchSorter)
.TreatMovesAsRemoveAdd()
.Bind(out _filteredModLists)
Expand Down Expand Up @@ -286,8 +303,12 @@ private async Task LoadModLists()
{
var allowedTags = await _wjClient.LoadAllowedTags();
AllTags = new(allowedTags.Select(t => new ModListTag(t)).OrderBy(t => t.Name).Prepend(new ModListTag("NSFW")).Prepend(new ModListTag("Featured")));
var searchIndex = await _wjClient.LoadSearchIndex();
ModsPerList = searchIndex.ModsPerList;
AllMods = searchIndex.AllMods.Select(mod => new ModListMod(mod)).ToHashSet();
AllModsOE = new ObservableCollection<ModListMod>(AllMods);
var modLists = await _wjClient.LoadLists();
var modlistSummaries = (await _wjClient.GetListStatuses())?.ToDictionary(summary => summary.MachineURL) ?? new();
var modlistSummaries = (await _wjClient.GetListStatuses()).ToDictionary(summary => summary.MachineURL);
var httpClient = _serviceProvider.GetRequiredService<HttpClient>();
var cacheManager = _serviceProvider.GetRequiredService<ImageCacheManager>();
foreach (var modlist in modLists)
Expand Down
48 changes: 27 additions & 21 deletions Wabbajack.App.Wpf/Views/ModListGalleryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
Expand Down Expand Up @@ -118,28 +119,22 @@
Foreground="{StaticResource ComplementaryWhite25Brush}" Margin="0, 4, 0, 0" />
</Grid>

<CheckBox
Grid.Row="5"
x:Name="OnlyInstalledCheckbox"
Margin="0, 24, 0, 0"
VerticalAlignment="Center"
Foreground="{StaticResource ForegroundBrush}"
ToolTip="Show only modlists for games you have installed on your PC">
<TextBlock Text="Show only modlists for installed games" FontSize="10"
VerticalAlignment="Center" />
</CheckBox>

<!--
<mahapps:MultiSelectionComboBox
x:Name="IncludesTagsFilter"
Grid.Row="5"
Margin="0, 12, 0, 0"
Style="{StaticResource TagsComboBox}"
mahapps:MultiSelectorHelper.SelectedItems="{Binding IncludedTags}"
ItemsSource="{Binding AllTags}">
</mahapps:MultiSelectionComboBox>
-->
<StackPanel Grid.Row="4" Orientation="Vertical" Margin="0, 24, 0, 0">
<TextBlock Text="Has mod(s)" />
<sdl:MultiSelectComboBox
x:Name="HasModsFilter"
Margin="0, 12, 0, 0"
ItemsSource="{Binding AllModsOE}"
IsEditable="True"
SelectionMode="Multiple"
BorderThickness="0"
BorderBrush="Transparent"
Background="{StaticResource ComplementaryPrimary08Brush}"
Style="{StaticResource TagsBox}"
/>

</StackPanel>
<StackPanel Grid.Row="5" Orientation="Vertical" Margin="0, 24, 0, 0">
<TextBlock Text="Has tag(s)" />
<sdl:MultiSelectComboBox
x:Name="HasTagsFilter"
Expand All @@ -154,6 +149,17 @@
/>
</StackPanel>

<CheckBox
Grid.Row="6"
x:Name="OnlyInstalledCheckbox"
Margin="0, 24, 0, 0"
VerticalAlignment="Center"
Foreground="{StaticResource ForegroundBrush}"
ToolTip="Show only modlists for games you have installed on your PC">
<TextBlock Text="Show only modlists for installed games" FontSize="10"
VerticalAlignment="Center" />
</CheckBox>

<local:WizardButton
x:Name="ResetFiltersButton"
Margin="0, 24, 0, 0"
Expand Down
11 changes: 9 additions & 2 deletions Wabbajack.App.Wpf/Views/ModListGalleryView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@ public ModListGalleryView()
vProp => vProp * Math.Pow(1024, 3))
.DisposeWith(dispose);

this.HasTagsFilter.Events().SelectedItemsChanged
.Subscribe(args =>
HasTagsFilter.Events().SelectedItemsChanged
.Subscribe(_ =>
{
ViewModel.HasTags = new(HasTagsFilter.SelectedItems.Cast<ModListTag>());
})
.DisposeWith(dispose);

HasModsFilter.Events().SelectedItemsChanged
.Subscribe(_ =>
{
ViewModel.HasMods = new(HasModsFilter.SelectedItems.Cast<ModListMod>());
})
.DisposeWith(dispose);

/*
this.IncludesTagsFilter.Events().SelectionChanged
.Subscribe(args =>
Expand Down

0 comments on commit ecc7186

Please sign in to comment.