Skip to content

Commit

Permalink
move async part out of GameV2.NewArenaCard, clear TempArenaDeck stead…
Browse files Browse the repository at this point in the history
… of setting to null
  • Loading branch information
Alexander Zeier committed Oct 30, 2015
1 parent cf20969 commit cdd1f63
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
75 changes: 39 additions & 36 deletions Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GameV2 : IGame
private static List<string> _hsLogLines = new List<string>();
public readonly List<Deck> DiscardedArenaDecks = new List<Deck>();
private GameMode _currentGameMode;
public Deck TempArenaDeck;
public Deck TempArenaDeck = new Deck();

public GameV2()
{
Expand Down Expand Up @@ -187,7 +187,7 @@ public void NewArenaDeck(string heroId)
Logger.WriteLine("Created new arena deck: " + TempArenaDeck.Class);
}

public async void NewArenaCard(string cardId)
public void NewArenaCard(string cardId)
{
if(TempArenaDeck == null || string.IsNullOrEmpty(cardId))
return;
Expand All @@ -210,7 +210,7 @@ public async void NewArenaCard(string cardId)
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;
TempArenaDeck.Cards.Clear();
return;
}
if(DiscardedArenaDecks.Any(d => d.Cards.All(c => TempArenaDeck.Cards.Any(c2 => c.Id == c2.Id && c.Count == c2.Count))))
Expand All @@ -223,46 +223,49 @@ public async void NewArenaCard(string cardId)
Logger.WriteLine("...auto saving new arena deck.");
Core.MainWindow.SetNewDeck(TempArenaDeck);
Core.MainWindow.SaveDeck(false, TempArenaDeck.Version);
TempArenaDeck = null;
TempArenaDeck.Cards.Clear();
}
else if(Config.Instance.SelectedArenaImportingBehaviour.Value == ArenaImportingBehaviour.AutoAsk)
{
if(_awaitingMainWindowOpen)
return;
_awaitingMainWindowOpen = true;

if(Core.MainWindow.WindowState == WindowState.Minimized)
Core.TrayIcon.ShowMessage("New arena deck detected!");

while(Core.MainWindow.Visibility != Visibility.Visible
|| Core.MainWindow.WindowState == WindowState.Minimized)
await Task.Delay(100);

var result =
await
Core.MainWindow.ShowMessageAsync("New arena deck detected!",
"You can change this behaviour to \"auto save&import\" or \"manual\" in [options > tracker > importing]",
MessageDialogStyle.AffirmativeAndNegative,
new MessageDialogs.Settings {AffirmativeButtonText = "import", NegativeButtonText = "cancel"});

if(result == MessageDialogResult.Affirmative)
{
Logger.WriteLine("...saving new arena deck.");
Core.MainWindow.SetNewDeck(TempArenaDeck);
Core.MainWindow.ActivateWindow();
TempArenaDeck = null;
}
else
{
Logger.WriteLine("...discarded by user.");
DiscardedArenaDecks.Add(TempArenaDeck);
TempArenaDeck = null;
}
_awaitingMainWindowOpen = false;
ShowNewArenaDeckMessageAsync((Deck)TempArenaDeck.Clone());
TempArenaDeck.Cards.Clear();
}
}
}

private async void ShowNewArenaDeckMessageAsync(Deck deck)
{
if(_awaitingMainWindowOpen)
return;
_awaitingMainWindowOpen = true;

if(Core.MainWindow.WindowState == WindowState.Minimized)
Core.TrayIcon.ShowMessage("New arena deck detected!");

while(Core.MainWindow.Visibility != Visibility.Visible || Core.MainWindow.WindowState == WindowState.Minimized)
await Task.Delay(100);

var result =
await
Core.MainWindow.ShowMessageAsync("New arena deck detected!",
"You can change this behaviour to \"auto save&import\" or \"manual\" in [options > tracker > importing]",
MessageDialogStyle.AffirmativeAndNegative,
new MessageDialogs.Settings {AffirmativeButtonText = "import", NegativeButtonText = "cancel"});

if(result == MessageDialogResult.Affirmative)
{
Logger.WriteLine("...saving new arena deck.");
Core.MainWindow.SetNewDeck(deck);
Core.MainWindow.ActivateWindow();
}
else
{
Logger.WriteLine("...discarded by user.");
DiscardedArenaDecks.Add(deck);
}
_awaitingMainWindowOpen = false;
}

public static void AddHSLogLine(string logLine)
{
HSLogLines.Add(logLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void ExportDeck()
[PredefinedHotKeyAction("Import from game: arena", "Starts the webimport process with all dialogs.")]
public static async void ImportFromArena()
{
if(Core.Game.TempArenaDeck == null)
if(!Core.Game.TempArenaDeck.Cards.Any())
await Core.MainWindow.ShowMessageAsync("No arena deck found", "Please enter the arena screen (and build your deck).");
else
Core.MainWindow.SetNewDeck(Core.Game.TempArenaDeck);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private async void BtnArena_Click(object sender, RoutedEventArgs e)
}
else
{
if(Core.Game.TempArenaDeck == null)
if(!Core.Game.TempArenaDeck.Cards.Any())
{
await this.ShowMessageAsync("No arena deck found", "Please enter the arena screen (and build your deck).");
}
Expand Down

0 comments on commit cdd1f63

Please sign in to comment.