Skip to content

Commit

Permalink
Added a chart to the statistics page (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed May 8, 2021
1 parent ebda0ac commit 0135714
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 11 deletions.
28 changes: 22 additions & 6 deletions Gavilya/Pages/Statistics.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,32 @@
<TextBlock Text="{x:Static lang:Resources.StatsTimePlayed}" FontSize="16" FontWeight="Bold" Foreground="#FF64648C"/>
<TextBlock x:Name="TotalTimePlayedTxt" Text="" FontSize="48" FontWeight="Bold" d:Text="150,7h"/>
</StackPanel>

<Grid Margin="0,5,0,0" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ScrollViewer Template="{StaticResource ScrollViewerTemplate1}">
<StackPanel x:Name="GamesInfoDisplayer">
<!-- Content loaded on start -->
</StackPanel>
</ScrollViewer>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>

<Frame Grid.Row="0" Grid.Column="0" x:Name="GraphDisplayer" NavigationUIVisibility="Hidden" MinHeight="100" x:FieldModifier="public"/>

<Grid Grid.Row="1" Margin="0,15,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{x:Static lang:Resources.Top10MostPlayedGames}" FontSize="14" FontWeight="Bold" Foreground="#FF64648C"/>
<ScrollViewer Template="{StaticResource ScrollViewerTemplate1}" Grid.Row="1">
<StackPanel x:Name="GamesInfoDisplayer">
<!-- Content loaded on start -->
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
</Grid>
</Border>
Expand Down
7 changes: 6 additions & 1 deletion Gavilya/Pages/Statistics.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private void InitUI()
{
// Values
Dictionary<GameInfo, int> gameTimes = new(); // Create dictionnary
List<GameInfo> mostPlayed = new(); // Create list

for (int i = 0; i < Definitions.Games.Count; i++)
{
Expand All @@ -67,9 +68,10 @@ private void InitUI()
int c = 0; // Counter
foreach (KeyValuePair<GameInfo, int> keyValuePair in items)
{
if (c <= 10)
if (c < 10)
{
GamesInfoDisplayer.Children.Add(new StatInfoCard(keyValuePair.Key)); // Add item
mostPlayed.Add(keyValuePair.Key); // Add to the list
c++; // Increment counter
}
else
Expand All @@ -80,6 +82,9 @@ private void InitUI()

// Text
TotalTimePlayedTxt.Text = $"{Global.GetTotalTimePlayed() / 3600}{Properties.Resources.HourShort}"; // Set text

// Graph
GraphDisplayer.Content = new StatGraph(mostPlayed);
}
}
}
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 @@ -513,4 +513,7 @@
<data name="HourShort" xml:space="preserve">
<value>h</value>
</data>
<data name="Top10MostPlayedGames" xml:space="preserve">
<value>TOP 10 MOST PLAYED GAMES</value>
</data>
</root>
5 changes: 4 additions & 1 deletion Gavilya/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,12 @@
<value>Statistiques</value>
</data>
<data name="StatsTimePlayed" xml:space="preserve">
<value>TEMPS TOTAL JOUE</value>
<value>TEMPS TOTAL JOUÉ</value>
</data>
<data name="HourShort" xml:space="preserve">
<value>h</value>
</data>
<data name="Top10MostPlayedGames" xml:space="preserve">
<value>TOP 10 DES JEUX LES PLUS JOUÉS</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 @@ -523,4 +523,7 @@
<data name="HourShort" xml:space="preserve">
<value>h</value>
</data>
<data name="Top10MostPlayedGames" xml:space="preserve">
<value>TOP 10 MOST PLAYED GAMES</value>
</data>
</root>
20 changes: 20 additions & 0 deletions Gavilya/UserControls/StatGraph.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl x:Class="Gavilya.UserControls.StatGraph"
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"
mc:Ignorable="d"
FontFamily="..\Fonts\#Montserrat"
d:DesignHeight="200" d:DesignWidth="800" SizeChanged="UserControl_SizeChanged">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" Height="150" x:Name="GraphPanel" Grid.Row="0">

</StackPanel>
</Grid>
</UserControl>
85 changes: 85 additions & 0 deletions Gavilya/UserControls/StatGraph.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
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.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 StatGraph.xaml
/// </summary>
public partial class StatGraph : UserControl
{
List<GameInfo> Games { get; init; }
public StatGraph(List<GameInfo> gameInfos)
{
InitializeComponent();
Games = gameInfos; // Set

InitUI(); // Load the UI
}

private void InitUI()
{
GraphPanel.Children.Clear(); // Clear
int longestPlayed = Games[0].TotalTimePlayed;

for (int i = 0; i < Games.Count; i++)
{
double h = Games[i].TotalTimePlayed * GraphPanel.Height / longestPlayed;

Rectangle rectangle = new()
{
Margin = new(10, 0, 10, 0),
Fill = new SolidColorBrush { Color = Color.FromRgb(50, 50, 90) },
Height = h,
Width = 50,
RadiusX = 5,
RadiusY = 5,
VerticalAlignment = VerticalAlignment.Bottom
};

GraphPanel.Children.Add(rectangle); // Add bar
}
}

private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
InitUI();
}
}
}
4 changes: 2 additions & 2 deletions Gavilya/UserControls/StatInfoCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" x:Name="GameNameTxt" d:Text="GameNameHere" VerticalAlignment="Center" FontWeight="Bold" FontSize="16"/>
<TextBlock Grid.Column="1" x:Name="GameTimeTxt" d:Text="72,4h" VerticalAlignment="Center" FontWeight="Bold" FontSize="16"/>
<TextBlock Grid.Column="0" x:Name="GameNameTxt" d:Text="GameNameHere" VerticalAlignment="Center" FontWeight="Bold" FontSize="16" Margin="0,0,50,0"/>
<TextBlock Grid.Column="1" x:Name="GameTimeTxt" d:Text="72,4h" VerticalAlignment="Center" FontWeight="Bold" FontSize="16" Margin="0,0,5,0"/>
</Grid>
</Border>
</UserControl>
2 changes: 1 addition & 1 deletion Gavilya/UserControls/StatInfoCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void InitUI()

// Text
GameNameTxt.Text = GameInfo.Name; // Set text
GameTimeTxt.Text = $"{time}{Properties.Resources.HourShort}"; // Set text
GameTimeTxt.Text = $"{string.Format("{0:0.#}", time)}{Properties.Resources.HourShort}"; // Set text
}
}
}

0 comments on commit 0135714

Please sign in to comment.