Skip to content

Commit

Permalink
FavoriteStar fixed, visual fixes, settings added for gamepath
Browse files Browse the repository at this point in the history
  • Loading branch information
netquick committed Jul 17, 2024
1 parent c43076b commit 171642d
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 75 deletions.
2 changes: 2 additions & 0 deletions DeFRaG_Helper/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<!-- Correctly reference the BoolToVisibilityConverter within the local XML namespace -->
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<converters:BoolToAlignmentConverter x:Key="BoolToAlignmentConverter"/>
<converters:IntToBoolConverter x:Key="IntToBoolConverter"/>

<!-- Update this line -->
<converters:IntToInverseBooleanConverter x:Key="IntToInverseBooleanConverter"/>
<converters:PhysicsModeConverter x:Key="PhysicsModeConverter"/>
Expand Down
44 changes: 35 additions & 9 deletions DeFRaG_Helper/Converters/BoolToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

Expand All @@ -13,15 +9,45 @@ public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// Assuming the value is a boolean and targetType is Visibility
bool isVisible = (bool)value;
bool isVisible;

if (value is int intValue)
{
isVisible = intValue != 0; // Treat non-zero integers as true
}
else if (value is bool boolValue)
{
isVisible = boolValue;
}
else
{
throw new InvalidOperationException("Unsupported type");
}

bool invert = parameter != null && bool.Parse((string)parameter);

if (invert) isVisible = !isVisible;

return isVisible ? Visibility.Visible : Visibility.Collapsed;
}


public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// ConvertBack is not necessary for this use case
throw new NotImplementedException();
if (value is bool boolValue)
{
// Convert boolean back to integer (0 or 1) for SQLite storage.
return boolValue ? 1 : 0;
}
else
{
throw new ArgumentException("Expected value to be of type Boolean", nameof(value));
}
}




}

}
21 changes: 21 additions & 0 deletions DeFRaG_Helper/Converters/IntToBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace DeFRaG_Helper.Converters
{
public class IntToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// Assuming 1 represents true/favorite, and 0 (or null) represents false/not favorite
return value is int intValue && intValue == 1;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// Convert back to integer representation for the database
return value is bool boolValue && boolValue ? 1 : 0;
}
}
}
71 changes: 63 additions & 8 deletions DeFRaG_Helper/CustomStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -817,16 +817,48 @@
</Setter>
</Style>


<Style x:Key="FavoriteButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FilledStar">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FilledStar">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path x:Name="OutlineStar" Data="M 10,1 L 12,7 L 18,7 L 13,11 L 15,17 L 10,13 L 5,17 L 7,11 L 2,7 L 8,7 Z" Stroke="Black" Fill="Transparent"/>
<Path x:Name="FilledStar" Data="M 10,1 L 12,7 L 18,7 L 13,11 L 15,17 L 10,13 L 5,17 L 7,11 L 2,7 L 8,7 Z" Fill="Gold" Visibility="Collapsed"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>





<!-- FavoriteIcon Checkbox-->
<Style x:Key="FavoriteCheckBoxStyle" TargetType="CheckBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<Grid>
<Grid.LayoutTransform>
<!-- Adjust the ScaleX and ScaleY values to scale the star size -->
<ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
</Grid.LayoutTransform>
<Grid >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
Expand Down Expand Up @@ -855,15 +887,38 @@
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path x:Name="OutlineStar" Data="M 10,1 L 12,7 L 18,7 L 13,11 L 15,17 L 10,13 L 5,17 L 7,11 L 2,7 L 8,7 Z" Stroke="Black" Fill="Transparent"/>
<Path x:Name="FilledStar" Data="M 10,1 L 12,7 L 18,7 L 13,11 L 15,17 L 10,13 L 5,17 L 7,11 L 2,7 L 8,7 Z" Fill="Gold" Visibility="Collapsed"/>
<!-- Padding sets the star Size-->

<Border Background="Transparent" Padding="12">

<Viewbox HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid>
<Grid.LayoutTransform>
<!-- Adjust the ScaleX and ScaleY values to scale the star size -->
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
</Grid.LayoutTransform>
<Path x:Name="OutlineStar"
Data="M 10,1 L 12,7 L 18,7 L 13,11 L 15,17 L 10,13 L 5,17 L 7,11 L 2,7 L 8,7 Z"
Stroke="Black"
Fill="Transparent"/>
<Path x:Name="FilledStar"
Data="M 10,1 L 12,7 L 18,7 L 13,11 L 15,17 L 10,13 L 5,17 L 7,11 L 2,7 L 8,7 Z"
Fill="Gold"
Visibility="Collapsed"/>
</Grid>
</Viewbox>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="FilledStar" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>


<!-- Modern ProgressBar Style -->
<Style TargetType="ProgressBar">
<Setter Property="Foreground" Value="{DynamicResource ThemeColor}"/>
Expand Down
8 changes: 7 additions & 1 deletion DeFRaG_Helper/Helpers/CreateAndUpdateDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,15 @@ private async static Task GetMapDetails(MapData tempMap, int mapCount)
//update the map in the database with method UpdateOrAddMap in MapViewModel
var mapViewModel = await MapViewModel.GetInstanceAsync();

await mapViewModel.UpdateOrAddMap(map);
if (map.Name == null || map.Name == "")
{
map.Name = Path.GetFileNameWithoutExtension(tempMap.Name);
}

//Update or add map to the database
await mapViewModel.UpdateOrAddMap(map);

//set the map as parsed
await SetMapParsed(tempMap);


Expand Down
6 changes: 4 additions & 2 deletions DeFRaG_Helper/UserControls/DropDownButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ private async void PlayRandomMap()
{
// Assuming chkPhysics is accessible or you have a method in MainWindow to get its value
int physicsSetting = mainWindow.GetPhysicsSetting(); // method in MainWindow
//from the physics setting, we need to get maps with the same physics setting or 0 or 3 to find a random map
//from the physics setting, we need to get maps with the same physics setting or 0 or 3 to find a random map

var matchingMaps = viewModel.Maps.Where(m => m.Physics == physicsSetting || m.Physics == 0 || m.Physics == 3).ToList();
var matchingMaps = viewModel.Maps
.Where(m => (m.Physics == physicsSetting || m.Physics == 0 || m.Physics == 3) && m.GameType == "Defrag")
.ToList();

if (matchingMaps.Any())
{
Expand Down
20 changes: 13 additions & 7 deletions DeFRaG_Helper/UserControls/HighLightCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DeFRaG_Helper"
xmlns:local="clr-namespace:DeFRaG_Helper.UserControls"
xmlns:converters="clr-namespace:DeFRaG_Helper.Converters"

mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="200">
<UserControl.Resources>
<converters:SvgPathAndColorConverter x:Key="SvgPathAndColorConverter"/>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<converters:IntToBoolConverter x:Key="IntToBoolConverter"/>

</UserControl.Resources>
<Border Margin="10" CornerRadius="10" Background="#2d2d2d" MouseLeftButtonDown="Border_MouseLeftButtonDown">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -15,7 +22,7 @@
</Grid.RowDefinitions>
<Grid Grid.Row="0" Height="140" MaxWidth="200">
<Image Margin="10,10,10,0" Source="{Binding ImagePath}" MaxWidth="160"/>
<TextBlock Text="{Binding Name}" FontSize="20" Foreground="White" Margin="20,10,20,0" Height="96" VerticalAlignment="Top" TextWrapping="Wrap" MaxWidth="160"/>
<TextBlock Text="{Binding Name}" FontSize="20" Foreground="White" Margin="20,10,20,0" Height="96" VerticalAlignment="Top" TextWrapping="Wrap" MaxWidth="160" HorizontalAlignment="Center"/>
</Grid>
<!-- Adjusted inner Border with straight upper corners and rounded bottom corners -->
<Border Grid.Row="1" Height="60" Background="#2a2a2a" CornerRadius="0,0,10,10">
Expand All @@ -33,11 +40,10 @@
<!-- Binding the Hits property -->
<TextBlock Grid.Row="2" Text="{Binding Hits}" FontSize="9" Foreground="White" HorizontalAlignment="Center"/>
<!-- Assuming there's a Favorite property -->
<CheckBox Grid.Row="3" Height="26" Content="Favorite" Margin="0, 4, 0, 0" HorizontalAlignment="Center" IsChecked="{Binding IsFavorite}" Style="{StaticResource FavoriteCheckBoxStyle}" Checked="FavoriteCheckBox_Checked" Unchecked="FavoriteCheckBox_Unchecked">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
</CheckBox.LayoutTransform>
</CheckBox>

<CheckBox Grid.Row="2" Name="chkFav" IsChecked="{Binding IsFavorite, Mode=TwoWay, Converter={StaticResource IntToBoolConverter}}"
Width="40" Height="40" Style="{StaticResource FavoriteCheckBoxStyle}" VerticalAlignment="Top" Margin="70,0,70,0"
Checked="FavoriteCheckBox_Checked" Unchecked="FavoriteCheckBox_Unchecked" Grid.RowSpan="2" />
</Grid>
</Border>
</Grid>
Expand Down
27 changes: 16 additions & 11 deletions DeFRaG_Helper/UserControls/MapCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
d:DesignHeight="100" d:DesignWidth="1000">
<UserControl.Resources>
<converters:SvgPathAndColorConverter x:Key="SvgPathAndColorConverter"/>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<converters:IntToBoolConverter x:Key="IntToBoolConverter"/>

</UserControl.Resources>
<Border CornerRadius="10" Background="#2c2c2c">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="6*"/>
<!-- Left half -->
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="4*"/>
<!-- Right half (empty in this example) -->
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
Expand All @@ -39,18 +42,18 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" x:Name="Mapname" Text="{Binding Name}" FontSize="14" Foreground="White" Margin="10, 0, 10, 0" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="1" Grid.Column="0" x:Name="Filename" Text="{Binding Filename}" FontSize="14" Foreground="White" Margin="10, 0, 0, 10" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="0" Grid.Column="1" x:Name="Author" Text="{Binding Author}" FontSize="14" Foreground="White" Margin="10, 0, 0, 0" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="1" Grid.Column="1" x:Name="Date" Text="{Binding Releasedate}" FontSize="14" Foreground="White" Margin="10, 0, 0, 10" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="0" Grid.Column="2" x:Name="Hits" Text="{Binding Hits}" FontSize="14" Foreground="White" Margin="10, 0, 0, 0" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="1" Grid.Column="2" x:Name="Size" Text="{Binding Size, Converter={StaticResource SizeFormatConverter}}" FontSize="14" Foreground="White" Margin="10, 0, 0, 10" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="0" Grid.Column="3" x:Name="Type" Text="{Binding Gametype}" FontSize="14" Foreground="White" Margin="10, 0, 0, 0" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="0" Grid.Column="3" x:Name="Type" Text="{Binding GameType}" FontSize="14" Foreground="White" Margin="10, 0, 0, 0" FontFamily="Segoe UI"/>
<TextBlock Grid.Row="1" Grid.Column="3" x:Name="Style" Text="{Binding Style}" FontSize="14" Foreground="White" Margin="10, 0, 0, 10" FontFamily="Segoe UI"/>
</Grid>

Check warning on line 58 in DeFRaG_Helper/UserControls/MapCard.xaml

View workflow job for this annotation

GitHub Actions / build-and-test

'MapCard.Style' hides inherited member 'FrameworkElement.Style'. Use the new keyword if hiding was intended.

Expand Down Expand Up @@ -131,9 +134,12 @@
</Grid>

<Image Grid.Column="1" Source="{Binding ImagePath}" MaxHeight="70" Width="120" MaxWidth="120" Margin="5" ></Image>
<CheckBox Grid.Column="2" Name="chkFav" IsChecked="{Binding IsFavorite}" Style="{StaticResource FavoriteCheckBoxStyle}" VerticalAlignment="Center" Margin="20, 0, 20, 0" Checked="FavoriteCheckBox_Checked" Unchecked="FavoriteCheckBox_Unchecked"/>
<CheckBox Grid.Column="2" Name="chkFav" IsChecked="{Binding IsFavorite, Mode=TwoWay, Converter={StaticResource IntToBoolConverter}}"
Width="60" Height="60" Style="{StaticResource FavoriteCheckBoxStyle}" VerticalAlignment="Center" Margin="0, 0, 0, 0"
Checked="FavoriteCheckBox_Checked" Unchecked="FavoriteCheckBox_Unchecked"/>


<Button Name="btnPlay" Grid.Column="3" Width="40" Margin="5, 10, 5, 10"
<Button Name="btnPlay" Grid.Column="3" Width="40" Margin="5, 10, 5, 10"
Command="{Binding ElementName=MapsList, Path=DataContext.PlayMapCommand}" CommandParameter="{Binding}">
<StackPanel Orientation="Horizontal">
<Image Width="20" Height="20" Margin="0,0,0,0" VerticalAlignment="Center">
Expand Down Expand Up @@ -173,8 +179,7 @@
</Button>
<Button Name="btnEdit" Grid.Column="5" Width="40" Margin="5, 10, 10, 10"
Command="{Binding ElementName=MapsList, Path=DataContext.DownloadMapCommand}"
CommandParameter="{Binding}"
IsEnabled="{Binding IsDownloaded, Converter={StaticResource IntToInverseBooleanConverter}}">
CommandParameter="{Binding}">
<StackPanel Orientation="Horizontal">
<Image Width="20" Height="20" Margin="0,0,0,0" VerticalAlignment="Center">
<Image.Source>
Expand Down
Loading

0 comments on commit 171642d

Please sign in to comment.