Interaction logic for DeckShape.xaml
Inheritance: System.Windows.Controls.UserControl
Example #1
0
        /// <summary>
        /// Event handler for the card deck property changed event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CardDeckChanged(object sender, EventArgs e)
        {
            //Get Decks Shapes
            GameShape gameShape = GameShape.GetGameShape(this.Card.Deck.Game);
            DeckShape oldDeck   = (DeckShape)((Canvas)this.Parent).Parent;
            DeckShape newDeck   = gameShape.GetDeckShape(this.Card.Deck);

            //Get the animation positions in relation to the world (background)
            double startX = Canvas.GetLeft(oldDeck) + Canvas.GetLeft(this);
            double startY = Canvas.GetTop(oldDeck) + Canvas.GetTop(this);

            double endX = Canvas.GetLeft(newDeck);
            double endY = Canvas.GetTop(newDeck);

            //Change the card parent
            ((Canvas)this.Parent).Children.Remove(this);
            newDeck.LayoutRoot.Children.Add(this);

            //Maintain the same card position relative to the new parent
            Canvas.SetLeft(this, (double.IsNaN(startX) ? Convert.ToDouble(0) : startX) - endX);
            Canvas.SetTop(this, (double.IsNaN(startY) ? Convert.ToDouble(0) : startY) - endY);

            //Reorder decks
            oldDeck.UpdateCardShapes();
            newDeck.UpdateCardShapes();
        }
Example #2
0
 public void OnCardDrag(DeckShape fromDeckShape, DeckShape toDeckShape)
 {
     if ((fromDeckShape != null) && (CardDrag != null))
     {
         CardDrag(this, fromDeckShape, toDeckShape);
     }
 }
Example #3
0
 protected void cardShape_CardDrag(CardShape cardShape, DeckShape oldDeckShape, DeckShape newDeckShape)
 {
     if (CardDrag != null)
     {
         CardDrag(cardShape, oldDeckShape, newDeckShape);
     }
 }
Example #4
0
        /// <summary>
        /// Event handler for the image card mouse left button up.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void ImgCardMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (isDrag)
            {
                imgCard.ReleaseMouseCapture();
                isDrag = false;

                //Get which deck this card was dropped into
                GameShape gameShape        = GameShape.GetGameShape(this.Card.Deck.Game);
                DeckShape oldDeckShape     = gameShape.GetDeckShape(this.Card.Deck);
                DeckShape nearestDeckShape = null;
                double    nearestDistance  = double.MaxValue;

                foreach (var deck in gameShape.DeckShapes)
                {
                    if (deck.Deck.Enabled)
                    {
                        //double dx = Canvas.GetLeft(deck) - (Canvas.GetLeft(this) + Canvas.GetLeft((UIElement)((Canvas)this.Parent).Parent));
                        //double dy = Canvas.GetTop(deck) - (Canvas.GetTop(this) + Canvas.GetTop((UIElement)((Canvas)this.Parent).Parent));
                        var offset = VisualTreeHelper.GetOffset(deck);

                        var dx = offset.X - e.GetPosition((UIElement)((Canvas)this.Parent).Parent).X;
                        var dy = offset.Y - e.GetPosition((UIElement)((Canvas)this.Parent).Parent).Y;

                        double distance = Math.Sqrt(dx * dx + dy * dy);

                        if (distance < nearestDistance)
                        {
                            nearestDistance  = distance;
                            nearestDeckShape = deck;
                        }
                    }
                }

                if ((nearestDeckShape != null) && (CardDrag != null))
                {
                    CardDrag(this, gameShape.GetDeckShape(this.Card.Deck), nearestDeckShape);
                }

                gameShape.GetDeckShape(this.Card.Deck).UpdateCardShapes();
                Canvas.SetZIndex(oldDeckShape, 0);
            }

            if (CardMouseLeftButtonUp != null)
            {
                CardMouseLeftButtonUp(this, e);
            }
        }
Example #5
0
 public void OnCardDrag(DeckShape fromDeckShape, DeckShape toDeckShape)
 {
     if ((fromDeckShape != null) && (CardDrag != null))
     {
         CardDrag(this, fromDeckShape, toDeckShape);
     }
 }
Example #6
0
 protected void cardShape_CardDrag(CardShape cardShape, DeckShape oldDeckShape, DeckShape newDeckShape)
 {
     if (CardDrag != null)
         CardDrag(cardShape, oldDeckShape, newDeckShape);
 }