private void ShowSelectCardsWindow(ISelectableCards selectableCards, string startingPositionConfigName) { _logger.LogMessage($"Showing select card window: {selectableCards.Name}."); var left = View.Left + View.Width + 10; var width = (double)836; var top = View.Top; SelectCardsController controller = null; foreach (var selectCardsControllerInList in _selectCardsControllers) { if (selectCardsControllerInList.SelectableCards == selectableCards) { controller = selectCardsControllerInList; controller.Activate(); break; } else { if (selectCardsControllerInList.Top + selectCardsControllerInList.Height > top) { top = selectCardsControllerInList.Top + selectCardsControllerInList.Height + 10; width = selectCardsControllerInList.Width; left = selectCardsControllerInList.Left; } } } var startingPositionProperty = ViewModel.AppData.Configuration.GetType().GetProperty(startingPositionConfigName); var startingPosition = (Point)startingPositionProperty.GetValue(ViewModel.AppData.Configuration); if (controller == null) { controller = _controllerFactory.CreateController <SelectCardsController>(); controller.AppData = ViewModel.AppData; controller.SelectableCards = selectableCards; controller.Left = startingPosition.X == 0 ? left : startingPosition.X; controller.Top = startingPosition.Y == 0 ? top : startingPosition.Y; controller.Width = width; controller.Closed += () => { _selectCardsControllers.Remove(controller); }; controller.View.LocationChanged += (s, e) => { startingPositionProperty.SetValue(ViewModel.AppData.Configuration, new Point(controller.View.Left, controller.View.Top)); }; _selectCardsControllers.Add(controller); } if (!controller.SelectableCards.Loading) { controller.Show(); } else { _logger.LogMessage($"Delayed showing select card window: {selectableCards.Name}."); ShowSelectCardsWindowWhenFinishedLoading(controller); } }
private void ShowSelectCardsWindowWhenFinishedLoading(SelectCardsController selectCardsController) { var timer = new DispatcherTimer { Interval = new TimeSpan(500) }; timer.Tick += (x, y) => { if (selectCardsController.CardGroup.Loading) { return; } _logger.LogMessage($"Showing select card window after delay: {selectCardsController.CardGroup.Name}."); timer.Stop(); selectCardsController.Show(); }; timer.Start(); }