Skip to content

Commit

Permalink
Added the possibility to select a game stat card (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed May 9, 2021
1 parent 2812261 commit 2ffb9e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Gavilya/Pages/Statistics.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,23 @@ private void InitUI()
// Graph
GraphDisplayer.Content = new StatGraph(mostPlayed);
}

internal void UnCheckAllStatItems()
{
try
{
for (int i = 0; i < GamesInfoDisplayer.Children.Count; i++)
{
if (GamesInfoDisplayer.Children[i] is StatInfoCard)
{
((StatInfoCard)GamesInfoDisplayer.Children[i]).UnCheck(); // Uncheck
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
2 changes: 1 addition & 1 deletion Gavilya/UserControls/StatInfoCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
FontFamily="..\Fonts\#Montserrat"
mc:Ignorable="d" Foreground="#FFF"
Height="50" d:DesignWidth="400">
<Border CornerRadius="5" Cursor="Hand">
<Border x:Name="ItemBorder" CornerRadius="5" Cursor="Hand" MouseLeftButtonUp="Border_MouseLeftButtonUp" MouseEnter="ItemBorder_MouseEnter" MouseLeave="ItemBorder_MouseLeave">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down
37 changes: 37 additions & 0 deletions Gavilya/UserControls/StatInfoCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Gavilya.UserControls
public partial class StatInfoCard : UserControl
{
GameInfo GameInfo { get; init; }
internal bool isChecked = false;
public StatInfoCard(GameInfo gameInfo, int pos)
{
InitializeComponent();
Expand All @@ -62,6 +63,42 @@ private void InitUI(int pos)
GamePosTxt.Text = $"#{pos}"; // Set text
GameNameTxt.Text = GameInfo.Name; // Set text
GameTimeTxt.Text = $"{string.Format("{0:0.#}", time)}{Properties.Resources.HourShort}"; // Set text

isChecked = (pos == 1) ? true : false; // Set
if (isChecked)
{
ItemBorder.Background = new SolidColorBrush { Color = Color.FromRgb(60, 60, 80) }; // Set background color
}
}

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;
}

private void ItemBorder_MouseEnter(object sender, MouseEventArgs e)
{
ItemBorder.Background = new SolidColorBrush { Color = Color.FromRgb(40, 40, 60) }; // Set background color
}

private void ItemBorder_MouseLeave(object sender, MouseEventArgs e)
{
if (!isChecked)
{
ItemBorder.Background = new SolidColorBrush { Color = Colors.Transparent }; // Set background color
}
else
{
ItemBorder.Background = new SolidColorBrush { Color = Color.FromRgb(60, 60, 80) }; // Set background color
}
}

internal void UnCheck()
{
isChecked = false;
ItemBorder.Background = new SolidColorBrush { Color = Colors.Transparent }; // Set background color
}
}
}

0 comments on commit 2ffb9e7

Please sign in to comment.