Skip to content

Commit

Permalink
recap window
Browse files Browse the repository at this point in the history
  • Loading branch information
poma committed Apr 2, 2016
1 parent 9db8908 commit b5b49ef
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 34 deletions.
10 changes: 7 additions & 3 deletions StatsDisplay/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ internal async void ProcessRejoinFile(string path)

}

internal void ProcessReplayFile(string path)
internal async void ProcessReplayFile(string path)
{
FileProcessor.ProcessReplayFile(path, Game);
await FileProcessor.ProcessReplayFile(path, Game);
_currentWindow?.Close();
_currentWindow = new RecapStatsWindow();
if (Settings.AutoShow)
_currentWindow.Show();
}

private async void CheckForUpdates()
Expand All @@ -145,7 +149,7 @@ private async void CheckForUpdates()
}

/// <summary>
/// Curry function to allow execution of an action on the main thread using the synchronizatio context
/// Curry function to allow execution of an action on the main thread using the synchronization context
/// </summary>
/// <param name="action"></param>
private void RunOnMainThread(Action action)
Expand Down
3 changes: 2 additions & 1 deletion StatsDisplay/Settings/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
</TextBlock>
<StackPanel Orientation="Horizontal" Margin="0, 8, 0, 0" Visibility="{Binding IsTestButtonVisible, Converter={StaticResource booleanToVisibilityConverter}}">
<Button Content="Test 1" Command="{Binding Test1}" Padding="8, 0" Margin="0, 0, 8, 0" />
<Button Content="Test 2" Command="{Binding Test2}" Padding="8, 0" />
<Button Content="Test 2" Command="{Binding Test2}" Padding="8, 0" Margin="0, 0, 8, 0" />
<Button Content="Test 3" Command="{Binding Test3}" Padding="8, 0" />
</StackPanel>
</StackPanel>
</Grid>
Expand Down
9 changes: 8 additions & 1 deletion StatsDisplay/Settings/SettingsVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SettingsVm : ViewModelBase
public ICommand NavigateToHotsLogs { get; set; }
public ICommand Test1 { get; set; }
public ICommand Test2 { get; set; }
public ICommand Test3 { get; set; }

public string Title { get; private set; }
public string LogHotsUri => "http://www.hotslogs.com/Default?utm_source=HotsStats&amp;utm_medium=link";
Expand Down Expand Up @@ -68,6 +69,7 @@ public SettingsVm()
NavigateToHotsLogs = new RelayCommand(() => OnNavigate(LogHotsUri));
Test1 = new RelayCommand(() => OnTest1());
Test2 = new RelayCommand(() => OnTest2());
Test3 = new RelayCommand(() => OnTest3());
}

private void OnNavigate(string uri)
Expand All @@ -84,7 +86,12 @@ private void OnTest2()
{
(Application.Current as App).ProcessRejoinFile(@"save.StormSave");
}


private void OnTest3()
{
(Application.Current as App).ProcessReplayFile(@"replay.StormReplay");
}

public void OnActivated()
{
SetupTrayIcon();
Expand Down
24 changes: 10 additions & 14 deletions StatsDisplay/Stats/MockViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
using System.Collections.Generic;
using Heroes.ReplayParser;
using StatsFetcher;
using System.Linq;
using System.IO;
using System.Reflection;
using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace StatsDisplay.Stats
{
public class MockViewModel : ShortStatsVm
{
public MockViewModel()
{
var game = new Game {
Region = Region.EU,
GameMode = GameMode.QuickMatch,
Map = "Cursed Hollow"
};
var players = new List<PlayerProfile>();
for (int i = 0; i < 10; i++) {
var p = new PlayerProfile(game, $"Player {i}#10{i}", Region.EU) { Hero = "Raynor", HeroLevel = 4 + i, MapWinRate = 48.7f + i, HeroWinRate = 35.2f + i, HotslogsId = 123 + i, GamesCount = 200 * i, Team = i >= 5 ? 1 : 0 };
p.Ranks[GameMode.QuickMatch] = new PlayerProfile.MmrValue(GameMode.QuickMatch, 2200, null, null);
players.Add(p);
}
game.Players = players;
game.Me = players[3];
App.Game = game;
// todo: find a way to detect project dir at design time
string path = @"C:\Dev\HotsStats\StatsDisplay\bin\Debug\";
App.Game = FileProcessor.ProcessLobbyFile(path + @"replay.server.battlelobby");
FileProcessor.ProcessReplayFile(path + @"replay.StormSave", App.Game);
OnActivated();
}
}
Expand Down
85 changes: 78 additions & 7 deletions StatsDisplay/Stats/RecapStatsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,90 @@
xmlns:stats="clr-namespace:StatsDisplay.Stats"
mc:Ignorable="d"
Title="HotsStats"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DataContext="{Binding Source={StaticResource DesignViewModel}}"
Top="{Binding Settings.RecapStatsWindowTop, Mode=TwoWay}" Left="{Binding Settings.RecapStatsWindowLeft, Mode=TwoWay}">
d:DataContext="{Binding Source={d:DesignInstance Type=stats:MockViewModel, IsDesignTimeCreatable=True}}"
DataContext="{Binding RelativeSource={RelativeSource Self}}" Top="{Binding Settings.RecapStatsWindowTop, Mode=TwoWay}" Left="{Binding Settings.RecapStatsWindowLeft, Mode=TwoWay}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<stats:MockViewModel x:Key="DesignViewModel"/>
</ResourceDictionary>
</Window.Resources>
<Grid>

</Grid>
<StackPanel Margin="40, 50, 40, 40" Orientation="Horizontal">
<StackPanel Orientation="Vertical" Width="160" Style="{StaticResource TableHeaderVertical}">
<Label Content="Hero" />
<Label Content="Palyer" />
<Label Content="" />
<Label Content="Takedowns" />
<Label Content="Kills" />
<Label Content="Assists" />
<Label Content="Deaths" />
<Label Content="" />
<Label Content="Hero damage" />
<Label Content="Siege damage" />
<Label Content="Structure damage" />
<Label Content="Minion damage" />
<Label Content="Creep damage" />
<Label Content="Summon damage" />
<Label Content="" />
<Label Content="Healing" />
<Label Content="Self healing" />
<Label Content="Damage taken" />
<Label Content="" />
<Label Content="Time CCd enemy heroes" />
<Label Content="Time spent dead" />
<Label Content="" />
<Label Content="Experience contribution" />
<Label Content="Town kills" />
<Label Content="Merc camp captures" />
<Label Content="Watch Tower captures" />
</StackPanel>
<ItemsControl ItemsSource="{Binding Game.Players}" Style="{StaticResource TableHeader}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type fetcher:PlayerProfile}">
<StackPanel Orientation="Vertical" Width="120">
<!-- TargetNullValue is used to prevent lavel from collapsing when content is null -->
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<Label Content="{Binding Hero, TargetNullValue={}}" />
<Label Content="{Binding Name, TargetNullValue={}}" />
</StackPanel>
<Label Content="" />
<Label Content="{Binding Stats.Takedowns, TargetNullValue={}}" />
<Label Content="{Binding Stats.SoloKills, TargetNullValue={}}" />
<Label Content="{Binding Stats.Assists, TargetNullValue={}}" />
<Label Content="{Binding Stats.Deaths, TargetNullValue={}}" />
<Label Content="" />

<Label Content="{Binding Stats.HeroDamage, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.SiegeDamage, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.StructureDamage, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.MinionDamage, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.CreepDamage, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.SummonDamage, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="" />

<Label Content="{Binding Stats.Healing, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.SelfHealing, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.DamageTaken, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="" />

<Label Content="{Binding Stats.TimeCCdEnemyHeroes, TargetNullValue={}}" ContentStringFormat="{}{0:m\:ss}" />
<Label Content="{Binding Stats.TimeSpentDead, TargetNullValue={}}" ContentStringFormat="{}{0:m\:ss}" />
<Label Content="" />

<Label Content="{Binding Stats.ExperienceContribution, TargetNullValue={}}" ContentStringFormat="{}{0:N0}" />
<Label Content="{Binding Stats.TownKills, TargetNullValue={}}" />
<Label Content="{Binding Stats.MercCampCaptures, TargetNullValue={}}" />
<Label Content="{Binding Stats.WatchTowerCaptures, TargetNullValue={}}" />
</StackPanel>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
</StackPanel>
</stats:HeroesWindow>

2 changes: 1 addition & 1 deletion StatsDisplay/Stats/ShortStatsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xmlns:helpers="clr-namespace:StatsDisplay.Helpers"
mc:Ignorable="d"
Title="HotsStats"
d:DataContext="{Binding Source={StaticResource DesignViewModel}}"
d:DataContext="{Binding Source={d:DesignInstance Type=stats:MockViewModel, IsDesignTimeCreatable=True}}"
Top="{Binding Settings.ShortStatsWindowTop, Mode=TwoWay}" Left="{Binding Settings.ShortStatsWindowLeft, Mode=TwoWay}" d:DesignHeight="610.924">
<Window.Resources>
<ResourceDictionary>
Expand Down
4 changes: 2 additions & 2 deletions StatsDisplay/Stats/ShortStatsVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace StatsDisplay.Stats
{
public class ShortStatsVm : ViewModelBase
{
protected Game Game => App.Game;
protected Properties.Settings Settings => App.Settings;
public Game Game => App.Game;
public Properties.Settings Settings => App.Settings;
private int? _teamOneAverageMmr;
private int? _teamTwoAverageMmr;
private TeamVm _teamOne;
Expand Down
14 changes: 14 additions & 0 deletions StatsDisplay/Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
</Style.Resources>
</Style>

<Style x:Key="TableHeaderVertical">
<Style.Resources>
<Style TargetType="Label">
<Setter Property="Padding" Value="0" />
<Setter Property="FontSize" Value="12" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Foreground" Value="{StaticResource TableHeaderBrush}" />
<Setter Property="Effect" Value="{StaticResource ResourceKey=TextShadow}" />
</Style>
</Style.Resources>
</Style>

<DataTemplate DataType="{x:Type fetcher:PlayerProfile}" x:Key="RowTemplate">
<StackPanel Orientation="Horizontal">
<Border BorderThickness="3, 0, 0, 0" CornerRadius="3" Margin="0, 1, 3, 1">
Expand Down
17 changes: 12 additions & 5 deletions StatsFetcher/FileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,36 @@
using System.IO;
using Heroes.ReplayParser;
using Foole.Mpq;
using NLog;

namespace StatsFetcher
{
public static class FileProcessor
{
private static Logger _logger = LogManager.GetCurrentClassLogger();

public static Game ProcessLobbyFile(string path)
{
var game = new BattleLobbyParser(path).Parse();
FetchProfiles(game);
return game;
}

public static Game ProcessReplayFile(string path, Game game)
public static async Task ProcessReplayFile(string path, Game game)
{
var tmpPath = Path.GetTempFileName();
File.Copy(path, tmpPath);
// todo: we need a way to detect when HotS finished writing this file
// For now we will just wait 1 sec and hope it is enough
await Task.Delay(1000);
File.Copy(path, tmpPath, true);
var replay = DataParser.ParseReplay(tmpPath, true, true).Item2;

foreach (var profile in game.Players) {
var player = replay.Players.Single(p => p.Name == profile.Name);
var player = replay.Players.FirstOrDefault(p => p.Name == profile.Name);
if (player == null)
continue;
profile.Stats = player.ScoreResult;
}
return game;
}

public static async Task FetchProfiles(Game game)
Expand Down Expand Up @@ -61,7 +68,7 @@ public static async Task ProcessRejoinAsync(string path, Game game)
}


private static async Task SafeCopy(string source, string dest , bool overwrite)
private static async Task SafeCopy(string source, string dest, bool overwrite)
{
var watchdog = 10;
var retry = false;
Expand Down

0 comments on commit b5b49ef

Please sign in to comment.