/// <summary> /// Dependency Injection Initializer /// </summary> /// <param name="mvm"></param> /// <param name="optionsVM"></param> /// <returns></returns> public OptionsWindow Init( MainWindowVM mvm, OptionsWindowVM optionsVM ) { MainWindowVM = mvm; DataContext = OptionsViewModel = optionsVM; DraftHelperRunner = mvm.DraftHelperRunner; ConfigApp = mvm.Config; CardNames = mvm.AllCards.ToDictionary(i => i.grpId, i => i.name); return(this); }
/// <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:"); } }