Example #1
0
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            e.Handled = e.CanDrop = true;
            if ([email protected]())
            {
                return;
            }
            int idx = _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel));

            foreach (Card c in e.Cards)
            {
                bool doNotIncrement = (c.Group == @group && @group.GetCardIndex(c) < idx);
                c.MoveTo(@group, e.FaceUp != null && e.FaceUp.Value, idx);
                // Fix: some cards (notably copies like token) may be deleted when they change group
                // in those case we should increment idx, otherwise an IndexOutOfRange exception may occur
                if (c.Group != @group)
                {
                    doNotIncrement = true;
                }
                if (!doNotIncrement)
                {
                    idx++;
                }
            }
        }
Example #2
0
 protected override void OnCardDropped(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if (group.TryToManipulate())
         foreach (Card c in e.Cards)
             c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, 0);
 }
Example #3
0
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
            e.CardSize = CardSize;

            if (!Program.GameSettings.UseTwoSidedTable)
            {
                return;
            }
            var    cardCtrl = (CardControl)e.OriginalSource;
            Card   baseCard = cardCtrl.Card;
            double mouseY   = Mouse.GetPosition(cardsView).Y;
            double baseY    = (cardCtrl.IsInverted ||
                               (Player.LocalPlayer.InvertedTable && !cardCtrl.IsOnTableCanvas))
                               ? mouseY - Program.GameEngine.Definition.CardHeight + e.MouseOffset.Y
                               : mouseY - e.MouseOffset.Y;

            if (baseCard == null)
            {
                return;
            }
            foreach (CardDragAdorner adorner in e.Adorners)
            {
                if (adorner == null || adorner.SourceCard == null || adorner.SourceCard.Card == null)
                {
                    continue;
                }
                double y = baseY + adorner.SourceCard.Card.Y - baseCard.Y;
                adorner.OnHoverRequestInverted = IsInInvertedZone(y) ^ Player.LocalPlayer.InvertedTable;
            }
        }
Example #4
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     for (var i = 0; i < e.Cards.Length; i++)
     {
         e.CardSizes[i] = new Size(e.Cards[i].RealWidth * 100 / e.Cards[i].RealHeight, 100);
     }
     if (_fanPanel.HandDensity == 0)
     {
         if (bottomZone.Visibility != Visibility.Visible)
         {
             bottomZone.Visibility = Visibility.Visible;
             Anim.From             = 0;
             Anim.To = 0.4;
             bottomZone.BeginAnimation(OpacityProperty, Anim);
             Anim.From = null;
         }
         else
         {
             Anim.To = 0.4;
             bottomZone.BeginAnimation(OpacityProperty, Anim);
         }
     }
     else
     {
         //e.CardSize = new Size(100 * Program.GameEngine.Definition.DefaultSize.Width / Program.GameEngine.Definition.DefaultSize.Height, 100);
         _fanPanel.DisplayInsertIndicator(e.ClickedCard, _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel)));
     }
 }
Example #5
0
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            e.Handled = e.CanDrop = true;
            if ([email protected]())
            {
                return;
            }
            int idx   = _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel));
            var cards = e.Cards.ToArray();

            Card.MoveCardsTo(@group, cards, (args) =>
            {
                var c = args.Card;
                // Fix the target index if the card is already in the group at a lower index
                if (c.Group == @group && c.GetIndex() < idx)
                {
                    --idx;
                }
                args.Index          = idx;
                bool doNotIncrement = (c.Group == @group && @group.GetCardIndex(c) < idx);
                c.MoveTo(@group, e.FaceUp != null && e.FaceUp.Value, idx, false);
                // Fix: some cards (notably copies like token) may be deleted when they change group
                // in those case we should increment idx, otherwise an IndexOutOfRange exception may occur
                if (c.Group != @group)
                {
                    doNotIncrement = true;
                }
                if (!doNotIncrement)
                {
                    idx++;
                }
            }, false);
        }
Example #6
0
 protected virtual void OnCardOver(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     e.Handler = this;
     switch (group.Visibility)
     {
         case GroupVisibility.Nobody:
             e.FaceUp = false;
             break;
         case GroupVisibility.Everybody:
             e.FaceUp = true;
             break;
         case GroupVisibility.Owner:
             e.FaceUp = group.Owner == Player.LocalPlayer;
             break;
         case GroupVisibility.Undefined:
             if (e.ClickedCard.Group != group)
                 e.FaceUp = null;
             else
                 e.FaceUp = e.ClickedCard.FaceUp;
             break;
         case GroupVisibility.Custom:
             e.FaceUp = group.Viewers.Contains(Player.LocalPlayer);
             break;
         default:
             throw new NotImplementedException("Unknown visibility : " + group.Visibility);
     }
 }
Example #7
0
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
			for(var i = 0;i<e.Cards.Length;i++)
            {
                e.CardSizes[i] = new Size(cardsCtrl.ActualWidth, cardsCtrl.ActualHeight);
                if (cardsCtrl.ActualWidth > cardsCtrl.ActualHeight)
                {
                    e.CardSizes[i] = new Size(e.Cards[i].RealWidth*cardsCtrl.ActualHeight/e.Cards[i].RealHeight, cardsCtrl.ActualHeight);
                }
                else
                {
                    e.CardSizes[i] = new Size(cardsCtrl.ActualWidth, e.Cards[i].RealHeight * cardsCtrl.ActualWidth / e.Cards[i].RealWidth);
                }
            }

            if (bottomZone.Visibility != Visibility.Visible)
            {
                bottomZone.Visibility = Visibility.Visible;
                Anim.From = 0;
                Anim.To = 0.4;
                bottomZone.BeginAnimation(OpacityProperty, Anim);
                Anim.From = null;
            }
            else
            {
                Anim.To = 0.4;
                bottomZone.BeginAnimation(OpacityProperty, Anim);
            }
        }
Example #8
0
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
            for (var i = 0; i < e.Cards.Length; i++)
            {
                e.CardSizes[i] = new Size(cardsCtrl.ActualWidth, cardsCtrl.ActualHeight);
                if (cardsCtrl.ActualWidth > cardsCtrl.ActualHeight)
                {
                    e.CardSizes[i] = new Size(e.Cards[i].Size.Width * cardsCtrl.ActualHeight / e.Cards[i].Size.Height, cardsCtrl.ActualHeight);
                }
                else
                {
                    e.CardSizes[i] = new Size(cardsCtrl.ActualWidth, e.Cards[i].Size.Height * cardsCtrl.ActualWidth / e.Cards[i].Size.Width);
                }
            }

            if (bottomZone.Visibility != Visibility.Visible)
            {
                bottomZone.Visibility = Visibility.Visible;
                Anim.From             = 0;
                Anim.To = 0.4;
                bottomZone.BeginAnimation(OpacityProperty, Anim);
                Anim.From = null;
            }
            else
            {
                Anim.To = 0.4;
                bottomZone.BeginAnimation(OpacityProperty, Anim);
            }
        }
Example #9
0
        protected void DragCardCompleted()
        {
            // Release the card and its group
            foreach (Card c in DraggedCards)
            {
                c.ReleaseControl();
            }
            Card.Group.ReleaseControl();

            // Remove the visual feedback
            var mwc = _mainWin.Content as Visual;

            if (mwc != null)
            {
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(mwc);
                foreach (CardDragAdorner overlay in OverlayElements)
                {
                    layer.Remove(overlay);
                    overlay.Dispose();
                }
            }
            OverlayElements.Clear();

            // Raise CardOutEvent
            if (_lastDragTarget != null)
            {
                _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                _lastDragTarget = null;
            }

            // Raise CardDroppedEvent
            IInputElement res = Mouse.DirectlyOver;

            if (res != null)
            {
                var args = new CardsEventArgs(Card, DraggedCards, CardDroppedEvent, this)
                {
                    MouseOffset = _mouseOffset,
                    FaceUp      = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                };
                res.RaiseEvent(args);
            }

            // Restore full opacity
            // FIX (jods): if the cards have been moved to another group, groupCtrl is null.
            //					     But in this case nothing has to be done opacity-wise since
            //					   the CardControls have been unloaded.
            GroupControl groupCtrl = GroupControl;

            if (groupCtrl != null)
            {
                foreach (CardControl cardCtrl in Selection.GetCardControls(groupCtrl, this))
                {
                    cardCtrl.Opacity = 1;
                }
            }

            DraggedCards.Clear();
        }
Example #10
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     e.CardSize =
         new Size(
             100*Program.GameEngine.Definition.CardWidth/Program.GameEngine.Definition.CardHeight, 100);
     _fanPanel.DisplayInsertIndicator(e.ClickedCard, _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel)));
 }
Example #11
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     e.CardSize =
         new Size(
             100 * Program.Game.Definition.CardDefinition.Width / Program.Game.Definition.CardDefinition.Height, 100);
     _fanPanel.DisplayInsertIndicator(e.ClickedCard, _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel)));
 }
Example #12
0
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            StopDragScroll();
            e.Handled = e.CanDrop = true;
            if ([email protected]())
            {
                return;
            }
            int idx = _wrapPanel.GetIndexFromPoint(Mouse.GetPosition(_wrapPanel));

            // When the list is restricted, real index may be different from index in the GUI
            if (RestrictDrop)
            {
                Card c     = null;
                bool after = false;
                if (idx < _view.Count)
                {
                    c = (Card)_view.GetItemAt(idx);
                }
                else if (_view.Count > 0)
                {
                    c     = (Card)_view.GetItemAt(_view.Count - 1);
                    after = true;
                }

                if (c != null)
                {
                    idx = @group.Cards.IndexOf(c) + (after ? 1 : 0);
                }
            }

            foreach (Card c in e.Cards)
            {
                // Fix the target index if the card is already in the group at a lower index
                if (c.Group == @group && c.GetIndex() < idx)
                {
                    --idx;
                }
                c.MoveTo(@group, e.FaceUp != null && e.FaceUp.Value, idx++, false);
            }
        }
Example #13
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     for (var i = 0; i < e.Cards.Length; i++)
     {
         e.CardSizes[i] = new Size(e.Cards[i].Size.Width * 30 / e.Cards[i].Size.Height, 30);
     }
     //e.CardSize = new Size(30*group.Def.Width/group.Def.Height, 30);
 }
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
			for(var i = 0;i<e.Cards.Length;i++)
            {
                e.CardSizes[i] = new Size(e.Cards[i].RealWidth * 30 / e.Cards[i].RealHeight, 30);
            }
            //e.CardSize = new Size(30*group.Def.Width/group.Def.Height, 30);
        }
Example #15
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     for (var i = 0; i < e.Cards.Length; i++)
     {
         e.CardSizes[i] = new Size(e.Cards[i].RealWidth * 100 / e.Cards[i].RealHeight, 100);
     }
     //e.CardSize = new Size(100 * Program.GameEngine.Definition.DefaultSize.Width / Program.GameEngine.Definition.DefaultSize.Height, 100);
     _fanPanel.DisplayInsertIndicator(e.ClickedCard, _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel)));
 }
Example #16
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     for(var i = 0;i<e.Cards.Length;i++)
     {
         e.CardSizes[i] = new Size(e.Cards[i].Size.Width * 100 / e.Cards[i].Size.Height, 100);
     }
     //e.CardSize = new Size(100 * Program.GameEngine.Definition.DefaultSize.Width / Program.GameEngine.Definition.DefaultSize.Height, 100);
     _fanPanel.DisplayInsertIndicator(e.ClickedCard, _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel)));
 }
Example #17
0
        protected void DragMouseDelta(double dx, double dy)
        {
            IInputElement res = _mainWin.InputHitTest(Mouse.GetPosition(_mainWin));

            // Raise CardOverEvent
            if (res != null)
            {
                foreach (CardDragAdorner overlay in OverlayElements)
                {
                    overlay.OnHoverRequestInverted = false;
                }
                var overArgs = new CardsEventArgs(Card, DraggedCards, CardOverEvent, this)
                {
                    MouseOffset = _mouseOffset, Adorners = OverlayElements
                };
                res.RaiseEvent(overArgs);

                // Collapse/Expand multiple cards when inside/outside of table
                DragCollapseSelection(_lastDragTarget, overArgs.Handler);

                // Keep track of previous target and raise CardOutEvent
                if (overArgs.Handler != _lastDragTarget && _lastDragTarget != null)
                {
                    _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                }
                _lastDragTarget = overArgs.Handler;

                if (overArgs.CanDrop)
                {
                    if (!overArgs.FaceUp.HasValue)
                    {
                        overArgs.FaceUp = (Keyboard.Modifiers & ModifierKeys.Shift) == 0;
                    }

                    foreach (CardDragAdorner overlay in OverlayElements)
                    {
                        overlay.SetState(dx, dy, true, overArgs.CardSize, overArgs.FaceUp.Value,
                                         overlay.OnHoverRequestInverted);
                    }

                    return;
                }
            }
            else if (_lastDragTarget != null)
            {
                _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                _lastDragTarget = null;
            }

            // Update the visual feedback (can't drop)
            foreach (CardDragAdorner overlay in OverlayElements)
            {
                overlay.SetState(dx, dy, false, Size.Empty, false, false);
            }
        }
Example #18
0
 private void OnCardDroppedBottom(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if (group.TryToManipulate())
     {
         foreach (Card c in e.Cards)
         {
             c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, group.Count, false);
         }
     }
 }
Example #19
0
 protected override void OnCardDropped(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if (group.TryToManipulate())
     {
         foreach (Card c in e.Cards)
         {
             c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, 0, false);
         }
     }
 }
Example #20
0
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);

            // Set overlay card size
            for (var i = 0; i < e.Cards.Length; i++)
            {
                e.CardSizes[i] = new Size(e.Cards[i].RealWidth * 100 / e.Cards[i].RealHeight, 100);
            }
            //e.CardSize = new Size(Program.GameEngine.Definition.DefaultSize.Width * 100 / Program.GameEngine.Definition.DefaultSize.Height, 100);
            if (IsAlwaysUp)
            {
                e.FaceUp = true;
            }

            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.CanDrop = false;
                return;
            }

            // Display insert indicator
            _wrapPanel.DisplayInsertIndicator(e.ClickedCard, _wrapPanel.GetIndexFromPoint(e.ClickedCard, Mouse.GetPosition(_wrapPanel)));

            // Scroll the scroll viewer if required
            double pos = Mouse.GetPosition(scroller).Y;

            if (pos <= ScrollMargin || pos >= scroller.ActualHeight - ScrollMargin)
            {
                if (_scrollTimer == null)
                {
                    _scrollSpeed       = ScrollInitialSpeed;
                    _scrollDirectionUp = pos <= ScrollMargin;
                    _scrollTimer       = new DispatcherTimer {
                        Interval = TimeSpan.FromMilliseconds(ScrollTimeInterval)
                    };
                    _scrollTimer.Tick += DragScroll;
                    _scrollTimer.Start();
                }
            }
            else
            {
                StopDragScroll();
            }
        }
Example #21
0
 protected override void OnCardDropped(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if (group.CanManipulate())
     {
         var cards = e.Cards.ToArray();
         Card.MoveCardsTo(group, cards, 
             Enumerable.Repeat(e.FaceUp ?? false,cards.Length).ToArray()
             ,Enumerable.Repeat(0,cards.Length).ToArray(),false);
     }
     //foreach (Card c in e.Cards)
     //    c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, 0, false);
 }
Example #22
0
 protected override void OnCardDropped(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if (group.TryToManipulate())
     {
         var cards = e.Cards.ToArray();
         Card.MoveCardsTo(group, cards,
                          Enumerable.Repeat(e.FaceUp ?? false, cards.Length).ToArray()
                          , Enumerable.Repeat(0, cards.Length).ToArray(), false);
     }
     //foreach (Card c in e.Cards)
     //    c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, 0, false);
 }
Example #23
0
 private void OnCardDroppedBottom(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     //if (group.TryToManipulate())
     //    foreach (Card c in e.Cards)
     //        c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, group.Count,false);
     if (group.TryToManipulate())
     {
         var cards = e.Cards.ToArray();
         Card.MoveCardsTo(group, cards,
                          Enumerable.Repeat(e.FaceUp ?? false, cards.Length).ToArray()
                          , Enumerable.Range(group.Count, cards.Length).ToArray(), false);
     }
 }
 protected override void OnCardDropped(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
      if (group.TryToManipulate())
      {
     int idx = fanPanel.GetIndexFromPoint(Mouse.GetPosition(fanPanel));
     foreach (Card c in e.Cards)
     {
       bool doNotIncrement = (c.Group == group && group.GetCardIndex(c) < idx);
       c.MoveTo(group, e.FaceUp.Value, idx);
       if (!doNotIncrement) idx++;
     }
      }
 }
Example #25
0
 protected override void OnCardDropped(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if ([email protected]()) return;
     int idx = _fanPanel.GetIndexFromPoint(Mouse.GetPosition(_fanPanel));
     foreach (Card c in e.Cards)
     {
         bool doNotIncrement = (c.Group == @group && @group.GetCardIndex(c) < idx);
         c.MoveTo(@group, e.FaceUp != null && e.FaceUp.Value, idx,false);
         // Fix: some cards (notably copies like token) may be deleted when they change group
         // in those case we should increment idx, otherwise an IndexOutOfRange exception may occur
         if (c.Group != @group)
             doNotIncrement = true;
         if (!doNotIncrement) idx++;
     }
 }
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
             e.CardSize = new Size(cardsCtrl.ActualWidth, cardsCtrl.ActualHeight);

             if (bottomZone.Visibility != Visibility.Visible)
             {
            bottomZone.Visibility = Visibility.Visible;
            anim.From = 0; anim.To = 0.4;
            bottomZone.BeginAnimation(OpacityProperty, anim);
            anim.From = null;
             }
             else
             {
            anim.To = 0.4;
            bottomZone.BeginAnimation(OpacityProperty, anim);
             }
        }
Example #27
0
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
            e.CardSize = new Size(cardsCtrl.ActualWidth, cardsCtrl.ActualHeight);

            if (bottomZone.Visibility != Visibility.Visible)
            {
                bottomZone.Visibility = Visibility.Visible;
                Anim.From             = 0;
                Anim.To = 0.4;
                bottomZone.BeginAnimation(OpacityProperty, Anim);
                Anim.From = null;
            }
            else
            {
                Anim.To = 0.4;
                bottomZone.BeginAnimation(OpacityProperty, Anim);
            }
        }
Example #28
0
        protected virtual void OnCardOver(object sender, CardsEventArgs e)
        {
            e.Handled = e.CanDrop = true;
            e.Handler = this;
            switch (group.Visibility)
            {
            case GroupVisibility.Nobody:
                e.FaceUp = false;
                break;

            case GroupVisibility.Everybody:
                e.FaceUp = true;
                break;

            case GroupVisibility.Owner:
                e.FaceUp = group.Owner == Player.LocalPlayer;
                break;

            case GroupVisibility.Undefined:
                if (e.ClickedCard.Group != group)
                {
                    e.FaceUp = null;
                }
                else
                {
                    e.FaceUp = e.ClickedCard.FaceUp;
                }
                break;

            case GroupVisibility.Custom:
                e.FaceUp = group.Viewers.Contains(Player.LocalPlayer);
                break;

            default:
                throw new NotImplementedException("Unknown visibility : " + group.Visibility);
            }
        }
Example #29
0
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     bottomZone.Visibility = Visibility.Collapsed;
     _fanPanel.HideInsertIndicator();
 }
Example #30
0
 protected virtual void OnCardDropped(object sender, CardsEventArgs e)
 {
     // The method cannot be abstract, because abstract classes can't be named in XAML (e.g. TableControl.xaml)
     throw new NotImplementedException("OnCardDropped must be overriden");
 }
Example #31
0
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            StopDragScroll();
            e.Handled = e.CanDrop = true;
            if ([email protected]())
            {
                return;
            }
            int idx = _wrapPanel.GetIndexFromPoint(e.ClickedCard, Mouse.GetPosition(_wrapPanel));

            Trace.WriteLine("Index: " + idx);
            // When the list is restricted, real index may be different from index in the GUI
            if (RestrictDrop)
            {
                Card c     = null;
                bool after = false;
                if (idx < _view.Count)
                {
                    c = (Card)_view.GetItemAt(idx);
                }
                else if (_view.Count > 0)
                {
                    c     = (Card)_view.GetItemAt(_view.Count - 1);
                    after = true;
                }

                if (c != null)
                {
                    idx = @group.Cards.IndexOf(c) + (after ? 1 : 0);
                }
            }

            var cards = e.Cards.ToArray();
            var idxs  = new int[cards.Length];
            var fups  = new bool[cards.Length];

            for (var i = 0; i < cards.Length; i++)
            {
                var c = cards[i];
                // Fix the target index if the card is already in the group at a lower index
                if (c.Group == @group && c.GetIndex() < idx)
                {
                    --idx;
                }
                idxs[i] = idx;
                idx++;
                fups[i] = e.FaceUp ?? false;
            }
            Card.MoveCardsTo(@group, cards, fups, idxs, false);
        }
Example #32
0
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     bottomZone.Visibility = Visibility.Collapsed;
 }
Example #33
0
 private void OnCardDroppedBottom(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     //if (group.TryToManipulate())
     //    foreach (Card c in e.Cards)
     //        c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, group.Count,false);
     if (group.CanManipulate())
     {
         var cards = e.Cards.ToArray();
         Card.MoveCardsTo(group, cards, 
             Enumerable.Repeat(e.FaceUp ?? false,cards.Length).ToArray()
             ,Enumerable.Range(group.Count,cards.Length).ToArray(),false);
     }
 }
Example #34
0
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            e.Handled = e.CanDrop = true;
            var cardCtrl = e.OriginalSource as CardControl;

            int    delta = Program.GameEngine.Definition.CardHeight - Program.GameEngine.Definition.CardWidth;
            Table  table = Program.GameEngine.Table;
            Vector mouseOffset;

            if (cardCtrl != null && (cardCtrl.IsInverted ||
                                     (Player.LocalPlayer.InvertedTable && !cardCtrl.IsOnTableCanvas)))
            {
                mouseOffset = new Vector(Program.GameEngine.Definition.CardWidth - e.MouseOffset.X, Program.GameEngine.Definition.CardHeight - e.MouseOffset.Y);
            }
            else
            {
                mouseOffset = e.MouseOffset;
            }
            Point pt = MousePosition();

            pt -= mouseOffset;

            if (Selection.IsEmpty() || !(Selection.Source is Table))
            {
                if (Program.GameSettings.UseTwoSidedTable && (e.ClickedCard.Orientation & CardOrientation.Rot90) != 0)
                {
                    // We have to offset the position if we cross the middle line
                    bool newPosInverted = IsInInvertedZone(pt.Y);
                    if (cardCtrl != null && (!cardCtrl.IsInverted && newPosInverted))
                    {
                        pt.X += delta;
                        pt.Y += delta;
                    }
                    else if (cardCtrl != null && (cardCtrl.IsInverted && !newPosInverted))
                    {
                        pt.X -= delta;
                        pt.Y -= delta;
                    }
                }

                int idx = table.GetCardIndex(e.ClickedCard);
                if (idx != -1 || table.Visibility != DataNew.Entities.GroupVisibility.Undefined)
                {
                    e.FaceUp = e.ClickedCard.FaceUp;
                }
                if (idx == -1)
                {
                    idx = table.Cards.Count;
                }
                e.ClickedCard.MoveToTable((int)pt.X, (int)pt.Y, e.FaceUp != null && e.FaceUp.Value, idx, false);

                // If there were other cards (i.e. dragging from a count number in GroupWindow), move them accordingly
                double xOffset = Program.GameEngine.Definition.CardWidth * 1.05;
                foreach (Card c in e.Cards.Where(c => c != e.ClickedCard))
                {
                    pt.X += xOffset;
                    c.MoveToTable((int)pt.X, (int)pt.Y, e.FaceUp != null && e.FaceUp.Value, idx, false);
                }
            }
            else
            {
                // There are multiple cards, coming from the table. Offset them accordingly
                double dx = pt.X - e.ClickedCard.X;
                double dy = pt.Y - e.ClickedCard.Y;
                foreach (Card c in Selection.Cards)
                {
                    int x = (int)(c.X + dx), y = (int)(c.Y + dy);
                    int idx = table.GetCardIndex(c);
                    // If the card is tapped and has crossed the middle line in a two-sided table, we have to adjust its position
                    if (Program.GameSettings.UseTwoSidedTable && (c.Orientation & CardOrientation.Rot90) != 0)
                    {
                        bool oldPosInverted = IsInInvertedZone(c.Y);
                        bool newPosInverted = IsInInvertedZone(y);
                        if (!oldPosInverted && newPosInverted)
                        {
                            x += delta;
                            y += delta;
                        }
                        else if (oldPosInverted && !newPosInverted)
                        {
                            x -= delta;
                            y -= delta;
                        }
                    }
                    c.MoveToTable(x, y, c.FaceUp, idx, false);
                }
            }
        }
Example #35
0
 protected virtual void OnCardOut(object sender, CardsEventArgs e)
 {
     // Made to be overriden
 }
Example #36
0
 protected virtual void OnCardDropped(object sender, CardsEventArgs e)
 {
     // The method cannot be abstract, because abstract classes can't be named in XAML (e.g. TableControl.xaml)
     throw new NotImplementedException("OnCardDropped must be overriden");
 }
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            StopDragScroll();
            e.Handled = e.CanDrop = true;
            if ([email protected]()) return;
            int idx = _wrapPanel.GetIndexFromPoint(e.ClickedCard, Mouse.GetPosition(_wrapPanel));
            Trace.WriteLine("Index: " + idx);
            // When the list is restricted, real index may be different from index in the GUI
            if (RestrictDrop)
            {
                Card c = null;
                bool after = false;
                if (idx < _view.Count)
                    c = (Card)_view.GetItemAt(idx);
                else if (_view.Count > 0)
                {
                    c = (Card)_view.GetItemAt(_view.Count - 1);
                    after = true;
                }

                if (c != null) idx = @group.Cards.IndexOf(c) + (after ? 1 : 0);
            }

            var cards = e.Cards.ToArray();
            var idxs = new int[cards.Length];
            var fups = new bool[cards.Length];
            for (var i = 0; i < cards.Length; i++)
            {
                var c = cards[i];
                // Fix the target index if the card is already in the group at a lower index
                if (c.Group == @group && c.GetIndex() < idx) --idx;
                idxs[i] = idx;
                idx++;
                fups[i] = e.FaceUp ?? false;
            }
            Card.MoveCardsTo(@group, cards, fups, idxs, false);
        }
Example #38
0
        protected void DragCardCompleted()
        {
            // Release the card and its group
            foreach (Card c in DraggedCards) c.ReleaseControl();
            Card.Group.ReleaseControl();

            // Remove the visual feedback
            var mwc = _mainWin.Content as Visual;
            if (mwc != null)
            {
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(mwc);
                foreach (CardDragAdorner overlay in OverlayElements)
                {
                    layer.Remove(overlay);
                    overlay.Dispose();
                }
            }
            OverlayElements.Clear();

            // Raise CardOutEvent
            if (_lastDragTarget != null)
            {
                _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                _lastDragTarget = null;
            }

            // Raise CardDroppedEvent
            IInputElement res = Mouse.DirectlyOver;
            if (res != null)
            {
                var args = new CardsEventArgs(Card, DraggedCards, CardDroppedEvent, this)
                               {
                                   MouseOffset = _mouseOffset,
                                   FaceUp = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                               };
                res.RaiseEvent(args);
            }

            // Restore full opacity
            // FIX (jods): if the cards have been moved to another group, groupCtrl is null.
            //					 	 But in this case nothing has to be done opacity-wise since 
            //					   the CardControls have been unloaded.
            GroupControl groupCtrl = GroupControl;
            if (groupCtrl != null)
                foreach (CardControl cardCtrl in Selection.GetCardControls(groupCtrl, this))
                    cardCtrl.Opacity = 1;

            DraggedCards.Clear();
        }
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     e.Handled = true;
     _wrapPanel.HideInsertIndicator();
     StopDragScroll();
 }
Example #40
0
 private void OnCardOverBottom(object sender, CardsEventArgs e)
 {
     OnCardOver(sender, e);
     Anim.To = 0.8;
     bottomZone.BeginAnimation(OpacityProperty, Anim);
 }
Example #41
0
 private void OnCardOverBottom(object sender, CardsEventArgs e)
 {
     OnCardOver(sender, e);
     Anim.To = 0.8;
     bottomZone.BeginAnimation(OpacityProperty, Anim);
 }
Example #42
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     e.CardSize = new Size(30 * group.Def.Width / group.Def.Height, 30);
 }
Example #43
0
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     bottomZone.Visibility = Visibility.Collapsed;
 }
Example #44
0
 private void OnCardDroppedBottom(object sender, CardsEventArgs e)
 {
     e.Handled = e.CanDrop = true;
     if (group.TryToManipulate())
         foreach (Card c in e.Cards)
             c.MoveTo(group, e.FaceUp != null && e.FaceUp.Value, group.Count);
 }
Example #45
0
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     e.Handled = true;
     _fanPanel.HideInsertIndicator();
 }
Example #46
0
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     e.Handled = true;
     _wrapPanel.HideInsertIndicator();
     StopDragScroll();
 }
Example #47
0
        protected override void OnCardDropped(object sender, CardsEventArgs e)
        {
            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.Handled = true;
                e.CanDrop = false;
                return;
            }

            StopDragScroll();
            e.Handled = e.CanDrop = true;
            if ([email protected]()) return;
            int idx = _wrapPanel.GetIndexFromPoint(Mouse.GetPosition(_wrapPanel));

            // When the list is restricted, real index may be different from index in the GUI
            if (RestrictDrop)
            {
                Card c = null;
                bool after = false;
                if (idx < _view.Count)
                    c = (Card) _view.GetItemAt(idx);
                else if (_view.Count > 0)
                {
                    c = (Card) _view.GetItemAt(_view.Count - 1);
                    after = true;
                }

                if (c != null) idx = @group.Cards.IndexOf(c) + (after ? 1 : 0);
            }

            foreach (Card c in e.Cards)
            {
                // Fix the target index if the card is already in the group at a lower index
                if (c.Group == @group && c.GetIndex() < idx) --idx;
                c.MoveTo(@group, e.FaceUp != null && e.FaceUp.Value, idx++);
            }
        }
Example #48
0
 protected virtual void OnCardOut(object sender, CardsEventArgs e)
 {
     // Made to be overriden
 }
Example #49
0
 protected override void OnCardOut(object sender, CardsEventArgs e)
 {
     e.Handled = true;
     _fanPanel.HideInsertIndicator();
 }
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);

            // Set overlay card size
            for(var i = 0;i<e.Cards.Length;i++)
            {
                e.CardSizes[i] = new Size(e.Cards[i].Size.Width * 100 / e.Cards[i].Size.Height, 100);
            }
            //e.CardSize = new Size(Program.GameEngine.Definition.DefaultSize.Width * 100 / Program.GameEngine.Definition.DefaultSize.Height, 100);
            if (IsAlwaysUp) e.FaceUp = true;

            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.CanDrop = false;
                return;
            }

            // Display insert indicator
            _wrapPanel.DisplayInsertIndicator(e.ClickedCard, _wrapPanel.GetIndexFromPoint(e.ClickedCard, Mouse.GetPosition(_wrapPanel)));

            // Scroll the scroll viewer if required
            double pos = Mouse.GetPosition(scroller).Y;
            if (pos <= ScrollMargin || pos >= scroller.ActualHeight - ScrollMargin)
            {
                if (_scrollTimer == null)
                {
                    _scrollSpeed = ScrollInitialSpeed;
                    _scrollDirectionUp = pos <= ScrollMargin;
                    _scrollTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(ScrollTimeInterval) };
                    _scrollTimer.Tick += DragScroll;
                    _scrollTimer.Start();
                }
            }
            else
                StopDragScroll();
        }
Example #51
0
        protected void DragMouseDelta(double dx, double dy)
        {
            IInputElement res = _mainWin.InputHitTest(Mouse.GetPosition(_mainWin));

            // Raise CardOverEvent
            if (res != null)
            {
                foreach (CardDragAdorner overlay in OverlayElements) overlay.OnHoverRequestInverted = false;
                var overArgs = new CardsEventArgs(Card, DraggedCards, CardOverEvent, this)
                                   {MouseOffset = _mouseOffset, Adorners = OverlayElements};
                res.RaiseEvent(overArgs);

                // Collapse/Expand multiple cards when inside/outside of table
                DragCollapseSelection(_lastDragTarget, overArgs.Handler);

                // Keep track of previous target and raise CardOutEvent
                if (overArgs.Handler != _lastDragTarget && _lastDragTarget != null)
                    _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                _lastDragTarget = overArgs.Handler;

                if (overArgs.CanDrop)
                {
                    if (!overArgs.FaceUp.HasValue)
                        overArgs.FaceUp = (Keyboard.Modifiers & ModifierKeys.Shift) == 0;

                    foreach (CardDragAdorner overlay in OverlayElements)
                        overlay.SetState(dx, dy, true, overArgs.CardSize, overArgs.FaceUp.Value,
                                         overlay.OnHoverRequestInverted);

                    return;
                }
            }
            else if (_lastDragTarget != null)
            {
                _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                _lastDragTarget = null;
            }

            // Update the visual feedback (can't drop)
            foreach (CardDragAdorner overlay in OverlayElements)
                overlay.SetState(dx, dy, false, Size.Empty, false, false);
        }
Example #52
0
 protected override void OnCardOver(object sender, CardsEventArgs e)
 {
     base.OnCardOver(sender, e);
     e.CardSize = new Size(30*group.Def.Width/group.Def.Height, 30);
 }