Example #1
0
        private void AnimateMoveTask(MoveTask moveTask, bool isUndo)
        {
            MoveAnimationsFactory moveAnimationsFactory = new MoveAnimationsFactory();

            foreach (var pieceMove in moveTask.MovedPiecesCoordinates)
            {
                Coordinate fromCoordinate = isUndo ? pieceMove.Item2 : pieceMove.Item1;
                Coordinate toCoordinate   = isUndo ? pieceMove.Item1 : pieceMove.Item2;

                Point animationStartPoint = GetCoordinatePositionOnBoard(fromCoordinate);
                Point animationEndPoint   = GetCoordinatePositionOnBoard(toCoordinate);

                ContentPresenter pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(ViewModel.GetPiece(toCoordinate));
                moveAnimationsFactory.AddMoveAnimation(pieceItemView, animationStartPoint, animationEndPoint);
            }

            if (moveTask.CapturedPieceCoordinate != null)
            {
                // if is not undo the removed piece is marked to be removed and only removed after the animation
                ChessPieceViewModel removedPiece  = isUndo ? ViewModel.GetPiece(moveTask.CapturedPieceCoordinate) : ViewModel.GetRemovedPiece(moveTask.CapturedPieceCoordinate);
                ContentPresenter    pieceItemView = (ContentPresenter)piecesItemsControl.ContainerFromItem(removedPiece);
                moveAnimationsFactory.AddRemoveAnimation(pieceItemView);
            }

            moveAnimationsFactory.StoryBoard.Completed += (o, e) =>
            {
                moveTask.CompleteTask();
                IsHitTestVisible = true;
            };

            moveAnimationsFactory.StoryBoard.Begin();
            // dont allow user interactions with the board for the duration of the animation
            IsHitTestVisible = false;
        }
Example #2
0
        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();
            }
        }