internal void ShowDialogOptions()
        {
            try
            {
                var           ratingSources = DraftRatings.Get().Keys.ToArray();
                OptionsWindow optionsWindow = new OptionsWindow().Init(ConfigModel, ratingSources);
                optionsWindow.Owner = this;
                optionsWindow.ShowDialog();

                // The code will continue here only when the options window gets closed
                var newConfig = JsonConvert.DeserializeObject <ConfigModel>(JsonConvert.SerializeObject(ConfigModel));
                newConfig.LogFilePath               = optionsWindow.LogFilePathTextBox.Text.Trim();
                newConfig.GameFilePath              = optionsWindow.GameFilePathTextBox.Text.Trim();
                newConfig.RunOnStartup              = optionsWindow.RunOnStartupCheckbox.IsChecked ?? false;
                newConfig.ShowOpponentCardsAuto     = optionsWindow.ShowOpponentCardsCheckbox.IsChecked ?? false;
                newConfig.ShowOpponentCardsExternal = optionsWindow.ShowOpponentCardsExternalCheckBox.IsChecked ?? true;
                newConfig.MinimizeToSystemTray      = optionsWindow.MinimizeToTrayCheckBox.IsChecked ?? false;
                newConfig.AutoShowHideForMatch      = optionsWindow.AutoShowHideForMatchCheckBox.IsChecked ?? false;
                newConfig.ForceCardPopup            = optionsWindow.ForceCardPopupCheckbox.IsChecked ?? false;
                newConfig.OrderLibraryCardsBy       = optionsWindow.OrderLibraryComboBox.SelectedValue.ToString();
                newConfig.ForceCardPopupSide        = optionsWindow.ForceCardPopupSideComboBox?.SelectedValue?.ToString() ?? ConfigModel.ForceCardPopupSide;
                newConfig.ShowLimitedRatingsSource  = optionsWindow.ShowLimitedRatingsSourceComboBox?.SelectedValue?.ToString() ?? ConfigModel.ShowLimitedRatingsSource;

                if (JsonConvert.SerializeObject(ConfigModel) != JsonConvert.SerializeObject(newConfig))
                {
                    bool   oldLimitedRatings       = ConfigModel.ShowLimitedRatings;
                    string oldLimitedRatingsSource = ConfigModel.ShowLimitedRatingsSource;
                    newConfig.Save();
                    Utilities.CopyProperties(newConfig, ConfigModel);

                    if (MainWindowVM.MainWindowContext == WindowContext.Drafting &&
                        (ConfigModel.ShowLimitedRatings != oldLimitedRatings || ConfigModel.ShowLimitedRatingsSource != oldLimitedRatingsSource))
                    {
                        if (ConfigModel.ShowLimitedRatingsSource != oldLimitedRatingsSource)
                        {
                            SetCardsDraft(MainWindowVM.DraftingVM.CurrentDraftPickProgress);
                        }

                        DraftingControl.SetPopupRatingsSource(ConfigModel.ShowLimitedRatings, ConfigModel.ShowLimitedRatingsSource);
                    }

                    ResourcesLocator.LocateLogFilePath(ConfigModel);
                    ResourcesLocator.LocateGameClientFilePath(ConfigModel);
                    FileMonitor.SetFilePath(newConfig.LogFilePath);
                    //vm.ValidateUserId(newConfig.UserId);
                    //ServerApiGetCollection();

                    StartupManager.ManageRunOnStartup(newConfig.RunOnStartup);
                    ReadyControl.Init(ConfigModel.GameFilePath);

                    MainWindowVM.OrderLibraryCardsBy = ConfigModel.OrderLibraryCardsBy == "Converted Mana Cost" ? CardsListOrder.ManaCost : CardsListOrder.DrawChance;
                }

                UpdateCardPopupPosition();
            }
            catch (Exception ex)
            {
                Log.Write(LogEventLevel.Error, ex, "Unexpected error:");
            }
        }
Ejemplo n.º 2
0
        internal void ShowDialogOptions()
        {
            try
            {
                var ratingSources = draftRatings.Get().Keys.ToArray();
                var optionsWindow = new OptionsWindow().Init(this.configApp, ratingSources);
                optionsWindow.Owner = this;
                optionsWindow.ShowDialog();

                // The code will continue here only when the options window gets closed
                var newConfig = JsonConvert.DeserializeObject <ConfigModelApp>(JsonConvert.SerializeObject(configApp));
                newConfig.LogFilePath              = optionsWindow.txtLogFilePath.Text.Trim();
                newConfig.GameFilePath             = optionsWindow.txtGameFilePath.Text.Trim();
                newConfig.RunOnStartup             = optionsWindow.chkRunOnStartup.IsChecked.Value;
                newConfig.ShowOpponentCards        = optionsWindow.chkShowOpponentCards.IsChecked.Value;
                newConfig.MinimizeToSystemTray     = optionsWindow.chkMinimizeToSystemTray.IsChecked.Value;
                newConfig.AutoShowHideForMatch     = optionsWindow.chkAutoShowHideForMatch.IsChecked.Value;
                newConfig.ForceCardPopup           = optionsWindow.chkForceCardPopup.IsChecked.Value;
                newConfig.OrderLibraryCardsBy      = optionsWindow.lstOrderLibraryCardsBy.SelectedValue.ToString();
                newConfig.ForceCardPopupSide       = optionsWindow.lstForceCardPopupSide?.SelectedValue?.ToString() ?? configApp.ForceCardPopupSide;
                newConfig.ShowLimitedRatingsSource = optionsWindow.lstShowLimitedRatingsSource?.SelectedValue?.ToString() ?? configApp.ShowLimitedRatingsSource;

                ShowInTaskbar = !newConfig.MinimizeToSystemTray;
                if (configApp.MinimizeToSystemTray != newConfig.MinimizeToSystemTray)
                {
                    if (newConfig.MinimizeToSystemTray)
                    {
                        notifyIconManager.AddNotifyIcon(this);
                    }
                    else
                    {
                        notifyIconManager.RemoveNotifyIcon();
                    }
                }

                if (JsonConvert.SerializeObject(configApp) != JsonConvert.SerializeObject(newConfig))
                {
                    var oldLimitedRatings       = configApp.ShowLimitedRatings;
                    var oldLimitedRatingsSource = configApp.ShowLimitedRatingsSource;
                    newConfig.Save();
                    configApp = newConfig;

                    if (vm.MainWindowContext == MainWindowContextEnum.Drafting &&
                        (configApp.ShowLimitedRatings != oldLimitedRatings || configApp.ShowLimitedRatingsSource != oldLimitedRatingsSource))
                    {
                        if (configApp.ShowLimitedRatingsSource != oldLimitedRatingsSource)
                        {
                            SetCardsDraft(vm.DraftingVM.CurrentDraftPickProgress);
                        }

                        ucDraftHelper.SetPopupRatingsSource(configApp.ShowLimitedRatings, configApp.ShowLimitedRatingsSource);
                    }

                    resourcesLocator.LocateLogFilePath(configApp);
                    resourcesLocator.LocateGameClientFilePath(configApp);
                    fileMonitor.SetFilePath(newConfig.LogFilePath);
                    //vm.ValidateUserId(newConfig.UserId);
                    //ServerApiGetCollection();

                    startupManager.ManageRunOnStartup(newConfig.RunOnStartup);
                    ucReady.Init(configApp.GameFilePath);

                    vm.OrderLibraryCardsBy = configApp.OrderLibraryCardsBy == "Converted Mana Cost" ? CardsListOrder.Cmc : CardsListOrder.DrawChance;
                }

                UpdateCardPopupPosition();
            }
            catch (Exception ex)
            {
                Log.Write(LogEventLevel.Error, ex, "Unexpected error:");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Show the options window as a dialog and handle changes
        /// </summary>
        private void ShowOptionsWindow()
        {
            try
            {
                // Create the window, set the owner and show as a dialog window (blocking execution until closed)
                var optionsVM = mapper.Map <OptionsWindowVM>(ViewModel.Config);

                optionsVM.Sets                 = ViewModel.Sets.ToDictionary(i => i.Code, i => i);
                optionsVM.DraftRatings         = DraftRatings;
                optionsVM.LimitedRatingsSource = optionsVM.LimitedRatingsSourcesDict.First(i => i.Key == optionsVM.LimitedRatingsSource.Key);

                OptionsWindow win = new OptionsWindow().Init(ViewModel, optionsVM);
                win.Owner = this;
                win.ShowDialog();

                // Get a reference to the view model
                OptionsWindowVM ovm = win.OptionsViewModel;

                // Serialize the original config
                string origConfig = JsonConvert.SerializeObject(ViewModel.Config);

                // Perform a deep copy on the existing config
                var configModel = JsonConvert.DeserializeObject <ConfigModel>(origConfig);

                // Store the setting from the options window
                configModel.LogFilePath               = ovm.LogFilePath.Trim();
                configModel.GameFilePath              = ovm.GameFilePath.Trim();
                configModel.RunOnStartup              = ovm.RunOnStartup;
                configModel.ShowOpponentCardsAuto     = ovm.ShowOpponentCardsAuto;
                configModel.ShowOpponentCardsExternal = ovm.ShowOpponentCardsExternal;
                configModel.Minimize             = ovm.Minimize;
                configModel.AutoShowHideForMatch = ovm.AutoShowHideForMatch;
                configModel.OrderLibraryCardsBy  = ovm.OrderLibraryCardsBy;
                configModel.ForceCardPopupSide   = ovm.ForceCardPopupSide;
                configModel.ShowLimitedRatings   = ovm.ShowLimitedRatings;
                configModel.LimitedRatingsSource = ovm.LimitedRatingsSource.Key;
                configModel.ForceGameResolution  = ovm.ForceGameResolution;
                //configModel.GameResolutionBlackBorders = ovm.GameResolutionBlackBorders;
                configModel.GameResolution = ovm.GameResolution;

                // Serialize the new config
                string newConfig = JsonConvert.SerializeObject(configModel);

                // Check if the settings have changed
                if (origConfig != newConfig)
                {
                    var showLimitedRatingsChanged   = configModel.ShowLimitedRatings != ViewModel.Config.ShowLimitedRatings;
                    var limitedRatingsSourceChanged = configModel.LimitedRatingsSource != ViewModel.Config.LimitedRatingsSource;

                    // Copy the properties and save the config
                    ViewModel.Config.CopyPropertiesFrom(configModel);
                    ViewModel.Config.Save();

                    // Refresh custom ratings with latest from server
                    if (ViewModel.Config.LimitedRatingsSource == Constants.LIMITEDRATINGS_SOURCE_CUSTOM)
                    {
                        RefreshCustomRatingsFromServer();
                    }

                    // Handle changing the draft source during a draft
                    if (ViewModel.Context == WindowContext.Drafting && (showLimitedRatingsChanged || limitedRatingsSourceChanged))
                    {
                        ViewModel.DraftingVM.LimitedRatingsSource = ViewModel.Config.LimitedRatingsSource;

                        if (limitedRatingsSourceChanged)
                        {
                            SetCardsDraft(ViewModel.DraftingVM.DraftInfoBuffered.DraftProgress);
                        }

                        DraftingControl.SetPopupRatingsSource(ViewModel.Config.ShowLimitedRatings, ViewModel.Config.LimitedRatingsSource);
                    }

                    // If the external option is disabled, hide the external window
                    if (!ViewModel.Config.ShowOpponentCardsExternal)
                    {
                        ViewModel.OpponentWindowVM.ShowHideWindow();
                    }
                    // If auto was just enabled, show the window (the playing state is checked internally)
                    else if (ViewModel.Config.ShowOpponentCardsAuto)
                    {
                        ViewModel.OpponentWindowVM.ShowHideWindow(true);
                    }

                    // If the height is minimized and they changed the option, restore the window
                    if (ViewModel.Config.Minimize != MinimizeOption.Height && ViewModel.IsHeightMinimized)
                    {
                        ViewModel.RestoreWindow();
                    }

                    // Locate the resources from the new paths
                    ResourcesLocator.LocateLogFilePath(ViewModel.Config);
                    ResourcesLocator.LocateGameClientFilePath(ViewModel.Config);
                    FileMonitor.SetFilePath(configModel.LogFilePath);

                    // Set the start-up option
                    StartupManager.ManageRunOnStartup(configModel.RunOnStartup);

                    // Set the card order
                    ViewModel.OrderLibraryCardsBy = ViewModel.Config.OrderLibraryCardsBy == "Converted Mana Cost" ? CardsListOrder.ManaCost : CardsListOrder.DrawChance;
                }

                UpdateCardPopupPosition();
            }
            catch (Exception ex)
            {
                //if (ex is InvalidEmailException)
                //    MessageBox.Show(ex.Message, "Not available", MessageBoxButton.OK, MessageBoxImage.Information);
                //else
                Log.Write(LogEventLevel.Error, ex, "Unexpected error:");
            }
        }