internal async void BtnCloneSelectedVersion_Click(object sender, RoutedEventArgs e) { var deck = DeckPickerList.SelectedDecks.FirstOrDefault(); if (deck == null) { return; } deck = deck.GetSelectedDeckVersion(); var cloneStats = (await this.ShowMessageAsync("Clone game history?", "(Cloned games do not count towards class or overall stats.)", MessageDialogStyle.AffirmativeAndNegative, new MessageDialogs.Settings { AffirmativeButtonText = "clone history", NegativeButtonText = "do not clone history" })) == MessageDialogResult.Affirmative; var clone = (Deck)deck.CloneWithNewId(false); clone.ResetVersions(); clone.ResetHearthstatsIds(); clone.Archived = false; var originalStatsEntry = clone.DeckStats; DeckList.Instance.Decks.Add(clone); DeckPickerList.UpdateDecks(); DeckList.Save(); var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(clone)); if (newStatsEntry == null) { newStatsEntry = new DeckStats(clone); DeckStatsList.Instance.DeckStats.Add(newStatsEntry); } //clone game stats if (cloneStats) { foreach (var game in originalStatsEntry.Games) { newStatsEntry.AddGameResult(game.CloneWithNewId()); } Logger.WriteLine("cloned gamestats (version)", "Edit"); } DeckStatsList.Save(); //DeckPickerList.UpdateList(); DeckPickerList.SelectDeckAndAppropriateView(clone); if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { HearthStatsManager.UploadDeckAsync(clone).Forget(); } }
public async void SaveDecks() { var tags = Decks.Where(d => d.Tags != null).SelectMany(x => x.Tags).ToList(); if (tags.Any()) { var reloadTags = false; foreach (var tag in tags) { if (!DeckList.Instance.AllTags.Contains(tag)) { DeckList.Instance.AllTags.Add(tag); reloadTags = true; } } if (reloadTags) { DeckList.Save(); Core.MainWindow.ReloadTags(); } } var decks = Decks.Select(x => x.ToDeck()).ToList(); Core.MainWindow.ActivateWindow(); if (decks.Count > 1 || AutoSave) { var log = string.Format("Saving {0} decks", decks.Count); var controller = await Core.MainWindow.ShowProgressAsync(log, "Please wait..."); Logger.WriteLine(log); foreach (var deck in decks) { try { DeckList.Instance.Decks.Add(deck); if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { Logger.WriteLine("auto uploading new deck", "JsonDecksWrapper"); await HearthStatsManager.UploadDeckAsync(deck, background : true); } DeckManagerEvents.OnDeckCreated.Execute(deck); } catch (Exception ex) { Logger.WriteLine("Error saving deck: " + ex, "JsonDecksWrapper"); } } Core.MainWindow.DeckPickerList.UpdateDecks(); await controller.CloseAsync(); } else if (decks.Count == 1) { Core.MainWindow.SetNewDeck(decks[0]); } }
private async void BtnCloneDeck_Click(object sender, RoutedEventArgs e) { var cloneStats = (await this.ShowMessageAsync("Clone game history?", "(Cloned games do not count towards class or overall stats.)", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "clone history", NegativeButtonText = "do not clone history" })) == MessageDialogResult.Affirmative; var clone = (Deck)DeckList.Instance.ActiveDeck.CloneWithNewId(false); var originalStatsEntry = clone.DeckStats; /*while(DeckList.DecksList.Any(d => d.Name == clone.Name)) * { * var settings = new MetroDialogSettings {AffirmativeButtonText = "Set", DefaultText = clone.Name}; * var name = * await * this.ShowInputAsync("Name already exists", "You already have a deck with that name, please select a different one.", settings); * * if(string.IsNullOrEmpty(name)) * return; * * clone.Name = name; * }*/ DeckList.Instance.Decks.Add(clone); //DeckPickerList.AddAndSelectDeck(clone); DeckList.Save(); ; var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(clone)); if (newStatsEntry == null) { newStatsEntry = new DeckStats(clone); DeckStatsList.Instance.DeckStats.Add(newStatsEntry); } //clone game stats if (cloneStats) { foreach (var game in originalStatsEntry.Games) { newStatsEntry.AddGameResult(game.CloneWithNewId()); } Logger.WriteLine("cloned gamestats", "Edit"); } DeckStatsList.Save(); DeckPickerList.UpdateDecks(); HearthStatsManager.UploadDeckAsync(clone); }
internal async void BtnCloneDeck_Click(object sender, RoutedEventArgs e) { var deck = DeckPickerList.SelectedDecks.FirstOrDefault(); if (deck == null) { return; } var cloneStats = (await this.ShowMessageAsync("Clone game history?", "(Cloned games do not count towards class or overall stats.)", MessageDialogStyle.AffirmativeAndNegative, new MessageDialogs.Settings { AffirmativeButtonText = "clone history", NegativeButtonText = "do not clone history" })) == MessageDialogResult.Affirmative; var clone = (Deck)deck.CloneWithNewId(false); clone.ResetHearthstatsIds(); clone.Versions.ForEach(v => v.ResetHearthstatsIds()); clone.Archived = false; var originalStats = deck.DeckStats; DeckList.Instance.Decks.Add(clone); DeckList.Save(); DeckStats newStatsEntry; if (!DeckStatsList.Instance.DeckStats.TryGetValue(clone.DeckId, out newStatsEntry)) { newStatsEntry = new DeckStats(clone); DeckStatsList.Instance.DeckStats.TryAdd(clone.DeckId, newStatsEntry); } if (cloneStats) { foreach (var game in originalStats.Games) { newStatsEntry.AddGameResult(game.CloneWithNewId()); } Log.Info("cloned gamestats"); } DeckStatsList.Save(); DeckPickerList.SelectDeckAndAppropriateView(clone); if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { HearthStatsManager.UploadDeckAsync(clone).Forget(); } }
private async void SaveDeck(bool overwrite, SerializableVersion newVersion) { var deckName = TextBoxDeckName.Text; if (string.IsNullOrEmpty(deckName)) { var settings = new MetroDialogSettings { AffirmativeButtonText = "Set", DefaultText = deckName }; var name = await this.ShowInputAsync("No name set", "Please set a name for the deck", settings); if (String.IsNullOrEmpty(name)) { return; } deckName = name; TextBoxDeckName.Text = name; } /*while(DeckList.DecksList.Any(d => d.Name == deckName) && (!EditingDeck || !overwrite)) * { * var settings = new MetroDialogSettings {AffirmativeButtonText = "Set", DefaultText = deckName}; * var name = * await * this.ShowInputAsync("Name already exists", "You already have a deck with that name, please select a different one.", settings); * * if(String.IsNullOrEmpty(name)) * return; * * deckName = name; * TextBoxDeckName.Text = name; * }*/ if (_newDeck.Cards.Sum(c => c.Count) != 30) { var settings = new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No" }; var result = await this.ShowMessageAsync("Not 30 cards", string.Format("Deck contains {0} cards. Is this what you want to save anyway?", _newDeck.Cards.Sum(c => c.Count)), MessageDialogStyle.AffirmativeAndNegative, settings); if (result != MessageDialogResult.Affirmative) { return; } } var previousVersion = _newDeck.Version; if (overwrite && (_newDeck.Version != newVersion)) { AddDeckHistory(); _newDeck.Version = newVersion; _newDeck.SelectedVersion = newVersion; _newDeck.HearthStatsDeckVersionId = ""; //UpdateDeckHistoryPanel(_newDeck, false); } if (EditingDeck && overwrite) { DeckList.Instance.Decks.Remove(_newDeck); //DeckPickerList.RemoveDeck(_newDeck); } var oldDeckName = _newDeck.Name; _newDeck.Name = deckName; var newDeckClone = (Deck)_newDeck.Clone(); newDeckClone.Archived = false; DeckList.Instance.Decks.Add(newDeckClone); newDeckClone.LastEdited = DateTime.Now; DeckList.Save(); Logger.WriteLine("Saved Decks", "SaveDeck"); if (EditingDeck) { TagControlEdit.SetSelectedTags(new List <string>()); if (deckName != oldDeckName) { var statsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck)); if (statsEntry != null) { if (overwrite) { statsEntry.Name = deckName; Logger.WriteLine("Deck has new name, updated deckstats", "SaveDeck"); } else { var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck)); if (newStatsEntry == null) { newStatsEntry = new DeckStats(_newDeck); DeckStatsList.Instance.DeckStats.Add(newStatsEntry); } foreach (var game in statsEntry.Games) { newStatsEntry.AddGameResult(game.CloneWithNewId()); } Logger.WriteLine("cloned gamestats for \"Set as new\"", "SaveDeck"); } DeckStatsList.Save(); } } } if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { Logger.WriteLine("auto uploading new/edited deck", "SaveDeck"); if (EditingDeck) { if (previousVersion != newVersion) { HearthStatsManager.UploadVersionAsync(newDeckClone, _originalDeck.HearthStatsIdForUploading, background: true); } else { HearthStatsManager.UpdateDeckAsync(newDeckClone, background: true); } } else { HearthStatsManager.UploadDeckAsync(newDeckClone, background: true); } } //after cloning the stats, otherwise new stats will be generated //DeckPickerList.AddAndSelectDeck(newDeckClone); EditingDeck = false; foreach (var tag in _newDeck.Tags) { SortFilterDecksFlyout.AddSelectedTag(tag); } DeckPickerList.SelectDeckAndAppropriateView(newDeckClone); CloseNewDeck(); ClearNewDeckSection(); }
internal async void BtnCloneSelectedVersion_Click(object sender, RoutedEventArgs e) { var deck = DeckPickerList.SelectedDecks.FirstOrDefault(); if (deck == null) { return; } var cloneStats = (await this.ShowMessageAsync("Clone game history?", "(Cloned games do not count towards class or overall stats.)", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "clone history", NegativeButtonText = "do not clone history" })) == MessageDialogResult.Affirmative; var clone = (Deck)deck.CloneWithNewId(false); // bug #1316 - ResetVersions needs the current version as an argument clone.ResetVersions(); clone.ResetHearthstatsIds(); clone.Archived = false; var originalStatsEntry = clone.DeckStats; /*while(DeckList.DecksList.Any(d => d.Name == clone.Name)) * { * var settings = new MetroDialogSettings {AffirmativeButtonText = "Set", DefaultText = clone.Name}; * var name = * await * this.ShowInputAsync("Name already exists", "You already have a deck with that name, please select a different one.", settings); * * if(string.IsNullOrEmpty(name)) * return; * * clone.Name = name; * }*/ DeckList.Instance.Decks.Add(clone); DeckPickerList.UpdateDecks(); DeckList.Save(); var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(clone)); if (newStatsEntry == null) { newStatsEntry = new DeckStats(clone); DeckStatsList.Instance.DeckStats.Add(newStatsEntry); } //clone game stats if (cloneStats) { foreach (var game in originalStatsEntry.Games) { newStatsEntry.AddGameResult(game.CloneWithNewId()); } Logger.WriteLine("cloned gamestats (version)", "Edit"); } DeckStatsList.Save(); //DeckPickerList.UpdateList(); DeckPickerList.SelectDeckAndAppropriateView(clone); if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { HearthStatsManager.UploadDeckAsync(clone); } }
public async void SaveDeck(bool overwrite, SerializableVersion newVersion, bool workInProgressDeck = false) { var deckName = TextBoxDeckName.Text; if (string.IsNullOrEmpty(deckName)) { var settings = new MessageDialogs.Settings { AffirmativeButtonText = "Set", DefaultText = deckName }; var name = await this.ShowInputAsync("No name set", "Please set a name for the deck", settings); if (string.IsNullOrEmpty(name)) { return; } deckName = name; TextBoxDeckName.Text = name; } if (_newDeck.Cards.Sum(c => c.Count) != 30 && workInProgressDeck == false) { var settings = new MessageDialogs.Settings { AffirmativeButtonText = "Yes", NegativeButtonText = "No" }; var result = await this.ShowMessageAsync("Not 30 cards", $"Deck contains {_newDeck.Cards.Sum(c => c.Count)} cards. Is this what you want to save anyway?", MessageDialogStyle.AffirmativeAndNegative, settings); if (result != MessageDialogResult.Affirmative) { return; } } var previousVersion = _newDeck.Version; if (overwrite && (_newDeck.Version != newVersion)) { AddDeckHistory(); _newDeck.Version = newVersion; _newDeck.SelectedVersion = newVersion; _newDeck.HearthStatsDeckVersionId = ""; } if (EditingDeck && overwrite) { DeckList.Instance.Decks.Remove(_newDeck); } var oldDeckName = _newDeck.Name; _newDeck.Name = deckName; var newDeckClone = (Deck)_newDeck.Clone(); newDeckClone.Archived = false; DeckList.Instance.Decks.Add(newDeckClone); newDeckClone.LastEdited = DateTime.Now; DeckList.Save(); Log.Info("Saved Decks"); if (EditingDeck) { TagControlEdit.SetSelectedTags(new List <string>()); if (deckName != oldDeckName) { var statsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck)); if (statsEntry != null) { if (overwrite) { statsEntry.Name = deckName; Log.Info("Deck has new name, updated deckstats"); foreach (var game in statsEntry.Games) { game.DeckName = deckName; } } else { var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(_newDeck)); if (newStatsEntry == null) { newStatsEntry = new DeckStats(_newDeck); DeckStatsList.Instance.DeckStats.Add(newStatsEntry); } foreach (var game in statsEntry.Games) { newStatsEntry.AddGameResult(game.CloneWithNewId()); } Log.Info("cloned gamestats for \"Set as new\""); } DeckStatsList.Save(); } } } if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { Log.Info("auto uploading new/edited deck"); if (EditingDeck) { if (previousVersion != newVersion) { HearthStatsManager.UploadVersionAsync(newDeckClone, _originalDeck.HearthStatsIdForUploading, background: true).Forget(); } else { HearthStatsManager.UpdateDeckAsync(newDeckClone, background: true).Forget(); } } else { HearthStatsManager.UploadDeckAsync(newDeckClone, background: true).Forget(); } } if (EditingDeck) { DeckManagerEvents.OnDeckUpdated.Execute(newDeckClone); } else { DeckManagerEvents.OnDeckCreated.Execute(newDeckClone); } EditingDeck = false; foreach (var tag in _newDeck.Tags) { SortFilterDecksFlyout.AddSelectedTag(tag); } DeckPickerList.SelectDeckAndAppropriateView(newDeckClone); DeckPickerList.UpdateDecks(forceUpdate: new[] { newDeckClone }); SelectDeck(newDeckClone, true); CloseNewDeck(); ClearNewDeckSection(); }