Beispiel #1
0
        private async Task AnimateCribCardsToOwner(PlayerType owner)
        {
            CardContainer cribOwner = GridPlayer;

            if (owner == PlayerType.Computer)
            {
                cribOwner = GridComputer;
            }

            List <Task <Object> > tasks = new List <Task <object> >();

            //
            //  return player and computer cards to the deck

            GridPlayer.FlipAllCards(CardOrientation.FaceDown, tasks);
            GridPlayer.MoveAllCardsToTarget(GridDeck, tasks, MainPage.AnimationSpeeds.Medium, true);
            GridComputer.FlipAllCards(CardOrientation.FaceDown, tasks);
            GridComputer.MoveAllCardsToTarget(GridDeck, tasks, MainPage.AnimationSpeeds.Medium, true);


            //
            //  move crib cards back to player
            GridCrib.MoveAllCardsToTarget(cribOwner, tasks, MainPage.AnimationSpeeds.Medium, true);
            cribOwner.FlipAllCards(CardOrientation.FaceUp, tasks);
            await Task.WhenAll(tasks);
        }
 public void MoveAllCardsToTarget(CardContainer target, List <Task <object> > taskList, double animationDuration = Double.MaxValue, bool rotate = false, bool transferCard = true)
 {
     for (int i = this.Items.Count - 1; i >= 0; i--)
     {
         CardView card = this.Items[i];
         MoveCardToTarget(card, target, taskList, animationDuration, rotate, transferCard);
     }
 }
 public AsycUpdateCardLayout(CardContainer container, double duration = Double.MaxValue, bool rotation = false)
 {
     _container      = container;
     _rotate         = rotation;
     _duration       = duration;
     _timer.Interval = TimeSpan.FromMilliseconds(100);
     _timer.Tick    += AsycUpdate;
 }
        public void MoveCardToTargetAsync(CardView card, CardContainer target, double animationDuration = Double.MaxValue, bool rotate = false, bool transferCard = true)
        {
            if (animationDuration == Double.MaxValue)
            {
                animationDuration = MainPage.AnimationSpeeds.Medium;
            }
            Point ptTo = SetupCardForMove(card, target, rotate, transferCard);

            card.AnimateToAsync(ptTo, rotate, animationDuration);
            if (transferCard)
            {
                this.UpdateCardLayoutAsync();
            }
        }
        public void MoveCardToTarget(List <Task <object> > taskList, CardView card, CardContainer target, double animationDuration = Double.MaxValue, bool rotate = false, bool transferCard = true)
        {
            if (this.Items.Contains(card) == false)
            {
                //Debug.WriteLine("Attempting to move Card {0} from {1} to {2} and it is not in {1}", card.CardName, this.FriendlyName, target.FriendlyName);
                return;
            }

            if (animationDuration == Double.MaxValue)
            {
                animationDuration = MainPage.AnimationSpeeds.Medium;
            }
            Point ptTo = SetupCardForMove(card, target, rotate, transferCard);

            card.AnimateToTaskList(ptTo, rotate, animationDuration, taskList);
        }
        public async Task MoveAllCardsToTarget(CardContainer target, MoveCardOptions moveOptions = MoveCardOptions.MoveAllAtSameTime, double animationDuration = Double.MaxValue, bool rotate = false, bool transferCard = true)
        {
            if (moveOptions == MoveCardOptions.MoveAllAtSameTime)
            {
                List <Task <object> > localList = new List <Task <object> >();
                MoveAllCardsToTarget(target, localList, animationDuration, rotate, transferCard);
                await Task.WhenAll(localList);

                return;
            }

            for (int i = this.Items.Count - 1; i >= 0; i--)
            {
                CardView card = this.Items[i];
                await MoveCardToTarget(card, target, animationDuration, rotate, transferCard);
            }
        }
        public async Task OnEndOfHand(PlayerType dealer, int cribScore, int nComputerCountingPoint, int nPlayerCountingPoint, int ComputerPointsThisTurn, int PlayerPointsThisTurn)
        {
            CardContainer cribOwner = GridPlayer;

            if (dealer == PlayerType.Computer)
            {
                cribOwner = GridComputer;
            }
            await HintWindow.InsertEndOfHandSummary(dealer, cribScore, cribOwner.Items, nComputerCountingPoint, nPlayerCountingPoint, ComputerPointsThisTurn, PlayerPointsThisTurn, Hfs);


            List <Task <Object> > tasks = new List <Task <object> >();

            cribOwner.FlipAllCards(CardOrientation.FaceDown, tasks);
            cribOwner.MoveAllCardsToTarget(GridDeck, tasks, MainPage.AnimationSpeeds.Medium, true);
            await Task.WhenAll(tasks);
        }
        public async Task MoveCardToTarget(CardView card, CardContainer target, double animationDuration = Double.MaxValue, bool rotate = false, bool transferCard = true)
        {
            if (this.Items.Contains(card) == false)
            {
                //Debug.WriteLine("Attempting to move Card {0} from {1} to {2} and it is not in {1}", card.CardName, this.FriendlyName, target.FriendlyName);
                return;
            }

            if (animationDuration == Double.MaxValue)
            {
                animationDuration = MainPage.AnimationSpeeds.Medium;
            }
            Point ptTo = SetupCardForMove(card, target, rotate, transferCard);
            await card.AnimateTo(ptTo, rotate, false, animationDuration);

            if (transferCard) // if we don't transfer the card, UpdateCardLayout() just moves it back... :)
            {
                await this.UpdateCardLayout();
            }
        }
        public void TransferCard(CardView card, CardContainer target)
        {
            card.PointerPressed -= this.Card_OnPointerPressed;


            if (target.Selectable)
            {
                card.PointerPressed       += target.Card_OnPointerPressed;
                card.DoubleTapped         += target.Card_DoubleTapped;
                card.CardSelectionChanged += target.OnCardSelectionChanged;
            }
            else
            {
                card.PointerPressed       -= target.Card_OnPointerPressed;
                card.DoubleTapped         -= target.Card_DoubleTapped;
                card.CardSelectionChanged -= OnCardSelectionChanged;
            }

            this.Items.Remove(card);
            target.Items.Add(card);
        }
        private Point SetupCardForMove(CardView card, CardContainer target, bool rotate, bool transferCard)
        {
            int targetCount = target.Items.Count;

            //
            //  if they are overlapped, make the ZIndex such that they are on top of each other
            if (target.CardLayout == CardLayout.PlayedOverlapped)
            {
                if (targetCount > 0)
                {
                    int zIndex = Canvas.GetZIndex(target.Items.Last());
                    Canvas.SetZIndex(card, zIndex + 1);
                }
            }

            //SetCardSize(card);

            //
            //  set up the animation values so we can do the animation
            GeneralTransform gt   = target.TransformToVisual(card);
            Point            ptTo = gt.TransformPoint(target.GetCardTopLeft(targetCount));

            card.AnimationPosition = ptTo;
            if (rotate)
            {
                card.AnimateRotation += 360;
            }

            //
            // if we are going to transferownership...
            if (transferCard)
            {
                TransferCard(card, target);
            }
            return(ptTo);
        }
        public Task <Point> DragAsync(CardContainer container, CardView card, PointerRoutedEventArgs origE, DragList dragList, IDragAndDropProgress progress = null)
        {
            TaskCompletionSource <Point> taskCompletionSource = new TaskCompletionSource <Point>();
            UIElement mousePositionWindow = Window.Current.Content;
            Point     pointMouseDown      = origE.GetCurrentPoint(mousePositionWindow).Position;

            card.PushCard(true);
            bool dragging = false;

            if (dragList.Contains(card) == false)
            {
                dragList.Insert(0, card); // card you clicked is always the first one
            }
            PointerEventHandler pointerMovedHandler    = null;
            PointerEventHandler pointerReleasedHandler = null;

            pointerMovedHandler = (Object s, PointerRoutedEventArgs e) =>
            {
                Point pt    = e.GetCurrentPoint(mousePositionWindow).Position;
                Point delta = new Point();
                delta.X = pt.X - pointMouseDown.X;
                delta.Y = pt.Y - pointMouseDown.Y;

                CardView localCard    = (CardView)s;
                bool     reorderCards = false;
                //
                //  fixup our lists
                foreach (var c in this.SelectedCards)
                {
                    if (dragList.Contains(c) == false)
                    {
                        dragList.Add(c);
                    }
                }

                if (dragList.Contains(localCard) == false)
                {
                    dragList.Add(localCard);
                }

                if (dragList.Count > _maxSelected)
                {
                    CardView c = this.FirstSelectedCard;
                    c.Selected = false;
                    dragList.Remove(c);
                    c.UpdateLayout();
                }



                if (Math.Abs(delta.X - MOUSE_MOVE_SENSITIVITY) > 0 || Math.Abs(delta.Y - MOUSE_MOVE_SENSITIVITY) > 0)
                {
                    dragging = true;
                }

                //
                //  check to see if we have moved out of the container in the Y direction
                if (container.HitTest(pt))
                {
                    reorderCards = true;
                }

                if (dragList.Count > 1)
                {
                    reorderCards = false;
                    CardView otherCard = dragList[0];
                    double   cardWidth = card.CardWidth;
                    if (card.Index == otherCard.Index)
                    {
                        otherCard = dragList[1];
                    }

                    //
                    //  this moves the card to make space for reordering
                    int left = (int)(card.AnimationPosition.X - otherCard.AnimationPosition.X);

                    if (left > cardWidth)
                    {
                        otherCard.AnimateToReletiveAsync(new Point(left - cardWidth, 0), 0);
                        return;
                    }
                    else if (left < -card.CardWidth)
                    {
                        otherCard.AnimateToReletiveAsync(new Point(left + cardWidth, 0), 0);
                        return;
                    }
                }

                if (progress != null)
                {
                    progress.Report(pt);
                }

                foreach (CardView c in dragList)
                {
                    c.AnimateToReletiveAsync(delta);
                }

                if (reorderCards)
                {
                    int indexOfDraggedCard = container.Items.IndexOf(card);

                    if (delta.X > 0)
                    {
                        if (indexOfDraggedCard < container.Items.Count - 1)
                        {
                            CardView cardToMove = container.Items[indexOfDraggedCard + 1];
                            if (card.AnimationPosition.X + card.CardWidth * 0.5 > cardToMove.AnimationPosition.X)
                            {
                                cardToMove.AnimateToReletiveAsync(new Point(-card.CardWidth, 0), MainPage.AnimationSpeeds.VeryFast);
                                container.Items.Remove(card);
                                container.Items.Insert(container.Items.IndexOf(cardToMove) + 1, card);
                            }
                        }
                    }
                    else //moving left
                    {
                        if (indexOfDraggedCard > 0)
                        {
                            CardView cardToMove = container.Items[indexOfDraggedCard - 1];
                            if (card.AnimationPosition.X - card.CardWidth * 0.5 < cardToMove.AnimationPosition.X)
                            {
                                cardToMove.AnimateToReletiveAsync(new Point(card.CardWidth, 0), MainPage.AnimationSpeeds.VeryFast);
                                container.Items.Remove(card);
                                container.Items.Insert(container.Items.IndexOf(cardToMove), card);
                            }
                        }
                    }
                }


                pointMouseDown = pt;
            };

            pointerReleasedHandler = (Object s, PointerRoutedEventArgs e) =>
            {
                CardView localCard = (CardView)s;
                localCard.PointerMoved    -= pointerMovedHandler;
                localCard.PointerReleased -= pointerReleasedHandler;
                localCard.ReleasePointerCapture(origE.Pointer);
                localCard.PushCard(false);
                if (!dragging)
                {
                    ToggleSelectCard(card);
                    dragList.Clear();
                }



                Point exitPoint = e.GetCurrentPoint(mousePositionWindow).Position;

                if (progress != null)
                {
                    progress.PointerUp(exitPoint);
                }

                //if (container.HitTest(exitPoint) == true) // you landed where you started
                //    container.UpdateCardLayoutAsync(500, false);

                //
                //  returns the point that the mouse was released.  the _selectedCards list
                //  will have the cards that were selected.  if dragging occurred, the card(s)
                //  will be in the _draggingList
                taskCompletionSource.SetResult(exitPoint);
            };

            card.CapturePointer(origE.Pointer);
            card.PointerMoved    += pointerMovedHandler;
            card.PointerReleased += pointerReleasedHandler;
            return(taskCompletionSource.Task);
        }
 public HitTestClass(CardContainer container)
 {
     _container = container;
 }
Beispiel #13
0
        public void MoveCards(List <Task <object> > taskList, List <CardView> destinationList, CardContainer destinationContainer)
        {
            double duration = MainPage.AnimationSpeeds.Fast;

            foreach (CardView card in destinationList)
            {
                GridDeck.MoveCardToTarget(taskList, card, destinationContainer, duration, false, true);
            }
        }