Skip to content

Commit

Permalink
Added deck average
Browse files Browse the repository at this point in the history
  • Loading branch information
rembound committed Mar 8, 2017
1 parent d70dd20 commit 13965ad
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 34 deletions.
7 changes: 7 additions & 0 deletions ArenaHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<Compile Include="Controls\DebugTextBlock.xaml.cs">
<DependentUpon>DebugTextBlock.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\DeckRating.xaml.cs">
<DependentUpon>DeckRating.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Hero.xaml.cs">
<DependentUpon>Hero.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -124,6 +127,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\DeckRating.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\Hero.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
78 changes: 51 additions & 27 deletions ArenaWindow.xaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ArenaWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using MahApps.Metro.Controls.Dialogs;
using System.Windows.Navigation;
using System.Diagnostics;
using MahApps.Metro;

#endregion

Expand Down
20 changes: 20 additions & 0 deletions Controls/DeckRating.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl x:Class="ArenaHelper.Controls.DeckRating"
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:ArenaHelper"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<local:OutlinedTextBlock Grid.Row="0" HorizontalAlignment="Center" FontFamily="/ArenaHelper;component/resources/#Belwe Bd BT" FontSize="20" Text="Deck Average" Margin="0,8,0,0" />
<Grid Grid.Row="1" VerticalAlignment="Top" Margin="0,15,0,0">
<Ellipse Width="110" Height="110" Fill="#494949" Stroke="#2f2f2f" StrokeThickness="3"></Ellipse>
<TextBlock x:Name="DeckRatingText" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#f7f7f7" FontFamily="/ArenaHelper;component/resources/#Belwe Bd BT" FontSize="32" Text="65.3"/>
</Grid>
</Grid>
</UserControl>
28 changes: 28 additions & 0 deletions Controls/DeckRating.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 ArenaHelper.Controls
{
/// <summary>
/// Interaction logic for DeckRating.xaml
/// </summary>
public partial class DeckRating : UserControl
{
public DeckRating()
{
InitializeComponent();
}
}
}
5 changes: 4 additions & 1 deletion Controls/Hero.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
xmlns:local="clr-namespace:ArenaHelper"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="200">
<UserControl.Resources>
<SolidColorBrush x:Key="PortraitBackground" Color="#a0a0a0" />
</UserControl.Resources>
<StackPanel VerticalAlignment="Center">
<Border x:Name="HeroBorder" Height="40" Width="40" Grid.Row="0" Grid.Column="0" Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" Margin="0,0,0,0" MouseUp="Hero_MouseUp">
<Border x:Name="HeroBorder" Height="40" Width="40" Grid.Row="0" Grid.Column="0" Background="{StaticResource PortraitBackground}" Margin="0,0,0,0" MouseUp="Hero_MouseUp">
<Image x:Name="HeroImage" Width="32" Height="32" Margin="0,0,0,0" />
</Border>
<local:OutlinedTextBlock x:Name="HeroName" VerticalAlignment="Bottom" HorizontalAlignment="Center" Text="Paladin" FontFamily="/ArenaHelper;component/resources/#Belwe Bd BT" TextAlignment="Left" FontSize="13" Margin="0,4,0,0" />
Expand Down
84 changes: 78 additions & 6 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class ArenaData
public List<string> detectedheroes;
public string pickedhero;
public List<Tuple<string, string, string>> detectedcards;
public List<Tuple<double, double, double>> cardrating;
public List<string> pickedcards;

public ArenaData()
Expand All @@ -126,6 +127,7 @@ public ArenaData()
detectedheroes = new List<string>();
pickedhero = "";
detectedcards = new List<Tuple<string, string, string>>();
cardrating = new List<Tuple<double, double, double>>();
pickedcards = new List<string>();
}
}
Expand All @@ -135,6 +137,7 @@ public enum PluginState { Idle, SearchHeroes, SearchBigHero, DetectedHeroes, Sea
private List<Detection.DetectedInfo> detectedcards = new List<Detection.DetectedInfo>();
private List<Detection.DetectedInfo> detectedheroes = new List<Detection.DetectedInfo>();
private List<Detection.DetectedInfo> detectedbighero = new List<Detection.DetectedInfo>();
private List<double> currentcardvalues = new List<double>();
private static PluginState state;
private List<int> mouseindex = new List<int>();
private ArenaData arenadata = new ArenaData();
Expand Down Expand Up @@ -251,7 +254,7 @@ public string Author

public Version Version
{
get { return new Version("0.8.4"); }
get { return new Version("0.8.5"); }
}

public MenuItem MenuItem
Expand Down Expand Up @@ -775,6 +778,8 @@ private void LoadArenaData(string filename)
// Set the data
arenadata = loadedarenadata;
validarenadata = true;

Log.Info("Arena Helper: Card Rating: " + arenadata.cardrating.Count);
}
else
{
Expand Down Expand Up @@ -883,6 +888,7 @@ private void NewArena()
arenadata.detectedheroes.Clear();
arenadata.pickedhero = "";
arenadata.detectedcards.Clear();
arenadata.cardrating.Clear();
arenadata.pickedcards.Clear();

// Invalidate arena
Expand Down Expand Up @@ -1248,6 +1254,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
} else if (!stablearena && state != PluginState.Done)
{
ShowOverlay(false);
Expand All @@ -1257,6 +1264,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.SearchHeroes)
{
Expand All @@ -1269,6 +1277,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.SearchBigHero)
{
Expand All @@ -1278,6 +1287,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.DetectedHeroes)
{
Expand All @@ -1287,6 +1297,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.SearchCards)
{
Expand All @@ -1300,6 +1311,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.SearchCardValues)
{
Expand All @@ -1312,6 +1324,7 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.DetectedCards)
{
Expand All @@ -1320,15 +1333,18 @@ private void SetState(PluginState newstate)
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.Done)
{
arenawindow.DeckRatingControl1.DeckRatingText.Text = GetDeckRating().ToString("0.##", System.Globalization.CultureInfo.InvariantCulture);

ShowOverlay(false);
SetDetectingText("Done", DoneMessage, "");
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.DonePanel.Visibility = System.Windows.Visibility.Visible;
}
}

Expand Down Expand Up @@ -1838,11 +1854,11 @@ private async Task SearchCardValues()

// Get the actual numerical value
double maxvalue = 0;
List<double> cardvalues = new List<double>();
currentcardvalues.Clear();
for (int i = 0; i < 3; i++)
{
double dval = GetNumericalValue(values[i]);
cardvalues.Add(dval);
currentcardvalues.Add(dval);

if (i == 0 || dval > maxvalue)
{
Expand All @@ -1856,7 +1872,7 @@ private async Task SearchCardValues()
SetValueText(i, values[i]);

// Highlight the card with the highest value, if no cards are missing
if (!missing && cardvalues[i] == maxvalue)
if (!missing && currentcardvalues[i] == maxvalue)
{
valueoverlays[i].GradientStop1.Color = System.Windows.Media.Color.FromArgb(0xFF, 0xf5, 0xdb, 0x4c);
valueoverlays[i].GradientStop2.Color = System.Windows.Media.Color.FromArgb(0xFF, 0x8b, 0x68, 0x11);
Expand Down Expand Up @@ -2055,7 +2071,22 @@ private void PickCard(int pickindex)
Log.Info("AH: Missed a pick");
}

// Add picked card
arenadata.pickedcards.Add(cardid);

// Add card rating
double cardval0 = 0;
double cardval1 = 0;
double cardval2 = 0;
if (currentcardvalues.Count == 3)
{
cardval0 = currentcardvalues[0];
cardval1 = currentcardvalues[1];
cardval2 = currentcardvalues[2];
}
arenadata.cardrating.Add(new Tuple<double, double, double>(cardval0, cardval1, cardval2));

// Save
SaveArenaData();

plugins.CardPicked(arenadata, pickindex, pickedcard);
Expand Down Expand Up @@ -2141,6 +2172,47 @@ private void UpdateTitle()
{
arenawindow.Header.Text = "Picking card " + (arenadata.pickedcards.Count + 1) + "/" + MaxCardCount;
arenawindow.DeckName.Content = arenadata.deckname;
arenawindow.DeckRatingControl0.DeckRatingText.Text = GetDeckRating().ToString("0.##", System.Globalization.CultureInfo.InvariantCulture);
}

private double GetDeckRating()
{
int pcount = arenadata.pickedcards.Count;
int dcount = arenadata.detectedcards.Count;
int ccount = arenadata.cardrating.Count;

// Check if valid counts
if (!(pcount > 0 && pcount <= dcount && pcount == ccount))
{
return 0;
}

// Calculate total rating
double totalrating = 0;
for (int i = 0; i < pcount; i++)
{
string curcard = arenadata.pickedcards[i];
double curcardval = 0;
if (curcard == arenadata.detectedcards[i].Item1)
{
curcardval = arenadata.cardrating[i].Item1;
}
else if (curcard == arenadata.detectedcards[i].Item2)
{
curcardval = arenadata.cardrating[i].Item2;
}
else if (curcard == arenadata.detectedcards[i].Item3)
{
curcardval = arenadata.cardrating[i].Item3;
}

totalrating += curcardval;
}


// Return average
double deckrating = totalrating / (double)pcount;
return deckrating;
}

private void SetDetectingText(string title, string text, string text2)
Expand Down

0 comments on commit 13965ad

Please sign in to comment.