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:"); } }
//private void InitDraftHelperForHumanDraft(string set) //{ // RefreshCustomRatingsFromServer(); // ViewModel.SetMainWindowContext(WindowContext.Drafting); // DraftHelperRunner.Set = set; // ViewModel.DraftingVM.ResetDraftPicks(DraftHelperRunner.Set, true, Guid.NewGuid().ToString()); //} private void SetCardsDraft(DraftPickProgress draftInfo, bool isHuman = false) { var cardPool = draftInfo?.DraftPack; if (cardPool == null) { return; } var collection = ViewModel.Collection.Cards .Where(i => i.IdArena != 0) .ToDictionary(i => i.IdArena, i => i.Amount); var draftingInfo = DraftHelper.GetDraftPicksForCards( cardPool, draftInfo.PickedCards, ViewModel.Config.LimitedRatingsSource, collection, RareDraftingInfo, ViewModel.DraftingVM.CustomRatingsBySetThenCardName); ViewModel.DraftingVM.SetCardsDraftBuffered(draftInfo, draftingInfo, isHuman); if (draftInfo.PickNumber == 0) { Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => DraftingControl.HideCardListWheeled())); ViewModel.DraftingVM.ShowCardListThatDidNotWheel = false; } }
public void UpdateCardPopupPosition() { if (double.IsNaN(Top) || double.IsNaN(Left) || double.IsNaN(Width) || double.IsNaN(Height)) { return; } var top = (int)Top; var left = (int)Left; var width = (int)Width; DraftingControl.SetCardPopupPosition(ViewModel.Config.ForceCardPopupSide, top, left, width); PlayingControl.SetCardPopupPosition(ViewModel.Config.ForceCardPopupSide, top, left, width); }
private void UpdateCardPopupPosition() { if (double.IsNaN(Top) || double.IsNaN(Left) || double.IsNaN(Width) || double.IsNaN(Height)) { return; } var top = (int)Top; var left = (int)Left; var width = (int)Width; ForceCardPopupSideEnum side = GetCardPopupSide(); DraftingControl.SetCardPopupPosition(side, top, left, width); PlayingControl.SetCardPopupPosition(side, top, left, width); }
public MainWindow( ConfigModel configApp, ICollection <Card> allCards, MainWindowVM viewModel, ProcessMonitor processMonitor, LogFileZipper zipper, ServerApiCaller api, StartupShortcutManager startupManager, LogSplitter logSplitter, MtgaResourcesLocator resourcesLocator, FileMonitor fileMonitor, DraftCardsPicker draftHelper, ReaderMtgaOutputLog readerMtgaOutputLog, InGameTracker2 inMatchTracker, ExternalProviderTokenManager tokenManager, PasswordHasher passwordHasher, CacheSingleton <Dictionary <string, DraftRatings> > draftRatings, DraftHelperRunner draftHelperRunner) { // Set the config model reference ConfigModel = configApp; Reader = readerMtgaOutputLog; processMonitor.OnProcessMonitorStatusChanged += OnProcessMonitorStatusChanged; Zipper = zipper; Api = api; StartupManager = startupManager; LogSplitter = logSplitter; ResourcesLocator = resourcesLocator; FileMonitor = fileMonitor; fileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText; DraftHelper = draftHelper; //this.logProcessor = logProcessor; InGameTracker = inMatchTracker; TokenManager = tokenManager; PasswordHasher = passwordHasher; DraftRatings = draftRatings; DraftHelperRunner = draftHelperRunner; ResourcesLocator.LocateLogFilePath(ConfigModel); ResourcesLocator.LocateGameClientFilePath(ConfigModel); fileMonitor.SetFilePath(ConfigModel.LogFilePath); // Set the view model MainWindowVM = viewModel; // Set the data context to the view model DataContext = MainWindowVM; InitializeComponent(); WelcomeControl.Init(tokenManager); PlayingControl.Init(MainWindowVM); StatusBarTop.Init(this, MainWindowVM); ReadyControl.Init(ConfigModel.GameFilePath); DraftingControl.Init(allCards, MainWindowVM.DraftingVM); DraftingControl.SetPopupRatingsSource(ConfigModel.ShowLimitedRatings, ConfigModel.ShowLimitedRatingsSource); processMonitor.Start(new System.Threading.CancellationToken()); FileMonitor.Start(new System.Threading.CancellationToken()); var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; timer.Tick += (sender, e) => { MainWindowVM.SetCardsDraftFromBuffered(); MainWindowVM.SetCardsInMatchTrackingFromBuffered(); }; timer.Start(); var timerTokenRefresh = new DispatcherTimer { Interval = TimeSpan.FromMinutes(9) }; timerTokenRefresh.Tick += (sender, e) => { RefreshAccessToken(); }; timerTokenRefresh.Start(); }
/// <summary> /// Complete constructor /// </summary> public MainWindow(MainWindowVM viewModel) { mapper = viewModel.Mapper; ViewModel = viewModel; // Set the main window view model actions ViewModel.UploadLogAction = UploadLogAction; ViewModel.ShowOptionsAction = ShowOptionsWindow; ViewModel.LaunchArenaAction = LaunchArenaAction; ViewModel.ValidateUserAction = ValidateUserAction; // Set the resource locator ResourcesLocator = viewModel.ResourcesLocator; // Set the problem action ResourcesLocator.SetProblem = ViewModel.SetProblem; // Locate the log file ResourcesLocator.LocateLogFilePath(ViewModel.Config); // Locate the game path ResourcesLocator.LocateGameClientFilePath(ViewModel.Config); // Set the reference to the draft helper DraftHelperRunner = viewModel.DraftHelperRunner; Reader = viewModel.ReaderMtgaOutputLog; Api = viewModel.Api; StartupManager = viewModel.StartupManager; FileMonitor = viewModel.FileMonitor; FileMonitor.OnFileSizeChangedNewText += OnFileSizeChangedNewText; DraftHelper = viewModel.DraftHelper; //this.logProcessor = logProcessor; InGameTracker = viewModel.InMatchTracker; TokenManager = viewModel.TokenManager; PasswordHasher = viewModel.PasswordHasher; DraftRatings = viewModel.DraftRatings; FileMonitor.SetFilePath(ViewModel.Config.LogFilePath); // Set the data context to the view model DataContext = ViewModel; InitializeComponent(); PlayingControl.Init(ViewModel); DraftingControl.Init(ViewModel.DraftingVM, ViewModel.Config.LimitedRatingsSource); DraftingControl.SetPopupRatingsSource(ViewModel.Config.ShowLimitedRatings, ViewModel.Config.LimitedRatingsSource); // Set the process monitor status changed action viewModel.ProcessMonitor.OnProcessMonitorStatusChanged = OnProcessMonitorStatusChanged; // Start the process monitor without awaiting the task completion _ = viewModel.ProcessMonitor.Start(new System.Threading.CancellationToken()); // Start the file monitor without awaiting the task completion _ = FileMonitor.Start(new System.Threading.CancellationToken()); var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; timer.Tick += (sender, e) => { ViewModel.DraftingVM.SetCardsDraftFromBuffered(); ViewModel.InMatchState.SetInMatchStateFromBuffered(); }; timer.Start(); var timerTokenRefresh = new DispatcherTimer { Interval = TimeSpan.FromMinutes(9) }; timerTokenRefresh.Tick += (sender, e) => { RefreshAccessToken(); }; timerTokenRefresh.Start(); }
/// <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:"); } }