Пример #1
0
        public void SelectDeck(Deck deck, bool setActive)
        {
            if (DeckList.Instance.ActiveDeck != null)
            {
                DeckPickerList.ClearFromCache(DeckList.Instance.ActiveDeck);
            }
            if (deck != null)
            {
                //set up notes
                DeckNotesEditor.SetDeck(deck);
                var flyoutHeader = deck.Name.Length >= 20 ? string.Join("", deck.Name.Take(17)) + "..." : deck.Name;
                FlyoutNotes.Header = flyoutHeader;

                //set up tags
                TagControlEdit.SetSelectedTags(DeckPickerList.SelectedDecks);
                MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                MenuItemQuickSetTag.Items.Refresh();
                DeckPickerList.MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                DeckPickerList.MenuItemQuickSetTag.Items.Refresh();


                //set and save last used deck for class
                if (setActive)
                {
                    //Overlay.ListViewPlayer.ItemsSource = Core.Game.PlayerDeck;
                    //PlayerWindow.ListViewPlayer.ItemsSource = Core.Game.PlayerDeck;
                    //Logger.WriteLine("Set player itemsource as PlayerDeck", "Tracker");
                    while (DeckList.Instance.LastDeckClass.Any(ldc => ldc.Class == deck.Class))
                    {
                        var lastSelected = DeckList.Instance.LastDeckClass.FirstOrDefault(ldc => ldc.Class == deck.Class);
                        if (lastSelected != null)
                        {
                            DeckList.Instance.LastDeckClass.Remove(lastSelected);
                        }
                        else
                        {
                            break;
                        }
                    }
                    DeckList.Instance.LastDeckClass.Add(new DeckInfo {
                        Class = deck.Class, Name = deck.Name, Id = deck.DeckId
                    });
                    DeckList.Save();

                    Logger.WriteLine("Switched to deck: " + deck.Name, "Tracker");

                    int useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("useNoDeck");
                    Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Checked = false;
                }
            }
            else
            {
                Core.Game.IsUsingPremade = false;

                if (DeckList.Instance.ActiveDeck != null)
                {
                    DeckList.Instance.ActiveDeck.IsSelectedInGui = false;
                }

                DeckList.Instance.ActiveDeck = null;
                if (setActive)
                {
                    DeckPickerList.DeselectDeck();
                    //Overlay.ListViewPlayer.ItemsSource = Core.Game.PlayerDrawn;
                    //PlayerWindow.ListViewPlayer.ItemsSource = Core.Game.PlayerDrawn;
                    //Logger.WriteLine("set player item source to PlayerDrawn", "Tracker");
                }

                int useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("useNoDeck");
                Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Checked = true;
            }

            //set up stats
            var statsTitle = string.Format("Stats{0}", deck == null ? "" : ": " + deck.Name);

            Core.Windows.StatsWindow.Title = statsTitle;
            FlyoutDeckStats.Header         = statsTitle;
            Core.Windows.StatsWindow.StatsControl.SetDeck(deck);
            DeckStatsFlyout.SetDeck(deck);

            if (setActive)
            {
                UseDeck(deck);
            }
            UpdateDeckList(deck);
            EnableMenuItems(deck != null);
            ManaCurveMyDecks.SetDeck(deck);
            UpdatePanelVersionComboBox(deck);
            if (setActive)
            {
                Core.Overlay.ListViewPlayer.Items.Refresh();
                Core.Windows.PlayerWindow.ListViewPlayer.Items.Refresh();
            }
            DeckManagerEvents.OnDeckSelected.Execute(deck);
        }
Пример #2
0
        public async void ShowIncorrectDeckMessage()
        {
            if (Core.Game.Player.DrawnCards.Count == 0)
            {
                IsShowingIncorrectDeckMessage = false;
                return;
            }

            //wait for player hero to be detected and at least 3 cards to be drawn
            for (var i = 0; i < 50; i++)
            {
                if (Core.Game.Player.Class != null && Core.Game.Player.DrawnCards.Count >= 3)
                {
                    break;
                }
                await Task.Delay(100);
            }
            if (string.IsNullOrEmpty(Core.Game.Player.Class) || Core.Game.Player.DrawnCards.Count < 3)
            {
                IsShowingIncorrectDeckMessage = false;
                Logger.WriteLine("No player hero detected or less then 3 cards drawn. Not showing dialog.", "IncorrectDeckMessage");
                return;
            }
            await Task.Delay(1000);

            var decks =
                DeckList.Instance.Decks.Where(
                    d =>
                    d.Class == Core.Game.Player.Class && !d.Archived && d.IsArenaRunCompleted != true &&
                    Core.Game.Player.DrawnCardIdsTotal.Distinct().All(id => d.GetSelectedDeckVersion().Cards.Any(c => id == c.Id)) &&
                    Core.Game.Player.DrawnCards.All(c => d.GetSelectedDeckVersion().Cards.Any(c2 => c2.Id == c.Id && c2.Count >= c.Count)))
                .ToList();

            Logger.WriteLine(decks.Count + " possible decks found.", "IncorrectDeckMessage");
            Core.Game.NoMatchingDeck = decks.Count == 0;

            if (decks.Count == 1 && Config.Instance.AutoSelectDetectedDeck)
            {
                var deck = decks.First();
                Logger.WriteLine("Automatically selected deck: " + deck.Name, "IncorrectDeckMessage");
                DeckPickerList.SelectDeck(deck);
                UpdateDeckList(deck);
                UseDeck(deck);
            }
            else
            {
                decks.Add(new Deck("Use no deck", "", new List <Card>(), new List <string>(), "", "", DateTime.Now, false, new List <Card>(),
                                   SerializableVersion.Default, new List <Deck>(), false, "", Guid.Empty, ""));
                if (decks.Count == 1 && DeckList.Instance.ActiveDeckVersion != null)
                {
                    decks.Add(new Deck("No match - Keep using active deck", "", new List <Card>(), new List <string>(), "", "", DateTime.Now, false, new List <Card>(),
                                       SerializableVersion.Default, new List <Deck>(), false, "", Guid.Empty, ""));
                }
                var dsDialog = new DeckSelectionDialog(decks);
                dsDialog.ShowDialog();

                var selectedDeck = dsDialog.SelectedDeck;

                if (selectedDeck != null)
                {
                    if (selectedDeck.Name == "Use no deck")
                    {
                        SelectDeck(null, true);
                    }
                    else if (selectedDeck.Name == "No match - Keep using active deck")
                    {
                        Core.Game.IgnoreIncorrectDeck = DeckList.Instance.ActiveDeck;
                        Logger.WriteLine(string.Format("Now ignoring {0} as an incorrect deck", DeckList.Instance.ActiveDeck.Name), "IncorrectDeckMessage");
                    }
                    else
                    {
                        Logger.WriteLine("Selected deck: " + selectedDeck.Name, "IncorrectDeckMessage");
                        DeckPickerList.SelectDeck(selectedDeck);
                        UpdateDeckList(selectedDeck);
                        UseDeck(selectedDeck);
                    }
                }
                else
                {
                    this.ShowMessage("Deck detection disabled.", "Can be re-enabled in \"DECKS\" menu.");
                    CheckboxDeckDetection.IsChecked = false;
                    Config.Save();
                }
            }

            IsShowingIncorrectDeckMessage = false;
            NeedToIncorrectDeckMessage    = false;
        }
Пример #3
0
        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");
        }
        internal void LoadConfigSettings()
        {
            if (Config.Instance.TrackerWindowTop.HasValue)
            {
                Top = Config.Instance.TrackerWindowTop.Value;
            }
            if (Config.Instance.TrackerWindowLeft.HasValue)
            {
                Left = Config.Instance.TrackerWindowLeft.Value;
            }

            if (Config.Instance.WindowHeight < 0)
            {
                Config.Instance.Reset("WindowHeight");
            }
            Height = Config.Instance.WindowHeight;
            if (Config.Instance.WindowWidth < 0)
            {
                Config.Instance.Reset("WindowWidth");
            }
            Width = Config.Instance.WindowWidth;
            var titleBarCorners = new[]
            {
                new Point((int)Left + 5, (int)Top + 5),
                new Point((int)(Left + Width) - 5, (int)Top + 5),
                new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
                new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
            };

            if (!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
            {
                Top  = 100;
                Left = 100;
            }

            if (Config.Instance.StartMinimized)
            {
                WindowState = WindowState.Minimized;
                if (Config.Instance.MinimizeToTray)
                {
                    MinimizeToTray();
                }
            }

            Options.Load(Core.Game);
            Help.TxtblockVersion.Text = "v" + Helper.GetCurrentVersion().ToVersionString();

            Core.TrayIcon.SetContextMenuProperty("autoSelectDeck", "Checked", Config.Instance.AutoDeckDetection);

            // Don't select the 'archived' class on load
            var selectedClasses = Config.Instance.SelectedDeckPickerClasses.Where(c => c.ToString() != "Archived").ToList();

            if (selectedClasses.Count == 0)
            {
                selectedClasses.Add(HeroClassAll.All);
            }

            DeckPickerList.SelectClasses(selectedClasses);
            DeckPickerList.SelectDeckType(Config.Instance.SelectedDeckPickerDeckType, true);
            DeckPickerList.UpdateAutoSelectToggleButton();

            SortFilterDecksFlyout.LoadTags(DeckList.Instance.AllTags);

            SortFilterDecksFlyout.SetSelectedTags(Config.Instance.SelectedTags);

            TagControlEdit.LoadTags(DeckList.Instance.AllTags.Where(tag => tag != "All" && tag != "None").ToList());
            SortFilterDecksFlyout.OperationSwitch.IsChecked = Config.Instance.TagOperation == TagFilerOperation.And;

            SortFilterDecksFlyout.ComboboxDeckSorting.SelectedItem      = Config.Instance.SelectedDeckSorting;
            SortFilterDecksFlyout.CheckBoxSortByClass.IsChecked         = Config.Instance.SortDecksByClass;
            SortFilterDecksFlyout.ComboboxDeckSortingArena.SelectedItem = Config.Instance.SelectedDeckSortingArena;
            SortFilterDecksFlyout.CheckBoxSortByClassArena.IsChecked    = Config.Instance.SortDecksByClassArena;

            if (!Helper.EventKeys.Contains(Config.Instance.KeyPressOnGameStart))
            {
                Config.Instance.KeyPressOnGameStart = "None";
            }

            if (!Helper.EventKeys.Contains(Config.Instance.KeyPressOnGameEnd))
            {
                Config.Instance.KeyPressOnGameEnd = "None";
            }

            ManaCurveMyDecks.Visibility = Config.Instance.ManaCurveMyDecks ? Visibility.Visible : Visibility.Collapsed;

            Core.TrayIcon.SetContextMenuProperty("classCardsFirst", "Checked", Config.Instance.CardSortingClassFirst);
            Core.TrayIcon.SetContextMenuProperty("useNoDeck", "Checked", DeckList.Instance.ActiveDeck == null);

            MenuItemCheckBoxSyncOnStart.IsChecked        = Config.Instance.HearthStatsSyncOnStart;
            MenuItemCheckBoxAutoUploadDecks.IsChecked    = Config.Instance.HearthStatsAutoUploadNewDecks;
            MenuItemCheckBoxAutoUploadGames.IsChecked    = Config.Instance.HearthStatsAutoUploadNewGames;
            MenuItemCheckBoxAutoSyncBackground.IsChecked = Config.Instance.HearthStatsAutoSyncInBackground;
            MenuItemCheckBoxAutoDeleteDecks.IsChecked    = Config.Instance.HearthStatsAutoDeleteDecks;
            MenuItemCheckBoxAutoDeleteGames.IsChecked    = Config.Instance.HearthStatsAutoDeleteMatches;
        }
Пример #5
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();
        }
Пример #6
0
        public MainWindow()
        {
            // Set working directory to path of executable
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            InitializeComponent();

            EnableMenuItems(false);

            try
            {
                if (File.Exists("Updater_new.exe"))
                {
                    if (File.Exists("Updater.exe"))
                    {
                        File.Delete("Updater.exe");
                    }
                    File.Move("Updater_new.exe", "Updater.exe");
                }
            }
            catch
            {
                Logger.WriteLine("Error updating updater");
            }

            Helper.MainWindow = this;
            /*_configPath =*/
            Config.Load();
            HsLogReader.Create();

            var configVersion = string.IsNullOrEmpty(Config.Instance.CreatedByVersion)
                                                                        ? null
                                                                        : new Version(Config.Instance.CreatedByVersion);

            Version currentVersion;

            if (Config.Instance.CheckForUpdates)
            {
                currentVersion   = Helper.CheckForUpdates(out NewVersion);
                _lastUpdateCheck = DateTime.Now;
            }
            else
            {
                currentVersion = Helper.GetCurrentVersion();
            }

            var versionString = string.Empty;

            if (currentVersion != null)
            {
                versionString             = string.Format("{0}.{1}.{2}", currentVersion.Major, currentVersion.Minor, currentVersion.Build);
                Help.TxtblockVersion.Text = "Version: " + versionString;

                // Assign current version to the config instance so that it will be saved when the config
                // is rewritten to disk, thereby telling us what version of the application created it
                Config.Instance.CreatedByVersion = currentVersion.ToString();
            }

            ConvertLegacyConfig(currentVersion, configVersion);

            if (Config.Instance.SelectedTags.Count == 0)
            {
                Config.Instance.SelectedTags.Add("All");
            }

            if (Config.Instance.GenerateLog)
            {
                Directory.CreateDirectory("Logs");
                var listener = new TextWriterTraceListener(Config.Instance.LogFilePath);
                Trace.Listeners.Add(listener);
                Trace.AutoFlush = true;
            }

            _foundHsDirectory = FindHearthstoneDir();

            if (_foundHsDirectory)
            {
                _updatedLogConfig = UpdateLogConfigFile();
            }

            //hearthstone, loads db etc - needs to be loaded before playerdecks, since cards are only saved as ids now
            Game.Reset();

            _decksPath = Config.Instance.DataDir + "PlayerDecks.xml";
            SetupDeckListFile();
            try
            {
                DeckList = XmlManager <Decks> .Load(_decksPath);
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException +
                    "\n\n If you don't know how to fix this, please delete " + _decksPath +
                    " (this will cause you to lose your decks).",
                    "Error loading PlayerDecks.xml");
                Application.Current.Shutdown();
            }

            foreach (var deck in DeckList.DecksList)
            {
                DeckPickerList.AddDeck(deck);
            }

            SetupDeckStatsFile();
            DeckStatsList.Load();

            _notifyIcon = new NotifyIcon {
                Icon = new Icon(@"Images/HearthstoneDeckTracker16.ico"), Visible = true, ContextMenu = new ContextMenu(), Text = "Hearthstone Deck Tracker v" + versionString
            };
            _notifyIcon.ContextMenu.MenuItems.Add("Show", (sender, args) => ActivateWindow());
            _notifyIcon.ContextMenu.MenuItems.Add("Exit", (sender, args) => Close());
            _notifyIcon.MouseClick += (sender, args) => { if (args.Button == MouseButtons.Left)
                                                          {
                                                              ActivateWindow();
                                                          }
            };

            //create overlay
            Overlay = new OverlayWindow {
                Topmost = true
            };

            PlayerWindow   = new PlayerWindow(Config.Instance, Game.IsUsingPremade ? Game.PlayerDeck : Game.PlayerDrawn);
            OpponentWindow = new OpponentWindow(Config.Instance, Game.OpponentCards);
            TimerWindow    = new TimerWindow(Config.Instance);
            StatsWindow    = new StatsWindow();

            if (Config.Instance.PlayerWindowOnStart)
            {
                PlayerWindow.Show();
            }
            if (Config.Instance.OpponentWindowOnStart)
            {
                OpponentWindow.Show();
            }
            if (Config.Instance.TimerWindowOnStartup)
            {
                TimerWindow.Show();
            }
            if (!DeckList.AllTags.Contains("All"))
            {
                DeckList.AllTags.Add("All");
                WriteDecks();
            }
            if (!DeckList.AllTags.Contains("Arena"))
            {
                DeckList.AllTags.Add("Arena");
                WriteDecks();
            }
            if (!DeckList.AllTags.Contains("Constructed"))
            {
                DeckList.AllTags.Add("Constructed");
                WriteDecks();
            }

            Options.ComboboxAccent.ItemsSource    = ThemeManager.Accents;
            Options.ComboboxTheme.ItemsSource     = ThemeManager.AppThemes;
            Options.ComboboxLanguages.ItemsSource = Helper.LanguageDict.Keys;

            Options.ComboboxKeyPressGameStart.ItemsSource = EventKeys;
            Options.ComboboxKeyPressGameEnd.ItemsSource   = EventKeys;

            LoadConfig();

            FillElementSorters();

            //this has to happen before reader starts
            var lastDeck = DeckList.DecksList.FirstOrDefault(d => d.Name == Config.Instance.LastDeck);

            DeckPickerList.SelectDeck(lastDeck);

            TurnTimer.Create(90);

            SortFilterDecksFlyout.HideStuffToCreateNewTag();
            TagControlEdit.OperationSwitch.Visibility = Visibility.Collapsed;
            TagControlEdit.PnlSortDecks.Visibility    = Visibility.Collapsed;


            UpdateDbListView();

            _doUpdate = _foundHsDirectory;
            UpdateOverlayAsync();

            _initialized = true;
            Options.MainWindowInitialized();

            DeckPickerList.UpdateList();
            if (lastDeck != null)
            {
                DeckPickerList.SelectDeck(lastDeck);
                UpdateDeckList(lastDeck);
                UseDeck(lastDeck);
            }

            if (_foundHsDirectory)
            {
                HsLogReader.Instance.Start();
            }

            Helper.SortCardCollection(ListViewDeck.Items, Config.Instance.CardSortingClassFirst);
            DeckPickerList.SortDecks();
        }
        public void SelectDeck(Deck deck, bool setActive)
        {
            if (DeckList.Instance.ActiveDeck != null)
            {
                DeckPickerList.ClearFromCache(DeckList.Instance.ActiveDeck);
            }
            if (deck != null)
            {
                //set up tags
                TagControlEdit.SetSelectedTags(DeckPickerList.SelectedDecks);
                DeckPickerList.MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                DeckPickerList.MenuItemQuickSetTag.Items.Refresh();

                OnPropertyChanged(nameof(HsReplayButtonVisibility));

                //set and save last used deck for class
                if (setActive)
                {
                    while (DeckList.Instance.LastDeckClass.Any(ldc => ldc.Class == deck.Class))
                    {
                        var lastSelected = DeckList.Instance.LastDeckClass.FirstOrDefault(ldc => ldc.Class == deck.Class);
                        if (lastSelected != null)
                        {
                            DeckList.Instance.LastDeckClass.Remove(lastSelected);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (Core.Initialized)
                    {
                        DeckList.Instance.LastDeckClass.Add(new DeckInfo {
                            Class = deck.Class, Name = deck.Name, Id = deck.DeckId
                        });
                        DeckList.Save();
                    }

                    Log.Info($"Switched to deck: {deck.Name} ({deck.SelectedVersion.ShortVersionString})");
                    Core.TrayIcon.MenuItemUseNoDeck.Checked = false;
                }

                if (FlyoutDeckScreenshot.IsOpen)
                {
                    DeckScreenshotFlyout.Deck = deck.GetSelectedDeckVersion();
                }
                if (FlyoutDeckExport.IsOpen)
                {
                    DeckExportFlyout.Deck = deck.GetSelectedDeckVersion();
                }

                if (FlyoutDeckHistory.IsOpen)
                {
                    if (deck.HasVersions)
                    {
                        DeckHistoryFlyout.Deck = deck;
                    }
                    else
                    {
                        FlyoutDeckHistory.IsOpen = false;
                    }
                }
            }
            else
            {
                Core.Game.IsUsingPremade = false;

                if (DeckList.Instance.ActiveDeck != null)
                {
                    DeckList.Instance.ActiveDeck.IsSelectedInGui = false;
                }

                DeckList.Instance.ActiveDeck = null;
                if (setActive)
                {
                    DeckPickerList.DeselectDeck();
                }

                Core.TrayIcon.MenuItemUseNoDeck.Checked = true;
            }

            if (setActive)
            {
                UseDeck(deck);
            }
            DeckPickerList.SelectDeck(deck);
            UpdateDeckList(deck);
            ManaCurveMyDecks.SetDeck(deck);
            UpdatePanelVersionComboBox(deck);
            GroupBoxHsReplayDeckInfo.Visibility = deck?.IsArenaDeck == true ? Collapsed : Visible;
            if (setActive)
            {
                Core.Overlay.ListViewPlayer.Items.Refresh();
                Core.Windows.PlayerWindow.ListViewPlayer.Items.Refresh();
            }
            DeckManagerEvents.OnDeckSelected.Execute(deck);
        }
Пример #8
0
        private void LoadConfig()
        {
            if (Config.Instance.TrackerWindowTop.HasValue)
            {
                Top = Config.Instance.TrackerWindowTop.Value;
            }
            if (Config.Instance.TrackerWindowLeft.HasValue)
            {
                Left = Config.Instance.TrackerWindowLeft.Value;
            }

            var titleBarCorners = new[]
            {
                new Point((int)Left + 5, (int)Top + 5),
                new Point((int)(Left + Width) - 5, (int)Top + 5),
                new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
                new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
            };

            if (!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
            {
                Top  = 100;
                Left = 100;
            }

            if (Config.Instance.StartMinimized)
            {
                WindowState = WindowState.Minimized;
                if (Config.Instance.MinimizeToTray)
                {
                    MinimizeToTray();
                }
            }

            var theme = string.IsNullOrEmpty(Config.Instance.ThemeName)
                                                        ? ThemeManager.DetectAppStyle().Item1
                                                        : ThemeManager.AppThemes.First(t => t.Name == Config.Instance.ThemeName);
            var accent = string.IsNullOrEmpty(Config.Instance.AccentName)
                                                         ? ThemeManager.DetectAppStyle().Item2
                                                         : ThemeManager.Accents.First(a => a.Name == Config.Instance.AccentName);

            ThemeManager.ChangeAppStyle(Application.Current, accent, theme);
            Options.ComboboxTheme.SelectedItem  = theme;
            Options.ComboboxAccent.SelectedItem = accent;


            Height = Config.Instance.WindowHeight;
            Width  = Config.Instance.WindowWidth;
            Game.HighlightCardsInHand = Config.Instance.HighlightCardsInHand;
            Game.HighlightDiscarded   = Config.Instance.HighlightDiscarded;
            Options.CheckboxHideOverlayInBackground.IsChecked         = Config.Instance.HideInBackground;
            Options.CheckboxHideOpponentCardAge.IsChecked             = Config.Instance.HideOpponentCardAge;
            Options.CheckboxHideOpponentCardMarks.IsChecked           = Config.Instance.HideOpponentCardMarks;
            Options.CheckboxHideOverlayInMenu.IsChecked               = Config.Instance.HideInMenu;
            Options.CheckboxHighlightCardsInHand.IsChecked            = Config.Instance.HighlightCardsInHand;
            Options.CheckboxHideOverlay.IsChecked                     = Config.Instance.HideOverlay;
            Options.CheckboxHideDecksInOverlay.IsChecked              = Config.Instance.HideDecksInOverlay;
            Options.CheckboxKeepDecksVisible.IsChecked                = Config.Instance.KeepDecksVisible;
            Options.CheckboxMinimizeTray.IsChecked                    = Config.Instance.MinimizeToTray;
            Options.CheckboxWindowsTopmost.IsChecked                  = Config.Instance.WindowsTopmost;
            Options.CheckboxPlayerWindowOpenAutomatically.IsChecked   = Config.Instance.PlayerWindowOnStart;
            Options.CheckboxOpponentWindowOpenAutomatically.IsChecked = Config.Instance.OpponentWindowOnStart;
            Options.CheckboxTimerTopmost.IsChecked                    = Config.Instance.TimerWindowTopmost;
            Options.CheckboxTimerWindow.IsChecked                     = Config.Instance.TimerWindowOnStartup;
            Options.CheckboxTimerTopmostHsForeground.IsChecked        = Config.Instance.TimerWindowTopmostIfHsForeground;
            Options.CheckboxTimerTopmostHsForeground.IsEnabled        = Config.Instance.TimerWindowTopmost;
            Options.CheckboxSameScaling.IsChecked                     = Config.Instance.UseSameScaling;
            CheckboxDeckDetection.IsChecked = Config.Instance.AutoDeckDetection;
            Options.CheckboxWinTopmostHsForeground.IsChecked = Config.Instance.WindowsTopmostIfHsForeground;
            Options.CheckboxWinTopmostHsForeground.IsEnabled = Config.Instance.WindowsTopmost;
            Options.CheckboxAutoSelectDeck.IsEnabled         = Config.Instance.AutoDeckDetection;
            Options.CheckboxAutoSelectDeck.IsChecked         = Config.Instance.AutoSelectDetectedDeck;
            Options.CheckboxExportName.IsChecked             = Config.Instance.ExportSetDeckName;
            Options.CheckboxPrioGolden.IsChecked             = Config.Instance.PrioritizeGolden;
            Options.CheckboxBringHsToForegorund.IsChecked    = Config.Instance.BringHsToForeground;
            Options.CheckboxFlashHs.IsChecked                   = Config.Instance.FlashHsOnTurnStart;
            Options.CheckboxHideSecrets.IsChecked               = Config.Instance.HideSecrets;
            Options.CheckboxHighlightDiscarded.IsChecked        = Config.Instance.HighlightDiscarded;
            Options.CheckboxRemoveCards.IsChecked               = Config.Instance.RemoveCardsFromDeck;
            Options.CheckboxHighlightLastDrawn.IsChecked        = Config.Instance.HighlightLastDrawn;
            Options.CheckboxStartMinimized.IsChecked            = Config.Instance.StartMinimized;
            Options.CheckboxShowPlayerGet.IsChecked             = Config.Instance.ShowPlayerGet;
            Options.ToggleSwitchExtraFeatures.IsChecked         = Config.Instance.ExtraFeatures;
            Options.CheckboxCheckForUpdates.IsChecked           = Config.Instance.CheckForUpdates;
            Options.CheckboxRecordArena.IsChecked               = Config.Instance.RecordArena;
            Options.CheckboxRecordCasual.IsChecked              = Config.Instance.RecordCasual;
            Options.CheckboxRecordFriendly.IsChecked            = Config.Instance.RecordFriendly;
            Options.CheckboxRecordOther.IsChecked               = Config.Instance.RecordOther;
            Options.CheckboxRecordPractice.IsChecked            = Config.Instance.RecordPractice;
            Options.CheckboxRecordRanked.IsChecked              = Config.Instance.RecordRanked;
            Options.CheckboxFullTextSearch.IsChecked            = Config.Instance.UseFullTextSearch;
            Options.CheckboxDiscardGame.IsChecked               = Config.Instance.DiscardGameIfIncorrectDeck;
            Options.CheckboxExportPasteClipboard.IsChecked      = Config.Instance.ExportPasteClipboard;
            Options.CheckboxGoldenFeugen.IsChecked              = Config.Instance.OwnsGoldenFeugen;
            Options.CheckboxGoldenStalagg.IsChecked             = Config.Instance.OwnsGoldenStalagg;
            Options.CheckboxCloseWithHearthstone.IsChecked      = Config.Instance.CloseWithHearthstone;
            Options.CheckboxStatsInWindow.IsChecked             = Config.Instance.StatsInWindow;
            Options.CheckboxOverlaySecretToolTipsOnly.IsChecked = Config.Instance.OverlaySecretToolTipsOnly;
            Options.CheckboxTagOnImport.IsChecked               = Config.Instance.TagDecksOnImport;
            Options.CheckboxConfigSaveAppData.IsChecked         = Config.Instance.SaveConfigInAppData;
            Options.CheckboxDataSaveAppData.IsChecked           = Config.Instance.SaveDataInAppData;

            Options.SliderOverlayOpacity.Value         = Config.Instance.OverlayOpacity;
            Options.SliderOpponentOpacity.Value        = Config.Instance.OpponentOpacity;
            Options.SliderPlayerOpacity.Value          = Config.Instance.PlayerOpacity;
            Options.SliderOverlayPlayerScaling.Value   = Config.Instance.OverlayPlayerScaling;
            Options.SliderOverlayOpponentScaling.Value = Config.Instance.OverlayOpponentScaling;

            DeckPickerList.ShowAll = Config.Instance.ShowAllDecks;
            DeckPickerList.SetSelectedTags(Config.Instance.SelectedTags);

            Options.CheckboxHideTimers.IsChecked = Config.Instance.HideTimers;

            var delay = Config.Instance.DeckExportDelay;

            Options.ComboboxExportSpeed.SelectedIndex = delay < 40 ? 0 : delay < 60 ? 1 : delay < 100 ? 2 : delay < 150 ? 3 : 4;

            SortFilterDecksFlyout.LoadTags(DeckList.AllTags);

            SortFilterDecksFlyout.SetSelectedTags(Config.Instance.SelectedTags);
            DeckPickerList.SetSelectedTags(Config.Instance.SelectedTags);

            var tags = new List <string>(DeckList.AllTags);

            tags.Remove("All");
            TagControlEdit.LoadTags(tags);
            DeckPickerList.SetTagOperation(Config.Instance.TagOperation);
            SortFilterDecksFlyout.OperationSwitch.IsChecked = Config.Instance.TagOperation == Operation.And;

            SortFilterDecksFlyout.ComboboxDeckSorting.SelectedItem = Config.Instance.SelectedDeckSorting;

            Options.ComboboxWindowBackground.SelectedItem = Config.Instance.SelectedWindowBackground;
            Options.TextboxCustomBackground.IsEnabled     = Config.Instance.SelectedWindowBackground == "Custom";
            Options.TextboxCustomBackground.Text          = string.IsNullOrEmpty(Config.Instance.WindowsBackgroundHex)
                                                                                                           ? "#696969"
                                                                                                           : Config.Instance.WindowsBackgroundHex;
            Options.UpdateAdditionalWindowsBackground();

            if (Helper.LanguageDict.Values.Contains(Config.Instance.SelectedLanguage))
            {
                Options.ComboboxLanguages.SelectedItem = Helper.LanguageDict.First(x => x.Value == Config.Instance.SelectedLanguage).Key;
            }

            if (!EventKeys.Contains(Config.Instance.KeyPressOnGameStart))
            {
                Config.Instance.KeyPressOnGameStart = "None";
            }
            Options.ComboboxKeyPressGameStart.SelectedValue = Config.Instance.KeyPressOnGameStart;

            if (!EventKeys.Contains(Config.Instance.KeyPressOnGameEnd))
            {
                Config.Instance.KeyPressOnGameEnd = "None";
            }
            Options.ComboboxKeyPressGameEnd.SelectedValue = Config.Instance.KeyPressOnGameEnd;

            Options.CheckboxHideManaCurveMyDecks.IsChecked = Config.Instance.ManaCurveMyDecks;
            ManaCurveMyDecks.Visibility = Config.Instance.ManaCurveMyDecks ? Visibility.Visible : Visibility.Collapsed;

            Options.CheckboxTrackerCardToolTips.IsChecked           = Config.Instance.TrackerCardToolTips;
            Options.CheckboxWindowCardToolTips.IsChecked            = Config.Instance.WindowCardToolTips;
            Options.CheckboxOverlayCardToolTips.IsChecked           = Config.Instance.OverlayCardToolTips;
            Options.CheckboxOverlayAdditionalCardToolTips.IsEnabled = Config.Instance.OverlayCardToolTips;
            Options.CheckboxOverlayAdditionalCardToolTips.IsChecked = Config.Instance.AdditionalOverlayTooltips;

            Options.CheckboxDeckSortingClassFirst.IsChecked = Config.Instance.CardSortingClassFirst;

            DeckStatsFlyout.LoadConfig();
            GameDetailsFlyout.LoadConfig();
            StatsWindow.StatsControl.LoadConfig();
            StatsWindow.GameDetailsFlyout.LoadConfig();
        }
        public void SelectDeck(Deck deck, bool setActive)
        {
            if (DeckList.Instance.ActiveDeck != null)
            {
                DeckPickerList.ClearFromCache(DeckList.Instance.ActiveDeck);
            }
            if (deck != null)
            {
                //set up notes
                DeckNotesEditor.SetDeck(deck);
                var flyoutHeader = deck.Name.Length >= 20 ? string.Join("", deck.Name.Take(17)) + "..." : deck.Name;
                FlyoutNotes.Header = flyoutHeader;

                //set up tags
                TagControlEdit.SetSelectedTags(DeckPickerList.SelectedDecks);
                MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                MenuItemQuickSetTag.Items.Refresh();
                DeckPickerList.MenuItemQuickSetTag.ItemsSource = TagControlEdit.Tags;
                DeckPickerList.MenuItemQuickSetTag.Items.Refresh();


                //set and save last used deck for class
                if (setActive)
                {
                    while (DeckList.Instance.LastDeckClass.Any(ldc => ldc.Class == deck.Class))
                    {
                        var lastSelected = DeckList.Instance.LastDeckClass.FirstOrDefault(ldc => ldc.Class == deck.Class);
                        if (lastSelected != null)
                        {
                            DeckList.Instance.LastDeckClass.Remove(lastSelected);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (Core.Initialized)
                    {
                        DeckList.Instance.LastDeckClass.Add(new DeckInfo {
                            Class = deck.Class, Name = deck.Name, Id = deck.DeckId
                        });
                        DeckList.Save();
                    }

                    Log.Info($"Switched to deck: {deck.Name} ({deck.SelectedVersion.ShortVersionString})");

                    int useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey(TrayIcon.UseNoDeckMenuItemName);
                    Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Checked = false;
                }
            }
            else
            {
                Core.Game.IsUsingPremade = false;

                if (DeckList.Instance.ActiveDeck != null)
                {
                    DeckList.Instance.ActiveDeck.IsSelectedInGui = false;
                }

                DeckList.Instance.ActiveDeck = null;
                if (setActive)
                {
                    DeckPickerList.DeselectDeck();
                }

                var useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey(TrayIcon.UseNoDeckMenuItemName);
                Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Checked = true;
            }

            if (setActive)
            {
                UseDeck(deck);
            }
            DeckPickerList.SelectDeck(deck);
            UpdateDeckList(deck);
            EnableMenuItems(deck != null);
            ManaCurveMyDecks.SetDeck(deck);
            UpdatePanelVersionComboBox(deck);
            if (setActive)
            {
                Core.Overlay.ListViewPlayer.Items.Refresh();
                Core.Windows.PlayerWindow.ListViewPlayer.Items.Refresh();
            }
            DeckManagerEvents.OnDeckSelected.Execute(deck);
        }
        private void LoadConfig()
        {
            if (Config.Instance.TrackerWindowTop.HasValue)
            {
                Top = Config.Instance.TrackerWindowTop.Value;
            }
            if (Config.Instance.TrackerWindowLeft.HasValue)
            {
                Left = Config.Instance.TrackerWindowLeft.Value;
            }

            if (Config.Instance.WindowHeight < 0)
            {
                Config.Instance.Reset("WindowHeight");
            }
            Height = Config.Instance.WindowHeight;
            if (Config.Instance.WindowWidth < 0)
            {
                Config.Instance.Reset("WindowWidth");
            }
            Width = Config.Instance.WindowWidth;
            var titleBarCorners = new[]
            {
                new Point((int)Left + 5, (int)Top + 5),
                new Point((int)(Left + Width) - 5, (int)Top + 5),
                new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
                new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
            };

            if (!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
            {
                Top  = 100;
                Left = 100;
            }

            if (Config.Instance.StartMinimized)
            {
                WindowState = WindowState.Minimized;
                if (Config.Instance.MinimizeToTray)
                {
                    MinimizeToTray();
                }
            }

            var theme = string.IsNullOrEmpty(Config.Instance.ThemeName)
                                            ? ThemeManager.DetectAppStyle().Item1 : ThemeManager.AppThemes.First(t => t.Name == Config.Instance.ThemeName);
            var accent = string.IsNullOrEmpty(Config.Instance.AccentName)
                                             ? ThemeManager.DetectAppStyle().Item2 : ThemeManager.Accents.First(a => a.Name == Config.Instance.AccentName);

            ThemeManager.ChangeAppStyle(Application.Current, accent, theme);

            Options.Load();


            Game.HighlightCardsInHand       = Config.Instance.HighlightCardsInHand;
            Game.HighlightDiscarded         = Config.Instance.HighlightDiscarded;
            CheckboxDeckDetection.IsChecked = Config.Instance.AutoDeckDetection;
            SetContextMenuProperty("autoSelectDeck", "Checked", (bool)CheckboxDeckDetection.IsChecked);

            // Don't select the 'archived' class on load
            var selectedClasses = Config.Instance.SelectedDeckPickerClasses.Where(c => c.ToString() != "Archived").ToList();

            if (selectedClasses.Count == 0)
            {
                selectedClasses.Add(HeroClassAll.All);
            }

            DeckPickerList.SelectClasses(selectedClasses);
            DeckPickerList.SelectDeckType(Config.Instance.SelectedDeckType, true);

            SortFilterDecksFlyout.LoadTags(DeckList.Instance.AllTags);

            UpdateQuickFilterItemSource();

            SortFilterDecksFlyout.SetSelectedTags(Config.Instance.SelectedTags);

            TagControlEdit.LoadTags(DeckList.Instance.AllTags.Where(tag => tag != "All" && tag != "None").ToList());
            SortFilterDecksFlyout.OperationSwitch.IsChecked = Config.Instance.TagOperation == TagFilerOperation.And;

            SortFilterDecksFlyout.ComboboxDeckSorting.SelectedItem = Config.Instance.SelectedDeckSorting;

            if (!EventKeys.Contains(Config.Instance.KeyPressOnGameStart))
            {
                Config.Instance.KeyPressOnGameStart = "None";
            }

            if (!EventKeys.Contains(Config.Instance.KeyPressOnGameEnd))
            {
                Config.Instance.KeyPressOnGameEnd = "None";
            }

            ManaCurveMyDecks.Visibility = Config.Instance.ManaCurveMyDecks ? Visibility.Visible : Visibility.Collapsed;
            ManaCurveMyDecks.ListViewStatType.SelectedIndex = (int)Config.Instance.ManaCurveFilter;

            CheckboxClassCardsFirst.IsChecked = Config.Instance.CardSortingClassFirst;
            SetContextMenuProperty("classCardsFirst", "Checked", (bool)CheckboxClassCardsFirst.IsChecked);
            SetContextMenuProperty("useNoDeck", "Checked", DeckList.Instance.ActiveDeck == null);


            DeckStatsFlyout.LoadConfig();
            GameDetailsFlyout.LoadConfig();
            StatsWindow.StatsControl.LoadConfig();
            StatsWindow.GameDetailsFlyout.LoadConfig();

            MenuItemCheckBoxSyncOnStart.IsChecked        = Config.Instance.HearthStatsSyncOnStart;
            MenuItemCheckBoxAutoUploadDecks.IsChecked    = Config.Instance.HearthStatsAutoUploadNewDecks;
            MenuItemCheckBoxAutoUploadGames.IsChecked    = Config.Instance.HearthStatsAutoUploadNewGames;
            MenuItemCheckBoxAutoSyncBackground.IsChecked = Config.Instance.HearthStatsAutoSyncInBackground;
            MenuItemCheckBoxAutoDeleteDecks.IsChecked    = Config.Instance.HearthStatsAutoDeleteDecks;
            MenuItemCheckBoxAutoDeleteGames.IsChecked    = Config.Instance.HearthStatsAutoDeleteMatches;
        }
Пример #11
0
        private async void BtnCloneSelectedVersion_Click(object sender, RoutedEventArgs e)
        {
            var deck = DeckList.Instance.ActiveDeckVersion;

            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);

            clone.ResetVersions();

            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.UpdateDecks();
            HearthStatsManager.UploadDeckAsync(clone);
        }
Пример #12
0
        private async void SaveDeck(bool overwrite)
        {
            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;
                }
            }

            if (EditingDeck && overwrite)
            {
                DeckList.DecksList.Remove(_newDeck);
                DeckPickerList.RemoveDeck(_newDeck);
            }

            var oldDeckName = _newDeck.Name;

            _newDeck.Name = deckName;

            var newDeckClone = (Deck)_newDeck.Clone();

            DeckList.DecksList.Add(newDeckClone);

            newDeckClone.LastEdited = DateTime.Now;

            WriteDecks();
            Logger.WriteLine("Saved Decks");

            if (EditingDeck)
            {
                TagControlEdit.SetSelectedTags(new List <string>());
                if (deckName != oldDeckName)
                {
                    var statsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(d => d.Name == oldDeckName);
                    if (statsEntry != null)
                    {
                        if (overwrite)
                        {
                            statsEntry.Name = deckName;
                            Logger.WriteLine("Deck has new name, updated deckstats");
                        }
                        else
                        {
                            var newStatsEntry = DeckStatsList.Instance.DeckStats.FirstOrDefault(d => d.Name == deckName);
                            if (newStatsEntry == null)
                            {
                                newStatsEntry = new DeckStats(deckName);
                                DeckStatsList.Instance.DeckStats.Add(newStatsEntry);
                            }
                            foreach (var game in statsEntry.Games)
                            {
                                newStatsEntry.AddGameResult(game.CloneWithNewId());
                            }
                            Logger.WriteLine("cloned gamestats for \"Set as new\"");
                        }
                        DeckStatsList.Save();
                    }
                }
            }

            //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.UpdateList();
            DeckPickerList.SelectDeck(newDeckClone);

            CloseNewDeck();
            ClearNewDeckSection();
        }
Пример #13
0
        private async void BtnSaveDeck_Click(object sender, RoutedEventArgs e)
        {
            //NewDeck.Cards =
            //	new ObservableCollection<Card>(
            //		NewDeck.Cards.OrderBy(c => c.Cost).ThenByDescending(c => c.Type).ThenBy(c => c.Name).ToList());
            //ListViewNewDeck.ItemsSource = NewDeck.Cards;
            var deckName = TextBoxDeckName.Text;

            if (EditingDeck)
            {
                var settings = new MetroDialogSettings {
                    AffirmativeButtonText = "Overwrite", NegativeButtonText = "Save as new"
                };
                var result =
                    await
                    this.ShowMessageAsync("Saving deck", "How do you wish to save the deck?", MessageDialogStyle.AffirmativeAndNegative,
                                          settings);

                if (result == MessageDialogResult.Affirmative)
                {
                    SaveDeck(true);
                }
                else if (result == MessageDialogResult.Negative)
                {
                    SaveDeck(false);
                }
            }
            else if (DeckList.DecksList.Any(d => d.Name == deckName))
            {
                var settings = new MetroDialogSettings {
                    AffirmativeButtonText = "Overwrite", NegativeButtonText = "Set new name"
                };
                var result =
                    await
                    this.ShowMessageAsync("A deck with that name already exists", "Overwriting the deck can not be undone!",
                                          MessageDialogStyle.AffirmativeAndNegative, settings);

                if (result == MessageDialogResult.Affirmative)
                {
                    Deck oldDeck;
                    while ((oldDeck = DeckList.DecksList.FirstOrDefault(d => d.Name == deckName)) != null)
                    {
                        var deckStats = DeckStatsList.Instance.DeckStats.FirstOrDefault(ds => ds.Name == oldDeck.Name);
                        if (deckStats != null)
                        {
                            foreach (var game in deckStats.Games)
                            {
                                game.DeleteGameFile();
                            }
                            DeckStatsList.Instance.DeckStats.Remove(deckStats);
                            DeckStatsList.Save();
                            Logger.WriteLine("Deleted deckstats for deck: " + oldDeck.Name);
                        }
                        DeckList.DecksList.Remove(oldDeck);
                        DeckPickerList.RemoveDeck(oldDeck);
                    }

                    SaveDeck(true);
                }
                else if (result == MessageDialogResult.Negative)
                {
                    SaveDeck(false);
                }
            }
            else
            {
                SaveDeck(false);
            }

            editedDeckName = string.Empty;
        }
        private async void BtnScreenhot_Click(object sender, RoutedEventArgs e)
        {
            if (DeckPickerList.SelectedDeck == null)
            {
                return;
            }
            Logger.WriteLine("Creating screenshot of " + DeckPickerList.GetSelectedDeckVersion().GetDeckInfo(), "Screenshot");
            var screenShotWindow = new PlayerWindow(Config.Instance, DeckPickerList.GetSelectedDeckVersion().Cards, true);

            screenShotWindow.Show();
            screenShotWindow.Top  = 0;
            screenShotWindow.Left = 0;
            await Task.Delay(100);

            var source = PresentationSource.FromVisual(screenShotWindow);

            if (source == null)
            {
                return;
            }

            var dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11;
            var dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22;

            var fileName = Helper.ScreenshotDeck(screenShotWindow.ListViewPlayer, dpiX, dpiY, DeckPickerList.GetSelectedDeckVersion().Name);

            screenShotWindow.Shutdown();
            if (fileName == null)
            {
                await this.ShowMessageAsync("", "Error saving screenshot");
            }
            else
            {
                await ShowSavedFileMessage(fileName, "Screenshots");
            }
        }
Пример #15
0
        internal void LoadConfigSettings()
        {
            if (Config.Instance.TrackerWindowTop.HasValue)
            {
                Top = Config.Instance.TrackerWindowTop.Value;
            }
            if (Config.Instance.TrackerWindowLeft.HasValue)
            {
                Left = Config.Instance.TrackerWindowLeft.Value;
            }

            if (Config.Instance.WindowHeight < 0)
            {
                Config.Instance.Reset("WindowHeight");
            }
            Height = Config.Instance.WindowHeight;
            if (Config.Instance.WindowWidth < 0)
            {
                Config.Instance.Reset("WindowWidth");
            }
            Width = Config.Instance.WindowWidth;
            var titleBarCorners = new[]
            {
                new Point((int)Left + 5, (int)Top + 5),
                new Point((int)(Left + Width) - 5, (int)Top + 5),
                new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
                new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
            };

            if (!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
            {
                Top  = 100;
                Left = 100;
            }

            if (Config.Instance.StartMinimized)
            {
                WindowState = WindowState.Minimized;
                if (Config.Instance.MinimizeToTray)
                {
                    MinimizeToTray();
                }
            }

            Options.Load(Core.Game);

            Core.TrayIcon.MenuItemAutoSelect.Checked = Config.Instance.AutoDeckDetection;

            // Don't select the 'archived' class on load
            var selectedClasses = Config.Instance.SelectedDeckPickerClasses.Where(c => c.ToString() != "Archived").ToList();

            if (selectedClasses.Count == 0)
            {
                selectedClasses.Add(HeroClassAll.All);
            }

            DeckPickerList.SelectClasses(selectedClasses);
            DeckPickerList.SelectDeckType(Config.Instance.SelectedDeckPickerDeckType, true);

            SortFilterDecksFlyout.LoadTags(DeckList.Instance.AllTags);

            SortFilterDecksFlyout.SetSelectedTags(Config.Instance.SelectedTags);

            TagControlEdit.LoadTags(DeckList.Instance.AllTags.Where(tag => tag != "All" && tag != "None").ToList());
            SortFilterDecksFlyout.OperationSwitch.IsChecked = Config.Instance.TagOperation == TagFilerOperation.And;

            SortFilterDecksFlyout.ComboboxDeckSorting.SelectedItem      = Config.Instance.SelectedDeckSorting;
            SortFilterDecksFlyout.CheckBoxSortByClass.IsChecked         = Config.Instance.SortDecksByClass;
            SortFilterDecksFlyout.CheckBoxSortFavorites.IsChecked       = Config.Instance.SortDecksFavoritesFirst;
            SortFilterDecksFlyout.ComboboxDeckSortingArena.SelectedItem = Config.Instance.SelectedDeckSortingArena;
            SortFilterDecksFlyout.CheckBoxSortByClassArena.IsChecked    = Config.Instance.SortDecksByClassArena;

            ManaCurveMyDecks.Visibility = Config.Instance.ManaCurveMyDecks ? Visibility.Visible : Visibility.Collapsed;

            Core.TrayIcon.MenuItemClassCardsFirst.Checked = Config.Instance.CardSortingClassFirst;
            Core.TrayIcon.MenuItemUseNoDeck.Checked       = DeckList.Instance.ActiveDeck == null;

            UpdateMyGamesPanelVisibility();
        }
        private void LoadConfig()
        {
            if (Config.Instance.TrackerWindowTop.HasValue)
            {
                Top = Config.Instance.TrackerWindowTop.Value;
            }
            if (Config.Instance.TrackerWindowLeft.HasValue)
            {
                Left = Config.Instance.TrackerWindowLeft.Value;
            }

            if (Config.Instance.WindowHeight < 0)
            {
                Config.Instance.Reset("WindowHeight");
            }
            Height = Config.Instance.WindowHeight;
            if (Config.Instance.WindowWidth < 0)
            {
                Config.Instance.Reset("WindowWidth");
            }
            Width = Config.Instance.WindowWidth;
            var titleBarCorners = new[]
            {
                new Point((int)Left + 5, (int)Top + 5),
                new Point((int)(Left + Width) - 5, (int)Top + 5),
                new Point((int)Left + 5, (int)(Top + TitlebarHeight) - 5),
                new Point((int)(Left + Width) - 5, (int)(Top + TitlebarHeight) - 5)
            };

            if (!Screen.AllScreens.Any(s => titleBarCorners.Any(c => s.WorkingArea.Contains(c))))
            {
                Top  = 100;
                Left = 100;
            }

            if (Config.Instance.StartMinimized)
            {
                WindowState = WindowState.Minimized;
                if (Config.Instance.MinimizeToTray)
                {
                    MinimizeToTray();
                }
            }

            var theme = string.IsNullOrEmpty(Config.Instance.ThemeName)
                                            ? ThemeManager.DetectAppStyle().Item1 : ThemeManager.AppThemes.First(t => t.Name == Config.Instance.ThemeName);
            var accent = string.IsNullOrEmpty(Config.Instance.AccentName)
                                             ? ThemeManager.DetectAppStyle().Item2 : ThemeManager.Accents.First(a => a.Name == Config.Instance.AccentName);

            ThemeManager.ChangeAppStyle(Application.Current, accent, theme);

            Options.Load();


            Game.HighlightCardsInHand = Config.Instance.HighlightCardsInHand;
            Game.HighlightDiscarded   = Config.Instance.HighlightDiscarded;
            //Options.CheckboxHideOverlayInBackground.IsChecked = Config.Instance.HideInBackground;
            //Options.CheckboxHideOpponentCardAge.IsChecked = Config.Instance.HideOpponentCardAge;
            //Options.CheckboxHideOpponentCardMarks.IsChecked = Config.Instance.HideOpponentCardMarks;
            //Options.CheckboxHideOverlayInMenu.IsChecked = Config.Instance.HideInMenu;
            //Options.CheckboxHighlightCardsInHand.IsChecked = Config.Instance.HighlightCardsInHand;
            //Options.CheckboxHideOverlay.IsChecked = Config.Instance.HideOverlay;
            //Options.CheckboxHideDecksInOverlay.IsChecked = Config.Instance.HideDecksInOverlay;
            //Options.CheckboxKeepDecksVisible.IsChecked = Config.Instance.KeepDecksVisible;
            //Options.CheckboxMinimizeTray.IsChecked = Config.Instance.MinimizeToTray;
            //Options.CheckboxWindowsTopmost.IsChecked = Config.Instance.WindowsTopmost;
            //Options.CheckboxPlayerWindowOpenAutomatically.IsChecked = Config.Instance.PlayerWindowOnStart;
            //Options.CheckboxOpponentWindowOpenAutomatically.IsChecked = Config.Instance.OpponentWindowOnStart;
            //Options.CheckboxTimerTopmost.IsChecked = Config.Instance.TimerWindowTopmost;
            //Options.CheckboxTimerWindow.IsChecked = Config.Instance.TimerWindowOnStartup;
            //Options.CheckboxTimerTopmostHsForeground.IsChecked = Config.Instance.TimerWindowTopmostIfHsForeground;
            //Options.CheckboxTimerTopmostHsForeground.IsEnabled = Config.Instance.TimerWindowTopmost;
            //Options.CheckboxSameScaling.IsChecked = Config.Instance.UseSameScaling;
            CheckboxDeckDetection.IsChecked = Config.Instance.AutoDeckDetection;
            //Options.CheckboxWinTopmostHsForeground.IsChecked = Config.Instance.WindowsTopmostIfHsForeground;
            //Options.CheckboxWinTopmostHsForeground.IsEnabled = Config.Instance.WindowsTopmost;
            //Options.CheckboxAutoSelectDeck.IsEnabled = Config.Instance.AutoDeckDetection;
            //Options.CheckboxAutoSelectDeck.IsChecked = Config.Instance.AutoSelectDetectedDeck;
            //Options.CheckboxExportName.IsChecked = Config.Instance.ExportSetDeckName;
            //Options.CheckboxPrioGolden.IsChecked = Config.Instance.PrioritizeGolden;
            //Options.CheckboxBringHsToForegorund.IsChecked = Config.Instance.BringHsToForeground;
            //Options.CheckboxFlashHs.IsChecked = Config.Instance.FlashHsOnTurnStart;
            //Options.CheckboxHideSecrets.IsChecked = Config.Instance.HideSecrets;
            //Options.CheckboxHighlightDiscarded.IsChecked = Config.Instance.HighlightDiscarded;
            //Options.CheckboxRemoveCards.IsChecked = Config.Instance.RemoveCardsFromDeck;
            //Options.CheckboxHighlightLastDrawn.IsChecked = Config.Instance.HighlightLastDrawn;
            //Options.CheckboxStartMinimized.IsChecked = Config.Instance.StartMinimized;
            //Options.CheckboxShowPlayerGet.IsChecked = Config.Instance.ShowPlayerGet;
            //Options.ToggleSwitchExtraFeatures.IsChecked = Config.Instance.ExtraFeatures;
            //Options.CheckboxCheckForUpdates.IsChecked = Config.Instance.CheckForUpdates;
            //Options.CheckboxRecordArena.IsChecked = Config.Instance.RecordArena;
            //Options.CheckboxRecordCasual.IsChecked = Config.Instance.RecordCasual;
            //Options.CheckboxRecordFriendly.IsChecked = Config.Instance.RecordFriendly;
            //Options.CheckboxRecordOther.IsChecked = Config.Instance.RecordOther;
            //Options.CheckboxRecordPractice.IsChecked = Config.Instance.RecordPractice;
            //Options.CheckboxRecordRanked.IsChecked = Config.Instance.RecordRanked;
            //Options.CheckboxFullTextSearch.IsChecked = Config.Instance.UseFullTextSearch;
            //Options.CheckboxDiscardGame.IsChecked = Config.Instance.DiscardGameIfIncorrectDeck;
            //Options.CheckboxExportPasteClipboard.IsChecked = Config.Instance.ExportPasteClipboard;
            //Options.CheckboxGoldenFeugen.IsChecked = Config.Instance.OwnsGoldenFeugen;
            //Options.CheckboxGoldenStalagg.IsChecked = Config.Instance.OwnsGoldenStalagg;
            //Options.CheckboxCloseWithHearthstone.IsChecked = Config.Instance.CloseWithHearthstone;
            //Options.CheckboxStatsInWindow.IsChecked = Config.Instance.StatsInWindow;
            //Options.CheckboxOverlaySecretToolTipsOnly.IsChecked = Config.Instance.OverlaySecretToolTipsOnly;
            //Options.CheckboxTagOnImport.IsChecked = Config.Instance.TagDecksOnImport;
            //Options.CheckboxConfigSaveAppData.IsChecked = Config.Instance.SaveConfigInAppData;
            //Options.CheckboxDataSaveAppData.IsChecked = Config.Instance.SaveDataInAppData;
            //Options.CheckboxAdvancedWindowSearch.IsChecked = Config.Instance.AdvancedWindowSearch;
            //Options.CheckboxDeleteDeckKeepStats.IsChecked = Config.Instance.KeepStatsWhenDeletingDeck;
            //Options.CheckboxNoteDialog.IsChecked = Config.Instance.ShowNoteDialogAfterGame;
            //Options.CheckboxAutoClear.IsChecked = Config.Instance.AutoClearDeck;
            //Options.CheckboxLogTab.IsChecked = Config.Instance.ShowLogTab;
            //Options.CheckboxTimerAlert.IsChecked = Config.Instance.TimerAlert;
            //Options.CheckboxRecordSpectator.IsChecked = Config.Instance.RecordSpectator;
            //Options.CheckboxHideOverlayInSpectator.IsChecked = Config.Instance.HideOverlayInSpectator;
            //Options.TextboxExportDelay.Text = Config.Instance.ExportStartDelay.ToString();
            //Options.CheckboxDiscardZeroTurnGame.IsChecked = Config.Instance.DiscardZeroTurnGame;
            //Options.CheckboxSaveHSLogIntoReplayFile.IsChecked = Config.Instance.SaveHSLogIntoReplay;
            //Options.CheckboxNoteDialogDelayed.IsChecked = Config.Instance.NoteDialogDelayed;
            //Options.CheckboxNoteDialogDelayed.IsEnabled = Config.Instance.ShowNoteDialogAfterGame;
            //Options.CheckboxStartWithWindows.IsChecked = Config.Instance.StartWithWindows;
            //Options.CheckboxOverlayCardMarkToolTips.IsChecked = Config.Instance.OverlayCardMarkToolTips;
            //Options.ComboBoxLogLevel.SelectedValue = Config.Instance.LogLevel.ToString();
            //Options.CheckBoxForceExtraFeatures.IsChecked = Config.Instance.ForceMouseHook;
            //Options.CheckBoxForceExtraFeatures.IsEnabled = Config.Instance.ExtraFeatures;
            //Options.CheckboxAutoGrayoutSecrets.IsChecked = Config.Instance.AutoGrayoutSecrets;
            //Options.CheckboxImportNetDeck.IsChecked = Config.Instance.NetDeckClipboardCheck ?? false;
            //Options.CheckboxAutoSaveOnImport.IsChecked = Config.Instance.AutoSaveOnImport;

            //Options.SliderOverlayOpacity.Value = Config.Instance.OverlayOpacity;
            //Options.SliderOpponentOpacity.Value = Config.Instance.OpponentOpacity;
            //Options.SliderPlayerOpacity.Value = Config.Instance.PlayerOpacity;
            //Options.SliderOverlayPlayerScaling.Value = Config.Instance.OverlayPlayerScaling;
            //Options.SliderOverlayOpponentScaling.Value = Config.Instance.OverlayOpponentScaling;

            //DeckPickerList.ShowAll = Config.Instance.ShowAllDecks;
            //DeckPickerList.SetSelectedTags(Config.Instance.SelectedTags);

            // Don't select the 'archived' class on load
            var selectedClasses = Config.Instance.SelectedDeckPickerClasses.Where(c => c.ToString() != "Archived").ToList();

            if (selectedClasses.Count == 0)
            {
                selectedClasses.Add(HeroClassAll.All);
            }

            DeckPickerList.SelectClasses(selectedClasses);
            DeckPickerList.SelectDeckType(Config.Instance.SelectedDeckType, true);

            //Options.CheckboxHideTimers.IsChecked = Config.Instance.HideTimers;

            //var delay = Config.Instance.DeckExportDelay;
            //Options.ComboboxExportSpeed.SelectedIndex = delay < 40 ? 0 : delay < 60 ? 1 : delay < 100 ? 2 : delay < 150 ? 3 : 4;

            SortFilterDecksFlyout.LoadTags(DeckList.Instance.AllTags);

            UpdateQuickFilterItemSource();

            SortFilterDecksFlyout.SetSelectedTags(Config.Instance.SelectedTags);
            //DeckPickerList.SetSelectedTags(Config.Instance.SelectedTags);


            TagControlEdit.LoadTags(DeckList.Instance.AllTags.Where(tag => tag != "All" && tag != "None").ToList());
            //DeckPickerList.SetTagOperation(Config.Instance.TagOperation);
            SortFilterDecksFlyout.OperationSwitch.IsChecked = Config.Instance.TagOperation == TagFilerOperation.And;

            SortFilterDecksFlyout.ComboboxDeckSorting.SelectedItem = Config.Instance.SelectedDeckSorting;

            //Options.ComboboxWindowBackground.SelectedItem = Config.Instance.SelectedWindowBackground;
            //Options.TextboxCustomBackground.IsEnabled = Config.Instance.SelectedWindowBackground == "Custom";
            //Options.TextboxCustomBackground.Text = string.IsNullOrEmpty(Config.Instance.WindowsBackgroundHex)
            //	                                       ? "#696969" : Config.Instance.WindowsBackgroundHex;
            //Options.UpdateAdditionalWindowsBackground();

            //if(Helper.LanguageDict.Values.Contains(Config.Instance.SelectedLanguage))
            //	Options.ComboboxLanguages.SelectedItem = Helper.LanguageDict.First(x => x.Value == Config.Instance.SelectedLanguage).Key;

            if (!EventKeys.Contains(Config.Instance.KeyPressOnGameStart))
            {
                Config.Instance.KeyPressOnGameStart = "None";
            }
            //Options.ComboboxKeyPressGameStart.SelectedValue = Config.Instance.KeyPressOnGameStart;

            if (!EventKeys.Contains(Config.Instance.KeyPressOnGameEnd))
            {
                Config.Instance.KeyPressOnGameEnd = "None";
            }
            //Options.ComboboxKeyPressGameEnd.SelectedValue = Config.Instance.KeyPressOnGameEnd;

            //Options.CheckboxHideManaCurveMyDecks.IsChecked = Config.Instance.ManaCurveMyDecks;
            ManaCurveMyDecks.Visibility = Config.Instance.ManaCurveMyDecks ? Visibility.Visible : Visibility.Collapsed;

            //Options.CheckboxTrackerCardToolTips.IsChecked = Config.Instance.TrackerCardToolTips;
            //Options.CheckboxWindowCardToolTips.IsChecked = Config.Instance.WindowCardToolTips;
            //Options.CheckboxOverlayCardToolTips.IsChecked = Config.Instance.OverlayCardToolTips;
            //Options.CheckboxOverlayAdditionalCardToolTips.IsEnabled = Config.Instance.OverlayCardToolTips;
            //Options.CheckboxOverlayAdditionalCardToolTips.IsChecked = Config.Instance.AdditionalOverlayTooltips;

            CheckboxClassCardsFirst.IsChecked = Config.Instance.CardSortingClassFirst;

            DeckStatsFlyout.LoadConfig();
            GameDetailsFlyout.LoadConfig();
            StatsWindow.StatsControl.LoadConfig();
            StatsWindow.GameDetailsFlyout.LoadConfig();

            MenuItemImportArena.IsEnabled       = Config.Instance.ShowArenaImportMessage;
            MenuItemImportConstructed.IsEnabled = Config.Instance.ShowConstructedImportMessage;

            MenuItemCheckBoxSyncOnStart.IsChecked        = Config.Instance.HearthStatsSyncOnStart;
            MenuItemCheckBoxAutoUploadDecks.IsChecked    = Config.Instance.HearthStatsAutoUploadNewDecks;
            MenuItemCheckBoxAutoUploadGames.IsChecked    = Config.Instance.HearthStatsAutoUploadNewGames;
            MenuItemCheckBoxAutoSyncBackground.IsChecked = Config.Instance.HearthStatsAutoSyncInBackground;
            MenuItemCheckBoxAutoDeleteDecks.IsChecked    = Config.Instance.HearthStatsAutoDeleteDecks;
            MenuItemCheckBoxAutoDeleteGames.IsChecked    = Config.Instance.HearthStatsAutoDeleteMatches;
        }
Пример #17
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);
            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);
            CloseNewDeck();
            ClearNewDeckSection();
        }