예제 #1
0
    /// <summary>
    /// Used when the player is moving an itemUI. When called, check if the player can place
    /// the itemUI at the spot it's in.
    /// </summary>
    /// <param name="itemUI"></param>
    /// <param name="position"></param>
    /// <returns></returns>
    public bool PlaceItemUI(ItemUI itemUI, Vector2 position)
    {
        // Get the slot where the current UI is hovering over
        Vector2       index        = GetSlotFromPosition(position);
        InventorySlot originalSlot = itemUI.GetTopLeftSlot();

        //Debug.Log("move to:" + index);

        // Remove the data from the itemUI's previous spots
        RemoveItemFromSlot(itemUI);
        slotsUsed -= itemUI.GetItem().itemHeight *itemUI.GetItem().itemHeight;

        // Check if we can place the ui in that slot
        Item item = itemUI.GetItem();

        if (!CheckInventorySlot((int)index.y, (int)index.x, item.itemWidth, item.itemHeight))
        {
            //Debug.Log("Cannot place here");
            // Give the reference to the slot back so it can call this method again
            itemUI.SetTopLeftSlot(originalSlot);
            return(false);
        }
        else
        {
            Debug.Log("Can place here");

            // Then add the itemUI to this new slot
            AddItemToSlot(itemUI.GetItem(), (int)index.y, (int)index.x, itemUI);
            //Debug.Log("topleftslot:" + itemUI.GetTopLeftSlot());
            return(true);
        }
    }
예제 #2
0
    void OnInventoryChanged()
    {
        List <Item> itemsToAdd = new List <Item>();

        if (currentInventory)
        {
            itemsToAdd.AddRange(currentInventory.GetItems());
        }

        for (int i = content.childCount - 1; i >= 0; i--)
        {
            ItemUI ui = content.GetChild(i).GetComponent <ItemUI>();
            if (!itemsToAdd.Contains(ui.GetItem()))
            {
                Destroy(ui.gameObject);
            }
            else
            {
                itemsToAdd.Remove(ui.GetItem());
            }
        }

        foreach (Item item in itemsToAdd)
        {
            ItemUI ui = Instantiate(itemUIPrefab.gameObject).GetComponent <ItemUI>();
            ui.SetItem(item);
            ui.transform.SetParent(content);
            ui.GetComponent <RectTransform>().localScale = Vector3.one;
        }
    }
예제 #3
0
 public void UseItem()
 {
     if (itemUI.GetItem() != null)
     {
         if (itemUI.GetItem().itemType == ItemType.Useable && itemUI.Bag.items[itemUI.Index].amount > 0)
         {
             GameManager.Instance.playerStats.AddHealth(itemUI.GetItem().usableData.healthRecover);
             itemUI.Bag.items[itemUI.Index].amount -= 1;
         }
         UpdateItem();
     }
 }
예제 #4
0
        private void ingresaArticuloToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool another = true;

            while (another)
            {
                ItemUI na = new ItemUI();
                na.ShowDialog();
                if (na.Valid)
                {
                    DBConnection.AddItem(na.GetItem());
                    dgvResultados.DataSource = DBConnection.getItems();
                }
                another = na.Another;
            }
        }
예제 #5
0
 public void OnPointerClick(PointerEventData eventData)
 {
     if (slotType != SlotType.SHOP && (eventData.clickCount % 2 == 0 || eventData.button == PointerEventData.InputButton.Right))
     {
         UseItem();
     }
     else if (slotType == SlotType.SHOP && eventData.button == PointerEventData.InputButton.Right)
     {
         InventoryManager.Instance.inventoryData.AddItem(itemUI.GetItem(), 1);
         InventoryManager.Instance.inventoryUI.RefreshHolders();
     }
 }
예제 #6
0
    /// <summary>
    /// Remove an item from designated slots by marking all those slots as not occupied
    /// and a removing the corresponding references. Note that this does not destroy the
    /// given UI.
    /// </summary>
    /// <param name="itemUI"></param>
    private void RemoveItemFromSlot(ItemUI itemUI)
    {
        // Get the item from the itemUI
        Item item   = itemUI.GetItem();
        int  width  = item.itemWidth;
        int  height = item.itemHeight;

        // Get the top left slot
        InventorySlot topLeft = itemUI.GetTopLeftSlot();

        // Remove the topLeftSlot from the itemUI
        itemUI.SetTopLeftSlot(null);

        // Find all the slots that this item occupies
        // and set them
        Vector2 index    = topLeft.GetIndex();
        int     startRow = (int)index.y;
        int     startCol = (int)index.x;

        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                // Debug
                //int y = startRow + i;
                //int x = startCol + j;
                //Debug.Log(gameObject.name + " set " + y + "," + x + " to NOT occupied");

                // Get the slot at this place
                InventorySlot slot = inventorySlots[startRow + i, startCol + j];

                // Set its references to remove the item from it
                slot.SetOccupancy(false);
                slot.SetParentItemUI(null);
            }
        }

        // Done!
    }