private void DoCraft()
    {
        //EVAN - some sort of ding or "crafting complete!" sound
        AkSoundEngine.PostEvent("Crafting_Success", gameObject);
        CraftingModule.CraftConsumable(shipInventory, playerInventory, playerResourceInventory, queuedRecipe);
        var poptext = Instantiate(popText);

        poptext.popText.SetText($"{queuedRecipe.DisplayName} crafted");
        poptext.gameObject.transform.SetParent(CraftButton.transform);
        poptext.GetComponent <RectTransform>().anchoredPosition = Vector3.zero;
        storageDials.UpdateDials();
        UpdateOwnedAmounts();

        queuedRecipe = null;
        popTextMSG   = null;
    }
    public bool CanCraftConsumable(ResourceInventory ResourceInv, InventoryController SourceInv, ResourceInventory TargetInv, ConsumableRecipe CraftRecipe)
    {
        if (SourceInv == null || TargetInv == null || ResourceInv == null || TargetInv == null)
        {
            Debug.LogError(SourceInv);
            Debug.LogError(TargetInv);
            Debug.LogError(ResourceInv);
            return(false);
        }

        foreach (var itemIn in CraftRecipe.ItemInput)
        {
            if (SourceInv.GetItemAmount(itemIn.item) < itemIn.amount)
            {
                return(false);
            }
        }

        foreach (var resIn in CraftRecipe.ResourceInput)
        {
            if (ResourceInv.GetResource(resIn.resource) < resIn.amount)
            {
                return(false);
            }
        }

        if (CraftRecipe.isUpgrade)
        {
            return(true);
        }

        var resource = CraftRecipe.Output;

        if (TargetInv.GetResource(resource) == resource.GetMaximum())
        {
            Debug.Log($"{resource} is full");
        }
        return(true);
    }
    public bool CraftConsumable(ResourceInventory ResourceInv, InventoryController SourceInv, ResourceInventory TargetInv, ConsumableRecipe CraftRecipe, bool ByPassCraftCheck = false)
    {
        if (!ByPassCraftCheck) //optimization to skip checking if we can craft this recipe
        {
            if (!CanCraftConsumable(ResourceInv, SourceInv, TargetInv, CraftRecipe))
            {
                return(false);
            }
        }

        foreach (var itemIn in CraftRecipe.ItemInput) //TODO Optimize data structure to allow use of a single foreach for inputs
        {
            SourceInv.RemoveFromItemBucket(itemIn.item, itemIn.amount);
        }
        foreach (var resourceIn in CraftRecipe.ResourceInput)
        {
            ResourceInv.RemoveResource(resourceIn.resource, resourceIn.amount);
        }

        if (CraftRecipe.isUpgrade)
        {
            Debug.Log("Before Amount: " + TargetInv.GetResource(CraftRecipe.Output));
            //if(CraftRecipe.Output.name == "Health")
            //{
            //    UIRootModule.UIRoot.GetScreen<GameHUD>().healthUpgrade.Upgrade(CraftRecipe.OutputAmount);
            //}
            if (CraftRecipe.Output.name == "Fuel")
            {
                UIRootModule.UIRoot.GetScreen <GameHUD>().fuelUpgrade.Upgrade(CraftRecipe.OutputAmount);
            }
            //Add Resource already contains a clamp so resource cannot go over max
            TargetInv.AddResource(CraftRecipe.Output, CraftRecipe.Output.GetMaximum());
            Debug.Log("After Amount: " + TargetInv.GetResource(CraftRecipe.Output));
        }
        else
        {
            //Add Resource already contains a clamp so resource cannot go over max
            TargetInv.AddResource(CraftRecipe.Output, CraftRecipe.OutputAmount);
        }
        return(true);
    }
 public void SetCraftInfo(ConsumableRecipe recipe, string popTextMSG)
 {
     queuedRecipe = recipe;
     popTextMSG   = $"{recipe.DisplayName} crafted";
 }
    //use an array of recipe objects to generate crafting screen buttons & their associated functionality
    public void PopulateRecipePanel(ConsumableRecipe[] recipeList, int contentGroup)
    {
        foreach (var recipe in recipeList)
        {
            var newButton = AddNewButton(recipe.DisplayName, contentGroups[contentGroup].GetComponent <VerticalLayoutGroup>());

            //set up what the recipe button does when you click it - used to fill in all the
            //recipe info on the crafting panel (# of ingredients, names, amount needed, etc)
            newButton.GetComponent <Button>().onClick.AddListener(() =>
            {
                TitleText.SetText(recipe.DisplayName);
                TitleText.gameObject.SetActive(true);
                RequiresText.SetActive(true);

                int childCount = ProductGroup.transform.childCount;

                //REFRESH CRAFTING PANEL AFTER CLICKING A RECIPE
                //remove the "products" of the previous recipe
                for (int i = 0; i < childCount; i++)
                {
                    Destroy(ProductGroup.transform.GetChild(i).gameObject);
                }

                childCount = IngredientGroup.transform.childCount;

                //remove the "ingredients" of the previous recipe
                for (int i = 0; i < childCount; i++)
                {
                    //Debug.Log("INGREDIENT:" + IngredientGroup.transform.GetChild(0).GetComponentsInChildren<TextMeshProUGUI>()[0].text);
                    Destroy(IngredientGroup.transform.GetChild(i).gameObject);
                }

                //add new products and ingredients
                var product = Instantiate(Product);
                product.transform.SetParent(ProductGroup.transform);
                //there's two text portions on the UI element, the name and the amount
                var outputText = product.GetComponentsInChildren <TextMeshProUGUI>();
                outputText[0].SetText(recipe.DisplayName);
                outputText[1].SetText("x1");
                outputText[2].SetText(recipe.ItemDesc);

                foreach (var input in recipe.ResourceInput)
                {
                    //create ingredient box
                    var ingredient = Instantiate(Ingredient);
                    ingredient.transform.SetParent(IngredientGroup.transform);

                    //set the icon on the box to the resource icon
                    var resourceIcon = input.resource.resourceIcon;
                    if (resourceIcon != null)
                    {
                        var image    = ingredient.GetComponentInChildren <Image>();
                        image.sprite = resourceIcon;
                        image.color  = input.resource.ResourceColor;
                    }

                    var inputText = ingredient.GetComponentsInChildren <TextMeshProUGUI>();

                    inputText[0].SetText(input.resource.DisplayName);
                    inputText[0].color = input.resource.ResourceColor;
                    //adding owned amount to dictionary for updating
                    TextToResource.Add(inputText[1], input.resource);
                    inputText[2].SetText($"/ {input.amount}");
                }

                foreach (var input in recipe.ItemInput)
                {
                    //create ingredient box
                    var ingredient = Instantiate(Ingredient);
                    ingredient.transform.SetParent(IngredientGroup.transform);

                    //set the icon on the box to the resource icon
                    var itemIcon = input.item.Icon;
                    if (itemIcon != null)
                    {
                        ingredient.GetComponentInChildren <Image>().sprite = itemIcon;
                    }

                    var inputText = ingredient.GetComponentsInChildren <TextMeshProUGUI>();

                    inputText[0].SetText(input.item.Name);
                    //adding owned amount to dictionary for updating
                    TextToItem.Add(inputText[1], input.item);
                    inputText[2].SetText($"/ {input.amount}");
                }

                //show how much of each mat they have
                UpdateOwnedAmounts();

                CraftButton.gameObject.SetActive(true);
                currentRecipe = recipe;
                //change what the craft button does
                CraftButton.onClick.RemoveAllListeners();

                EventTrigger trigger = CraftButton.GetComponent <EventTrigger>();

                //clear any triggers from previous recipes
                trigger.triggers.Clear();

                EventTrigger.Entry entry = new EventTrigger.Entry();
                entry.eventID            = EventTriggerType.PointerDown;
                entry.callback.AddListener((eventData) =>
                {
                    if (!CraftingModule.CanCraftConsumable(shipInventory, playerInventory, playerResourceInventory, currentRecipe))
                    {
                        return;
                    }
                    queuedRecipe    = recipe;
                    popTextMSG      = $"{recipe.DisplayName} crafted";
                    var pointerData = (PointerEventData)eventData;
                    timerDial.transform.position = pointerData.position;
                    HoldTimer();
                });
                trigger.triggers.Add(entry);

                entry         = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.PointerUp;
                entry.callback.AddListener((eventData) =>
                {
                    ReleaseTimer();
                });
                trigger.triggers.Add(entry);
            });
        }
    }