From 961fb39f9ad13ab0b53ca8645d0aa8c3fe24e17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kham=C3=BBl?= <32278516+LordOfRhun@users.noreply.github.com> Date: Sun, 10 May 2020 00:35:39 -0400 Subject: [PATCH 01/13] Added persistent filters on exit and more * Added persistent filters on exit * settings to disable the persistent filters * fixed a bug related to game comboBox and OnlyInstalled ( the comboBox is now disabled if OnlyInstalled is checked) --- Wabbajack/Settings.cs | 13 ++++ .../View Models/Gallery/ModListGalleryVM.cs | 59 +++++++++++++++-- Wabbajack/View Models/Settings/SettingsVM.cs | 3 +- Wabbajack/Views/ModListGalleryView.xaml | 1 + .../Settings/ModlistGallerySettingsView.xaml | 65 +++++++++++++++++++ .../ModlistGallerySettingsView.xaml.cs | 39 +++++++++++ Wabbajack/Views/Settings/SettingsView.xaml | 1 + Wabbajack/Views/Settings/SettingsView.xaml.cs | 2 + 8 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml create mode 100644 Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs 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); }); } } From 75a14bfaf264b4492e4014b1d9c25a4a8b211268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kham=C3=BBl?= <32278516+LordOfRhun@users.noreply.github.com> Date: Sun, 10 May 2020 00:59:34 -0400 Subject: [PATCH 02/13] fixed variable names --- Wabbajack/Settings.cs | 4 ++-- Wabbajack/View Models/Gallery/ModListGalleryVM.cs | 8 ++++---- .../Views/Settings/ModlistGallerySettingsView.xaml.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Wabbajack/Settings.cs b/Wabbajack/Settings.cs index 1aa60f9a..4987666f 100644 --- a/Wabbajack/Settings.cs +++ b/Wabbajack/Settings.cs @@ -99,12 +99,12 @@ namespace Wabbajack [JsonObject(MemberSerialization.OptOut)] public class FiltersSettings : ViewModel { - public bool showNSFW { get; set; } + 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); } + public bool IsPersistent { get => _isPersistent; set => RaiseAndSetIfChanged(ref _isPersistent, value); } } [JsonName("PerformanceSettings")] diff --git a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs index fbbddb25..fafac642 100644 --- a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs +++ b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs @@ -65,10 +65,10 @@ namespace Wabbajack // load persistent filter settings settings = MWVM.Settings.Filters; - if (settings.isPersistent) + if (settings.IsPersistent) { GameType = !string.IsNullOrEmpty(settings.Game) ? settings.Game : ALL_GAME_TYPE; - ShowNSFW = settings.showNSFW; + ShowNSFW = settings.ShowNSFW; OnlyInstalled = settings.OnlyInstalled; if (OnlyInstalled) GameTypeEnabled = false; @@ -215,13 +215,13 @@ namespace Wabbajack private void UpdateFiltersSettings() { - if (!settings.isPersistent) + if (!settings.IsPersistent) return; if (!string.IsNullOrEmpty(GameType)) settings.Game = GameType; if (Search != null) settings.Search = Search; - settings.showNSFW = ShowNSFW; + settings.ShowNSFW = ShowNSFW; settings.OnlyInstalled = OnlyInstalled; } } diff --git a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs index bdf02b49..f314727f 100644 --- a/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs +++ b/Wabbajack/Views/Settings/ModlistGallerySettingsView.xaml.cs @@ -31,7 +31,7 @@ namespace Wabbajack this.WhenActivated(disposable => { // Bind Values - this.Bind(this.ViewModel, x => x.isPersistent, x => x.FilterPersistCheckBox.IsChecked) + this.Bind(this.ViewModel, x => x.IsPersistent, x => x.FilterPersistCheckBox.IsChecked) .DisposeWith(disposable); }); } From 99113507c477ebecb7715f7ace1a5794517db4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kham=C3=BBl?= <32278516+LordOfRhun@users.noreply.github.com> Date: Sun, 10 May 2020 13:12:43 -0400 Subject: [PATCH 03/13] Subcribe to settings SaveSignal --- Wabbajack/View Models/Gallery/ModListGalleryVM.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs index fafac642..512661a6 100644 --- a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs +++ b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs @@ -73,6 +73,10 @@ namespace Wabbajack if (OnlyInstalled) GameTypeEnabled = false; Search = settings.Search; + // subscribe to save signal + MWVM.Settings.SaveSignal + .Subscribe(_ => UpdateFiltersSettings()) + .DisposeWith(this.CompositeDisposable); } else GameType = ALL_GAME_TYPE; @@ -85,7 +89,6 @@ namespace Wabbajack Search = string.Empty; GameType = ALL_GAME_TYPE; GameTypeEnabled = true; - UpdateFiltersSettings(); }); var random = new Random(); @@ -141,7 +144,6 @@ 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; @@ -152,13 +154,11 @@ 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; })) @@ -172,14 +172,12 @@ namespace Wabbajack 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; })) From 5e5c1bb3849e7ca2453861977d22813929dec976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kham=C3=BBl?= <32278516+LordOfRhun@users.noreply.github.com> Date: Sun, 10 May 2020 13:18:55 -0400 Subject: [PATCH 04/13] Simplifying the process of disabling gameType --- .../View Models/Gallery/ModListGalleryVM.cs | 20 ------------------- Wabbajack/Views/ModListGalleryView.xaml | 3 +-- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs index 512661a6..447eef0b 100644 --- a/Wabbajack/View Models/Gallery/ModListGalleryVM.cs +++ b/Wabbajack/View Models/Gallery/ModListGalleryVM.cs @@ -30,8 +30,6 @@ namespace Wabbajack private const string ALL_GAME_TYPE = "All"; - public ICommand OnlyInstalledCheckedCommand { get; } - [Reactive] public IErrorResponse Error { get; set; } @@ -46,9 +44,6 @@ namespace Wabbajack [Reactive] public string GameType { get; set; } - - [Reactive] - public bool GameTypeEnabled { get; set; } public List GameTypeEntries { get { return GetGameTypeEntries(); } } @@ -61,7 +56,6 @@ namespace Wabbajack : base(mainWindowVM) { MWVM = mainWindowVM; - GameTypeEnabled = true; // load persistent filter settings settings = MWVM.Settings.Filters; @@ -70,8 +64,6 @@ namespace Wabbajack GameType = !string.IsNullOrEmpty(settings.Game) ? settings.Game : ALL_GAME_TYPE; ShowNSFW = settings.ShowNSFW; OnlyInstalled = settings.OnlyInstalled; - if (OnlyInstalled) - GameTypeEnabled = false; Search = settings.Search; // subscribe to save signal MWVM.Settings.SaveSignal @@ -88,7 +80,6 @@ namespace Wabbajack ShowNSFW = false; Search = string.Empty; GameType = ALL_GAME_TYPE; - GameTypeEnabled = true; }); var random = new Random(); @@ -124,17 +115,6 @@ namespace Wabbajack .Select(c => c > 0) .ToProperty(this, nameof(Loaded)); - OnlyInstalledCheckedCommand = ReactiveCommand.Create(() => - { - if (OnlyInstalled) - { - GameType = ALL_GAME_TYPE; - GameTypeEnabled = false; - } - else - GameTypeEnabled = true; - }); - // Convert to VM and bind to resulting list sourceList .ObserveOnGuiThread() diff --git a/Wabbajack/Views/ModListGalleryView.xaml b/Wabbajack/Views/ModListGalleryView.xaml index 4b04971d..75f252a6 100644 --- a/Wabbajack/Views/ModListGalleryView.xaml +++ b/Wabbajack/Views/ModListGalleryView.xaml @@ -108,7 +108,7 @@ ItemsSource="{Binding Path=GameTypeEntries}" SelectedItem="{Binding GameType, Mode=TwoWay}" ToolTip="Select a game" - IsEnabled="{Binding GameTypeEnabled}" + IsEnabled="{Binding OnlyInstalled, Converter={StaticResource InverseBooleanConverter}}" Width="130" />