void RepopulateItems() { foreach (GameObject itemScreen in itemScreens) { GameObject.Destroy(itemScreen); } itemScreens.Clear(); storedFood.Clear(); storedFood = storageManager.GetStoredItems(Item.Category.FOOD); foreach (Item_And_Quantity storedItem in storedFood) { if (storedItem.quantity > 0) { GameObject newItemScreen = GameObject.Instantiate(itemTemplate); newItemScreen.transform.SetParent(itemPanelParent, false); itemScreens.Add(newItemScreen); Screen_Item_Manager itemScreen = newItemScreen.GetComponent <Screen_Item_Manager>(); itemScreen.nameText.text = storedItem.item.name; itemScreen.quantityText.text = storedItem.quantity.ToString(); itemScreen.image.sprite = storedItem.item.storageSprite; } } }
void OnClickCraftableItem(Item craftableItem) { selectedItemToCraft = craftableItem; foreach (GameObject craftItemScreen in requiredCraftItemsScreens) { GameObject.Destroy(craftItemScreen); } requiredCraftItemsScreens.Clear(); craftDialog.SetActive(true); bool canCraft = true; foreach (Item_And_Quantity requiredItem in selectedItemToCraft.requiredMaterialsToCraft.requiredItems) { Item_And_Quantity storedRequiredItem = storageManager.GetStoredItemAndQuantity(requiredItem); GameObject newCraftItemScreen = GameObject.Instantiate(itemTemplate); newCraftItemScreen.transform.SetParent(craftMaterialRequirementsParent, false); requiredCraftItemsScreens.Add(newCraftItemScreen); Screen_Item_Manager newCraftItemManager = newCraftItemScreen.GetComponent <Screen_Item_Manager>(); newCraftItemManager.nameText.text = requiredItem.item.name; newCraftItemManager.quantityText.text = storedRequiredItem.quantity + "/" + requiredItem.quantity.ToString(); newCraftItemManager.image.sprite = requiredItem.item.storageSprite; if (storedRequiredItem.quantity >= requiredItem.quantity) { newCraftItemManager.quantityText.color = Color.green; } else { newCraftItemManager.quantityText.color = Color.red; canCraft = false; } } if (canCraft) { craftButton.interactable = true; } else { craftButton.interactable = false; } }
public void ShowScreen() { gameObject.SetActive(true); List <Item_And_Quantity> scavengedItems = scavengingManager.PreviousScavengedItems(); foreach (Item_And_Quantity scavengedItem in scavengedItems) { GameObject item = GameObject.Instantiate(itemTemplate, panelRewardsParent, false); Screen_Item_Manager manager = item.GetComponent <Screen_Item_Manager>(); manager.nameText.text = scavengedItem.item.name; manager.image.sprite = scavengedItem.item.storageSprite; manager.quantityText.text = scavengedItem.quantity.ToString(); shownItems.Add(item); } }
void RepopulateItems() { foreach (GameObject itemScreen in itemScreens) { GameObject.Destroy(itemScreen); } itemScreens.Clear(); storedItemsOfCategoryAndRarity.Clear(); storedItemsOfCategoryAndRarity = storageManager.GetStoredItems(currentCategory, currentRarity); foreach (Item_And_Quantity storedItem in storedItemsOfCategoryAndRarity) { if (storedItem.item.requiredMaterialsToCraft != null && storedItem.item.requiredMaterialsToCraft.requiredItems != null && storedItem.item.requiredMaterialsToCraft.requiredItems.Count > 0) { GameObject newItemScreen = GameObject.Instantiate(itemTemplate); newItemScreen.transform.SetParent(itemPanelParent, false); Button button = newItemScreen.AddComponent <Button>(); button.onClick.AddListener(() => OnClickCraftableItem(storedItem.item)); itemScreens.Add(newItemScreen); Screen_Item_Manager itemScreen = newItemScreen.GetComponent <Screen_Item_Manager>(); itemScreen.nameText.text = storedItem.item.name; itemScreen.quantityText.text = storedItem.quantity.ToString(); itemScreen.image.sprite = storedItem.item.storageSprite; } else { GameObject newItemScreen = GameObject.Instantiate(itemTemplate); newItemScreen.transform.SetParent(itemPanelParent, false); Button button = newItemScreen.AddComponent <Button>(); button.onClick.AddListener(() => OnClickScavengableOnlyItem(storedItem.item)); itemScreens.Add(newItemScreen); Screen_Item_Manager itemScreen = newItemScreen.GetComponent <Screen_Item_Manager>(); itemScreen.nameText.text = storedItem.item.name; itemScreen.quantityText.text = storedItem.quantity.ToString(); itemScreen.image.sprite = storedItem.item.storageSprite; } } }
void RefreshScreen() { // Clear screens foreach (GameObject itemScreen in itemScreens) { GameObject.Destroy(itemScreen); } itemScreens.Clear(); foreach (GameObject perkScreen in perkScreens) { GameObject.Destroy(perkScreen); } perkScreens.Clear(); // Level int homeLevel = homeManager.CurrentLevel(); if (homeManager.HasUpgradeAvailable()) { homeLevelText.text = "HOME UPGRADE " + (homeLevel + 1).ToString(); canUpgrade = true; storedItems = new List <Item_And_Quantity>(); itemsRequiredToUpgrade = homeManager.GetRequiredItemsToUpgrade(); foreach (Item_And_Quantity requiredItemAndQuantity in itemsRequiredToUpgrade) { // Get stored item Item_And_Quantity storedItem = storageManager.GetStoredItemAndQuantity(requiredItemAndQuantity); storedItems.Add(storedItem); // Add item to GUI GameObject newItemScreen = GameObject.Instantiate(itemTemplate); newItemScreen.transform.SetParent(itemPanelParent, false); itemScreens.Add(newItemScreen); Screen_Item_Manager itemScreen = newItemScreen.GetComponent <Screen_Item_Manager>(); itemScreen.nameText.text = requiredItemAndQuantity.item.name; itemScreen.quantityText.text = storedItem.quantity.ToString() + " / " + requiredItemAndQuantity.quantity.ToString(); itemScreen.image.sprite = requiredItemAndQuantity.item.storageSprite; // Determine if can upgrade if (storedItem.quantity < requiredItemAndQuantity.quantity) { canUpgrade = false; itemScreen.quantityText.color = Color.red; } else { itemScreen.quantityText.color = Color.green; } } // Add perks List <string> perks = homeManager.GetPerksOfUpgrade(); foreach (string perk in perks) { GameObject newPerkScreen = GameObject.Instantiate(perkTemplate, perkPanelParent, false); perkScreens.Add(newPerkScreen); Screen_Perk_Manager perkScreenManager = newPerkScreen.GetComponent <Screen_Perk_Manager>(); perkScreenManager.perkText.text = perk; } } else { homeLevelText.text = "MAX HOME LEVEL REACHED"; canUpgrade = false; upgradeButton.gameObject.SetActive(false); } if (canUpgrade) { upgradeButton.interactable = true; } else { upgradeButton.interactable = false; } }