diff --git a/Wabbajack/Settings.cs b/Wabbajack/Settings.cs index 091f7f12..1aa60f9a 100644 --- a/Wabbajack/Settings.cs +++ b/Wabbajack/Settings.cs @@ -21,6 +21,7 @@ namespace Wabbajack public double Height { get; set; } public double Width { get; set; } public InstallerSettings Installer { get; set; } = new InstallerSettings(); + public FiltersSettings Filters { get; set; } = new FiltersSettings(); public CompilerSettings Compiler { get; set; } = new CompilerSettings(); public PerformanceSettings Performance { get; set; } = new PerformanceSettings(); @@ -93,6 +94,18 @@ namespace Wabbajack public AbsolutePath OutputLocation { get; set; } public MO2CompilationSettings MO2Compilation { get; } = new MO2CompilationSettings(); } + + [JsonName("FiltersSettings")] + [JsonObject(MemberSerialization.OptOut)] + public class FiltersSettings : ViewModel + { + public bool showNSFW { get; set; } + public bool OnlyInstalled { get; set; } + public string Game { get; set; } + public string Search { get; set; } + private bool _isPersistent = true; + public bool isPersistent { get => _isPersistent; set => RaiseAndSetIfChanged(ref _isPersistent, value); } + } [JsonName("PerformanceSettings")] [JsonObject(MemberSerialization.OptOut)] diff --git a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs index 63150809..fbbddb25 100644 --- a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs +++ b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs @@ -24,6 +24,8 @@ namespace Wabbajack public ObservableCollectionExtended ModLists { get; } = new ObservableCollectionExtended(); + private FiltersSettings settings; + private int missingHashFallbackCounter; private const string ALL_GAME_TYPE = "All"; @@ -44,6 +46,9 @@ namespace Wabbajack [Reactive] public string GameType { get; set; } + + [Reactive] + public bool GameTypeEnabled { get; set; } public List GameTypeEntries { get { return GetGameTypeEntries(); } } @@ -56,8 +61,22 @@ namespace Wabbajack : base(mainWindowVM) { MWVM = mainWindowVM; - GameType = ALL_GAME_TYPE; + GameTypeEnabled = true; + // load persistent filter settings + settings = MWVM.Settings.Filters; + if (settings.isPersistent) + { + GameType = !string.IsNullOrEmpty(settings.Game) ? settings.Game : ALL_GAME_TYPE; + ShowNSFW = settings.showNSFW; + OnlyInstalled = settings.OnlyInstalled; + if (OnlyInstalled) + GameTypeEnabled = false; + Search = settings.Search; + } + else + GameType = ALL_GAME_TYPE; + ClearFiltersCommand = ReactiveCommand.Create( () => { @@ -65,6 +84,8 @@ namespace Wabbajack ShowNSFW = false; Search = string.Empty; GameType = ALL_GAME_TYPE; + GameTypeEnabled = true; + UpdateFiltersSettings(); }); var random = new Random(); @@ -102,7 +123,13 @@ namespace Wabbajack OnlyInstalledCheckedCommand = ReactiveCommand.Create(() => { - GameType = ALL_GAME_TYPE; + if (OnlyInstalled) + { + GameType = ALL_GAME_TYPE; + GameTypeEnabled = false; + } + else + GameTypeEnabled = true; }); // Convert to VM and bind to resulting list @@ -114,6 +141,7 @@ namespace Wabbajack .Filter(this.WhenAny(x => x.OnlyInstalled) .Select>(onlyInstalled => (vm) => { + UpdateFiltersSettings(); if (!onlyInstalled) return true; if (!GameRegistry.Games.TryGetValue(vm.Metadata.Game, out var gameMeta)) return false; return gameMeta.IsInstalled; @@ -124,11 +152,13 @@ namespace Wabbajack .Select>(search => (vm) => { if (string.IsNullOrWhiteSpace(search)) return true; + UpdateFiltersSettings(); return vm.Metadata.Title.ContainsCaseInsensitive(search); })) .Filter(this.WhenAny(x => x.ShowNSFW) .Select>(showNSFW => vm => { + UpdateFiltersSettings(); if (!vm.Metadata.NSFW) return true; return vm.Metadata.NSFW && showNSFW; })) @@ -139,11 +169,17 @@ namespace Wabbajack { if (GameType == ALL_GAME_TYPE) return true; - return GameType == EnumExtensions.GetDescription(vm.Metadata.Game).ToString(); + if (string.IsNullOrEmpty(GameType)) + return false; + + UpdateFiltersSettings(); + return GameType == vm.Metadata.Game.GetDescription().ToString(); + })) .Filter(this.WhenAny(x => x.ShowNSFW) .Select>(showNSFW => vm => { + UpdateFiltersSettings(); if (!vm.Metadata.NSFW) return true; return vm.Metadata.NSFW && showNSFW; })) @@ -173,11 +209,20 @@ namespace Wabbajack private List GetGameTypeEntries() { List gameEntries = new List { ALL_GAME_TYPE }; - foreach (var gameType in EnumExtensions.GetAllItems() ) - { - gameEntries.Add(EnumExtensions.GetDescription(gameType)); - } + gameEntries.AddRange(EnumExtensions.GetAllItems().Select(gameType => gameType.GetDescription())); return gameEntries; } + + private void UpdateFiltersSettings() + { + if (!settings.isPersistent) + return; + if (!string.IsNullOrEmpty(GameType)) + settings.Game = GameType; + if (Search != null) + settings.Search = Search; + settings.showNSFW = ShowNSFW; + settings.OnlyInstalled = OnlyInstalled; + } } } diff --git a/Wabbajack/View Models/Settings/SettingsVM.cs b/Wabbajack/View Models/Settings/SettingsVM.cs index 4175f7f2..b2b19344 100644 --- a/Wabbajack/View Models/Settings/SettingsVM.cs +++ b/Wabbajack/View Models/Settings/SettingsVM.cs @@ -13,7 +13,7 @@ namespace Wabbajack public MainWindowVM MWVM { get; } public LoginManagerVM Login { get; } public PerformanceSettings Performance { get; } - + public FiltersSettings Filters { get; } public AuthorFilesVM AuthorFile { get; } public SettingsVM(MainWindowVM mainWindowVM) @@ -23,6 +23,7 @@ namespace Wabbajack Login = new LoginManagerVM(this); Performance = mainWindowVM.Settings.Performance; AuthorFile = new AuthorFilesVM(this); + Filters = mainWindowVM.Settings.Filters; } } diff --git a/Wabbajack/Views/ModListGalleryView.xaml b/Wabbajack/Views/ModListGalleryView.xaml index af20b13d..4b04971d 100644 --- a/Wabbajack/Views/ModListGalleryView.xaml +++ b/Wabbajack/Views/ModListGalleryView.xaml @@ -108,6 +108,7 @@ ItemsSource="{Binding Path=GameTypeEntries}" SelectedItem="{Binding GameType, Mode=TwoWay}" ToolTip="Select a game" + IsEnabled="{Binding GameTypeEnabled}" Width="130" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs new file mode 100644 index 00000000..bdf02b49 --- /dev/null +++ b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Disposables; +using System.Reactive.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using ReactiveUI; +using Wabbajack.Common; + +namespace Wabbajack +{ + /// + /// Interaction logic for ModlistGallerySettingsView.xaml + /// + public partial class ModlistGallerySettingsView : ReactiveUserControl + { + public ModlistGallerySettingsView() + { + InitializeComponent(); + + this.WhenActivated(disposable => + { + // Bind Values + this.Bind(this.ViewModel, x => x.isPersistent, x => x.FilterPersistCheckBox.IsChecked) + .DisposeWith(disposable); + }); + } + } +} diff --git a/Wabbajack/Views/Settings/SettingsView.xaml b/Wabbajack/Views/Settings/SettingsView.xaml index 76b43e9f..fdef4c03 100644 --- a/Wabbajack/Views/Settings/SettingsView.xaml +++ b/Wabbajack/Views/Settings/SettingsView.xaml @@ -47,6 +47,7 @@ + diff --git a/Wabbajack/Views/Settings/SettingsView.xaml.cs b/Wabbajack/Views/Settings/SettingsView.xaml.cs index 70b80258..b3237bbf 100644 --- a/Wabbajack/Views/Settings/SettingsView.xaml.cs +++ b/Wabbajack/Views/Settings/SettingsView.xaml.cs @@ -34,6 +34,8 @@ namespace Wabbajack .DisposeWith(disposable); this.OneWayBindStrict(this.ViewModel, x => x.Performance, x => x.PerformanceView.ViewModel) .DisposeWith(disposable); + this.OneWayBindStrict(this.ViewModel, x => x.Filters, x => x.ModlistGalleryView.ViewModel) + .DisposeWith(disposable); }); } }