//Resets the numbers when we remove items private void renumberItemSlots() { foreach (GameObject UIItem in itemUIElements) { UIItem.GetComponentInChildren <Text>().text = "" + (itemUIElements.IndexOf(UIItem) + 1); } }
public void LoadEmptyItem(UIItem p_uiItem, Item p_item) { Image image = p_uiItem.GetComponent <Image>(); p_uiItem.m_item = p_item; image.color = new Color(1, 1, 1, 0); p_uiItem.GetComponentInChildren <TextMeshProUGUI>().enabled = false; }
public void LoadOutline(UIItem p_uiItem, Item p_item) { Image image = p_uiItem.GetComponent <Image>(); TextMeshProUGUI amount = p_uiItem.GetComponentInChildren <TextMeshProUGUI>(); image.sprite = p_item.m_outlineSprite; image.color = new Color(1, 1, 1, 1); amount.text = ""; }
public bool RemoveFirstItemInInventory(int id) { ItemData itemToRemove = database.FetchItemByID(id); if (itemToRemove != null) { int existingItemIndex = FindFirstItemInInventory(itemToRemove.ID); //-1 = no existing item if (existingItemIndex != -1) { UIItem existingUIItem = inventorySlots [existingItemIndex].GetComponentInChildren <UIItem> (); //if item is stackable and stack size is bigger than 1 //TODO: this may lead to problems if we have several stacks of the same item (e.g. ammo) if (itemToRemove.Stackable && existingUIItem.amount > 1) { existingUIItem.amount--; existingUIItem.GetComponentInChildren <Text>().text = existingUIItem.amount.ToString(); } else { //delete item from slot inventoryItems.Remove(inventoryItems[existingItemIndex]); GameObject.Destroy(inventorySlots[existingItemIndex].transform.GetChild(0).gameObject); } return(true); } else //new item not present in inventory { Debug.Log("Trying to remove an item that is not in the inventory" + itemToRemove.Slug); return(false); } } else { Debug.Log("Couldn't find item to remove (id = " + id); return(false); } }
public override void AcceptModal() { UIItem toDelete = m_info as UIItem; Image image = toDelete.GetComponent <Image>(); if (toDelete == UIItem.HeldItem) { toDelete.HideHeldItem(); } toDelete.m_item.m_inventory.Remove(toDelete.m_item); toDelete.m_item = new Item(toDelete.m_item.m_inventory, toDelete.m_item.m_inventoryIndex); image.color = new Color(255, 255, 255, 0); toDelete.GetComponentInChildren <TextMeshProUGUI>().enabled = false; if (m_eventToFireOnSuccess) { m_eventToFireOnSuccess.Raise(); } CloseModal(); }
public void LoadItem(UIItem p_uiItem, Item p_item) { Image image = p_uiItem.GetComponent <Image>(); TextMeshProUGUI amount = p_uiItem.GetComponentInChildren <TextMeshProUGUI>(); p_uiItem.m_item = p_item; image.sprite = p_item.m_item.m_sprite; p_uiItem.m_ghost.sprite = image.sprite; image.color = new Color(255, 255, 255, 255); p_uiItem.m_ghost.color = new Color(255, 255, 255, 255); if (p_item.m_amount == 1 && p_item.m_item.m_maxStackSize == 1) { amount.text = ""; } else { amount.text = p_item.m_amount.ToString(); } }