private void DoCraft() { //EVAN - some sort of ding or "crafting complete!" sound AkSoundEngine.PostEvent("Crafting_Success", gameObject); CraftingModule.CraftSatellite(shipInventory, playerInventory, satInventory, queuedRecipe); var poptext = Instantiate(popText); poptext.popText.SetText($"{queuedRecipe.DisplayName} crafted"); poptext.gameObject.transform.SetParent(CraftButton.transform); poptext.GetComponent <RectTransform>().anchoredPosition = Vector3.zero; //show the player how many of the output item they already have var ownedSat = satInventory.GetSatellite(); if (ownedSat != null) { amountInInventory.SetText($"Satellite Inventory: <b><color=#FF1B00>FULL</color></b>\nCurrently Equipped: {queuedRecipe.DisplayName}"); } else { amountInInventory.SetText($"Satellite Inventory: <b><color=#06FF00>Empty</color></b>"); } storageDials.UpdateDials(); UpdateOwnedAmounts(); UpdateCraftableRecipes(); mainCrafting.UpdateCraftableRecipes(); EventSystem.current.SetSelectedGameObject(null); queuedRecipe = null; popTextMSG = null; }
public bool CanCraftSatellite(ResourceInventory ResourceInv, InventoryController SourceInv, SatelliteInventory TargetInv, SatelliteRecipe 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.CreatesByProducts) { foreach (var resOut in CraftRecipe.ResourceByProducts) { if (ResourceInv.GetResource(resOut.resource) + resOut.amount > resOut.resource.GetMaximum()) { return(false); //holy crap this is a kludge. TODO: Fix this } } } if (TargetInv.StoredSatellites.Count != 0 && TargetInv.StoredSatellites[0] != null) { return(false); } return(true); }
public bool CraftSatellite(ResourceInventory ResourceInv, InventoryController SourceInv, SatelliteInventory TargetInv, SatelliteRecipe CraftRecipe, bool ByPassCraftCheck = false) { if (!ByPassCraftCheck) //optimization to skip checking if we can craft this recipe { if (!CanCraftSatellite(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); } TargetInv.SetSatellite(CraftRecipe.Output); //TODO (If required) Implement resource and item byproducts return(true); }
public void SetCraftInfo(SatelliteRecipe 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(SatelliteRecipe[] recipeList, int contentGroup) { foreach (var recipe in recipeList) { //EVAN - this is where you place a sound for clicking a specific recipe button AkSoundEngine.PostEvent("MainMenu_Button_Play", gameObject); var newButton = AddNewButton(recipe.DisplayName, contentGroups[contentGroup].GetComponent <VerticalLayoutGroup>()); //save association between button and its recipe so we can sort recipes by which ones you have the ingredients for ButtonToRecipe.Add(newButton, recipe); if (!CraftingModule.CanCraftSatellite(shipInventory, playerInventory, satInventory, recipe)) { newButton.gameObject.GetComponent <Image>().color = newButton.colors.disabledColor; } //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); if (RequiresText.activeSelf != true) { TitleText.gameObject.SetActive(true); RequiresText.SetActive(true); amountInInventory.gameObject.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); product.GetComponentInChildren <Image>().sprite = recipe.Output.satIcon; //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); //show the player how many of the output item they already have var ownedSat = satInventory.GetSatellite(); if (ownedSat != null) { amountInInventory.SetText($"Satellite Inventory: <b><color=#FF1B00>FULL</color></b>\nCurrently Equipped: {ownedSat.DisplayName}"); } else { amountInInventory.SetText($"Satellite Inventory: <b><color=#06FF00>Empty</color></b>"); } 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}"); var tooltip = ingredient.GetComponent <GetTooltip>().GetTooltipScript(); tooltip.GetTitle().color = input.resource.ResourceColor; tooltip.SetTitle(input.resource.DisplayName); tooltip.SetDesc(input.resource.Desc); //tooltips for resources dont have the extra panel for ingredients at the bottom var sizeDelta = tooltip.GetBkImg().GetComponent <RectTransform>().sizeDelta; sizeDelta.y -= 50; tooltip.GetBkImg().GetComponent <RectTransform>().sizeDelta = sizeDelta; } 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}"); var tooltip = ingredient.GetComponent <GetTooltip>().GetTooltipScript(); tooltip.SetTitle(input.item.Name); tooltip.SetDesc(input.item.ItemDesc); tooltip.AddSubIngredients(input.item.CraftingRecipe, shipInventory, playerInventory); } //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) => { //EVAN - this is where clicking the "craft" button first happens - you already have a sound further down for //holding the craft button down if (!CraftingModule.CanCraftSatellite(shipInventory, playerInventory, satInventory, 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); }); } //after instantiating all buttons, sort them all by which can be crafted UpdateCraftableRecipes(); }