Skip to content

Commit

Permalink
QOL improvements and fixes
Browse files Browse the repository at this point in the history
- Fixes bug where data-based logs were done even if logging is disabled.
- Adds the ability to see medal details when tapped on one of them in the medal view.
- Adds a query that can find all matches based on medal ID.
- Rudimentary support for matches browsing from medal view
  • Loading branch information
dend committed Feb 28, 2024
1 parent e2dd7c9 commit 577a31d
Show file tree
Hide file tree
Showing 18 changed files with 788 additions and 263 deletions.
200 changes: 200 additions & 0 deletions src/OpenSpartan.Workshop/Controls/MatchesGridControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="OpenSpartan.Workshop.Controls.MatchesGridControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:OpenSpartan.Workshop.Controls"
xmlns:models="using:OpenSpartan.Workshop.Models"
xmlns:converters="using:OpenSpartan.Workshop.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:shared="using:OpenSpartan.Workshop.Shared"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="MatchesGridControlEntity"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<UserControl.Resources>
<converters:MetadataLoadingStateToVisibilityConverter x:Key="MetadataLoadingStateToVisibilityConverter"></converters:MetadataLoadingStateToVisibilityConverter>
<converters:OutcomeToBackgroundConverter x:Key="OutcomeToBackgroundConverter"></converters:OutcomeToBackgroundConverter>
<converters:OutcomeToForegroundConverter x:Key="OutcomeToForegroundConverter"></converters:OutcomeToForegroundConverter>
<converters:PerformanceToGlyphConverter x:Key="PerformanceToGlyphConverter"></converters:PerformanceToGlyphConverter>
<converters:PerformanceToColorConverter x:Key="PerformanceToColorConverter"></converters:PerformanceToColorConverter>
</UserControl.Resources>

<Grid>
<controls:DataGrid IsReadOnly="True"
RowDetailsVisibilityMode="Collapsed"
CanUserReorderColumns="False"
CanUserSortColumns="True"
x:Name="dgdMatches"
AutoGenerateColumns="False"
ItemsSource="{Binding MatchSource, ElementName=MatchesGridControlEntity}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Disabled"
PointerReleased="dgdMatches_PointerReleased">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="Start Time" Width="*" Binding="{Binding StartTime}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Match ID" Width="*" Binding="{Binding MatchId}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Outcome" Width="120" Binding="{Binding Outcome}">
<controls:DataGridTextColumn.CellStyle>
<Style TargetType="controls:DataGridCell">
<Setter Property="shared:BindingHelper.CellForegroundBindingPath" Value="Outcome" />
<Setter Property="shared:BindingHelper.CellBackgroundBindingPath" Value="Outcome" />
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
</controls:DataGridTextColumn.CellStyle>
</controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Team MMR" Width="*" Binding="{Binding TeamMmr}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Duration" Width="*" Binding="{Binding Duration}"></controls:DataGridTextColumn>
<controls:DataGridTemplateColumn Header="Kills" Width="*">
<controls:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:DataType="models:MatchTableEntity">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="12,0,0,0" Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Kills}"></TextBlock>
<FontIcon FontWeight="Bold" Grid.Column="1" VerticalAlignment="Center" Margin="4" Glyph="{Binding KillPerformance, Converter={StaticResource PerformanceToGlyphConverter}}" Foreground="{Binding KillPerformance, Converter={StaticResource PerformanceToColorConverter}}"/>
</Grid>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTextColumn Header="Expected Kills" Width="*" Binding="{Binding ExpectedKills}"></controls:DataGridTextColumn>
<controls:DataGridTemplateColumn Header="Deaths" Width="*">
<controls:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:DataType="models:MatchTableEntity">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="12,0,0,0" Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Deaths}"></TextBlock>
<FontIcon FontWeight="Bold" Grid.Column="1" VerticalAlignment="Center" Margin="4" Glyph="{Binding DeathPerformance, Converter={StaticResource PerformanceToGlyphConverter}}" Foreground="{Binding DeathPerformance, Converter={StaticResource PerformanceToColorConverter}}"/>
</Grid>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTextColumn Header="Expected Deaths" Width="*" Binding="{Binding ExpectedDeaths}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Rank" Width="*" Binding="{Binding Rank}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Category" Width="*" Binding="{Binding Category}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Map" Width="*" Binding="{Binding Map}"></controls:DataGridTextColumn>
<controls:DataGridTextColumn Header="Playlist" Width="*" Binding="{Binding Playlist}"></controls:DataGridTextColumn>
</controls:DataGrid.Columns>
<controls:DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Height="600" Margin="24,12" Padding="5" Spacing="3" Orientation="Horizontal">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="0">
<TextBlock FontWeight="Bold" Text="Match ID"/>
<TextBlock FontWeight="Bold" Text="Outcome"/>
<TextBlock FontWeight="Bold" Text="Map" />
<TextBlock FontWeight="Bold" Text="Playlist" />
<TextBlock FontWeight="Bold" Text="Joined in-progress" />
<TextBlock FontWeight="Bold" Text="Left in-progress" />
<TextBlock FontWeight="Bold" Text="Present at start" />
<TextBlock FontWeight="Bold" Text="Present at end" />
<TextBlock FontWeight="Bold" Text="Time played" />
<TextBlock FontWeight="Bold" Text="Last team ID" />
</StackPanel>

<StackPanel Grid.Column="1">
<TextBlock Text="{Binding MatchId}"/>
<TextBlock Text="{Binding Outcome}"/>
<TextBlock Text="{Binding Map}" />
<TextBlock Text="{Binding Playlist}" />
<TextBlock Text="{Binding ParticipationInfo.JoinedInProgress}"></TextBlock>
<TextBlock Text="{Binding ParticipationInfo.LeftInProgress}"></TextBlock>
<TextBlock Text="{Binding ParticipationInfo.PresentAtBeginning}"></TextBlock>
<TextBlock Text="{Binding ParticipationInfo.PresentAtCompletion}"></TextBlock>
<TextBlock Text="{Binding ParticipationInfo.TimePlayed}"></TextBlock>
<TextBlock Text="{Binding LastTeamId}"></TextBlock>
</StackPanel>
</Grid>

<Grid Margin="48,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="0">
<TextBlock FontWeight="Bold" Text="Accuracy"/>
<TextBlock FontWeight="Bold" Text="Assists"/>
<TextBlock FontWeight="Bold" Text="Average life"/>
<TextBlock FontWeight="Bold" Text="Betrayals"/>
<TextBlock FontWeight="Bold" Text="Callout assists"/>
<TextBlock FontWeight="Bold" Text="Damage dealt"/>
<TextBlock FontWeight="Bold" Text="Damage taken"/>
<TextBlock FontWeight="Bold" Text="Driver assists"/>
<TextBlock FontWeight="Bold" Text="EMP assists"/>
<TextBlock FontWeight="Bold" Text="Grenade kills"/>
<TextBlock FontWeight="Bold" Text="Headshot kills"/>
<TextBlock FontWeight="Bold" Text="Hijacks"/>
<TextBlock FontWeight="Bold" Text="KDA"/>
<TextBlock FontWeight="Bold" Text="Kills"/>
<TextBlock FontWeight="Bold" Text="Deaths"/>
<TextBlock FontWeight="Bold" Text="Max killing spree"/>
<TextBlock FontWeight="Bold" Text="Medals"/>
<TextBlock FontWeight="Bold" Text="Melee kills"/>
<TextBlock FontWeight="Bold" Text="Objectives done"/>
<TextBlock FontWeight="Bold" Text="Personal score"/>
<TextBlock FontWeight="Bold" Text="Power weapon kills"/>
<TextBlock FontWeight="Bold" Text="Rounds lost"/>
<TextBlock FontWeight="Bold" Text="Rounds tied"/>
<TextBlock FontWeight="Bold" Text="Rounds won"/>
<TextBlock FontWeight="Bold" Text="Score"/>
<TextBlock FontWeight="Bold" Text="Shots fired" />
<TextBlock FontWeight="Bold" Text="Shots hit" />
<TextBlock FontWeight="Bold" Text="Spawns" />
<TextBlock FontWeight="Bold" Text="Suicides" />
<TextBlock FontWeight="Bold" Text="Vehicle destroys" />
</StackPanel>

<StackPanel Grid.Column="1">
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Accuracy}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Assists}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.AverageLifeDuration}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Betrayals}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.CalloutAssists}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.DamageDealt}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.DamageTaken}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.DriverAssists}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.EmpAssists}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.GrenadeKills}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.HeadshotKills}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Hijacks}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.KDA}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Kills}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Deaths}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.MaxKillingSpree}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Medals.Count}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.MeleeKills}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.ObjectivesCompleted}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.PersonalScore}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.PowerWeaponKills}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.RoundsLost}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.RoundsTied}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.RoundsWon}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Score}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.ShotsFired}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.ShotsHit}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Spawns}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.Suicides}"/>
<TextBlock Text="{Binding PlayerTeamStats[0].Stats.CoreStats.VehicleDestroys}"/>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</controls:DataGrid.RowDetailsTemplate>
</controls:DataGrid>
</Grid>
</UserControl>
64 changes: 64 additions & 0 deletions src/OpenSpartan.Workshop/Controls/MatchesGridControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using CommunityToolkit.WinUI.UI.Controls;
using System.Collections;

namespace OpenSpartan.Workshop.Controls
{
public sealed partial class MatchesGridControl : UserControl
{
public static readonly DependencyProperty MatchSourceProperty =
DependencyProperty.Register(
"MatchSource", // Name of the property
typeof(IEnumerable), // Type of the property
typeof(MatchesGridControl), // Type of the owner (your user control)
new PropertyMetadata(null) // Optional metadata, e.g., default value
);

public IEnumerable MatchSource
{
get { return (IEnumerable)GetValue(MatchSourceProperty); }
set { SetValue(MatchSourceProperty, value); }
}

public MatchesGridControl()
{
this.InitializeComponent();
}

private void dgdMatches_PointerReleased(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
DataGridRow row = FindParent<DataGridRow>((UIElement)e.OriginalSource);

if (row != null)
{
if (row.DetailsVisibility == Visibility.Visible)
{
row.DetailsVisibility = Visibility.Collapsed;
}
else
{
row.DetailsVisibility = Visibility.Visible;
}
}
}

public static T FindParent<T>(DependencyObject childElement) where T : Control
{
DependencyObject currentElement = childElement;

while (currentElement != null)
{
if (currentElement is T matchingElement)
{
return matchingElement;
}

currentElement = VisualTreeHelper.GetParent(currentElement);
}

return null;
}
}
}
Loading

0 comments on commit 577a31d

Please sign in to comment.