public bool addItem(itemStack input) { foreach (itemStack stack in inventoryContents) { if (stack.isEmpty()) { stack.setStack(input); return(true); } else { if (itemStack.areItemsEqual(input, stack)) { if (stack.canAddTo(input.getCount())) { stack.increaseAmount(input.getCount()); return(true); } else { int difference = (stack.getCount() + input.getCount()) - stack.getItem().maxStack; stack.setCount(stack.getItem().maxStack); input.setCount(difference); } } } } return(false); }
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); } } }
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; } }
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(); } }
// makes a stack public void setStack(itemStack itemIn) { this.item = itemIn.getItem(); this.count = itemIn.getCount(); }