Skip to content

Commit

Permalink
Added a card recapitulating a game informations (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed May 9, 2021
1 parent 2ffb9e7 commit bc789eb
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gavilya/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected override void OnStartup(StartupEventArgs e)

ProfileManager.LoadProfiles(); // Load profiles
new GameSaver().Load(); // Load the .gav file in the Definitions class

Definitions.StatGameInfoControl = new(); // New control
Definitions.Statistics = new(); // New page

if (Definitions.Settings.IsFirstRun) // If it is the app first run
Expand Down
6 changes: 6 additions & 0 deletions Gavilya/Classes/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using Gavilya.Pages;
using Gavilya.UserControls;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -67,6 +68,11 @@ public static LinearGradientBrush HomeButtonBackColor
}
}

/// <summary>
/// The <see cref="UserControls.StatGameInfoControl"/> control.
/// </summary>
internal static StatGameInfoControl StatGameInfoControl { get; set; }

/// <summary>
/// The default platform of a game.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Gavilya/Pages/Statistics.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
</StackPanel>
</ScrollViewer>
</Grid>

<Frame x:Name="GameInfoDisplayer" Grid.Column="1" Grid.RowSpan="2"/>

</Grid>
</Grid>
</Border>
Expand Down
6 changes: 6 additions & 0 deletions Gavilya/Pages/Statistics.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ namespace Gavilya.Pages
/// </summary>
public partial class Statistics : Page
{

public Statistics()
{
InitializeComponent();


InitUI();
}

Expand Down Expand Up @@ -85,6 +88,9 @@ private void InitUI()

// Graph
GraphDisplayer.Content = new StatGraph(mostPlayed);

// Controls
GameInfoDisplayer.Content = Definitions.StatGameInfoControl; // Set content
}

internal void UnCheckAllStatItems()
Expand Down
9 changes: 9 additions & 0 deletions Gavilya/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Gavilya/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,7 @@
<data name="Top10MostPlayedGames" xml:space="preserve">
<value>TOP 10 MOST PLAYED GAMES</value>
</data>
<data name="StatsLastTimePlayed" xml:space="preserve">
<value>LAST USAGE</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Gavilya/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,7 @@
<data name="Top10MostPlayedGames" xml:space="preserve">
<value>TOP 10 DES JEUX LES PLUS JOUÉS</value>
</data>
<data name="StatsLastTimePlayed" xml:space="preserve">
<value>DERNIÈRE UTILISATION</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Gavilya/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,7 @@
<data name="Top10MostPlayedGames" xml:space="preserve">
<value>TOP 10 MOST PLAYED GAMES</value>
</data>
<data name="StatsLastTimePlayed" xml:space="preserve">
<value>LAST USAGE</value>
</data>
</root>
67 changes: 67 additions & 0 deletions Gavilya/UserControls/StatGameInfoControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<UserControl x:Class="Gavilya.UserControls.StatGameInfoControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:Gavilya.UserControls"
xmlns:lang="clr-namespace:Gavilya.Properties"
mc:Ignorable="d" Foreground="#fff"
FontFamily="..\Fonts\#Montserrat"
d:DesignHeight="500" >
<ScrollViewer Template="{DynamicResource ScrollViewerTemplate1}" HorizontalScrollBarVisibility="Hidden">
<Grid x:Name="ContentGrid" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<Border Grid.Row="0" Margin="10" CornerRadius="10">
<Border.Background>
<ImageBrush x:Name="BackgroundImage" Stretch="UniformToFill" Opacity="0.9"></ImageBrush>
</Border.Background>

<Grid Height="100">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0A0A1E" Offset="1"/>
<GradientStop Color="#00000000" Offset="0"/>
</LinearGradientBrush>
</Grid.Background>
<TextBlock x:Name="GameNameTxt" Grid.Row="0" d:Text="GameName" Margin="5" FontSize="24" FontWeight="Bold" TextAlignment="Left" VerticalAlignment="Bottom"/>
</Grid>
</Border>

<Border Grid.Row="1" CornerRadius="10" Background="#FF28283C" Margin="10" Padding="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Static lang:Resources.StatsTimePlayed}" FontSize="14" FontWeight="Bold" Foreground="#FF64648C"/>
<TextBlock Text="{x:Static lang:Resources.StatsLastTimePlayed}" FontSize="14" FontWeight="Bold" Foreground="#FF64648C" Grid.Column="1"/>

<TextBlock x:Name="TotalTimePlayedTxt" d:Text="74,5h" Margin="0,10,10,10" FontSize="22" FontWeight="Bold" TextAlignment="Left" Grid.Column="0" Grid.Row="1"/>
<TextBlock x:Name="LastTimePlayedTxt" d:Text="10 December 2021" Margin="0,10,10,10" FontSize="22" FontWeight="Bold" TextAlignment="Left" Grid.Column="1" Grid.Row="1"/>
</Grid>
</Border>

<StackPanel Grid.Row="2" Orientation="Vertical">
<TextBlock Text="{x:Static lang:Resources.Description}" FontSize="18" FontWeight="Bold"/>
<TextBlock x:Name="DescriptionTxt" d:Text="{x:Static lang:Resources.Description}" FontSize="14" FontWeight="Normal" Margin="0,3,0,0" TextWrapping="Wrap"/>
</StackPanel>
</Grid>

</Grid>
</ScrollViewer>
</UserControl>
94 changes: 94 additions & 0 deletions Gavilya/UserControls/StatGameInfoControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using Gavilya.Classes;
using System;
using System.Collections.Generic;
using System.IO;
using System.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;

namespace Gavilya.UserControls
{
/// <summary>
/// Interaction logic for StatGameInfoControl.xaml
/// </summary>
public partial class StatGameInfoControl : UserControl
{
public StatGameInfoControl()
{
InitializeComponent();
}

internal void InitUI(GameInfo gameInfo)
{
// Text
GameNameTxt.Text = gameInfo.Name; // Set text
DescriptionTxt.Text = gameInfo.Description; // Set text

double timePlayed = (double)gameInfo.TotalTimePlayed / 3600;
TotalTimePlayedTxt.Text = $"{string.Format("{0:0.#}", timePlayed)}{Properties.Resources.HourShort}";

if (gameInfo.LastTimePlayed != 0) // If the game was played
{
DateTime LastTimePlayed = Global.UnixTimeToDateTime(gameInfo.LastTimePlayed); // Get the date time
LastTimePlayedTxt.Text = $"{LastTimePlayed.Day} {Global.NumberToMonth(LastTimePlayed.Month)} {LastTimePlayed.Year}"; // Last time played
}
else
{
LastTimePlayedTxt.Text = Properties.Resources.Never; // Set the text
}

// Icon
if (gameInfo.IconFileLocation != string.Empty) // If a custom image is used
{
var bitmap = new BitmapImage();
var stream = File.OpenRead(gameInfo.IconFileLocation);

bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
bitmap.EndInit();
stream.Close();
stream.Dispose();
bitmap.Freeze();
BackgroundImage.ImageSource = bitmap;
}
else
{
System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(gameInfo.FileLocation);
BackgroundImage.ImageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); // Show the image
}
}
}
}
2 changes: 2 additions & 0 deletions Gavilya/UserControls/StatInfoCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private void InitUI(int pos)
if (isChecked)
{
ItemBorder.Background = new SolidColorBrush { Color = Color.FromRgb(60, 60, 80) }; // Set background color
Definitions.StatGameInfoControl.InitUI(GameInfo); // Load UI
}
}

Expand All @@ -76,6 +77,7 @@ private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
Definitions.Statistics.UnCheckAllStatItems(); // Clear
ItemBorder.Background = new SolidColorBrush { Color = Color.FromRgb(60, 60, 80) }; // Set background color
isChecked = true;
Definitions.StatGameInfoControl.InitUI(GameInfo); // Load UI
}

private void ItemBorder_MouseEnter(object sender, MouseEventArgs e)
Expand Down

0 comments on commit bc789eb

Please sign in to comment.