Octgn.Play.Gui.CardControl.DragCardCompleted C# (CSharp) Method

DragCardCompleted() protected method

protected DragCardCompleted ( ) : void
return void
        protected void DragCardCompleted()
        {
            if (!_isDragging) return;
            _isDragging = false;
            if (Card.Controller != Player.LocalPlayer) return;
            // Release the card and its group
            foreach (Card c in DraggedCards)
            {
                if (c != null)
                    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();
        }