Skip to content

Commit

Permalink
new arena importing method
Browse files Browse the repository at this point in the history
  • Loading branch information
Epix37 committed Aug 21, 2015
1 parent 0f8d02b commit 20b956f
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 54 deletions.
6 changes: 6 additions & 0 deletions Hearthstone Deck Tracker/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ public class Config
[DefaultValue(5)]
public double SecretsTop = 5;

[DefaultValue(ArenaImportingBehaviour.AutoAsk)]
public ArenaImportingBehaviour? SelectedArenaImportingBehaviour = ArenaImportingBehaviour.AutoAsk;

[DefaultValue(new[] {HeroClassAll.All})]
public HeroClassAll[] SelectedDeckPickerClasses = {HeroClassAll.All};

Expand Down Expand Up @@ -732,6 +735,9 @@ public class Config
[DefaultValue(false)]
public bool UseFullTextSearch = false;

[DefaultValue(false)]
public bool UseOldArenaImporting = false;

[DefaultValue(true)]
public bool UseSameScaling = true;

Expand Down
20 changes: 20 additions & 0 deletions Hearthstone Deck Tracker/Enums/ArenaImportingBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#region

using System.ComponentModel;

#endregion

namespace Hearthstone_Deck_Tracker.Enums
{
public enum ArenaImportingBehaviour
{
[Description("Auto import&save")]
AutoImportSave,

[Description("Auto ask to import")]
AutoAsk,

[Description("Manual")]
Manual
}
}
9 changes: 8 additions & 1 deletion Hearthstone Deck Tracker/Enums/EnumDescriptionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
if(value == null)
return DependencyProperty.UnsetValue;
return GetDescription((Enum)value);
try
{
return GetDescription((Enum)value);
}
catch(Exception)
{
return DependencyProperty.UnsetValue;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,56 @@
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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:enums="clr-namespace:Hearthstone_Deck_Tracker.Enums"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="300">
<UserControl.Resources>
<enums:EnumDescriptionConverter x:Key="EnumDescriptionConverter"/>
</UserControl.Resources>
<Grid>
<GroupBox Header="Importing">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel>
<CheckBox x:Name="CheckBoxAutoDetectCardCount" Content="[BETA] Auto detect card count for arena"
HorizontalAlignment="Left" Margin="10,5,0,0"
VerticalAlignment="Top" Checked="CheckBoxAutoDetectCardCount_Checked"
Unchecked="CheckBoxAutoDetectCardCount_Unchecked" />
<TextBlock Margin="10,5,0,0" Text="[This feature is still a work in progress!]" FontWeight="Bold"></TextBlock>
<TextBlock Margin="10,5,0,15" Text="Currently only for arena. Can currently only detect &quot;more than 1&quot;, which sets it to 2, not the actual number. Yes, both of those things will come." TextWrapping="Wrap"></TextBlock>
<GroupBox Header="Arena">
<StackPanel>
<DockPanel Margin="10,5,10,0" >
<TextBlock DockPanel.Dock="Left" Text="Importing Behaviour:" VerticalAlignment="Center"/>
<ComboBox Name="ComboboxArenaImportingBehaviour" Margin="5,0,0,0" SelectionChanged="ComboboxArenaImportingBehaviour_OnSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=., Converter={StaticResource EnumDescriptionConverter}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DockPanel>
<CheckBox Name="CheckboxUseOldArenaImporting" Content="Use old arena importing method" Margin="10,5,0,0" Checked="CheckboxUseOldArenaImporting_OnChecked" Unchecked="CheckboxUseOldArenaImporting_OnUnchecked"/>
<Button Name="BtnArenaHowTo" Margin="10,5,10,0" HorizontalAlignment="Stretch" Content="SHOW ARENA IMPORTING HOW-TO" Click="ButtonArenaHowTo_OnClick" IsEnabled="False"/>
<GroupBox Header="Arena deck name template">
<DockPanel>
<DockPanel DockPanel.Dock="Bottom" Margin="0,5,0,0">
<TextBlock Text="Preview:" />
<TextBlock Name="TextBlockNamePreview" Margin="5,0,0,0"/>
</DockPanel>
<Button Name="BtnEditTemplate" Content="EDIT" DockPanel.Dock="Right" Margin="5,0,0,0" Click="BtnEditTemplate_Click"/>
<TextBox Name="TextBoxArenaTemplate" IsEnabled="False" TextChanged="TextBoxArenaTemplate_OnTextChanged"/>
</DockPanel>
</GroupBox>
</StackPanel>
</GroupBox>
<CheckBox x:Name="CheckboxTagOnImport" Content="Tag decks on import"
HorizontalAlignment="Left" Margin="10,5,0,0"
VerticalAlignment="Top" Checked="CheckboxTagOnImport_Checked"
Unchecked="CheckboxTagOnImport_Unchecked" />
<CheckBox Name="CheckboxAutoSaveOnImport" Content="Auto save deck on import" Margin="10,5,0,0" Checked="CheckboxAutoSaveOnImport_OnChecked" Unchecked="CheckboxAutoSaveOnImport_OnUnchecked"/>
<CheckBox Name="CheckboxImportNetDeck" Content="Auto import via NetDeck" Margin="10,5,0,0" Checked="CheckboxImportNetDeck_OnChecked" Unchecked="CheckboxImportNetDeck_OnUnchecked"/>
<GroupBox Header="Arena deck name template">
<DockPanel>
<DockPanel DockPanel.Dock="Bottom" Margin="0,5,0,0">
<TextBlock Text="Preview:" />
<TextBlock Name="TextBlockNamePreview" Margin="5,0,0,0"/>
</DockPanel>
<Button Name="BtnEditTemplate" Content="EDIT" DockPanel.Dock="Right" Margin="5,0,0,0" Click="BtnEditTemplate_Click"/>
<TextBox Name="TextBoxArenaTemplate" IsEnabled="False" TextChanged="TextBoxArenaTemplate_OnTextChanged"/>
</DockPanel>
</GroupBox>

<TextBlock Margin="10,2,0,0">
<Hyperlink NavigateUri="https://chrome.google.com/webstore/detail/netdeck/lpdbiakcpmcppnpchohihcbdnojlgeel"
RequestNavigate="Hyperlink_RequestNavigate">
Download NetDeck (Chrome ext.)
</Hyperlink>
</TextBlock>
<Button Margin="10,5,10,0" HorizontalAlignment="Stretch" Content="SHOW ARENA IMPORTING HOW-TO" Click="ButtonArenaHowTo_OnClick"/>
<Button Margin="10,5,10,0" HorizontalAlignment="Stretch" Content="SHOW CONSTRUCTED IMPORTING HOW-TO" Click="ButtonConstructedHowTo_OnClick"/>
<Button Margin="10,5,10,0" HorizontalAlignment="Stretch" Content="SET UP CONSTRUCTED IMPORTING" Click="ButtonSetUpConstructed_OnClick"/>
<Button Margin="10,10,10,0" HorizontalAlignment="Stretch" Content="ACTIVATE HDT PROTOCOL" Click="ButtonActivateHdtProtocol_OnClick"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#region

using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Hearthstone_Deck_Tracker.Enums;
using MahApps.Metro.Controls.Dialogs;

#endregion
Expand All @@ -29,7 +31,12 @@ private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e

public void Load()
{
CheckBoxAutoDetectCardCount.IsChecked = Config.Instance.DeckImportAutoDetectCardCount;
ComboboxArenaImportingBehaviour.IsEnabled = !Config.Instance.UseOldArenaImporting;
ComboboxArenaImportingBehaviour.ItemsSource = Enum.GetValues(typeof(ArenaImportingBehaviour));
if(Config.Instance.SelectedArenaImportingBehaviour.HasValue)
ComboboxArenaImportingBehaviour.SelectedItem = Config.Instance.SelectedArenaImportingBehaviour.Value;
CheckboxUseOldArenaImporting.IsChecked = Config.Instance.UseOldArenaImporting;
BtnArenaHowTo.IsEnabled = Config.Instance.UseOldArenaImporting;
CheckboxTagOnImport.IsChecked = Config.Instance.TagDecksOnImport;
CheckboxImportNetDeck.IsChecked = Config.Instance.NetDeckClipboardCheck ?? false;
CheckboxAutoSaveOnImport.IsChecked = Config.Instance.AutoSaveOnImport;
Expand Down Expand Up @@ -129,21 +136,39 @@ private void ButtonActivateHdtProtocol_OnClick(object sender, RoutedEventArgs e)
{
Helper.MainWindow.SetupProtocol();
}

private void CheckBoxAutoDetectCardCount_Checked(object sender, RoutedEventArgs e)
private void CheckboxUseOldArenaImporting_OnChecked(object sender, RoutedEventArgs e)
{
if(!_initialized)
return;
Config.Instance.DeckImportAutoDetectCardCount = true;
Config.Instance.UseOldArenaImporting = true;
ComboboxArenaImportingBehaviour.IsEnabled = false;
ComboboxArenaImportingBehaviour.SelectedIndex = -1;
BtnArenaHowTo.IsEnabled = true;
Config.Save();
}

private void CheckBoxAutoDetectCardCount_Unchecked(object sender, RoutedEventArgs e)
private void CheckboxUseOldArenaImporting_OnUnchecked(object sender, RoutedEventArgs e)
{
if(!_initialized)
return;
Config.Instance.DeckImportAutoDetectCardCount = false;
Config.Instance.UseOldArenaImporting = false;
ComboboxArenaImportingBehaviour.IsEnabled = true;
ComboboxArenaImportingBehaviour.SelectedItem = ArenaImportingBehaviour.AutoAsk;
BtnArenaHowTo.IsEnabled = false;
Config.Save();
}

private void ComboboxArenaImportingBehaviour_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(!_initialized)
return;
var selected = ComboboxArenaImportingBehaviour.SelectedItem as ArenaImportingBehaviour?;
if(selected != null)
{
Config.Instance.SelectedArenaImportingBehaviour = selected;
Config.Save();
}
}
}
}
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<DependentUpon>ElementSorterItem.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\DeckPicker\MarginConverter.cs" />
<Compile Include="Enums\ArenaImportingBehaviour.cs" />
<Compile Include="Enums\DeckLayout.cs" />
<Compile Include="Enums\IconStyle.cs" />
<Compile Include="Errors\ErrorItem.xaml.cs">
Expand Down
76 changes: 76 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Hearthstone_Deck_Tracker.Hearthstone.Entities;
using Hearthstone_Deck_Tracker.Replay;
using Hearthstone_Deck_Tracker.Stats;
using MahApps.Metro.Controls.Dialogs;

#endregion

Expand Down Expand Up @@ -869,5 +870,80 @@ public static string GetHeroNameFromId(string id, bool returnIdIfNotFound = true
}

#endregion

public static Deck TempArenaDeck;
public static readonly List<Deck> DiscardedArenaDecks = new List<Deck>();

public static void NewArenaDeck(string heroId)
{
TempArenaDeck = new Deck
{
Name = Helper.ParseDeckNameTemplate(Config.Instance.ArenaDeckNameTemplate),
IsArenaDeck = true,
Class = GetHeroNameFromId(heroId)
};
Logger.WriteLine("Created new arena deck: " + TempArenaDeck.Class);
}

public static async void NewArenaCard(string cardId)
{
if(TempArenaDeck == null)
return;
var existingCard = TempArenaDeck.Cards.FirstOrDefault(c => c.Id == cardId);
if(existingCard != null)
existingCard.Count++;
else
TempArenaDeck.Cards.Add((Card)GetCardFromId(cardId).Clone());
var numCards = TempArenaDeck.Cards.Sum(c => c.Count);
Logger.WriteLine(string.Format("Added new card to arena deck: {0} ({1}/30)", cardId, numCards));
if(numCards == 30)
{
Logger.WriteLine("Found complete arena deck!");
if(!Config.Instance.SelectedArenaImportingBehaviour.HasValue)
{
Logger.WriteLine("...but we are using the old importing method.");
return;
}
var recentArenaDecks = DeckList.Instance.Decks.Where(d => d.IsArenaDeck).OrderByDescending(d => d.LastPlayedNewFirst).Take(15);
if(recentArenaDecks.Any(d => d.Cards.All(c => TempArenaDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))))
{
Logger.WriteLine("...but we already have that one. Discarding.");
TempArenaDeck = null;
return;
}
if(DiscardedArenaDecks.Any(d => d.Cards.All(c => TempArenaDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))))
{
Logger.WriteLine("...but it was already discarded by the user. No automatic action taken.");
return;
}
if(Config.Instance.SelectedArenaImportingBehaviour.Value == ArenaImportingBehaviour.AutoImportSave)
{
Logger.WriteLine("...auto saving new arena deck.");
Helper.MainWindow.SetNewDeck(TempArenaDeck);
Helper.MainWindow.SaveDeck(false, TempArenaDeck.Version);
TempArenaDeck = null;
}
else if(Config.Instance.SelectedArenaImportingBehaviour.Value == ArenaImportingBehaviour.AutoAsk)
{
var result =
await
Helper.MainWindow.ShowMessageAsync("New arena deck detected!", "", MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings {AffirmativeButtonText = "import", NegativeButtonText = "cancel"});
if(result == MessageDialogResult.Affirmative)
{
Logger.WriteLine("...saving new arena deck.");
Helper.MainWindow.SetNewDeck(TempArenaDeck);
Helper.MainWindow.ActivateWindow();
TempArenaDeck = null;
}
else
{
Logger.WriteLine("...discarded by user.");
DiscardedArenaDecks.Add(TempArenaDeck);
TempArenaDeck = null;
}
}
}
}
}
}
Loading

0 comments on commit 20b956f

Please sign in to comment.