Skip to content

Commit

Permalink
Changes for v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rembound committed Jul 2, 2015
1 parent 1f36fd7 commit 7cffc24
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 21 deletions.
1 change: 1 addition & 0 deletions ArenaWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<CheckBox x:Name="CheckBoxManual" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,8,0,0" Checked="CheckBoxManual_Checked" Unchecked="CheckBoxManual_Unchecked">
<TextBlock TextWrapping="Wrap" VerticalAlignment="Top">Manual card picking<LineBreak />Pick a card in Hearthstone, afterwards, click the card in the Arena Helper window. Don't detect picks automatically.</TextBlock>
</CheckBox>
<CheckBox x:Name="CheckBoxAutoSave" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,8,0,0" Checked="CheckBoxAutoSave_Checked" Unchecked="CheckBoxAutoSave_Unchecked" Content="Automatically save and use the deck" />
<CheckBox x:Name="CheckBoxDebug" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,8,0,0" Checked="CheckBoxDebug_Checked" Unchecked="CheckBoxDebug_Unchecked" Content="Enable debug mode" />
</StackPanel>
</controls:Flyout>
Expand Down
17 changes: 17 additions & 0 deletions ArenaWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public partial class ArenaWindow
public delegate void OnCheckbox(bool check);
public OnCheckbox oncheckboxoverlay = null;
public OnCheckbox oncheckboxmanual = null;
public OnCheckbox oncheckboxautosave = null;
public OnCheckbox oncheckboxdebug = null;

public bool initconfig = false;
Expand Down Expand Up @@ -303,6 +304,22 @@ private void CheckBoxManual_Unchecked(object sender, RoutedEventArgs e)
}
}

private void CheckBoxAutoSave_Checked(object sender, RoutedEventArgs e)
{
if (oncheckboxautosave != null)
{
oncheckboxautosave(true);
}
}

private void CheckBoxAutoSave_Unchecked(object sender, RoutedEventArgs e)
{
if (oncheckboxautosave != null)
{
oncheckboxautosave(false);
}
}

private void CheckBoxDebug_Checked(object sender, RoutedEventArgs e)
{
if (oncheckboxdebug != null)
Expand Down
134 changes: 113 additions & 21 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ConfigData
public bool manualclicks;
public bool overlay;
public bool debug;
public bool autosave;

public ConfigData()
{
Expand All @@ -40,6 +41,7 @@ public ConfigData()
manualclicks = false;
overlay = true;
debug = false;
autosave = false;
}
}

Expand Down Expand Up @@ -129,6 +131,7 @@ public void Confirm(int cindex)
public class ArenaData
{
public string deckname;
public string deckguid;
public List<string> detectedheroes;
public string pickedhero;
public List<Tuple<string, string, string>> detectedcards;
Expand All @@ -137,6 +140,7 @@ public class ArenaData
public ArenaData()
{
deckname = "";
deckguid = "";
detectedheroes = new List<string>();
pickedhero = "";
detectedcards = new List<Tuple<string, string, string>>();
Expand Down Expand Up @@ -238,6 +242,10 @@ public enum PluginState { Idle, SearchHeroes, SearchBigHero, DetectedHeroes, Sea
private const int BigHeroConfirmations = 0; // Confirm immediately
private const int maxcarddistance = 10;
private const int maxherodistance = 14;
private const string DetectingArena = "Detecting arena...";
private const string DetectingHeroes = "Detecting heroes...";
private const string DetectingCards = "Detecting cards...";
private const string DetectingValues = "Getting values...";
private const string DetectionWarning = "Please make sure nothing overlaps the arena heroes and cards and the Hearthstone window has the focus. Don't make a selection yet!";
private const string DoneMessage = "All cards are picked. You can start a new arena run or save the deck.";
private const string ConfigFile = "arenahelper.json";
Expand Down Expand Up @@ -278,7 +286,7 @@ public string Author

public Version Version
{
get { return new Version("0.3.0"); }
get { return new Version("0.4.0"); }
}

public MenuItem MenuItem
Expand All @@ -298,7 +306,7 @@ public void OnLoad()
herohashlist.Add(new HeroHashData(1, "Shaman", "shaman_small.png", 18366959783178990451));
herohashlist.Add(new HeroHashData(2, "Rogue", "rogue_small.png", 5643619427529904809));
herohashlist.Add(new HeroHashData(3, "Paladin", "paladin_small.png", 11505795398351105139));
herohashlist.Add(new HeroHashData(4, "Hunter", "hunter_small.png", 2294799430464257123));
herohashlist.Add(new HeroHashData(4, "Hunter", "hunter_small.png", 2294799430464257123, 12942361696967163803, 17552924014479703963)); // Rexxar, Alleria small, Alleria big
herohashlist.Add(new HeroHashData(5, "Druid", "druid_small.png", 5433851923975358071));
herohashlist.Add(new HeroHashData(6, "Warlock", "warlock_small.png", 10186248321710093033));
herohashlist.Add(new HeroHashData(7, "Mage", "mage_small.png", 15770007155810004267, 8631746754340092973, 8343516378188643373)); // Jaina, Medivh small, Medivh big
Expand Down Expand Up @@ -383,6 +391,7 @@ protected async Task InitializeMainWindow()

arenawindow.oncheckboxoverlay = new ArenaWindow.OnCheckbox(OnCheckboxOverlay);
arenawindow.oncheckboxmanual = new ArenaWindow.OnCheckbox(OnCheckboxManual);
arenawindow.oncheckboxautosave = new ArenaWindow.OnCheckbox(OnCheckboxAutoSave);
arenawindow.oncheckboxdebug = new ArenaWindow.OnCheckbox(OnCheckboxDebug);

// Get the latest arena data
Expand Down Expand Up @@ -432,6 +441,7 @@ private void LoadConfig()
// Set options
arenawindow.CheckBoxOverlay.IsChecked = configdata.overlay;
arenawindow.CheckBoxManual.IsChecked = configdata.manualclicks;
arenawindow.CheckBoxAutoSave.IsChecked = configdata.autosave;
arenawindow.CheckBoxDebug.IsChecked = configdata.debug;
}

Expand All @@ -449,12 +459,15 @@ private void ApplyConfig()
{
testtext.Visibility = System.Windows.Visibility.Hidden;
}

// Overlay
//ShowOverlay(configdata.overlay);
}

private void ShowOverlay(bool show)
{
ShowValueOverlay(show);
ShowAdviceOverlay(show);
}

private void ShowValueOverlay(bool show)
{
System.Windows.Visibility vis = System.Windows.Visibility.Hidden;
if (show)
Expand All @@ -466,6 +479,16 @@ private void ShowOverlay(bool show)
{
overlay.Visibility = vis;
}
}

private void ShowAdviceOverlay(bool show)
{
System.Windows.Visibility vis = System.Windows.Visibility.Hidden;
if (show)
{
vis = System.Windows.Visibility.Visible;
}

adviceoverlay.Visibility = vis;
}

Expand Down Expand Up @@ -516,7 +539,7 @@ private async void ShowDialog()

public void OnButtonSaveClick()
{
SaveDeck();
SaveDeck(false);
}

public void OnHeroClick(int index)
Expand Down Expand Up @@ -587,6 +610,16 @@ public void OnCheckboxManual(bool check)
}
}

public void OnCheckboxAutoSave(bool check)
{
if (configinit)
{
configdata.autosave = check;
SaveConfig();
ApplyConfig();
}
}

public void OnCheckboxDebug(bool check)
{
if (configinit)
Expand All @@ -597,13 +630,18 @@ public void OnCheckboxDebug(bool check)
}
}

private void SaveDeck()
private void SaveDeck(bool autosave)
{
// Save deck
Deck deck = new Deck();
deck.Name = arenadata.deckname;
deck.IsArenaDeck = true;

if (autosave)
{
deck.DeckId = new Guid(arenadata.deckguid);
}

foreach (var cardid in arenadata.pickedcards)
{
Card pickedcard = GetCard(cardid);
Expand Down Expand Up @@ -635,11 +673,25 @@ private void SaveDeck()
// Add tag
deck.Tags.Add("Arena");

// Set the new deck
Helper.MainWindow.SetNewDeck(deck);
if (!autosave)
{
// Set the new deck
Helper.MainWindow.SetNewDeck(deck);

// Activate the window
Helper.MainWindow.ActivateWindow();
}
else
{
// Set the new deck in editing mode
Helper.MainWindow.SetNewDeck(deck, true);

// Save the deck
Helper.MainWindow.SaveDeck(true, SerializableVersion.Default, true);

// Activate the window
Helper.MainWindow.ActivateWindow();
// Select the deck and make it active
Helper.MainWindow.SelectDeck(deck, true);
}
}

private void SaveArenaData()
Expand Down Expand Up @@ -677,6 +729,13 @@ private async Task LoadArenaData(string filename)
// Load the data
arenadata = JsonConvert.DeserializeObject<ArenaData>(File.ReadAllText(filename));

// Make sure there is a guid for legacy arena runs
if (arenadata.deckguid == "")
{
arenadata.deckguid = Guid.NewGuid().ToString();
SaveArenaData();
}

if (arenadata.pickedhero != "")
{
// Hero is picked
Expand Down Expand Up @@ -749,6 +808,7 @@ private void NewArena()

// Clear data
arenadata.deckname = Helper.ParseDeckNameTemplate(Config.Instance.ArenaDeckNameTemplate);
arenadata.deckguid = Guid.NewGuid().ToString();
arenadata.detectedheroes.Clear();
arenadata.pickedhero = "";
arenadata.detectedcards.Clear();
Expand Down Expand Up @@ -948,17 +1008,23 @@ private void SetState(PluginState newstate)
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
} else if (!stablearena && state != PluginState.Done)
{
ShowOverlay(false);
SetDetectingText("Detecting arena...", DetectionWarning, "");
ShowValueOverlay(false);
SetAdviceText(DetectingArena);
ShowAdviceOverlay(configdata.overlay);

SetDetectingText(DetectingArena, DetectionWarning, "");
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.SearchHeroes)
{
ShowOverlay(false);
SetDetectingText("Detecting heroes...", DetectionWarning, "Override hero selection by clicking the rectangle in the top-left corner.");
ShowValueOverlay(false);
SetAdviceText(DetectingHeroes);
ShowAdviceOverlay(configdata.overlay);

SetDetectingText(DetectingHeroes, DetectionWarning, "Override hero selection by clicking the rectangle in the top-left corner.");
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
Expand All @@ -984,18 +1050,24 @@ private void SetState(PluginState newstate)
}
else if (newstate == PluginState.SearchCards)
{
ShowOverlay(false);
ShowValueOverlay(false);
SetAdviceText(DetectingCards);
ShowAdviceOverlay(configdata.overlay);

ClearDetected();
SetDetectingText("Detecting cards...", DetectionWarning, "");
SetDetectingText(DetectingCards, DetectionWarning, "");
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.CardPanel.Visibility = System.Windows.Visibility.Hidden;
}
else if (newstate == PluginState.SearchCardValues)
{
ShowOverlay(false);
SetDetectingText("Getting card values...", DetectionWarning, "");
ShowValueOverlay(false);
SetAdviceText(DetectingValues);
ShowAdviceOverlay(configdata.overlay);

SetDetectingText(DetectingValues, DetectionWarning, "");
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Visible;
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.HeroPanel.Visibility = System.Windows.Visibility.Hidden;
Expand Down Expand Up @@ -1342,7 +1414,7 @@ private async Task SearchCardValues(List<int> cardindices)
// Set value text
for (int i = 0; i < valueoverlays.Count; i++)
{
valueoverlays[i].ValueText.Text = values[i];
SetValueText(i, values[i]);
if (i == maxvalueindex)
{
valueoverlays[i].GradientStop1.Color = System.Windows.Media.Color.FromArgb(0xFF, 0xf5, 0xdb, 0x4c);
Expand All @@ -1357,7 +1429,8 @@ private async Task SearchCardValues(List<int> cardindices)
valueoverlays[i].UpdateLayout();
}
UpdateSize(); // Update size to center the labels
adviceoverlay.AdviceText.Text = advice;

SetAdviceText(advice);

arenawindow.Update();

Expand All @@ -1367,6 +1440,19 @@ private async Task SearchCardValues(List<int> cardindices)
await WaitCardPick(cardindices);
}

private void SetValueText(int index, string value)
{
if (index >= 0 && index < valueoverlays.Count)
{
valueoverlays[index].ValueText.Text = value;
}
}

private void SetAdviceText(string advice)
{
adviceoverlay.AdviceText.Text = advice;
}

public double GetNumericalValue(string str)
{
// Ignore everything after the first space
Expand Down Expand Up @@ -1548,6 +1634,12 @@ private async Task PickCard(int pickindex)
}

UpdateTitle();

// Save the deck when auto saving
if (configdata.autosave)
{
SaveDeck(true);
}
}

public static Card GetCard(string id)
Expand Down
3 changes: 3 additions & 0 deletions TestPlugin/TestPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public override async Task<List<string>> GetCardValues(ArenaHelper.Plugin.ArenaD
{
List<string> values = new List<string>();

// Add a test delay to simulate an API call
await Task.Delay(1000);

// Add the three card values
for (int i = 0; i < 3; i++)
{
Expand Down

0 comments on commit 7cffc24

Please sign in to comment.