mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #803 from LordOfRhun/game-filter
[Feature] added a filter for games
This commit is contained in:
commit
f561a160ef
@ -134,6 +134,11 @@ namespace Wabbajack.Common
|
|||||||
|
|
||||||
return attrs.Length > 0 ? ((DescriptionAttribute)attrs[0]).Description : enumerationValue.ToString();
|
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
|
public class GameRegistry
|
||||||
|
@ -26,6 +26,10 @@ namespace Wabbajack
|
|||||||
|
|
||||||
private int missingHashFallbackCounter;
|
private int missingHashFallbackCounter;
|
||||||
|
|
||||||
|
private const string ALL_GAME_TYPE = "All";
|
||||||
|
|
||||||
|
public ICommand OnlyInstalledCheckedCommand { get; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public IErrorResponse Error { get; set; }
|
public IErrorResponse Error { get; set; }
|
||||||
|
|
||||||
@ -34,10 +38,15 @@ namespace Wabbajack
|
|||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public bool OnlyInstalled { get; set; }
|
public bool OnlyInstalled { get; set; }
|
||||||
|
|
||||||
[Reactive]
|
[Reactive]
|
||||||
public bool ShowNSFW { get; set; }
|
public bool ShowNSFW { get; set; }
|
||||||
|
|
||||||
|
[Reactive]
|
||||||
|
public string GameType { get; set; }
|
||||||
|
|
||||||
|
public List<string> GameTypeEntries { get { return GetGameTypeEntries(); } }
|
||||||
|
|
||||||
private readonly ObservableAsPropertyHelper<bool> _Loaded;
|
private readonly ObservableAsPropertyHelper<bool> _Loaded;
|
||||||
public bool Loaded => _Loaded.Value;
|
public bool Loaded => _Loaded.Value;
|
||||||
|
|
||||||
@ -47,6 +56,7 @@ namespace Wabbajack
|
|||||||
: base(mainWindowVM)
|
: base(mainWindowVM)
|
||||||
{
|
{
|
||||||
MWVM = mainWindowVM;
|
MWVM = mainWindowVM;
|
||||||
|
GameType = ALL_GAME_TYPE;
|
||||||
|
|
||||||
ClearFiltersCommand = ReactiveCommand.Create(
|
ClearFiltersCommand = ReactiveCommand.Create(
|
||||||
() =>
|
() =>
|
||||||
@ -54,6 +64,7 @@ namespace Wabbajack
|
|||||||
OnlyInstalled = false;
|
OnlyInstalled = false;
|
||||||
ShowNSFW = false;
|
ShowNSFW = false;
|
||||||
Search = string.Empty;
|
Search = string.Empty;
|
||||||
|
GameType = ALL_GAME_TYPE;
|
||||||
});
|
});
|
||||||
|
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
@ -89,6 +100,11 @@ namespace Wabbajack
|
|||||||
.Select(c => c > 0)
|
.Select(c => c > 0)
|
||||||
.ToProperty(this, nameof(Loaded));
|
.ToProperty(this, nameof(Loaded));
|
||||||
|
|
||||||
|
OnlyInstalledCheckedCommand = ReactiveCommand.Create(() =>
|
||||||
|
{
|
||||||
|
GameType = ALL_GAME_TYPE;
|
||||||
|
});
|
||||||
|
|
||||||
// Convert to VM and bind to resulting list
|
// Convert to VM and bind to resulting list
|
||||||
sourceList
|
sourceList
|
||||||
.ObserveOnGuiThread()
|
.ObserveOnGuiThread()
|
||||||
@ -116,6 +132,21 @@ namespace Wabbajack
|
|||||||
if (!vm.Metadata.NSFW) return true;
|
if (!vm.Metadata.NSFW) return true;
|
||||||
return vm.Metadata.NSFW && showNSFW;
|
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
|
// Put broken lists at bottom
|
||||||
.Sort(Comparer<ModListMetadataVM>.Create((a, b) => a.IsBroken.CompareTo(b.IsBroken)))
|
.Sort(Comparer<ModListMetadataVM>.Create((a, b) => a.IsBroken.CompareTo(b.IsBroken)))
|
||||||
.Bind(ModLists)
|
.Bind(ModLists)
|
||||||
@ -138,5 +169,15 @@ namespace Wabbajack
|
|||||||
{
|
{
|
||||||
Error = null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
xmlns:rxui="http://reactiveui.net"
|
xmlns:rxui="http://reactiveui.net"
|
||||||
xmlns:system="clr-namespace:System;assembly=mscorlib"
|
xmlns:system="clr-namespace:System;assembly=mscorlib"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="900"
|
||||||
x:TypeArguments="local:ModListGalleryVM"
|
x:TypeArguments="local:ModListGalleryVM"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Grid>
|
<Grid>
|
||||||
@ -97,6 +97,18 @@
|
|||||||
Margin="5,5,5,10"
|
Margin="5,5,5,10"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Orientation="Horizontal">
|
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
|
<TextBlock
|
||||||
Margin="0,0,5,0"
|
Margin="0,0,5,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
@ -104,19 +116,20 @@
|
|||||||
Text="Search" />
|
Text="Search" />
|
||||||
<TextBox
|
<TextBox
|
||||||
x:Name="SearchBox"
|
x:Name="SearchBox"
|
||||||
Width="160"
|
Width="95"
|
||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
<CheckBox
|
<CheckBox
|
||||||
x:Name="ShowNSFW"
|
x:Name="ShowNSFW"
|
||||||
Margin="20,0,10,0"
|
Margin="10,0,10,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Content="Show NSFW"
|
Content="Show NSFW"
|
||||||
Foreground="{StaticResource ForegroundBrush}"/>
|
Foreground="{StaticResource ForegroundBrush}"/>
|
||||||
<CheckBox
|
<CheckBox
|
||||||
x:Name="OnlyInstalledCheckbox"
|
x:Name="OnlyInstalledCheckbox"
|
||||||
Margin="20,0,10,0"
|
Margin="10,0,10,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Content="Only Installed"
|
Content="Only Installed"
|
||||||
|
Command="{Binding OnlyInstalledCheckedCommand}"
|
||||||
Foreground="{StaticResource ForegroundBrush}" />
|
Foreground="{StaticResource ForegroundBrush}" />
|
||||||
<Button
|
<Button
|
||||||
x:Name="ClearFiltersButton"
|
x:Name="ClearFiltersButton"
|
||||||
@ -139,4 +152,4 @@
|
|||||||
<iconPacks:PackIconMaterial Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" Kind="ArrowLeft" />
|
<iconPacks:PackIconMaterial Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" Kind="ArrowLeft" />
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</rxui:ReactiveUserControl>
|
</rxui:ReactiveUserControl>
|
Loading…
Reference in New Issue
Block a user