internal async void BtnName_Click(object sender, RoutedEventArgs e) { var deck = DeckList.Instance.ActiveDeck; if (deck == null) { return; } var settings = new MetroDialogSettings { AffirmativeButtonText = "set", NegativeButtonText = "cancel", DefaultText = deck.Name }; var newName = await this.ShowInputAsync("Set deck name", "", settings); if (!string.IsNullOrEmpty(newName) && deck.Name != newName) { deck.Name = newName; DeckList.Save(); DeckPickerList.UpdateDecks(); if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { HearthStatsManager.UpdateDeckAsync(deck, true, true); } } }
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(); }
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(); 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) { 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); } if (Config.Instance.SelectedDeckType != DeckType.All) { if (newDeckClone.IsArenaDeck && Config.Instance.SelectedDeckType != DeckType.Arena) { DeckPickerList.SelectDeckType(DeckType.Arena); } else if (!newDeckClone.IsArenaDeck && Config.Instance.SelectedDeckType != DeckType.Constructed) { DeckPickerList.SelectDeckType(DeckType.Constructed); } } if (!DeckPickerList.SelectedClasses.Contains(HeroClassAll.All)) { HeroClassAll deckClass; if (Enum.TryParse(newDeckClone.Class, out deckClass)) { if (!DeckPickerList.SelectedClasses.Contains(deckClass)) { DeckPickerList.SelectClasses(new List <HeroClassAll> { deckClass }); } } } DeckPickerList.UpdateDecks(); DeckPickerList.SelectDeck(newDeckClone); CloseNewDeck(); ClearNewDeckSection(); }
private async void DeleteDeck(Deck deck, bool saveAndUpdate = true) { if (deck == null) { return; } var deckStats = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.BelongsToDeck(deck)); if (deckStats != null) { if (deckStats.Games.Any()) { if (Config.Instance.KeepStatsWhenDeletingDeck) { var defaultDeck = DefaultDeckStats.Instance.GetDeckStats(deck.Class); if (defaultDeck != null) { defaultDeck.Games.AddRange(deckStats.Games); } DefaultDeckStats.Save(); Logger.WriteLine(string.Format("Moved deckstats for deck {0} to default stats", deck.Name), "Edit"); } else { try { foreach (var game in deckStats.Games) { game.DeleteGameFile(); } Logger.WriteLine("Deleted games from deck: " + deck.Name, "Edit"); } catch (Exception) { Logger.WriteLine("Error deleting games", "Edit"); } } } DeckStatsList.Instance.DeckStats.Remove(deckStats); if (saveAndUpdate) { DeckStatsList.Save(); } Logger.WriteLine("Removed deckstats from deck: " + deck.Name, "Edit"); } if (HearthStatsAPI.IsLoggedIn && deck.HasHearthStatsId && await CheckHearthStatsDeckDeletion()) { HearthStatsManager.DeleteDeckAsync(deck, false, true); } DeckList.Instance.Decks.Remove(deck); if (saveAndUpdate) { DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.UpdateArchivedClassVisibility(); } ListViewDeck.ItemsSource = null; Logger.WriteLine("Deleted deck: " + deck.Name, "Edit"); }