Esempio n. 1
0
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (dataType != null)
            {
                Collection <int> _ChildNodeIDs = ViewModels.AssetTreeExViewModel.ChildNodeIDs;

                int _assetid = 0;
                if (this.AssociatedObject.DataContext.GetType().Equals(typeof(ViewModels.TVAssetViewModel)))
                {
                    _assetid = ((ViewModels.TVAssetViewModel) this.AssociatedObject.DataContext).Asset.ID;
                }
                if (!_ChildNodeIDs.Contains(_assetid))
                {
                    //if the data type can be dropped
                    if (e.Data.GetDataPresent(dataType))
                    {
                        //drop the data
                        IDropable target = this.AssociatedObject.DataContext as IDropable;
                        target.Drop(e.Data.GetData(dataType));

                        //remove the data from the source
                        //IDragable source = e.Data.GetData(dataType) as IDragable;
                        //source.Remove(e.Data.GetData(dataType));
                    }
                }
            }
            if (this.adorner != null)
            {
                this.adorner.Remove();
            }

            e.Handled = true;
            return;
        }
Esempio n. 2
0
        void AssociatedObject_DragEnter(object sender, DragEventArgs e)
        {
            e.Effects = _effect = DragDropEffects.None;
            Type dataType = GetDataType(e);

            if (dataType != null)
            {
                //Debug.WriteLine("Timer START");
                _openTimer.Start();

                // can drop?
                IDropable dropable = GetDropable();
                _canDrop   = dropable.CanDrop(GetData(e), this.AssociatedObject.DataContext, out _message);
                _data      = GetData(e);
                _target    = this.AssociatedObject.DataContext;
                _uiElement = sender as UIElement;

                if (_adorner == null)
                {
                    MakeAdorner(_uiElement, _data, _target, false, _canDrop, _message);
                }

                // give mouse effect
                if (_canDrop)
                {
                    e.Effects = _effect = DragDropEffects.Move;
                }
            }
            e.Handled = true;
        }
Esempio n. 3
0
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (_dataType != null)
            {
                //if the data type can be dropped
                if (e.Data.GetDataPresent(_dataType))
                {
                    //drop the data
                    IDropable target = AssociatedObject.DataContext as IDropable;
                    //var point = e.GetPosition(this.AssociatedObject.DataContext as IInputElement);
                    if (target != null)
                    {
                        target.Drop(e.Data.GetData(_dataType), e);
                    }

                    //remove the data from the source
                    IDragable source = e.Data.GetData(_dataType) as IDragable;
                    if (source != null)
                    {
                        source.Remove(e.Data.GetData(_dataType));
                    }
                }
            }

            //if (this.adorner != null)
            //    this.adorner.Remove();

            e.Handled = true;
        }
Esempio n. 4
0
        /// <summary>
        /// Get move list for King
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public override List <MoveBase> GetMoveList(IDropable dropedTile)
        {
            var tile = dropedTile as Tile;

            if (tile == null)
            {
                return(null);
            }

            var enemyMoves = GetAllEnemyPiecesMoveList(tile.Piece.Color);
            var list       = new List <MoveBase>();
            var i          = 1;
            //Diagonal Moves
            var ppdrow    = (int)tile.Row + i;
            var ppdcolumn = (int)tile.Column + i;

            tile.GetNextMove(ref list, ppdrow, ppdcolumn);

            var npdrow    = (int)tile.Row - i;
            var npdcolumn = (int)tile.Column + i;

            tile.GetNextMove(ref list, npdrow, npdcolumn);

            var pndrow    = (int)tile.Row + i;
            var pndcolumn = (int)tile.Column - i;

            tile.GetNextMove(ref list, pndrow, pndcolumn);

            var nndrow    = (int)tile.Row - i;
            var nndcolumn = (int)tile.Column - i;

            tile.GetNextMove(ref list, nndrow, nndcolumn);

            //Right Angled moves
            var pphrow    = (int)tile.Row;
            var pphcolumn = (int)tile.Column + i;

            tile.GetNextMove(ref list, pphrow, pphcolumn);

            var pnhrow    = (int)tile.Row;
            var pnhcolumn = (int)tile.Column - i;

            tile.GetNextMove(ref list, pnhrow, pnhcolumn);

            var nphrow    = (int)tile.Row + i;
            var nphcolumn = (int)tile.Column;

            tile.GetNextMove(ref list, nphrow, nphcolumn);

            var nnhrow    = (int)tile.Row - i;
            var nnhcolumn = (int)tile.Column;

            tile.GetNextMove(ref list, nnhrow, nnhcolumn);

            var moveList = list.Except(enemyMoves, new MoveComparer());

            var finalList = moveList.SkipWhile(m => m.GetType() == typeof(AttackMove) && !GetAllEnemyPiecesMoveList(tile.Piece.Color).Any(em => em.Row == m.Row && em.Column == m.Column));

            return(finalList.ToList());
        }
Esempio n. 5
0
        /// <summary>
        /// Drop event to call the respective classes to handle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (dataType != null)
            {
                //if the data type can be dropped
                if (e.Data.GetDataPresent(dataType))
                {
                    //drop the data
                    IDropable target = AssociatedObject.DataContext as IDropable;
                    if (target.CanDrop)
                    {
                        target.Drop(e.Data.GetData(dataType));

                        //remove the data from the source
                        IDragable source = e.Data.GetData(dataType) as IDragable;
                        source.Remove(e.Data.GetData(dataType));
                    }
                }
            }
            if (adorner != null)
            {
                adorner.Remove();
            }

            e.Handled = true;
            return;
        }
Esempio n. 6
0
        /// <summary>
        /// Updates the ardoner after Drag
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AssociatedObject_PreviewDragOver(object sender, DragEventArgs e)
        {
            IDropable dropObject = this.AssociatedObject.DataContext as IDropable;

            if (dropObject != null)
            {
                if (dropObject.CanDrop)
                {
                    if (dataType != null)
                    {
                        //if item can be dropped
                        if (e.Data.GetDataPresent(dataType))
                        {
                            //give mouse effect
                            SetDragDropEffects(e);
                            //draw the dots
                            if (adorner != null)
                            {
                                adorner.Update();
                            }
                        }
                    }
                }
            }
            e.Handled = true;
        }
Esempio n. 7
0
 private void AssociatedObjectOnDragLeave(object sender, DragEventArgs dragEventArgs)
 {
     if (_transferedType != null && dragEventArgs.Data.GetDataPresent(_transferedType))
     {
         IDropable dropable = AssociatedObject.DataContext as IDropable;
         dropable?.DragLeave();
     }
 }
Esempio n. 8
0
    public void OnDrop(PointerEventData eventData)
    {
        IDropable droppedObject = null;

        if (eventData.pointerDrag.TryGetComponent <IDropable>(out droppedObject))
        {
            droppedObject.OnDrop();
        }
    }
Esempio n. 9
0
 private void AssociatedObjectOnDragEnter(object sender, DragEventArgs dragEventArgs)
 {
     if (_transferedType == null && AssociatedObject != null)
     {
         IDropable dropable = AssociatedObject.DataContext as IDropable;
         if (dropable != null)
         {
             _transferedType = dropable.DataType;
         }
     }
 }
Esempio n. 10
0
        private void AssociatedObjectDragEnter(object sender, DragEventArgs e)
        {
            if (_dataType == null)
            {
                IDropable dropTarget = this.AssociatedObject.DataContext as IDropable;
                if (dropTarget != null)
                {
                    _dataType = dropTarget.DataType;
                }
            }

            e.Handled = true;
        }
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (dataType != null)
            {
                if (e.Data.GetDataPresent(dataType))
                {
                    IDropable target = this.AssociatedObject.DataContext as IDropable;
                    target.Drop(e);

                    IDragable source = e.Data.GetData(dataType) as IDragable;
                    source.Remove();
                }
            }
        }
Esempio n. 12
0
 protected virtual void AssociatedObject_Drop(object sender, DragEventArgs e)
 {
     if (DataType != null)
     {
         //if the data type can be dropped
         if (e.Data.GetDataPresent(DataType))
         {
             //drop the data
             IDropable target = AssociatedObject.DataContext as IDropable;
             target?.Drop(e.Data.GetData(DataType));
         }
     }
     e.Handled = true;
 }
Esempio n. 13
0
        protected virtual void AssociatedObject_DragEnter(object sender, DragEventArgs e)
        {
            //if the DataContext implements IDropable, record the data type that can be dropped
            if (DataType == null)
            {
                IDropable dropObject = AssociatedObject.DataContext as IDropable;
                if (dropObject != null)
                {
                    DataType = dropObject.DataType;
                }
            }

            e.Handled = true;
        }
Esempio n. 14
0
 private void AssociatedObjectOnDragOver(object sender, DragEventArgs dragEventArgs)
 {
     if (_transferedType != null && dragEventArgs.Data.GetDataPresent(_transferedType))
     {
         var data = dragEventArgs.Data.GetData(_transferedType);
         dragEventArgs.Effects = DragDropEffects.Move;
         IDropable dropable = AssociatedObject.DataContext as IDropable;
         if (dropable != null)
         {
             var position = dragEventArgs.GetPosition(AssociatedObject);
             dropable.DragOver(position.X, position.Y, data);
         }
     }
 }
Esempio n. 15
0
        public override List <MoveBase> GetMoveList(IDropable droppedTile)
        {
            var tile = droppedTile as Tile;

            if (tile == null)
            {
                return(null);
            }
            if (tile.IsEmptyTile)
            {
                return(null);
            }

            var list      = new List <MoveBase>();
            var ppcanMove = true;
            var pncanMove = true;
            var npcanMove = true;
            var nncanMove = true;

            for (int i = 1; i <= 8; i++)
            {
                if (ppcanMove)
                {
                    var row    = (int)tile.Row;
                    var column = (int)tile.Column + i;
                    ppcanMove = tile.GetNextMove(ref list, row, column);
                }
                if (pncanMove)
                {
                    var row    = (int)tile.Row;
                    var column = (int)tile.Column - i;
                    pncanMove = tile.GetNextMove(ref list, row, column);
                }
                if (npcanMove)
                {
                    var row    = (int)tile.Row + i;
                    var column = (int)tile.Column;
                    npcanMove = tile.GetNextMove(ref list, row, column);
                }
                if (nncanMove)
                {
                    var row    = (int)tile.Row - i;
                    var column = (int)tile.Column;
                    nncanMove = tile.GetNextMove(ref list, row, column);
                }
            }

            return(list);
        }
Esempio n. 16
0
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            IDropable target = this.AssociatedObject.DataContext as IDropable;
            int       index  = -1;

            if (target != null)
            {
                if (((DataGrid)sender) != null)
                {
                    index = ((DataGrid)sender).SelectedIndex;
                }
                target.Drop(e.Data.GetData(DataFormats.FileDrop), index);
            }
            e.Handled = true;
        }
Esempio n. 17
0
        void AssociatedObject_DragLeave(object sender, DragEventArgs e)
        {
            try
            {
                DistroyAdorner();

                Dropable = null;

                e.Handled = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
 /// <summary>
 /// Initialize drag and drop
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void AssociatedObject_DragEnter(object sender, DragEventArgs e)
 {
     if (this.dataType == null)
     {
         if (this.AssociatedObject.DataContext != null)
         {
             IDropable dropObject = this.AssociatedObject.DataContext as IDropable;
             if (dropObject != null)
             {
                 this.dataType = dropObject.DataType;
             }
         }
     }
     e.Handled = true;
 }
Esempio n. 19
0
        /// <summary>
        /// Method to get the move list of a Bishop
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public override List <MoveBase> GetMoveList(IDropable dropedTile)
        {
            var tile = dropedTile as Tile;

            if (tile == null)
            {
                return(null);
            }
            if (tile.Piece == null)
            {
                return(null);
            }

            var list      = new List <MoveBase>();
            var canMovePP = true;
            var canMovePN = true;
            var canMoveNP = true;
            var canMoveNN = true;

            for (int i = 1; i < 8; i++)
            {
                if (canMovePP)
                {
                    var pprow = (int)tile.Row + i;
                    var ppcol = (int)tile.Column + i;
                    canMovePP = tile.GetNextMove(ref list, pprow, ppcol);
                }
                if (canMovePN)
                {
                    var pnrow = (int)tile.Row + i;
                    var pncol = (int)tile.Column - i;
                    canMovePN = tile.GetNextMove(ref list, pnrow, pncol);
                }
                if (canMoveNP)
                {
                    var nprow = (int)tile.Row - i;
                    var npcol = (int)tile.Column + i;
                    canMoveNP = tile.GetNextMove(ref list, nprow, npcol);
                }
                if (canMoveNN)
                {
                    var nnrow = (int)tile.Row - i;
                    var nncol = (int)tile.Column - i;
                    canMoveNN = tile.GetNextMove(ref list, nnrow, nncol);
                }
            }
            return(list);
        }
Esempio n. 20
0
        public DropBehavior()
        {
            _blinkStopTimer.Elapsed += (s, e) =>
            {
                // do open
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IDropable dropable = GetDropable();
                    if (dropable != null)
                    {
                        //if (dropable.CanOpen(_data, _target))
                        dropable.Open(_data, _target);
                    }
                    _blinkTimer.Stop();
                });
            };

            _blinkTimer.Elapsed += (s, e) =>
            {
                // flash
                Application.Current.Dispatcher.Invoke(() =>
                {
                    if (_uiElement != null)
                    {
                        _isOpening = !_isOpening;
                        RemoveAdorner();
                        MakeAdorner(_uiElement, _data, _target, _isOpening, _canDrop, _message);
                    }
                });
            };

            _openTimer.Elapsed += (s, e) =>
            {
                // user waited for open
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IDropable dropable = GetDropable();
                    if (dropable != null)
                    {
                        if (dropable.CanOpen(_data, _target))
                        {
                            _blinkTimer.Start();
                            _blinkStopTimer.Start();
                        }
                    }
                });
            };
        }
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            //if the data type can be dropped
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                //drop the data
                IDropable target = this.AssociatedObject.DataContext as IDropable;
                target.Drop(e.Data.GetData(DataFormats.FileDrop));

                //remove the data from the source
                //IDragable source = e.Data.GetData(DataFormats.FileDrop) as IDragable;
                //source.Remove(e.Data.GetData(DataFormats.FileDrop));
            }

            e.Handled = true;
            return;
        }
Esempio n. 22
0
        /// <summary>
        /// Gets the IDropable which will handle the dropping.
        /// </summary>
        private IDropable GetDropable()
        {
            IDropable dropable = null;
            // get dropable parent
            FrameworkElement el = this.AssociatedObject;

            while (el != null && !(el.DataContext is IDropable))
            {
                el = (FrameworkElement)VisualTreeHelper.GetParent(el);
            }

            if (el != null && el.DataContext is IDropable)
            {
                dropable = (IDropable)el.DataContext;
            }
            return(dropable);
        }
Esempio n. 23
0
        /// <summary>
        /// Method to get all the moves for a Pawn including Capturing and Normal move
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public override List <MoveBase> GetMoveList(IDropable droppedTile)
        {
            var tile = droppedTile as Tile;

            if (tile == null)
            {
                return(null);
            }
            if (!tile.IsEmptyTile)
            {
                var listArea = ChessBoard.Instance.GetSurroundingTiles(tile, SQUAREAREALENGTH);
                if (listArea != null && listArea.Length > 0)
                {
                    var list = GetList(listArea, tile);
                    return(list);
                }
            }
            return(null);
        }
        /// <summary>
        /// The associated object_ drop.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            // if the data type can be dropped
            if (this.dataType != null)
            {
                if (e.Data.GetDataPresent(this.dataType))
                {
                    // first find the UIElement that it was dropped over, then we determine if it's
                    // dropped above or under the UIElement, then insert at the correct index.
                    ItemsControl dropContainer = sender as ItemsControl;

                    // get the UIElement that was dropped over
                    UIElement droppedOverItem = UIHelper.GetUIElement(dropContainer, e.GetPosition(dropContainer));
                    int       dropIndex       = -1; // the location where the item will be dropped
                    dropIndex = dropContainer.ItemContainerGenerator.IndexFromContainer(droppedOverItem) + 1;

                    // find if it was dropped above or below the index item so that we can insert
                    // the item in the correct place
                    if (UIHelper.IsPositionAboveElement(droppedOverItem, e.GetPosition(droppedOverItem)))
                    {
                        // if above
                        dropIndex = dropIndex - 1; // we insert at the index above it
                    }

                    // remove the data from the source
                    IDragable source = e.Data.GetData(this.dataType) as IDragable;
                    source.Remove(e.Data.GetData(this.dataType));

                    // drop the data
                    IDropable target = this.AssociatedObject.DataContext as IDropable;
                    target.Drop(e.Data.GetData(this.dataType), dropIndex);
                }
            }

            if (this.insertAdornerManager != null)
            {
                this.insertAdornerManager.Clear();
            }

            e.Handled = true;
            return;
        }
Esempio n. 25
0
        /// <summary>
        /// Gets the first acceptable Type for dropping.
        /// </summary>
        private Type GetDataType(DragEventArgs e)
        {
            IDropable dropable = GetDropable();

            if (dropable != null && dropable.DropableDataTypes != null)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop) && dropable.DropableDataTypes.Contains(typeof(FileInfo)))
                {
                    return(typeof(FileInfo));
                }
                else
                {
                    return(dropable.DropableDataTypes.FirstOrDefault(t => e.Data.GetDataPresent(t)));
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 26
0
        void AssociatedObject_DragEnter(object sender, DragEventArgs e)
        {
            //if the DataContext implements IDropable, record the data type that can be dropped
            if (this.dataType == null)
            {
                if (this.AssociatedObject.DataContext != null)
                {
                    IDropable dropObject = this.AssociatedObject.DataContext as IDropable;
                    if (dropObject != null)
                    {
                        this.dataType = dropObject.DataType;
                    }
                }
            }

            if (this.adorner == null)
            {
                this.adorner = new FrameworkElementAdorner(sender as UIElement);
            }
            e.Handled = true;
        }
Esempio n. 27
0
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            try
            {
                if (Dropable != null && CanDrop(e))
                {
                    Dropable.Drop(ExtractDragable(e), CreateDropContext(e));
                }

                if (this.Adorner != null)
                {
                    this.Adorner.Remove();
                }

                Dropable = null;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
Esempio n. 28
0
        void AssociatedObject_DragEnter(object sender, DragEventArgs e)
        {
            try
            {
                DistroyAdorner();

                if (Dropable == null)
                {
                    Dropable = this.AssociatedObject.DataContext as IDropable;
                }

                if (Dropable != null && Adorner == null)
                {
                    CreateAdorner();
                }

                e.Handled = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Method to get the List of moves for Knight
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public override List <MoveBase> GetMoveList(IDropable droppedTile)
        {
            var tile = droppedTile as Tile;

            if (tile == null)
            {
                return(null);
            }
            if (tile.IsEmptyTile)
            {
                return(null);
            }

            var list            = new List <MoveBase>();
            var surroundingList = ChessBoard.Instance.GetSurroundingTiles(tile, SQUAREAREALENGTH);

            foreach (var nxtTile in surroundingList)
            {
                if (nxtTile != null)
                {
                    var dist = nxtTile.GetDistance(tile);
                    if (dist == KNIGHTMOVEDISTANCE)
                    {
                        if (nxtTile.IsEmptyTile)
                        {
                            list.Add(new NormalMove(nxtTile.Row, nxtTile.Column));
                            continue;
                        }
                        else if (nxtTile.Piece.Color != tile.Piece.Color)
                        {
                            list.Add(new AttackMove(nxtTile.Row, nxtTile.Column, nxtTile.Piece));
                        }
                    }
                }
            }
            return(list);
        }
Esempio n. 30
0
        private void AssociatedObjectOnDrop(object sender, DragEventArgs dragEventArgs)
        {
            if (_dataType != null)
            {
                if (dragEventArgs.Data.GetDataPresent(_dataType))
                {
                    IDropable target = this.AssociatedObject.DataContext as IDropable;
                    if (target != null)
                    {
                        IDragable source = dragEventArgs.Data.GetData(_dataType) as IDragable;
                        if (source != null)
                        {
                            Debug.WriteLine("Drop");
                            Point currentPosition = dragEventArgs.GetPosition(RelativeElement);
                            source.Update(currentPosition.X, currentPosition.Y);
                        }

                        //target.Drop(dragEventArgs.Data.GetData(_dataType));
                    }
                }
            }

            dragEventArgs.Handled = true;
        }