Пример #1
0
    /// <summary>
    ///     rather direct method that doesn't check anything.
    ///     probably should check if you CanPutItemToSlot before using it
    /// </summary>
    public static void UpdateSlot(UISlotObject slotInfo)
    {
        if (string.IsNullOrEmpty(slotInfo.SlotUUID) && !string.IsNullOrEmpty(slotInfo.FromSlotUUID))
        {
            //Dropping updates:
            var _fromSlot = InventorySlotCache.GetSlotByUUID(slotInfo.FromSlotUUID);
            if (_fromSlot != null)
            {
                CheckStorageHandlerOnMove(_fromSlot.Item);
                _fromSlot.Clear();
                return;
            }
        }
        //Logger.LogTraceFormat("Updating slots: {0}", Category.UI, slotInfo);
        //			InputTrigger.Touch(slotInfo.SlotContents);
        var slot = InventorySlotCache.GetSlotByUUID(slotInfo.SlotUUID);

        if (slot != null)
        {
            slot.SetItem(slotInfo.SlotContents);
        }

        var  fromSlot = InventorySlotCache.GetSlotByUUID(slotInfo.FromSlotUUID);
        bool fromS    = fromSlot != null;
        bool fromSI   = fromSlot?.Item != null;

        if (fromSlot && (fromSlot.image.enabled || fromSlot?.Item == slotInfo.SlotContents))
        {
            CheckStorageHandlerOnMove(fromSlot.Item);
            fromSlot.Clear();
        }
    }
Пример #2
0
    public static bool CanPutItemToSlot(UISlotObject proposedSlotInfo)
    {
        if (proposedSlotInfo.IsEmpty() || !SendUpdateAllowed(proposedSlotInfo.SlotContents))
        {
            return(false);
        }

        InventorySlot invSlot = InventoryManager.GetSlotFromUUID(proposedSlotInfo.SlotUUID, false);
        PlayerScript  lps     = PlayerManager.LocalPlayerScript;

        if (!lps || lps.canNotInteract() || invSlot.Item != null)
        {
            return(false);
        }

        UI_ItemSlot uiItemSlot = InventorySlotCache.GetSlotByUUID(invSlot.UUID);

        if (uiItemSlot == null)
        {
            //Could it be a storage obj that is closed?
            ItemSize checkMaxSizeOfStorage;
            if (SlotIsFromClosedBag(invSlot, out checkMaxSizeOfStorage))
            {
                var itemAtts = proposedSlotInfo.SlotContents.GetComponent <ItemAttributes>();
                if (itemAtts != null)
                {
                    if (itemAtts.size <= checkMaxSizeOfStorage)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }

        if (!uiItemSlot.CheckItemFit(proposedSlotInfo.SlotContents))
        {
            return(false);
        }
        return(true);
    }