Exemplo n.º 1
0
        //Called when an item is dragged and released
        public void setNewIndex(InventoryItem i)
        {
            Vector2 itemCenter = i.getCenter();

            for (int x = 0; x < items.GetLength(0); x++)
            {
                for (int y = 0; y < items.GetLength(1); y++)
                {
                    //int itemX = (int)(itemCenter.X + 0.5);
                    //int itemY = (int)(itemCenter.Y + 0.5);
                    //Blame merle. He'll fix this later.
                    if (itemRectangles[x, y].Contains(itemCenter) && (items[x, y] == null || (items[x, y] != null && !items[x, y].Equals(i))))
                    {
                        if (items[x, y] == null)
                        {
                            removeItem(i);
                            items[x, y] = i;
                            i.setX(itemRectangles[x, y].X);
                            i.setY(itemRectangles[x, y].Y);
                        }
                        else
                        {
                            if (items[x, y].combineItems(i))
                            {
                                removeItem(i);
                            }
                            else
                            {
                                returnItemToSlot(i);
                            }
                        }

                        return;
                    }
                }
            }

            if (itemCenter.X > 0 && itemCenter.X < inventoryGraphic.Width && itemCenter.Y > 0 && itemCenter.Y < inventoryGraphic.Height)
            {
                returnItemToSlot(i);
            }
            else
            {
                Player    p    = (Player)(Game1.creatures[0]);
                Rectangle rect = p.getHitBox();
                foreach (Platform plat in Game1.platforms)
                {
                    if (p.getX() == plat.getX() && p.getY() == plat.getY())
                    {
                        bool added = plat.addItemToPlatform(i);
                        if (added)
                        {
                            removeItem(i);
                            return;
                        }
                    }
                }
                returnItemToSlot(i);
            }
        }
Exemplo n.º 2
0
        public void drawBox(SpriteBatch sb)
        {
            sb.Draw(getGraphic(), new Vector2(this.x, this.y), Color.White);
            if (storedItem != null)
            {
                if (!selected)
                {
                    storedItem.setX(this.x + 34);
                    storedItem.setY(this.y + 34);
                }

                sb.Draw(storedItem.getGraphic(), new Vector2(storedItem.getX(), storedItem.getY()), Color.White);

                storedItem.setHitBox(new Rectangle(this.x + 34, this.y + 34, 32, 32));
            }
        }
Exemplo n.º 3
0
 public void setInventoryItem(InventoryItem ii, int x, int y)
 {
     if (ii == null)
     {
         items[x, y] = null;
         return;
     }
     ii.setX(itemRectangles[x, y].X);
     ii.setY(itemRectangles[x, y].Y);
     items[x, y] = ii;
 }
Exemplo n.º 4
0
 public void returnItemToSlot(InventoryItem i)
 {
     for (int x = 0; x < items.GetLength(0); x++)
     {
         for (int y = 0; y < items.GetLength(1); y++)
         {
             if (i.Equals(items[x, y]))
             {
                 i.setX(itemRectangles[x, y].X);
                 i.setY(itemRectangles[x, y].Y);
                 return;
             }
         }
     }
 }
Exemplo n.º 5
0
        public bool setStoredItem(InventoryItem i)
        {
            if(i == null)
            {
                storedItem = i;
                return true;
            }

            if(storedItem == null)
            {
                storedItem = i;
                storedItem.setX(this.x + 34);
                storedItem.setY(this.y + 34);
                return true;
            }
            return false;
        }
Exemplo n.º 6
0
        public bool setStoredItem(InventoryItem i)
        {
            if (i == null)
            {
                storedItem = i;
                return(true);
            }

            if (storedItem == null)
            {
                storedItem = i;
                storedItem.setX(this.x + 34);
                storedItem.setY(this.y + 34);
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        //Called when an item is dragged and released
        public void setNewIndex(InventoryItem i)
        {
            Vector2 itemCenter = i.getCenter();
            for(int x = 0; x < items.GetLength(0); x++)
            {
                for(int y = 0; y < items.GetLength(1); y++)
                {

                    //int itemX = (int)(itemCenter.X + 0.5);
                    //int itemY = (int)(itemCenter.Y + 0.5);
                    //Blame merle. He'll fix this later.
                    if(itemRectangles[x,y].Contains(itemCenter) && (items[x,y] == null ||(items[x,y] != null && !items[x,y].Equals(i))))
                    {
                        if(items[x,y] == null)
                        {
                            removeItem(i);
                            items[x, y] = i;
                            i.setX(itemRectangles[x, y].X);
                            i.setY(itemRectangles[x, y].Y);
                        }
                        else
                        {
                            if(items[x, y].combineItems(i))
                                removeItem(i);
                            else
                                returnItemToSlot(i);
                        }

                        return;
                    }
                }
            }

            if(itemCenter.X > 0 && itemCenter.X < inventoryGraphic.Width && itemCenter.Y > 0 && itemCenter.Y < inventoryGraphic.Height)
            {
                returnItemToSlot(i);
            }
            else{
                Player p = (Player)(Game1.creatures[0]);
                Rectangle rect = p.getHitBox();
                foreach(Platform plat in Game1.platforms)
                {
                    if(p.getX() == plat.getX() && p.getY() == plat.getY())
                    {
                        bool added = plat.addItemToPlatform(i);
                        if(added)
                        {
                            removeItem(i);
                            return;
                        }
                    }
                }
                returnItemToSlot(i);
            }
        }
Exemplo n.º 8
0
 public void setInventoryItem(InventoryItem ii, int x, int y)
 {
     if (ii == null)
     {
         items[x, y] = null;
         return;
     }
     ii.setX(itemRectangles[x, y].X);
     ii.setY(itemRectangles[x, y].Y);
     items[x, y] = ii;
 }
Exemplo n.º 9
0
 public void returnItemToSlot(InventoryItem i)
 {
     for (int x = 0; x < items.GetLength(0); x++)
     {
         for (int y = 0; y < items.GetLength(1); y++)
         {
             if (i.Equals(items[x, y]))
             {
                 i.setX(itemRectangles[x, y].X);
                 i.setY(itemRectangles[x, y].Y);
                 return;
             }
         }
     }
 }