Esempio n. 1
0
    /**
     *	Delete item from the inventory
     */
    public override void DeleteItem(Equipment item)
    {
        InventoryGridItem gridItem = item.inventoryGridItem;

        for (int k = 0; k < gridItem.width; k++)
        {
            for (int q = 0; q < gridItem.height; q++)
            {
                gridFills[gridItem.x + k, gridItem.y + q] = false;
            }
        }

        for (int i = 0; i < numHotkeys; i++)
        {
            if (hotkeyItems[i] == item)
            {
                hotkeyItems[i] = null;
            }
        }

        if (currentItem == item)
        {
            currentItem = null;
        }

        base.DeleteItem(item);
    }
Esempio n. 2
0
    [HideInInspector] public int x, y;          // x,y coords of the top left corner in terms of tiles

    public InventoryGridItem(InventoryGridItem copy)
    {
        this.texture       = copy.texture;
        this.textureHotkey = copy.textureHotkey;
        this.width         = copy.width;
        this.height        = copy.height;
        this.x             = copy.x;
        this.y             = copy.y;
        this.equipment     = copy.GetEquipment();
    }
 public InventoryGridItem(InventoryGridItem copy)
 {
     this.texture = copy.texture;
     this.textureHotkey = copy.textureHotkey;
     this.width = copy.width;
     this.height = copy.height;
     this.x = copy.x;
     this.y = copy.y;
     this.equipment = copy.GetEquipment();
 }
Esempio n. 4
0
 /**
  * Given an item and a tile coordinate pair, can it fit in that position?
  */
 public bool CanItemFit(InventoryGridItem item, int i, int j)
 {
     for (int k = 0; k < item.width; k++) {
         for (int q = 0; q < item.height; q++) {
             if (i < 0 || j < 0 || i + k >= numTilesX || j + q >= numTilesY)
                 return false;
             Equipment targetItem = ItemAtGridPoint(i + k, j + q);
             if ((gridFills[i + k, j + q] && targetItem != item.GetEquipment()))
                 return false;
         }
     }
     return true;
 }
Esempio n. 5
0
        static void InventoryGridItem_OnClick_Postfix(InventoryGridItem __instance)
        {
            if (!Input.GetMouseButtonUp(1) || InterfaceManager.m_Panel_Container.IsEnabled())
            {
                return;
            }

            if (!UIHelper.invPanel.m_ItemDescriptionPage.CanDrop(__instance.m_GearItem) || __instance.m_GearItem.m_WaterSupply)
            {
                return;
            }

            UIHelper.startPlaceObject(__instance.m_GearItem.gameObject, PlaceMeshFlags.UpdateInventoryOnSuccess);
        }
Esempio n. 6
0
    private Rect RectFromGridItem(InventoryGridItem item)
    {
        int  x         = item.x;
        int  y         = item.y;
        Rect rectStart = tileRects[x, y];
        Rect rectEnd   = tileRects[x + item.width - 1, y + item.height - 1];
        Rect rect      = new Rect(
            rectStart.x,
            rectStart.y,
            rectEnd.x - rectStart.x + rectEnd.width,
            rectEnd.y - rectStart.y + rectEnd.height
            );

        return(rect);
    }
Esempio n. 7
0
    /**
     * Attempt to add an item to this grid in any spot that it will fit
     * Return false if no space
     */
    public override bool AddItem(Equipment item)
    {
        InventoryGridItem gridItem = item.inventoryGridItem;

        for (int i = 0; i + gridItem.width <= numTilesX; i++)
        {
            for (int j = 0; j + gridItem.height <= numTilesY; j++)
            {
                // If the item fits, add it to the inventory
                if (CanItemFit(item.inventoryGridItem, i, j))
                {
                    bool inserted = base.AddItem(item);
                    // If it was successfully added, add it to the grid
                    if (inserted)
                    {
                        gridItem.x = i;
                        gridItem.y = j;
                        for (int k = 0; k < gridItem.width; k++)
                        {
                            for (int q = 0; q < gridItem.height; q++)
                            {
                                gridFills[gridItem.x + k, gridItem.y + q] = true;
                            }
                        }
                        // Auto add it to an available hotkey slot if the item is flagged to do so
                        if (item.inventoryGridItem.autoAddToHotkey)
                        {
                            for (int q = 0; q < numHotkeys; q++)
                            {
                                if (hotkeyItems[q] == null)
                                {
                                    hotkeyItems[q] = item;
                                    break;
                                }
                            }
                        }
                    }
                    return(inserted);
                }
            }
        }
        return(false);
    }
Esempio n. 8
0
 /**
  * Given an item and a tile coordinate pair, can it fit in that position?
  */
 public bool CanItemFit(InventoryGridItem item, int i, int j)
 {
     for (int k = 0; k < item.width; k++)
     {
         for (int q = 0; q < item.height; q++)
         {
             if (i < 0 || j < 0 || i + k >= numTilesX || j + q >= numTilesY)
             {
                 return(false);
             }
             Equipment targetItem = ItemAtGridPoint(i + k, j + q);
             if ((gridFills[i + k, j + q] && targetItem != item.GetEquipment()))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Esempio n. 9
0
    void Update()
    {
        // Select item from hotkey slots
        if (CrossPlatformInputManager.GetButtonDown("Fire1"))
        {
            itemSelected = inventoryGrid.GetHotkeyItem(MousePosToHotkey());
        }

        if (isGridEnabled)
        {
            /* Determine which item the mouse is hovering over */
            int[] mouseCoords = MouseToTileCoords();
            itemMouseHover = null;
            if (mouseCoords[0] >= 0 && mouseCoords[1] >= 0)
            {
                Equipment item = inventoryGrid.ItemAtGridPoint(mouseCoords[0], mouseCoords[1]);
                if (item)
                {
                    itemMouseHover = item;
                }
            }

            /* Select item from grid */
            if (CrossPlatformInputManager.GetButtonDown("Fire1"))
            {
                if (itemMouseHover)
                {
                    itemSelected = itemMouseHover;
                }
            }

            /* Remove item from hotkey */
            if (CrossPlatformInputManager.GetButtonDown("Fire2"))
            {
                inventoryGrid.SetHotkeyItem(MousePosToHotkey(), null);
            }

            /* Click-and-drag to move items around */
            if (CrossPlatformInputManager.GetButtonDown("Fire1") && itemMouseHover)
            {
                itemMoving      = itemMouseHover;
                itemMovingDummy = new InventoryGridItem(itemMoving.inventoryGridItem);
                // Set pixel coords offset (mouse pos - corner of item)
                Rect corner = tileRects[itemMoving.inventoryGridItem.x, numTilesY - 1 - itemMoving.inventoryGridItem.y];
                dummyOffsetPixels.x = Input.mousePosition.x - corner.center.x;
                dummyOffsetPixels.y = Input.mousePosition.y - corner.center.y;
            }
            // Update dummy item's tile coords when user is moving an item around the grid
            // If not on the grid, set to (-1, -1)
            if (itemMoving)
            {
                int[] tileCoords = MouseToTileCoords_Unconstrained(Input.mousePosition - dummyOffsetPixels);
                if (tileCoords[0] < 0 || tileCoords[0] > numTilesX - itemMovingDummy.width ||
                    tileCoords[1] < 0 || tileCoords[1] > numTilesY - itemMovingDummy.height)
                {
                    itemMovingDummy.x = -1;
                    itemMovingDummy.y = -1;
                }
                else
                {
                    itemMovingDummy.x = tileCoords[0];
                    itemMovingDummy.y = tileCoords[1];
                }
            }
            // Attempt to drop an item off when user let's go after click-and-drag
            if (CrossPlatformInputManager.GetButtonUp("Fire1"))
            {
                if (itemMoving)
                {
                    // (1) Drop it into a new spot in the grid if it fits
                    bool moved = inventoryGrid.MoveItem(itemMoving, itemMovingDummy.x, itemMovingDummy.y);
                    // (2) If 1 didn't happen, drop it into a hotkey slot if possible
                    if (!moved)
                    {
                        moved = inventoryGrid.SetHotkeyItem(MousePosToHotkey(), itemMoving);
                    }

                    /*
                     * // (3) If 1 and 2 didn't happen, remove the item from the inventory and drop it in the world
                     * if (!moved) {
                     *      inventoryGrid.DropItem(itemMoving);
                     *      if (itemSelected = itemMoving)
                     *              itemSelected = null;
                     *      for (int i = 0; i < numHotkeys; i++)
                     *              if (inventoryGrid.GetHotkeyItem(i) == itemMoving)
                     *                      inventoryGrid.SetHotkeyItem(i, null);
                     * }
                     */
                }
                itemMoving      = null;
                itemMovingDummy = null;
            }
        }

        // Double click to equip
        if (itemSelected && Time.unscaledTime - timeLastClick <= doubleClickMaxDelay && itemLastClick == itemSelected)
        {
            inventoryGrid.SetCurrentItem(itemSelected);
        }
        timeLastClick = Time.unscaledTime;
        itemLastClick = itemSelected;
    }
Esempio n. 10
0
 public void DisableGrid()
 {
     isGridEnabled   = false;
     itemMoving      = null;
     itemMovingDummy = null;
 }
Esempio n. 11
0
    private float timeLastClick = 0; // To determine double clicks

    #endregion Fields

    #region Methods

    public void DisableGrid()
    {
        isGridEnabled = false;
        itemMoving = null;
        itemMovingDummy = null;
    }
Esempio n. 12
0
    void Update()
    {
        // Select item from hotkey slots
        if (CrossPlatformInputManager.GetButtonDown("Fire1")) {
            itemSelected = inventoryGrid.GetHotkeyItem(MousePosToHotkey());
        }

        if (isGridEnabled)
        {
            /* Determine which item the mouse is hovering over */
            int[] mouseCoords = MouseToTileCoords();
            itemMouseHover = null;
            if (mouseCoords[0] >= 0 && mouseCoords[1] >= 0) {
                Equipment item = inventoryGrid.ItemAtGridPoint(mouseCoords[0], mouseCoords[1]);
                if (item)
                    itemMouseHover = item;
            }

            /* Select item from grid */
            if (CrossPlatformInputManager.GetButtonDown("Fire1")) {
                if (itemMouseHover)
                    itemSelected = itemMouseHover;
            }

            /* Remove item from hotkey */
            if (CrossPlatformInputManager.GetButtonDown("Fire2"))
                inventoryGrid.SetHotkeyItem(MousePosToHotkey(), null);

            /* Click-and-drag to move items around */
            if (CrossPlatformInputManager.GetButtonDown("Fire1") && itemMouseHover) {
                itemMoving = itemMouseHover;
                itemMovingDummy = new InventoryGridItem(itemMoving.inventoryGridItem);
                // Set pixel coords offset (mouse pos - corner of item)
                Rect corner = tileRects[itemMoving.inventoryGridItem.x, numTilesY - 1 - itemMoving.inventoryGridItem.y];
                dummyOffsetPixels.x = Input.mousePosition.x - corner.center.x;
                dummyOffsetPixels.y = Input.mousePosition.y - corner.center.y;
            }
            // Update dummy item's tile coords when user is moving an item around the grid
            // If not on the grid, set to (-1, -1)
            if (itemMoving) {
                int[] tileCoords = MouseToTileCoords_Unconstrained(Input.mousePosition - dummyOffsetPixels);
                if (tileCoords[0] < 0 || tileCoords[0] > numTilesX - itemMovingDummy.width
                    || tileCoords[1] < 0 || tileCoords[1] > numTilesY - itemMovingDummy.height)
                {
                    itemMovingDummy.x = -1;
                    itemMovingDummy.y = -1;
                }
                else {
                    itemMovingDummy.x = tileCoords[0];
                    itemMovingDummy.y = tileCoords[1];
                }
            }
            // Attempt to drop an item off when user let's go after click-and-drag
            if (CrossPlatformInputManager.GetButtonUp("Fire1")) {
                if (itemMoving) {
                    // (1) Drop it into a new spot in the grid if it fits
                    bool moved = inventoryGrid.MoveItem(itemMoving, itemMovingDummy.x, itemMovingDummy.y);
                    // (2) If 1 didn't happen, drop it into a hotkey slot if possible
                    if (!moved)
                        moved = inventoryGrid.SetHotkeyItem(MousePosToHotkey(), itemMoving);
                    /*
                    // (3) If 1 and 2 didn't happen, remove the item from the inventory and drop it in the world
                    if (!moved) {
                        inventoryGrid.DropItem(itemMoving);
                        if (itemSelected = itemMoving)
                            itemSelected = null;
                        for (int i = 0; i < numHotkeys; i++)
                            if (inventoryGrid.GetHotkeyItem(i) == itemMoving)
                                inventoryGrid.SetHotkeyItem(i, null);
                    }
                    */
                }
                itemMoving = null;
                itemMovingDummy = null;
            }
        }

        // Double click to equip
        if (itemSelected && Time.unscaledTime - timeLastClick <= doubleClickMaxDelay && itemLastClick == itemSelected)
            inventoryGrid.SetCurrentItem(itemSelected);
        timeLastClick = Time.unscaledTime;
        itemLastClick = itemSelected;
    }
Esempio n. 13
0
 private Rect RectFromGridItem(InventoryGridItem item)
 {
     int x = item.x;
     int y = item.y;
     Rect rectStart = tileRects[x, y];
     Rect rectEnd = tileRects[ x + item.width - 1, y + item.height - 1 ];
     Rect rect = new Rect(
         rectStart.x,
         rectStart.y,
         rectEnd.x - rectStart.x + rectEnd.width,
         rectEnd.y - rectStart.y + rectEnd.height
     );
     return rect;
 }