Exemplo n.º 1
0
        //IEnumerable<IGridItem> GetCloseEnemiesAux(IGridItem item)
        IEnumerable <IGridItem> GetCloseEnemiesAux(int cellX, int cellZ)
        {
            //Determine which grid cell the friendly soldier is in
            //int cellX = (int)(item.Pos2.x / cellSize);
            //int cellZ = (int)(item.Pos2.y / cellSize);

            //Get the first enemy in grid
            IGridItem enemy = cells[cellX, cellZ];

            //Find the closest soldier of all in the linked list
            IGridItem closestSoldier = null;

            float bestDistSqr = Mathf.Infinity;

            //Loop through the linked list
            while (enemy != null)
            {
                //The distance sqr between the soldier and this enemy
                float distSqr = 0;//**-- (enemy.Pos2 - item.Pos2).sqrMagnitude;

                //If this distance is better than the previous best distance, then we have found an enemy that's closer
                if (distSqr < bestDistSqr)
                {
                    bestDistSqr = distSqr;

                    closestSoldier = enemy;
                }

                yield return(enemy);

                //Get the next enemy in the list
                enemy = enemy.NextItem;
            }
        }
Exemplo n.º 2
0
 public void InitializeGrid(int width, int height, IGridItem info)
 {
     sizeW = info.Width;
     sizeH = info.Height;
     Generate(width, height);
     Slots = width * height;
 }
Exemplo n.º 3
0
 public GridViewCellArgs(GridColumn gridColumn, int row, int column, IGridItem item)
 {
     this.GridColumn = gridColumn;
     this.Row        = row;
     this.Column     = column;
     this.Item       = item;
 }
Exemplo n.º 4
0
 public int GetRowOfItem(IGridItem item)
 {
     if (collection == null)
     {
         return(-1);
     }
     return(collection.IndexOf(item));
 }
Exemplo n.º 5
0
        IEnumerable <IGridItem> GetCloseEnemiesAux(IGridItem item)
        {
            //Determine which grid cell the friendly soldier is in
            int cellX = (int)(item.Pos2.x / cellSize);
            int cellZ = (int)(item.Pos2.y / cellSize);

            return(GetCloseEnemiesAux(cellX, cellZ));
        }
Exemplo n.º 6
0
        public GLib.Value GetColumnValue(IGridItem item, int dataColumn, int row)
        {
            int column;

            if (ColumnMap.TryGetValue(dataColumn, out column))
            {
                var colHandler = (IGridColumnHandler)Widget.Columns[column].Handler;
                return(colHandler.GetValue(item, dataColumn, row));
            }
            return(new GLib.Value((string)null));
        }
    public GameObject Get(string key, object data)
    {
        if (templatesById.ContainsKey(key))
        {
            GameObject newObject = GameObject.Instantiate(templatesById[key]);
            IGridItem  item      = newObject.GetComponent <IGridItem>();
            item.Setup(data);
            return(newObject);
        }
        else
        {
            Debug.LogErrorFormat("{0} - The template {1} does not exist in {2}", this.GetType(), key, DataPath);
        }

        return(null);
    }
Exemplo n.º 8
0
        /// <summary>
        ///     Identify the class of grid item and render as required.
        /// </summary>
        /// <param name="gridItem">Grid item</param>
        /// <param name="squareSize">Size of the square</param>
        /// <returns>Rendered view of grid item</returns>
        public static Rectangle RenderGridItem(IGridItem gridItem, int squareSize)
        {
            // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull

            if (gridItem is Tank)
            {
                return(RenderTank((Tank)gridItem, squareSize));
            }

            if (gridItem is Coinpack)
            {
                return(RenderCoinpack((Coinpack)gridItem, squareSize));
            }

            if (gridItem is Lifepack)
            {
                return(RenderLifepack((Lifepack)gridItem, squareSize));
            }

            if (gridItem is BrickWall)
            {
                return(RenderBrickWall((BrickWall)gridItem, squareSize));
            }

            if (gridItem is StoneWall)
            {
                return(RenderStoneWall((StoneWall)gridItem, squareSize));
            }

            if (gridItem is Water)
            {
                return(RenderWater((Water)gridItem, squareSize));
            }

            // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull

            return(new Rectangle
            {
                Width = squareSize,
                Height = squareSize,
                Stroke = new SolidColorBrush(Colors.DimGray)
            });
        }
Exemplo n.º 9
0
        //Add a unity to the grid
        public void Add(IGridItem item)
        {
            //Determine which grid cell the soldier is in
            int cellX = (int)(item.Pos2.x / cellSize);
            int cellZ = (int)(item.Pos2.y / cellSize);

            //Add the soldier to the front of the list for the cell it's in
            item.PreviousItem = null;
            item.NextItem     = cells[cellX, cellZ];

            //Associate this cell with this soldier
            cells[cellX, cellZ] = item;

            if (item.NextItem != null)
            {
                //Set this soldier to be the previous soldier of the next soldier of this soldier (linked lists ftw)
                item.NextItem.PreviousItem = item;
            }
        }
Exemplo n.º 10
0
        //A soldier in the grid has moved, so see if we need to update in which grid the soldier is
        public void Move(IGridItem item, Vector3 oldPos)
        {
            //See which cell it was in
            int oldCellX = (int)(oldPos.x / cellSize);
            int oldCellZ = (int)(oldPos.z / cellSize);

            //See which cell it is in now
            int cellX = (int)(item.Pos2.x / cellSize);
            int cellZ = (int)(item.Pos2.y / cellSize);

            //If it didn't change cell, we are done
            if (oldCellX == cellX && oldCellZ == cellZ)
            {
                return;
            }

            //Unlink it from the list of its old cell
            if (item.PreviousItem != null)
            {
                item.PreviousItem.NextItem = item.NextItem;
            }

            if (item.NextItem != null)
            {
                item.NextItem.PreviousItem = item.PreviousItem;
            }

            //If it's the head of a list, remove it
            if (cells[oldCellX, oldCellZ] == item)
            {
                cells[oldCellX, oldCellZ] = item.NextItem;
            }

            //Add it bacl to the grid at its new cell
            Add(item);
        }
Exemplo n.º 11
0
        private void MoveItem(IGridItem gridItem)
        {
            GridControl targetGrid = GetTargetGrid();
            // TODO check if current parent and targetGrid are the same
            // if yes, drop to the original position

            // TODO relayout existing items to accomodate the new one

            int newItemCount = targetGrid.Items.Count + 1;

            Console.WriteLine("new item count: {0}", newItemCount);
            targetGrid.RecalculateGrid(newItemCount);

            Rect itemRect = targetGrid.Grid.GetItemRect(newItemCount - 1);

            double top  = itemRect.Top;
            double left = itemRect.Left;

            Vector offset = VisualTreeHelper.GetOffset(gridItem);

            double oldLeft = !Double.IsNaN(Canvas.GetLeft(gridItem)) ? Canvas.GetLeft(gridItem) : offset.X;
            double oldTop  = !Double.IsNaN(Canvas.GetTop(gridItem)) ? Canvas.GetTop(gridItem) : offset.Y;

            Point gridItemPt   = gridItem.TranslatePoint(new Point(left, top), targetGrid);
            Point gridItemEnds = gridItem.TranslatePoint(new Point(itemRect.Right, itemRect.Bottom), targetGrid);

            gridItem.RenderTransform = gridItem.TranslateTransform;

            DoubleAnimation xAnim = new DoubleAnimation(oldLeft - gridItemPt.X + left * 2, TimeSpan.FromMilliseconds(1000))
            {
                EasingFunction = new PowerEase {
                    EasingMode = EasingMode.EaseOut
                },
                BeginTime    = TimeSpan.FromMilliseconds(0),
                FillBehavior = FillBehavior.Stop
            };

            DoubleAnimation yAnim = new DoubleAnimation(oldTop - gridItemPt.Y + top * 2, TimeSpan.FromMilliseconds(1000))
            {
                EasingFunction = new PowerEase {
                    EasingMode = EasingMode.EaseOut
                },
                BeginTime    = TimeSpan.FromMilliseconds(0),
                FillBehavior = FillBehavior.Stop
            };

            Storyboard.SetTarget(xAnim, gridItem);
            Storyboard.SetTargetProperty(xAnim, new PropertyPath("(Canvas.Left)"));
            Storyboard.SetTarget(yAnim, gridItem);
            Storyboard.SetTargetProperty(yAnim, new PropertyPath("(Canvas.Top)"));

            gridItem.RenderTransform = gridItem.ScaleTransform;


            // TODO fix this sizing issue
            DoubleAnimation wAnim = new DoubleAnimation()
            {
                To             = (itemRect.Right - itemRect.Left) / gridItem.ActualWidth,
                Duration       = new Duration(TimeSpan.FromMilliseconds(1000)),
                EasingFunction = new PowerEase {
                    EasingMode = EasingMode.EaseOut
                },
            };

            DoubleAnimation hAnim = new DoubleAnimation()
            {
                To             = (itemRect.Bottom - itemRect.Top) / gridItem.ActualHeight,
                Duration       = new Duration(TimeSpan.FromMilliseconds(1000)),
                EasingFunction = new PowerEase {
                    EasingMode = EasingMode.EaseOut
                },
            };

            Storyboard.SetTarget(hAnim, gridItem);
            Storyboard.SetTargetProperty(hAnim, new PropertyPath("RenderTransform.ScaleX"));
            Storyboard.SetTarget(wAnim, gridItem);
            Storyboard.SetTargetProperty(wAnim, new PropertyPath("RenderTransform.ScaleY"));

            Storyboard moveStoryboard = new Storyboard();

            moveStoryboard.Children.Add(xAnim);
            moveStoryboard.Children.Add(yAnim);
//            moveStoryboard.Children.Add(wAnim);
//            moveStoryboard.Children.Add(hAnim);

            moveStoryboard.Completed += (sender, args) => {
                Console.WriteLine("Animation complete");
                Canvas.SetLeft(gridItem, left);
                Canvas.SetTop(gridItem, top);
                gridItem.Width  = itemRect.Right - itemRect.Left;
                gridItem.Height = itemRect.Bottom - itemRect.Top;
                gridItem.GetParent().Children.Remove(gridItem);
                targetGrid.Add(gridItem);
            };

            moveStoryboard.Begin();
        }
Exemplo n.º 12
0
 public void HandleItemDrag(IGridItem gridItem)
 {
     MoveItem(gridItem);
 }
Exemplo n.º 13
0
 public void HandleItemDrag(IGridItem gridItem)
 {
     GetParent().HandleItemDrag(gridItem);
 }
Exemplo n.º 14
0
 public override void AddFrom(IGridControl gridControl, IGridItem item)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 15
0
 public override void Add(IGridItem gridItem)
 {
     Items.Add(gridItem);
     Children.Add(gridItem);
 }