Example #1
0
        private void InitializeSlots(List <Recipe> recipeList)
        {
            recipes.Clear();
            recipes.AddRange(recipeList);
            //TODO optomize this to reuse slots!
            foreach (CraftingSlot cs in craftingSlots)
            {
                Destroy(cs.gameObject);
            }
            craftingSlots.Clear();
            int i = 0;

            foreach (Recipe recipe in recipes)
            {
                CraftingSlot newCraftingSlot = Instantiate(craftingSlotPrefab) as CraftingSlot;
                newCraftingSlot.transform.SetParent(craftingSlotContainer);
                newCraftingSlot.titleText.text     = recipe.displayName;
                newCraftingSlot.ingredient         = recipe.craftedItem;
                newCraftingSlot.recipe             = recipe;
                newCraftingSlot.selectToggle.group = toggleGroup;

                craftingSlots.Add(newCraftingSlot);
                i++;
            }

            if (craftingSlots.Count > 0)
            {
                SelectCraftingSlot(craftingSlots[0]);
            }
        }
Example #2
0
    void UpdateSlot(KeyValuePair <Recipe, int> recipe, GameObject craftingSlot)
    {
        if (recipe.Key != null)
        {
            GameObject image = craftingSlot.transform.GetChild(0).gameObject;
            image.SetActive(true);
            image.GetComponent <Image>().sprite = recipe.Key.recipeSprite;
            GameObject text = image.transform.GetChild(0).gameObject;
            if (recipe.Value > 1)
            {
                text.GetComponent <TMP_Text>().SetText(recipe.Value.ToString());
            }
            else
            {
                text.GetComponent <TMP_Text>().SetText("");
            }
        }
        else
        {
            GameObject image = craftingSlot.transform.GetChild(0).gameObject;
            image.SetActive(false);
        }
        if (recipe.Value <= 0)
        {
            craftingSlot.GetComponent <Button>().interactable = false;
        }
        else
        {
            craftingSlot.GetComponent <Button>().interactable = true;
        }
        CraftingSlot slotScript = craftingSlot.GetComponent <CraftingSlot>();

        slotScript.recipeID = recipe.Key.recipeID;
        slotScript.amount   = recipe.Value;
    }
Example #3
0
    void OnClickCraftingSlot(GameObject craftingSlot)
    {
        CraftingSlot slotScript = craftingSlot.GetComponent <CraftingSlot>();

        if (Input.GetKey(KeyCode.LeftShift))
        {
            CraftingManagerQueue queue;
            if (inventory.gameObject.TryGetComponent(out queue))
            {
                queue.SetRecipe(Definitions.Instance.RecipeDictionaryIndexed[slotScript.recipeID], Mathf.Min(slotScript.amount, 5));
                return;
            }
        }
        else if (Input.GetKey(KeyCode.LeftControl))
        {
            CraftingManagerQueue queue;
            if (inventory.gameObject.TryGetComponent(out queue))
            {
                queue.SetRecipe(Definitions.Instance.RecipeDictionaryIndexed[craftingSlot.GetComponent <CraftingSlot>().recipeID], slotScript.amount);
                return;
            }
        }
        CraftingManager craftingManager;

        if (inventory.gameObject.TryGetComponent(out craftingManager))
        {
            craftingManager.SetRecipe(Definitions.Instance.RecipeDictionaryIndexed[slotScript.recipeID]);
        }
        if (menuToHideOnRecipeSelect != null)
        {
            menuToHideOnRecipeSelect.TogglePanelOff();
        }
    }
Example #4
0
	public void SelectCraftingSlot(CraftingSlot slot){
		icon.sprite = slot.icon.sprite;
		itemName.text = slot.itemName.text;
		description.text = slot.description.text;
		mItem = slot.observedItem as InventoryItem;
		if (ingredientContainer == null) {
			ingredientContainer=GetComponentInChildren<IngredientContainer>();
		}
		ingredientContainer.Add(mItem);
	}
Example #5
0
    private void HandleCombination()
    {
        CraftingSlot item_1 = slot_1.GetComponentInChildren <CraftingSlot>();
        CraftingSlot item_2 = slot_2.GetComponentInChildren <CraftingSlot>();
        CraftingSlot item_3 = slot_3.GetComponentInChildren <CraftingSlot>();


        //var combinationList = new List<T>();

        List <string> combinationItems = new List <string>();

        if (item_1 != null)
        {
            combinationItems.Add(item_1.name);
        }
        if (item_2 != null)
        {
            combinationItems.Add(item_2.name);
        }
        //  if(item_3 != null)
        // {
        //   combinationItems.Add(item_3.name);
        // }

        // foreach(string item in combinationItems)
        // {
        //   Debug.Log(item);
        // }

        if (item_1 == null || item_2 == null)
        {
            return;
        }

        foreach (Recipe r in recipes)
        {
            Item[] items = { r.input01, r.input02 };

            if ((items.Any(item => item.name == item_1.name) &&
                 items.Any(item => item.name == item_2.name)))
            {
                if (!Storage.Instance.HasItem(r.result.name))
                {
                    SuccessPanel.SetActive(true);
                    unlockedItemName.text   = r.result.name;
                    unlockedItemIcon.sprite = r.result.icon;
                    //storage.unlockedItem.Add(new UnlockedItem(r.result.name, 0, r.result.producer, 1, r.result.icon));
                    Storage.Instance.AddItem(r.result);
                    // Production.Instance.AddItem(r.result);
                    RefreshDisplay();
                }
            }
        }
    }
Example #6
0
 public void Add(CraftingSlot craftingItem)
 {
     slots.Add(craftingItem);
     // Because of how the UI works, crafting slots can be added or removed without changing the recipe.
     // We don't want to add an item to the crafting recipe again if it already exists.
     if (inRecipe(craftingItem.item.item.id))
     {
         return;
     }
     recipe.Add(craftingItem.item);
     UpdateList();
 }
    public void CraftBtnClicked()
    {
        CraftingSlot selectedSlot = craftsHandler.GetSlotSelected();

        foreach (Item s in selectedSlot.GetRecipe())
        {
            Item removedItem = inventoryManager.GetItem(s);
            inventoryManager.RemoveItem(removedItem);
        }
        inventoryManager.AddItem(selectedSlot.GetItem());
        craftButton.interactable = false;
        if (selectedSlot.GetItem().IsSameAs(Resources.Load <Gear>("Items/Gear/Radio")))
        {
            pop.PopMessage(PopupSystem.Popup.Radio);
        }
        UpdateCraftable();
    }
Example #8
0
    void UpdateItemUI()
    {
        // Clearing the crafting manager only clears the buttons used
        craftingManager.Clear();

        List<int> heldItems = new List<int>();
        // We have an equal number of inventoryItems to item slots in the inventory
        for (int i = 0; i < inventoryItems.Length; i++)
        {
            InventoryItem item = inventory.items[i];
            CraftingSlot slot = inventoryItems[i].GetComponent<CraftingSlot>();
            slot.Clear();
            slot.selected = false;

            if (item != null && item.item.craftingItem && !heldItems.Contains(item.item.id))
            {
                int quantity = item.quantity;
                inventoryItems[i].gameObject.SetActive(true);
                for (int j = i + 1; j < inventoryItems.Length; j++)
                {
                    if (inventory.items[j] != null && inventory.items[j].item.id == item.item.id)
                    {
                        quantity += inventory.items[j].quantity;
                    }
                }
                heldItems.Add(item.item.id);
                inventoryItems[i].GetComponentInChildren<Text>().text = item.item.name + " : " + quantity;
                slot.item = new CraftingItem(item.item, quantity);

                // Check to see if the button is part of the currently selected recipe, if it is, select the button and add it back to the crafting button list
                if (craftingManager.inRecipe(item.item.id))
                {
                    craftingManager.Add(slot);
                    slot.Select();
                    slot.selected = true;
                }
            }
            else
            {
                slot.item = new CraftingItem(null, 0);
                inventoryItems[i].gameObject.SetActive(false);
            }

        }
    }
Example #9
0
    // Update is called once per frame
    void Update()
    {
        foreach (Transform Child in transform)
        {
            Child.gameObject.SetActive(false);
        }

        for (int i = 0; i < CraftingRecipes.Length; i++)
        {
            if (CraftingRecipes[i].CanCraft())
            {
                CraftingSlot ChildCraftingSlot = transform.GetChild(i).GetComponent <CraftingSlot>();
                ChildCraftingSlot.RecipeToCraft = CraftingRecipes[i];
                ChildCraftingSlot.ItemSprite    = CraftingRecipes[i].Results[0].Item.Icon;
                transform.GetChild(i).gameObject.SetActive(true);
            }
        }
    }
Example #10
0
    public void Show(CraftingSlot selectedItem)
    {
        Clear();

        recipe = selectedItem.GetRecipe();
        slots  = new List <NumberSlot>();
        GameObject obj;
        NumberSlot slot;

        int  n        = 1;
        Item previous = recipe[0];

        for (int i = 1; i < recipe.Count; i++)
        {
            if (!previous.IsSameAs(recipe[i]))
            {
                obj = Instantiate(numberPrefab);

                slot = obj.GetComponent <NumberSlot>();
                slot.AddItem(previous);
                slot.SetNumbers(getNumberInInvenotry(previous), n);

                obj.transform.SetParent(contentPanel.transform, false);

                slots.Add(slot);
                n = 1;
            }
            else
            {
                n++;
            }
            previous = recipe[i];
        }
        obj = Instantiate(numberPrefab);

        slot = obj.GetComponent <NumberSlot>();
        slot.AddItem(previous);
        slot.SetNumbers(getNumberInInvenotry(previous), n);

        obj.transform.SetParent(contentPanel.transform, false);

        slots.Add(slot);
    }
    public void UpdateCraftable()
    {
        craftsHandler.UpdateRecipe();
        CraftingSlot selectedSlot = craftsHandler.GetSlotSelected();

        if (selectedSlot == null)
        {
            return;
        }
        numbersHandler.UpdateNumbers();
        if (selectedSlot.GetIsCraftable())
        {
            StartCoroutine(ExecuteAfterTime(1f));
        }
        else
        {
            craftButton.interactable = false;
        }
    }
Example #12
0
    public void Show()
    {
        Clear();
        slots = new List <CraftingSlot>();

        foreach (Item item in craftingList)
        {
            GameObject obj = Instantiate(craftPrefab);

            CraftingSlot slot = obj.GetComponent <CraftingSlot>();
            slot.inventoryManager = inventoryManager;
            slot.craftsHandler    = this;
            slot.AddItem(Instantiate(item));

            obj.transform.SetParent(contentPanel.transform, false);

            slots.Add(slot);
        }
    }
    public void SlotSelected()
    {
        CraftingSlot selectedSlot = craftsHandler.GetSlotSelected();
        Item         selectedItem = selectedSlot.GetItem();

        descBackground.SetActive(true);
        nameText.SetText(selectedItem.name);
        descriptionText.SetText(selectedItem.GetDescription());
        itemPreview.sprite = selectedItem.GetSprite();
        if (selectedSlot.GetIsCraftable())
        {
            craftButton.interactable = true;
        }
        else
        {
            craftButton.interactable = false;
        }
        numbersHandler.Show(selectedSlot);
    }
Example #14
0
        public void SelectCraftingSlot(CraftingSlot craftingSlot)
        {
            foreach (CraftingSlot cs in craftingSlots)
            {
                cs.IsSelected = false;
            }

            craftingSlot.IsSelected = true;

            craftingInfoPanel.SelectedRecipe = craftingSlot.recipe;
            craftingInfoPanel.craftButton.interactable = true;

            foreach (RecipePortion rp in craftingSlot.recipe.requiredIngredients)
            {
                if (UIManager.GetMenu<Inventory>().GetIngredientAmount(rp.ingredient) < rp.ingredientCount)
                {
                    craftingInfoPanel.craftButton.interactable = false;
                }
            }
        }
Example #15
0
        public void SelectCraftingSlot(CraftingSlot craftingSlot)
        {
            foreach (CraftingSlot cs in craftingSlots)
            {
                cs.IsSelected = false;
            }

            craftingSlot.IsSelected = true;

            craftingInfoPanel.SelectedRecipe           = craftingSlot.recipe;
            craftingInfoPanel.craftButton.interactable = true;

            foreach (RecipePortion rp in craftingSlot.recipe.requiredIngredients)
            {
                if (UIManager.GetMenu <Inventory>().GetIngredientAmount(rp.ingredient) < rp.ingredientCount)
                {
                    craftingInfoPanel.craftButton.interactable = false;
                }
            }
        }
Example #16
0
    // private void AddItem(Unlock itemToAdd, Sh)

    public void handleItemTransfer(Item unlockedItem)
    {
        if (slot_1.transform.childCount == 0)
        {
            GameObject   itemObj = Instantiate(itemPrefab, slot_1);
            CraftingSlot slot    = itemObj.GetComponent <CraftingSlot>();
            slot.Setup(unlockedItem, 1);
        }
        else if (slot_2.transform.childCount == 0)
        {
            GameObject   itemObj = Instantiate(itemPrefab, slot_2);
            CraftingSlot slot    = itemObj.GetComponent <CraftingSlot>();
            slot.Setup(unlockedItem, 2);
        }
        else if (slot_3.transform.childCount == 0)
        {
            GameObject   itemObj = Instantiate(itemPrefab, slot_3);
            CraftingSlot slot    = itemObj.GetComponent <CraftingSlot>();
            slot.Setup(unlockedItem, 3);
        }
    }
Example #17
0
    public void Initialize()
    {
        for (int i = 0; i < m_CraftingSlots.Count; i++)
        {
            m_CraftingSlots[i].Initialize(this);

            switch (m_CraftingSlots[i].SlotType)
            {
            case GameConstants.eSlot.FLOWER:
                m_FlowerSlot = m_CraftingSlots[i];
                break;

            case GameConstants.eSlot.STEM:
                m_StemSlot = m_CraftingSlots[i];
                break;

            case GameConstants.eSlot.ROOT:
                m_RootSlot = m_CraftingSlots[i];
                break;
            }
        }
    }
Example #18
0
    // Update is called once per frame
    void FixedUpdate()
    {
        pointerData = new PointerEventData(EventSystem.current)
        {
            position = Input.mousePosition
        };
        results.Clear();
        EventSystem.current.RaycastAll(pointerData, results);
        InventorySlot tempItem  = null;
        CraftingSlot  tempCraft = null;

        for (int i = 0; i < results.Count; i++)
        {
            if (results[i].gameObject.TryGetComponent(out tempItem))
            {
                break;
            }
            else if (results[i].gameObject.TryGetComponent(out tempCraft))
            {
                itemSlot = null;
                break;
            }
        }
        if ((tempCraft != null && recipeSlot != null && tempCraft.recipeID != recipeSlot.recipeID) ||
            tempCraft == null)
        {
            changed = true;
        }
        recipeSlot = tempCraft;
        if ((tempItem != null && tempItem.item != null && itemSlot != null && itemSlot.item != null && tempItem.item.id != itemSlot.item.id) ||
            tempItem == null || tempItem.item == null)
        {
            changed = true;
        }
        itemSlot = tempItem;



        if (itemSlot != null && itemSlot.item != null && changed)
        {
            tooltipPanel.SetActive(true);
            mainHeader.GetComponentInChildren <TextMeshProUGUI>().SetText(itemSlot.item.name);
            if (itemSlot.item.description != null && itemSlot.item.description != "")
            {
                description.SetActive(true);
                description.GetComponentInChildren <TextMeshProUGUI>().text = itemSlot.item.description;
            }
            else
            {
                description.SetActive(false);
            }
            //if the item is ammo or thrown list damage.
            ingredientsPanel.SetActive(false);
            resultsPanel.SetActive(false);
            craftingTime.SetActive(false);
            ItemAmmo itemAmmo = itemSlot.item as ItemAmmo;
            if (itemAmmo != null)
            {
                damageHeader.SetActive(true);
                damageDescriptionAmmo.SetActive(true);
                damageDescriptionAmmo.GetComponentInChildren <TextMeshProUGUI>().SetText(System.Enum.GetName(typeof(Health.DamageType), itemAmmo.damageType) + " Damage " + itemAmmo.damage +
                                                                                         "\nFiring Rate {0:1}/s", (50.0f / itemAmmo.firingRate));
            }
            else
            {
                damageHeader.SetActive(false);
                damageDescriptionAmmo.SetActive(false);
            }
            changed = false;
        }
        else if (recipeSlot != null && changed)
        {
            tooltipPanel.SetActive(true);
            Recipe recipe = Definitions.Instance.RecipeDictionaryIndexed[recipeSlot.recipeID];
            if (recipe.Results.Count > 1)
            {
                description.SetActive(false);
                damageHeader.SetActive(false);
                damageDescriptionAmmo.SetActive(false);
                resultsPanel.SetActive(true);
            }
            else
            {
                if (recipe.Results[0].item.description != null && recipe.Results[0].item.description != "")
                {
                    description.SetActive(true);
                    description.GetComponentInChildren <TextMeshProUGUI>().text = recipe.Results[0].item.description;
                }
                else
                {
                    description.SetActive(false);
                }
                resultsPanel.SetActive(false);
                ItemAmmo itemAmmo = recipe.Results[0].item as ItemAmmo;
                if (itemAmmo != null)
                {
                    damageHeader.SetActive(true);
                    damageDescriptionAmmo.SetActive(true);
                    damageDescriptionAmmo.GetComponentInChildren <TextMeshProUGUI>().SetText(System.Enum.GetName(typeof(Health.DamageType), itemAmmo.damageType) + " Damage " + itemAmmo.damage +
                                                                                             "\nFiring Rate {0:1}/s", (50.0f / itemAmmo.firingRate));
                }
                else
                {
                    damageHeader.SetActive(false);
                    damageDescriptionAmmo.SetActive(false);
                }
            }
            mainHeader.GetComponentInChildren <TextMeshProUGUI>().SetText(recipe.name);
            ingredientsPanel.SetActive(true);
            craftingTime.SetActive(true);
            craftingTime.GetComponentInChildren <TextMeshProUGUI>().SetText("{0:1}s Crafting Time", (recipe.craftingTime / 50.0f));

            for (int i = 0; i < ingredientsItemElements.Count; i++)
            {
                if (i < recipe.Ingredients.Count)
                {
                    if (ingredientsItemElements[i] == null)
                    {
                        ingredientsItemElements[i] = Instantiate(ingredientsItemPrefab, ingredientsPanel.transform, false);
                    }
                    ingredientsItemElements[i].SetActive(true);
                    ingredientsItemElements[i].transform.GetComponentInChildren <Image>().sprite = recipe.Ingredients[i].item.itemSprite;
                    ingredientsItemElements[i].transform.GetComponentInChildren <TextMeshProUGUI>().SetText("x " + recipe.Ingredients[i].Amount + " " + recipe.Ingredients[i].item.name);
                }
                else
                {
                    if (ingredientsItemElements[i] != null)
                    {
                        ingredientsItemElements[i].SetActive(false);
                    }
                }
            }

            if (recipe.Results.Count > 1)
            {
                for (int i = 0; i < resultsItemElements.Count; i++)
                {
                    if (i < recipe.Results.Count)
                    {
                        if (resultsItemElements[i] == null)
                        {
                            resultsItemElements[i] = Instantiate(ingredientsItemPrefab, resultsPanel.transform, false);
                        }
                        resultsItemElements[i].SetActive(true);
                        resultsItemElements[i].transform.GetComponentInChildren <Image>().sprite = recipe.Results[i].item.itemSprite;
                        resultsItemElements[i].transform.GetComponentInChildren <TextMeshProUGUI>().SetText("x " + recipe.Results[i].Amount + " " + recipe.Results[i].item.name);
                    }
                    else
                    {
                        if (resultsItemElements[i] != null)
                        {
                            resultsItemElements[i].SetActive(false);
                        }
                    }
                }
            }


            changed = false;
        }
        else if (changed == true)
        {
            tooltipPanel.SetActive(false);
            changed = false;
        }

        float   width    = tooltipPanelTransform.rect.width * canvas.scaleFactor;
        float   height   = tooltipPanelTransform.rect.height * canvas.scaleFactor;
        Vector3 position = Input.mousePosition;

        if (Input.mousePosition.x + width > Screen.width)
        {
            position.x -= width;
            position.x -= adjustXY;
        }
        else
        {
            position.x += adjustXY;
        }
        if (Input.mousePosition.y - height < 0)
        {
            position.y += height;
            position.y += adjustXY;
        }
        else
        {
            position.y -= adjustXY;
        }
        this.transform.position = position;
    }
Example #19
0
 public void SlotSelected(CraftingSlot slot)
 {
     slotSelected = slot;
     craftingController.SlotSelected();
     UpdateSlots();
 }
Example #20
0
 public void Remove(CraftingSlot craftingItem)
 {
     slots.Remove(craftingItem);
     UpdateCrafting();
 }
Example #21
0
 public void SetSelectedSlot(CraftingSlot slot)
 {
     m_SelectedSlot = slot;
 }