private void OnAnimatePromotionMoveTask(GenericMessage <PromotionMoveTask> message) { promotionTask = message.Content; Move promotionMove = promotionTask.Move; if (promotionTask.InstantMove) { ChangePieceLocation(promotionMove.GetFrom(), promotionMove.GetTo()); ShowPromotionPopup(); } else { Point animationStartPoint = GetCoordinatePositionOnBoard(promotionMove.GetFrom()); Point animationEndPoint = GetCoordinatePositionOnBoard(promotionMove.GetTo()); ContentPresenter pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(ViewModel.GetPiece(promotionMove.GetFrom())); MoveAnimationsFactory moveAnimationsFactory = new MoveAnimationsFactory(); moveAnimationsFactory.AddMoveAnimation(pieceItemView, animationStartPoint, animationEndPoint); // dont allow user interactions with the board for the duration of the animation IsHitTestVisible = false; moveAnimationsFactory.StoryBoard.Completed += (o, e) => { IsHitTestVisible = true; ShowPromotionPopup(); }; moveAnimationsFactory.StoryBoard.Begin(); } }
private void CancelPromotionMove() { if (promotionTask == null) { throw new NotSupportedException("No promotion task pending"); } Move promotionMove = promotionTask.Move; //move the pawn back to original position ChangePieceLocation(promotionMove.GetFrom(), promotionMove.GetFrom()); promotionTask = null; }
private void ShowPromotionPopup() { if (promotionTask == null) { return; } Move promotionMove = promotionTask.Move; PromotionView promotionView = new PromotionView(); Point toSquarePoint = GetCoordinatePositionOnBoard(promotionMove.GetTo()); bool isBlackPromotion = promotionMove.GetTo().Y == 0; // if the popup apears on bottom, display the queen on the bottom bool displayedOnBottom = toSquarePoint.Y != 0; PromotionViewModel promotionVM = new PromotionViewModel(isBlackPromotion ? PieceColor.Black : PieceColor.White, displayedOnBottom) { PieceSelectedCommand = new RelayCommand((p) => { promotionTask.OnPieceSelected((PieceType)p); if ((PieceType)p == PieceType.None) { CancelPromotionMove(); } promotionTask = null; promotionSelectionPopup.IsOpen = false; }) }; promotionView.DataContext = promotionVM; double squareWidth = board.ActualWidth / 8; promotionView.PieceSize = squareWidth; promotionSelectionPopup.Child = promotionView; promotionSelectionPopup.IsOpen = true; promotionSelectionPopup.HorizontalOffset = toSquarePoint.X; promotionSelectionPopup.VerticalOffset = 0; if (displayedOnBottom) { promotionSelectionPopup.VerticalOffset = (8 - promotionVM.Pieces.Count) * squareWidth; } }