Merge pull request #803 from LordOfRhun/game-filter

[Feature] added a filter for games
This commit is contained in:
Timothy Baldridge 2020-05-08 21:51:44 -07:00 committed by GitHub
commit f561a160ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 6 deletions

View File

@ -134,6 +134,11 @@ namespace Wabbajack.Common
return attrs.Length > 0 ? ((DescriptionAttribute)attrs[0]).Description : enumerationValue.ToString();
}
public static IEnumerable<T> GetAllItems<T>() where T : struct
{
return Enum.GetValues(typeof(T)).Cast<T>();
}
}
public class GameRegistry

View File

@ -26,6 +26,10 @@ namespace Wabbajack
private int missingHashFallbackCounter;
private const string ALL_GAME_TYPE = "All";
public ICommand OnlyInstalledCheckedCommand { get; }
[Reactive]
public IErrorResponse Error { get; set; }
@ -34,10 +38,15 @@ namespace Wabbajack
[Reactive]
public bool OnlyInstalled { get; set; }
[Reactive]
public bool ShowNSFW { get; set; }
[Reactive]
public string GameType { get; set; }
public List<string> GameTypeEntries { get { return GetGameTypeEntries(); } }
private readonly ObservableAsPropertyHelper<bool> _Loaded;
public bool Loaded => _Loaded.Value;
@ -47,6 +56,7 @@ namespace Wabbajack
: base(mainWindowVM)
{
MWVM = mainWindowVM;
GameType = ALL_GAME_TYPE;
ClearFiltersCommand = ReactiveCommand.Create(
() =>
@ -54,6 +64,7 @@ namespace Wabbajack
OnlyInstalled = false;
ShowNSFW = false;
Search = string.Empty;
GameType = ALL_GAME_TYPE;
});
var random = new Random();
@ -89,6 +100,11 @@ 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()
@ -116,6 +132,21 @@ namespace Wabbajack
if (!vm.Metadata.NSFW) return true;
return vm.Metadata.NSFW && showNSFW;
}))
// Filter by Game
.Filter(this.WhenAny(x => x.GameType)
.Debounce(TimeSpan.FromMilliseconds(150), RxApp.MainThreadScheduler)
.Select<string, Func<ModListMetadataVM, bool>>(GameType => (vm) =>
{
if (GameType == ALL_GAME_TYPE)
return true;
return GameType == EnumExtensions.GetDescription<Game>(vm.Metadata.Game).ToString();
}))
.Filter(this.WhenAny(x => x.ShowNSFW)
.Select<bool, Func<ModListMetadataVM, bool>>(showNSFW => vm =>
{
if (!vm.Metadata.NSFW) return true;
return vm.Metadata.NSFW && showNSFW;
}))
// Put broken lists at bottom
.Sort(Comparer<ModListMetadataVM>.Create((a, b) => a.IsBroken.CompareTo(b.IsBroken)))
.Bind(ModLists)
@ -138,5 +169,15 @@ namespace Wabbajack
{
Error = null;
}
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));
}
return gameEntries;
}
}
}

View File

@ -10,7 +10,7 @@
xmlns:rxui="http://reactiveui.net"
xmlns:system="clr-namespace:System;assembly=mscorlib"
d:DesignHeight="450"
d:DesignWidth="800"
d:DesignWidth="900"
x:TypeArguments="local:ModListGalleryVM"
mc:Ignorable="d">
<Grid>
@ -97,6 +97,18 @@
Margin="5,5,5,10"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Label
Margin="0,0,0,0"
VerticalAlignment="Center"
Content="Game" />
<ComboBox
Margin="0,0,10,0"
VerticalAlignment="Center"
Foreground="{StaticResource ForegroundBrush}"
ItemsSource="{Binding Path=GameTypeEntries}"
SelectedItem="{Binding GameType, Mode=TwoWay}"
ToolTip="Select a game"
Width="130" />
<TextBlock
Margin="0,0,5,0"
VerticalAlignment="Center"
@ -104,19 +116,20 @@
Text="Search" />
<TextBox
x:Name="SearchBox"
Width="160"
Width="95"
VerticalContentAlignment="Center" />
<CheckBox
x:Name="ShowNSFW"
Margin="20,0,10,0"
Margin="10,0,10,0"
VerticalAlignment="Center"
Content="Show NSFW"
Foreground="{StaticResource ForegroundBrush}"/>
<CheckBox
x:Name="OnlyInstalledCheckbox"
Margin="20,0,10,0"
Margin="10,0,10,0"
VerticalAlignment="Center"
Content="Only Installed"
Command="{Binding OnlyInstalledCheckedCommand}"
Foreground="{StaticResource ForegroundBrush}" />
<Button
x:Name="ClearFiltersButton"
@ -139,4 +152,4 @@
<iconPacks:PackIconMaterial Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" Kind="ArrowLeft" />
</Button>
</Grid>
</rxui:ReactiveUserControl>
</rxui:ReactiveUserControl>