예제 #1
0
    public void updateSlot()
    {
        if (!myStack.isEmpty())
        {
            itemIcon.enabled = true;
            itemIcon.sprite  = myStack.getItem().itemIcon;

            if (myStack.getCount() > 1)
            {
                itemAmount.text = myStack.getCount().ToString();
            }
            else
            {
                itemAmount.text = string.Empty;
            }
        }
        else
        {
            itemIcon.enabled = false;
            itemAmount.text  = string.Empty;
        }
    }
예제 #2
0
    private void drawItem()
    {
        if (!myStack.isEmpty())
        {
            itemIcon.enabled = true;
            itemIcon.sprite  = myStack.getItem().itemIcon;
            this.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(90, 90);

            if (myStack.getCount() > 1)
            {
                //Debug.Log(myStack.getItem().itemIcon);
                itemAmount.text = myStack.getCount().ToString();
            }
            else
            {
                //Debug.Log("draw stack");
                itemAmount.text = string.Empty;
            }
        }
        else
        {
            disableDragItem();
        }
    }
예제 #3
0
    private void onLeftClick(itemStack currentDraggedItem, itemStack itemCopy)
    {
        if (!myStack.isEmpty() && currentDraggedItem.isEmpty())
        {
            inventoryManager.setDragged(itemCopy);
            this.setSlotContents(itemStack.Empty);
        }

        if (myStack.isEmpty() && !currentDraggedItem.isEmpty())
        {
            this.setSlotContents(currentDraggedItem);
            inventoryManager.setDragged(itemStack.Empty);
        }
        if (!myStack.isEmpty() && !currentDraggedItem.isEmpty())
        {
            if (itemStack.areItemsEqual(itemCopy, currentDraggedItem))
            {
                if (itemCopy.canAddTo(currentDraggedItem.getCount()))
                {
                    itemCopy.increaseAmount(currentDraggedItem.getCount());
                    this.setSlotContents(itemCopy);
                    inventoryManager.setDragged(itemStack.Empty);
                }
                else
                {
                    int difference = (itemCopy.getCount() + currentDraggedItem.getCount()) - itemCopy.getItem().maxStack;
                    itemCopy.setCount(myStack.getItem().maxStack);
                    itemStack dragCopy = currentDraggedItem.copy();
                    dragCopy.setCount(difference);
                    this.setSlotContents(itemCopy);
                    inventoryManager.setDragged(dragCopy);
                }
            }
            else
            {
                itemStack currentDragCopy = currentDraggedItem.copy();
                this.setSlotContents(currentDraggedItem);
                inventoryManager.setDragged(itemCopy);
            }
        }
    }
예제 #4
0
 // makes a stack
 public void setStack(itemStack itemIn)
 {
     this.item  = itemIn.getItem();
     this.count = itemIn.getCount();
 }
예제 #5
0
 //checks if items can stack or not
 public bool isItemEqual(itemStack stackIn)
 {
     //Debug.Log("Stacking");
     return(!stackIn.isEmpty() && this.item == stackIn.getItem());
 }