Merge pull request #816 from LordOfRhun/Persistant-filters

Added persistent filters on exit and more
This commit is contained in:
Timothy Baldridge 2020-05-13 05:14:22 -07:00 committed by GitHub
commit 147a183cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 165 additions and 15 deletions

View File

@ -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)]

View File

@ -26,8 +26,6 @@ namespace Wabbajack
private const string ALL_GAME_TYPE = "All";
public ICommand OnlyInstalledCheckedCommand { get; }
[Reactive]
public IErrorResponse Error { get; set; }
@ -46,6 +44,9 @@ namespace Wabbajack
public List<string> GameTypeEntries { get { return GetGameTypeEntries(); } }
private readonly ObservableAsPropertyHelper<bool> _Loaded;
private FiltersSettings settings => MWVM.Settings.Filters;
public bool Loaded => _Loaded.Value;
public ICommand ClearFiltersCommand { get; }
@ -54,7 +55,22 @@ namespace Wabbajack
: base(mainWindowVM)
{
MWVM = mainWindowVM;
GameType = ALL_GAME_TYPE;
// load persistent filter settings
if (settings.IsPersistent)
{
GameType = !string.IsNullOrEmpty(settings.Game) ? settings.Game : ALL_GAME_TYPE;
ShowNSFW = settings.ShowNSFW;
OnlyInstalled = settings.OnlyInstalled;
Search = settings.Search;
}
else
GameType = ALL_GAME_TYPE;
// subscribe to save signal
MWVM.Settings.SaveSignal
.Subscribe(_ => UpdateFiltersSettings())
.DisposeWith(this.CompositeDisposable);
ClearFiltersCommand = ReactiveCommand.Create(
() =>
@ -65,6 +81,15 @@ namespace Wabbajack
GameType = ALL_GAME_TYPE;
});
this.WhenAny(x => x.OnlyInstalled)
.Subscribe(val =>
{
if(val)
GameType = ALL_GAME_TYPE;
})
.DisposeWith(CompositeDisposable);
var random = new Random();
var sourceList = Observable.Return(Unit.Default)
.ObserveOn(RxApp.TaskpoolScheduler)
@ -98,11 +123,6 @@ namespace Wabbajack
.Select(c => c > 0)
.ToProperty(this, nameof(Loaded));
OnlyInstalledCheckedCommand = ReactiveCommand.Create(() =>
{
GameType = ALL_GAME_TYPE;
});
// Convert to VM and bind to resulting list
sourceList
.ObserveOnGuiThread()
@ -137,7 +157,11 @@ namespace Wabbajack
{
if (GameType == ALL_GAME_TYPE)
return true;
return GameType == EnumExtensions.GetDescription<Game>(vm.Metadata.Game).ToString();
if (string.IsNullOrEmpty(GameType))
return false;
return GameType == vm.Metadata.Game.GetDescription<Game>().ToString();
}))
.Filter(this.WhenAny(x => x.ShowNSFW)
.Select<bool, Func<ModListMetadataVM, bool>>(showNSFW => vm =>
@ -171,11 +195,16 @@ namespace Wabbajack
private List<string> GetGameTypeEntries()
{
List<string> gameEntries = new List<string> { ALL_GAME_TYPE };
foreach (var gameType in EnumExtensions.GetAllItems<Game>() )
{
gameEntries.Add(EnumExtensions.GetDescription<Game>(gameType));
}
gameEntries.AddRange(EnumExtensions.GetAllItems<Game>().Select(gameType => gameType.GetDescription<Game>()));
return gameEntries;
}
private void UpdateFiltersSettings()
{
settings.Game = GameType;
settings.Search = Search;
settings.ShowNSFW = ShowNSFW;
settings.OnlyInstalled = OnlyInstalled;
}
}
}

View File

@ -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;
}
}

View File

@ -108,6 +108,7 @@
ItemsSource="{Binding Path=GameTypeEntries}"
SelectedItem="{Binding GameType, Mode=TwoWay}"
ToolTip="Select a game"
IsEnabled="{Binding OnlyInstalled, Converter={StaticResource InverseBooleanConverter}}"
Width="130" />
<TextBlock
Margin="0,0,5,0"
@ -129,7 +130,6 @@
Margin="10,0,10,0"
VerticalAlignment="Center"
Content="Only Installed"
Command="{Binding OnlyInstalledCheckedCommand}"
Foreground="{StaticResource ForegroundBrush}" />
<Button
x:Name="ClearFiltersButton"

View File

@ -0,0 +1,65 @@
<rxui:ReactiveUserControl
x:Class="Wabbajack.ModlistGallerySettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:rxui="http://reactiveui.net"
xmlns:xwpf="http://schemas.xceed.com/wpf/xaml/toolkit"
d:DesignHeight="450"
d:DesignWidth="800"
x:TypeArguments="local:FiltersSettings"
mc:Ignorable="d">
<Border
x:Name="PerformanceView"
MinWidth="280"
Margin="5"
Background="{StaticResource BackgroundBrush}"
BorderBrush="{StaticResource ButtonNormalBorder}"
BorderThickness="1">
<Grid Margin="15,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
FontFamily="Lucida Sans"
FontSize="20"
FontWeight="Bold"
Text="Modlist Gallery" />
<Grid
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="3">
<Grid.Resources>
<Style BasedOn="{StaticResource MainButtonStyle}" TargetType="Button">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" />
<Setter Property="Background" Value="{StaticResource SecondaryBackgroundBrush}" />
<Setter Property="BorderBrush" Value="{StaticResource DarkSecondaryBrush}" />
</Trigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<CheckBox Name="FilterPersistCheckBox" Content="Filters are saved on exit" HorizontalAlignment="Left" Margin="0,5,0,0" VerticalAlignment="Top">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1.2" ScaleY="1.2" />
</CheckBox.LayoutTransform>
</CheckBox>
</Grid>
</Grid>
</Border>
</rxui:ReactiveUserControl>

View File

@ -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
{
/// <summary>
/// Interaction logic for ModlistGallerySettingsView.xaml
/// </summary>
public partial class ModlistGallerySettingsView : ReactiveUserControl<FiltersSettings>
{
public ModlistGallerySettingsView()
{
InitializeComponent();
this.WhenActivated(disposable =>
{
// Bind Values
this.Bind(this.ViewModel, x => x.IsPersistent, x => x.FilterPersistCheckBox.IsChecked)
.DisposeWith(disposable);
});
}
}
}

View File

@ -47,6 +47,7 @@
<WrapPanel>
<local:LoginSettingsView x:Name="LoginView" />
<local:PerformanceSettingsView x:Name="PerformanceView" />
<local:ModlistGallerySettingsView x:Name="ModlistGalleryView" />
<local:AuthorFilesView x:Name="AuthorFilesView"></local:AuthorFilesView>
</WrapPanel>
</ScrollViewer>

View File

@ -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);
});
}
}