Skip to content

Commit

Permalink
- You can now filter by game state in the library
Browse files Browse the repository at this point in the history
- Bug fix: Sometimes the colors of the Genre/Tag pills were too bright
- Bug fix: Sometimes the add buttons on the pill selector were cut off
  • Loading branch information
Yelo420 committed Oct 25, 2024
1 parent 52d2d67 commit 193f106
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
Recommended Gamevault Server Version: `v13.0.0`
### Changes

- You can now filter by game state in the library
- GameVault now stores the forced installation type for the uninstallation
- Bug fix: Application name is blank in the taskbar
- Bug fix: Sometimes the colors of the Genre/Tag pills were too bright
- Bug fix: Sometimes the add buttons on the pill selector were cut off

## 1.12.5
Recommended Gamevault Server Version: `v13.0.0`
Expand Down
7 changes: 6 additions & 1 deletion gamevault/Converter/EnumDescriptionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ internal class EnumDescriptionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((GameType)value != GameType.UNDETECTABLE)
if (value is GameType && (GameType)value != GameType.UNDETECTABLE)
{
string result = ((DescriptionAttribute[])typeof(GameType).GetField(((GameType)value).ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false))[0].Description.ToString();
return result;
}
else if (value is State)
{
string result = ((DescriptionAttribute[])typeof(State).GetField(((State)value).ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false))[0].Description.ToString();
return result;
}
return string.Empty;
}

Expand Down
16 changes: 9 additions & 7 deletions gamevault/Converter/StringToColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
}
return Brushes.Black;
}

private Color GenerateColor(int numericValue)
{
byte red = (byte)((numericValue >> 16) & 0xFF);
byte green = (byte)((numericValue >> 8) & 0xFF);
byte blue = (byte)(numericValue & 0xFF);

// Darken the color by reducing each component by a fixed amount
const int darkeningAmount = 10;
red = (byte)Math.Max(0, red - darkeningAmount);
green = (byte)Math.Max(0, green - darkeningAmount);
blue = (byte)Math.Max(0, blue - darkeningAmount);
// Ensure the color is saturated by setting the maximum component to 255
byte maxComponent = Math.Max(red, Math.Max(green, blue));
if (maxComponent > 0)
{
float scale = 200f / maxComponent;
red = (byte)(red * scale);
green = (byte)(green * scale);
blue = (byte)(blue * scale);
}

return Color.FromRgb(red, green, blue);
}


public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Colors.White;
Expand Down
2 changes: 1 addition & 1 deletion gamevault/Helper/AnalyticsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal AnalyticsHelper()
{
trackingEnabled = SettingsViewModel.Instance.SendAnonymousAnalytics;
#if DEBUG
// trackingEnabled = false;
trackingEnabled = false;
#endif
if (!trackingEnabled)
return;
Expand Down
2 changes: 1 addition & 1 deletion gamevault/UserControls/GameViewUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
<DataTemplate>
<Button Style="{StaticResource ButtonWrapper}" Cursor="Hand" Height="25" Margin="5,0,0,0" Click="Genre_Clicked">
<Border CornerRadius="5" Background="{Binding Name,Converter={StaticResource nameColorConv}}" Padding="0" >
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="8,0,8,0" FontSize="10" FontWeight="Bold"/>
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Foreground="{DynamicResource MahApps.Brushes.IdealForeground}" Margin="8,0,8,0" FontSize="10" FontWeight="Bold"/>
</Border>
</Button>
</DataTemplate>
Expand Down
2 changes: 1 addition & 1 deletion gamevault/UserControls/GameViewUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void Tag_Clicked(object sender, RoutedEventArgs e)
{
TagMetadata data = (TagMetadata)((FrameworkElement)sender).DataContext;
MainWindowViewModel.Instance.Library.ClearAllFilters();
MainWindowViewModel.Instance.Library.uiFilterPillSelector.SetEntries(new Pill[] { new Pill() { ID = data.ID, Name = data.Name, ProviderDataId = data.ProviderDataId } });
MainWindowViewModel.Instance.Library.uiFilterTagSelector.SetEntries(new Pill[] { new Pill() { ID = data.ID, Name = data.Name, ProviderDataId = data.ProviderDataId } });
MainWindowViewModel.Instance.SetActiveControl(MainControl.Library);
}
catch { }
Expand Down
4 changes: 2 additions & 2 deletions gamevault/UserControls/GeneralControls/PillSelector.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
<StackPanel Margin="5">
<TextBlock x:Name="uiTxtSelectionHeader" HorizontalAlignment="Center"/>
<TextBox Style="{DynamicResource SearchTextBox}" Height="26" TextChanged="Search_TextChanged" Margin="0,1,0,5"/>
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" MaxHeight="200">
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Visible" MaxHeight="200">
<ItemsControl x:Name="uiSelectionEntries">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="2" MaxWidth="180">
<Grid Margin="2" Width="170" HorizontalAlignment="Left">
<Border CornerRadius="5" Background="{Binding Name,Converter={StaticResource colorConv}}" Margin="0,0,25,0">
<TextBlock Text="{Binding Name}" Foreground="{DynamicResource MahApps.Brushes.IdealForeground}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
Expand Down
49 changes: 33 additions & 16 deletions gamevault/UserControls/GeneralControls/PillSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public enum Selection
{
Tags,
Genres,
GameType
GameType,
GameState

}
public partial class PillSelector : UserControl
{
Expand All @@ -44,6 +46,7 @@ private async void UserControl_Loaded(object sender, RoutedEventArgs e)
Selection.Tags => "Tags",
Selection.Genres => "Genres",
Selection.GameType => "Game Type",
Selection.GameState => "Game State",
_ => uiTxtHeader.Text
};
InitTimer();
Expand All @@ -60,6 +63,9 @@ public string GetSelectedEntries()
if (SelectionType == Selection.GameType)
return string.Join(",", selectedEntries.Select(o => o.OriginName));

if (SelectionType == Selection.GameState)
return string.Join(",", selectedEntries.Select(o => o.OriginName));

return string.Join(",", selectedEntries.Select(o => o.Name));
}
public bool HasEntries()
Expand Down Expand Up @@ -92,7 +98,32 @@ private async void DebounceTimerElapsed(object? sender, EventArgs e)
private async Task LoadSelectionEntries()
{
Pill[] data = null;
if (SelectionType != Selection.GameType)
if (SelectionType == Selection.GameType)
{
EnumDescriptionConverter conv = new EnumDescriptionConverter();
List<Pill> list = new List<Pill>();
foreach (GameType type in Enum.GetValues(typeof(GameType)))
{
if (type == GameType.UNDETECTABLE)
continue;

list.Add(new Pill() { OriginName = type.ToString(), Name = (string)conv.Convert(type, null, null, null) });
}
data = list.ToArray();
data = data.Where(x => x.Name.Contains(debounceTimer.Data, StringComparison.OrdinalIgnoreCase)).ToArray();
}
else if (SelectionType == Selection.GameState)
{
EnumDescriptionConverter conv = new EnumDescriptionConverter();
List<Pill> list = new List<Pill>();
foreach (State type in Enum.GetValues(typeof(State)))
{
list.Add(new Pill() { OriginName = type.ToString(), Name = (string)conv.Convert(type, null, null, null) });
}
data = list.ToArray();
data = data.Where(x => x.Name.Contains(debounceTimer.Data, StringComparison.OrdinalIgnoreCase)).ToArray();
}
else
{
string url = string.Empty;
url = SelectionType switch
Expand All @@ -119,20 +150,6 @@ await Task.Run(() =>
}
});
}
else
{
EnumDescriptionConverter conv = new EnumDescriptionConverter();
List<Pill> list = new List<Pill>();
foreach (GameType type in Enum.GetValues(typeof(GameType)))
{
if (type == GameType.UNDETECTABLE)
continue;

list.Add(new Pill() { OriginName = type.ToString(), Name = (string)conv.Convert(type, null, null, null) });
}
data = list.ToArray();
data = data.Where(x => x.Name.Contains(debounceTimer.Data, StringComparison.OrdinalIgnoreCase)).ToArray();
}
uiSelectionEntries.ItemsSource = data;
}
private void OpenSelection_Click(object sender, MouseButtonEventArgs e)
Expand Down
7 changes: 4 additions & 3 deletions gamevault/UserControls/LibraryUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@
<Grid Visibility="{Binding FilterVisibility}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<local:PillSelector x:Name="uiFilterGameTypeSelector" SelectionType="GameType" Margin="12,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterPillSelector" SelectionType="Tags" Margin="0,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterGenreSelector" SelectionType="Genres" Margin="0,0,23,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterTagSelector" SelectionType="Tags" Margin="0,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterGenreSelector" SelectionType="Genres" Margin="0,0,24,0" Width="175" EntriesUpdated="FilterUpdated"/>
<local:PillSelector x:Name="uiFilterGameStateSelector" SelectionType="GameState" Margin="0,0,23,0" Width="175" EntriesUpdated="FilterUpdated"/>
<StackPanel Margin="0,0,97,0">
<TextBlock Text="Release Year" FontSize="15"/>
<local:DateRangeSelector x:Name="uiFilterReleaseDateRangeSelector" EntriesUpdated="FilterUpdated"/>
Expand Down Expand Up @@ -158,7 +159,7 @@
</StackPanel>
<StackPanel>
<TextBlock Text="Bookmarks" FontSize="15"/>
<ToggleButton x:Name="uiFilterBookmarks" Cursor="Hand" Margin="3,3,0,0" HorizontalAlignment="Left" Click="FilterUpdated">
<ToggleButton x:Name="uiFilterBookmarks" Cursor="Hand" Margin="0,3,0,0" HorizontalAlignment="Left" Click="FilterUpdated">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Style.Setters>
Expand Down
15 changes: 11 additions & 4 deletions gamevault/UserControls/LibraryUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ public void ClearAllFilters()
{
uiFilterGameTypeSelector.ClearEntries();
uiFilterGenreSelector.ClearEntries();
uiFilterPillSelector.ClearEntries();
uiFilterTagSelector.ClearEntries();
uiFilterGameStateSelector.ClearEntries();
uiFilterReleaseDateRangeSelector.ClearSelection();

uiFilterBookmarks.IsChecked = false;
Expand Down Expand Up @@ -300,14 +301,19 @@ private string ApplyFilter(string filter)
{
filter += $"&filter.metadata.genres.name=$in:{genres}";
}
string tags = uiFilterPillSelector.GetSelectedEntries();
string tags = uiFilterTagSelector.GetSelectedEntries();
if (tags != string.Empty)
{
filter += $"&filter.metadata.tags.name=$in:{tags}";
}
string gameStates = uiFilterGameStateSelector.GetSelectedEntries();
if (gameStates != string.Empty)
{
filter += $"&filter.progresses.state=$in:{gameStates}&filter.progresses.user.id=$eq:{LoginManager.Instance.GetCurrentUser()?.ID}";
}
if (uiFilterBookmarks.IsChecked == true)
{
filter += $"&filter.bookmarked_users.id=$eq:{LoginManager.Instance.GetCurrentUser().ID}";
filter += $"&filter.bookmarked_users.id=$eq:{LoginManager.Instance.GetCurrentUser()?.ID}";
}
return filter;
}
Expand Down Expand Up @@ -439,7 +445,8 @@ private void RefreshFilterCounter()
int filterCount = 0;
filterCount += uiFilterGameTypeSelector.HasEntries() ? 1 : 0;
filterCount += uiFilterGenreSelector.HasEntries() ? 1 : 0;
filterCount += uiFilterPillSelector.HasEntries() ? 1 : 0;
filterCount += uiFilterTagSelector.HasEntries() ? 1 : 0;
filterCount += uiFilterGameStateSelector.HasEntries() ? 1 : 0;
filterCount += (bool)uiFilterEarlyAccess.IsChecked ? 1 : 0;
filterCount += (bool)uiFilterBookmarks.IsChecked ? 1 : 0;

Expand Down
2 changes: 1 addition & 1 deletion gamevault/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:uc="clr-namespace:gamevault.UserControls"
xmlns:conv="clr-namespace:gamevault.Converter"
mc:Ignorable="d"
Title="GameVault"
Title="GameVault" TitleForeground="Transparent"
WindowTitleBrush="Transparent" NonActiveWindowTitleBrush="Transparent"
Height="450" Width="800" WindowStartupLocation="CenterScreen" WindowState="Maximized" MinWidth="600" MinHeight="345" Loaded="MetroWindow_Loaded" Closing="MetroWindow_Closing">
<mah:MetroWindow.TaskbarItemInfo>
Expand Down

0 comments on commit 193f106

Please sign in to comment.