internal async void BtnDeleteDeck_Click(object sender, RoutedEventArgs e) { var decks = DeckPickerList.SelectedDecks; if (!decks.Any()) { return; } var settings = new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No" }; var keepStatsInfo = Config.Instance.KeepStatsWhenDeletingDeck ? "The stats will be kept (can be changed in options)" : "The stats will be deleted (can be changed in options)"; var result = await this.ShowMessageAsync("Deleting " + (decks.Count == 1 ? decks.First().Name : decks.Count + " decks"), "Are you Sure?\n" + keepStatsInfo, MessageDialogStyle.AffirmativeAndNegative, settings); if (result == MessageDialogResult.Negative) { return; } DeckManagerEvents.OnDeckDeleted.Execute(decks); SelectDeck(null, true); foreach (var deck in decks) { DeleteDeck(deck, false); } DeckStatsList.Save(); DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.UpdateArchivedClassVisibility(); }
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); defaultDeck?.Games.AddRange(deckStats.Games); DefaultDeckStats.Save(); Logger.WriteLine($"Moved deckstats for deck {deck.Name} to default stats", "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).Forget(); } DeckList.Instance.Decks.Remove(deck); if (saveAndUpdate) { DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.UpdateArchivedClassVisibility(); } ListViewDeck.ItemsSource = null; Logger.WriteLine("Deleted deck: " + deck.Name, "Edit"); }
public void LoadAndUpdateDecks() { UpdateDeckList(DeckList.Instance.ActiveDeck); UpdateDbListView(); SelectDeck(DeckList.Instance.ActiveDeck, true); Helper.SortCardCollection(ListViewDeck.Items, Config.Instance.CardSortingClassFirst); DeckPickerList.PropertyChanged += DeckPickerList_PropertyChanged; DeckPickerList.UpdateDecks(); DeckPickerList.UpdateArchivedClassVisibility(); ManaCurveMyDecks.UpdateValues(); }
internal void BtnArchiveDeck_Click(object sender, RoutedEventArgs e) { foreach (var deck in DeckPickerList.SelectedDecks) { ArchiveDeck(deck, true, false); } DeckList.Save(); DeckPickerList.UpdateDecks(); SelectDeck(null, true); DeckPickerList.UpdateArchivedClassVisibility(); }
internal void UnArchiveDecks(IEnumerable <Deck> decks) { foreach (var deck in DeckPickerList.SelectedDecks) { ArchiveDeck(deck, false, false); } DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.SelectDeckAndAppropriateView(DeckPickerList.SelectedDecks.FirstOrDefault()); DeckPickerList.UpdateArchivedClassVisibility(); }
internal void ArchiveDecks(IEnumerable <Deck> decks) { foreach (var deck in decks) { ArchiveDeck(deck, true, false); } DeckList.Save(); DeckPickerList.UpdateDecks(); SelectDeck(null, true); DeckPickerList.UpdateArchivedClassVisibility(); }
internal void BtnUnarchiveDeck_Click(object sender, RoutedEventArgs e) { foreach (var deck in DeckPickerList.SelectedDecks) { ArchiveDeck(deck, false, false); } DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.SelectDeckAndAppropriateView(DeckPickerList.SelectedDecks.FirstOrDefault()); UpdateMenuItemVisibility(); DeckPickerList.UpdateArchivedClassVisibility(); }
public void ArchiveDeck(Deck deck, bool archive, bool saveAndUpdate = true) { if (deck == null) { return; } var oldArchived = deck.Archived; if (oldArchived == archive) { return; } deck.Archived = archive; deck.Edited(); try { if (saveAndUpdate) { DeckList.Save(); DeckPickerList.UpdateDecks(); if (archive) { SelectDeck(null, true); } else { DeckPickerList.SelectDeckAndAppropriateView(deck); UpdateMenuItemVisibility(); } DeckPickerList.UpdateArchivedClassVisibility(); } var archivedLog = archive ? "archived" : "unarchived"; Logger.WriteLine(String.Format("Successfully {0} deck: {1}", archivedLog, deck.Name), "ArchiveDeck"); if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn) { Logger.WriteLine(String.Format("auto uploading {0} deck", archivedLog), "ArchiveDeck"); HearthStatsManager.UpdateDeckAsync(deck, background: true); } } catch (Exception) { Logger.WriteLine(String.Format("Error {0} deck", archive ? "archiving" : "unarchiving", deck.Name), "ArchiveDeck"); } }
internal void SaveDeckWithOverwriteCheck(SerializableVersion newVersion, bool saveAsNew = false) { if (saveAsNew) { EditingDeck = false; _newDeck.ResetVersions(); _newDeck.DeckId = Guid.NewGuid(); _newDeck.Archived = false; } SaveDeck(EditingDeck, newVersion); DeckPickerList.UpdateArchivedClassVisibility(); _editedDeckName = string.Empty; }
public void ArchiveDeck(Deck deck, bool archive, bool saveAndUpdate = true) { if (deck == null) { return; } var oldArchived = deck.Archived; if (oldArchived == archive) { return; } deck.Archived = archive; deck.Edited(); try { if (saveAndUpdate) { DeckList.Save(); DeckPickerList.UpdateDecks(); if (archive) { SelectDeck(null, true); } else { DeckPickerList.SelectDeckAndAppropriateView(deck); UpdateMenuItemVisibility(); } DeckPickerList.UpdateArchivedClassVisibility(); } var archivedLog = archive ? "archived" : "unarchived"; Log.Info($"Successfully {archivedLog} deck: {deck.Name}"); } catch (Exception ex) { Log.Error($"Error {(archive ? "archiving" : "unarchiving")} deck {deck.Name}/n{ex}"); } }
private void DeleteDeck(Deck deck, bool saveAndUpdate = true) { if (deck == null) { return; } if (Equals(DeckList.Instance.ActiveDeck, deck)) { SelectDeck(null, true); } DeckStats deckStats; if (DeckStatsList.Instance.DeckStats.TryGetValue(deck.DeckId, out deckStats)) { if (deckStats.Games.Any()) { if (Config.Instance.KeepStatsWhenDeletingDeck) { var defaultDeck = DefaultDeckStats.Instance.GetDeckStats(deck.Class); defaultDeck?.Games.AddRange(deckStats.Games); DefaultDeckStats.Save(); Log.Info($"Moved deckstats for deck {deck.Name} to default stats"); } } DeckStatsList.Instance.DeckStats.TryRemove(deckStats.DeckId, out deckStats); if (saveAndUpdate) { DeckStatsList.Save(); } Log.Info("Removed deckstats from deck: " + deck.Name); } DeckList.Instance.Decks.Remove(deck); if (saveAndUpdate) { DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.UpdateArchivedClassVisibility(); } Log.Info("Deleted deck: " + deck.Name); }
private async Task SaveDeckWithOverwriteCheck(SerializableVersion newVersion, bool saveAsNew = false) { var deckName = TextBoxDeckName.Text; if (saveAsNew) { EditingDeck = false; _newDeck.ResetVersions(); _newDeck.ResetHearthstatsIds(); _newDeck.DeckId = Guid.NewGuid(); _newDeck.Archived = false; } /*else if(!EditingDeck && DeckList.DecksList.Any(d => d.Name == deckName)) * { * var settings = new MetroDialogSettings {AffirmativeButtonText = "Overwrite", NegativeButtonText = "Set new name"}; * * var keepStatsInfo = Config.Instance.KeepStatsWhenDeletingDeck * ? "The stats will be moved to the default-deck (can be changed in options)" * : "The stats will be deleted (can be changed in options)"; * var result = * await * this.ShowMessageAsync("A deck with that name already exists", "Overwriting the deck can not be undone!\n" + keepStatsInfo, * MessageDialogStyle.AffirmativeAndNegative, settings); * if(result == MessageDialogResult.Affirmative) * { * Deck oldDeck; * while((oldDeck = DeckList.DecksList.FirstOrDefault(d => d.Name == deckName)) != null) * DeleteDeck(oldDeck); * * SaveDeck(true, newVersion); * } * else if(result == MessageDialogResult.Negative) * SaveDeck(false, newVersion); * }*/ SaveDeck(EditingDeck, newVersion); DeckPickerList.UpdateArchivedClassVisibility(); editedDeckName = string.Empty; }
internal async void ShowDeleteDecksMessage(IEnumerable <Deck> decks) { if (decks == null) { return; } var decksList = decks.ToList(); if (!decksList.Any()) { return; } var settings = new MessageDialogs.Settings { AffirmativeButtonText = "Yes", NegativeButtonText = "No" }; var keepStatsInfo = Config.Instance.KeepStatsWhenDeletingDeck ? "The stats will be kept (can be changed in options)" : "The stats will be deleted (can be changed in options)"; var result = await this.ShowMessageAsync("Deleting " + (decksList.Count == 1 ? decksList.First().Name : decksList.Count + " decks"), "Are you Sure?\n" + keepStatsInfo, MessageDialogStyle.AffirmativeAndNegative, settings); if (result == MessageDialogResult.Negative) { return; } foreach (var deck in decksList) { DeleteDeck(deck, false); } DeckStatsList.Save(); DeckList.Save(); DeckPickerList.UpdateDecks(); DeckPickerList.UpdateArchivedClassVisibility(); DeckManagerEvents.OnDeckDeleted.Execute(decksList); }