Beispiel #1
0
        //when something is dropped on slot
        public override void OnDrop(PointerEventData eventData)
        {
            ItemDragHandler itemDragHandler = eventData.pointerDrag.GetComponent <ItemDragHandler>();

            if (itemDragHandler == null)
            {
                return;
            }

            //check what previous slot is & then set or swap accordingly
            InventorySlot inventorySlot = itemDragHandler.ItemSlotUI as InventorySlot;

            /*treat slot as inventory slot, check if it actually is..
             * If YES, get item from slot, set, return..*/
            if (inventorySlot != null)
            {
                SlotItem = inventorySlot.ItemSlot.item;
                slotItem.inventoryItem = inventorySlot.ItemSlot.item;
                return;
            }

            HotBarSlot hotBarSlot = itemDragHandler.ItemSlotUI as HotBarSlot;

            /*SWAP..
             * if a hotbar slot is being dropped onto other hbs, store current slot item, set to new item,
             * THEN set item dropped to previous item*/
            if (hotBarSlot != null)
            {
                HotBarItem oldItem = SlotItem;
                SlotItem            = hotBarSlot.SlotItem;
                hotBarSlot.SlotItem = oldItem;
                return;
            }
        }
 public void Add(HotBarItem itemToAdd)
 {
     //checks slots to see if item can be held
     foreach (HotBarSlot hotBarSlot in hotBarSlots)
     {
         //stop checking
         if (hotBarSlot.AddItem(itemToAdd))
         {
             return;
         }
     }
 }
Beispiel #3
0
        public bool AddItem(HotBarItem itemToAdd)
        {
            //if occupied, don't add
            if (SlotItem != null)
            {
                return(false);
            }

            //otherwise...
            SlotItem = itemToAdd;
            return(true);
        }
        public void DisplayInfo(HotBarItem infoItem)
        {
            //create stringbuilder instance
            StringBuilder builder = new StringBuilder();

            //get item's custom display txt
            builder.Append("<size=35>").Append(infoItem.ColoredName).Append("</size>\n");
            builder.Append(infoItem.GetInfoDisplayText());

            //sets info text for display
            infoText.text = builder.ToString();

            //activates UI canvas
            popupCanvasObject.SetActive(true);

            //fix resize
            LayoutRebuilder.ForceRebuildLayoutImmediate(popupObject);
        }
Beispiel #5
0
 //check if what's being stored has a quantity
 private void SetItemQuantityUI()
 {
     //for when item is being stored & player uses the item, checks if quant. has reached 0
     if (SlotItem is InventoryItem inventoryItem)
     {
         if (inventory.HasItem(inventoryItem))
         {
             int quantityCount = inventory.GetTotalQuantity(inventoryItem);
             //if quantCount is > 1 (2+), then set to actual quantCount or blank string.. Hides count unless > 1
             itemQuantityText.text = quantityCount > 1 ? quantityCount.ToString() : "";
         }
         else
         {
             //clear slot if item is no longer there
             SlotItem = null;
         }
     }
     else
     {
         itemQuantityText.enabled = false;
     }
 }