Esempio n. 1
0
        internal async void BtnName_Click(object sender, RoutedEventArgs e)
        {
            var deck = DeckPickerList.SelectedDecks.FirstOrDefault();

            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;
                deck.Edited();
                if (deck.DeckStats.Games.Any())
                {
                    foreach (var game in deck.DeckStats.Games)
                    {
                        game.DeckName = newName;
                    }
                    DeckStatsList.Save();
                }

                DeckList.Save();
                DeckPickerList.UpdateDecks();
                if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
                {
                    HearthStatsManager.UpdateDeckAsync(deck, true, true);
                }
            }
        }
 private void SortFilterDecksFlyoutOnSelectedTagsChanged()
 {
     //only set tags if tags were changed in "My Decks"
     if (Name == nameof(Core.MainWindow.SortFilterDecksFlyout))
     {
         var tags = Tags.Where(tag => tag.Selected == true).Select(tag => tag.Name).ToList();
         Config.Instance.SelectedTags = tags;
         Config.Save();
         Core.MainWindow.DeckPickerList.UpdateDecks();
         Core.Windows.StatsWindow.StatsControl.LoadOverallStats();
         Core.MainWindow.DeckStatsFlyout.LoadOverallStats();
     }
     else if (Name == nameof(Core.MainWindow.TagControlEdit))
     {
         var tags   = Tags.Where(tag => tag.Selected == true).Select(tag => tag.Name).ToList();
         var ignore = Tags.Where(tag => tag.Selected == null).Select(tag => tag.Name).ToList();
         foreach (var deck in Core.MainWindow.DeckPickerList.SelectedDecks)
         {
             var keep = deck.Tags.Intersect(ignore);
             deck.Tags = new List <string>(tags.Concat(keep));
             deck.Edited();
             if (HearthStatsAPI.IsLoggedIn && Config.Instance.HearthStatsAutoUploadNewDecks)
             {
                 HearthStatsManager.UpdateDeckAsync(deck);
             }
         }
         Core.MainWindow.DeckPickerList.UpdateDecks(false);
         DeckList.Save();
         Core.MainWindow.UpdateQuickFilterItemSource();
     }
 }
Esempio n. 3
0
        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");
            }
        }
 public void SaveDeck()
 {
     if (!_noteChanged || _currentDeck == null)
     {
         return;
     }
     DeckList.Save();
     if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
     {
         Logger.WriteLine(string.Format("auto updating {0} deck", _currentDeck), "NoteDialog");
         HearthStatsManager.UpdateDeckAsync(_currentDeck, background: true);
     }
     _noteChanged      = false;
     BtnSave.IsEnabled = false;
     Helper.MainWindow.DeckPickerList.UpdateDecks();
 }
Esempio n. 5
0
 public void SaveDeck()
 {
     if (!_noteChanged || _currentDeck == null)
     {
         return;
     }
     DeckList.Save();
     if (Config.Instance.HearthStatsAutoUploadNewDecks && HearthStatsAPI.IsLoggedIn)
     {
         Log.Info($"auto updating {_currentDeck} deck");
         HearthStatsManager.UpdateDeckAsync(_currentDeck, background: true).Forget();
     }
     _noteChanged      = false;
     BtnSave.IsEnabled = false;
     Core.MainWindow.DeckPickerList.UpdateDecks();
 }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();
        }