Ejemplo n.º 1
0
    public void SetUp()
    {
        int childs = InventoryParent.childCount;

        for (int i = childs - 1; i >= 0; i--)
        {
            Destroy(InventoryParent.GetChild(i).gameObject);
        }

        childs = Parent.childCount;
        for (int i = childs - 1; i > 0; i--)
        {
            Destroy(Parent.GetChild(i).gameObject);
        }

        var worldObject = GetComponent <BuildingWorldObject>();

        crafter = worldObject.myCrafter;

        inventory = worldObject.myInventory;
        inventory.drawInventoryEvent += SetUp;

        craftingProcesses.Clear();
        timeoutCounters.Clear();
        if (crafter != null)
        {
            for (int i = 0; i < crafter.myCraftingProcesses.Length; i++)
            {
                CraftingProcess curProcess = crafter.myCraftingProcesses[i] as CraftingProcess;
                if (curProcess != null)
                {
                    GameObject pDisp = Instantiate(ProcessDisplayPrefab, Parent);
                    craftingProcesses.Add(pDisp);
                    timeoutCounters.Add(infoDisplayTimeoutTime - 1f);
                    for (int input = 0; input < curProcess.inputItemIds.Length; input++)
                    {
                        GameObject pIn = Instantiate(ProcessinoutPrefab, pDisp.GetComponent <MiniGUI_CraftingProcess>().InputsParent);
                        pIn.GetComponent <MiniGUI_InOutDisplay>().itemImage.sprite = DataHolder.s.GetItem(curProcess.inputItemIds[input]).GetSprite();
                        pIn.GetComponent <MiniGUI_InOutDisplay>().totalText.text   = curProcess.inputItemAmounts[input].ToString();
                    }

                    for (int output = 0; output < curProcess.outputItemIds.Length; output++)
                    {
                        GameObject pOut = Instantiate(ProcessinoutPrefab, pDisp.GetComponent <MiniGUI_CraftingProcess>().OutputsParent);
                        pOut.GetComponent <MiniGUI_InOutDisplay>().itemImage.sprite = DataHolder.s.GetItem(curProcess.outputItemIds[output]).GetSprite();
                        pOut.GetComponent <MiniGUI_InOutDisplay>().totalText.text   = curProcess.outputItemAmounts[output].ToString();
                    }

                    //craftingProcesses[craftingProcesses.Count-1].SetActive(false);
                }
            }
        }


        foreach (InventoryItemSlot it in inventory.inventory)
        {
            Instantiate(InventoryListingPrefab, InventoryParent).GetComponent <MiniGUI_InventoryListing>().SetUp(it, inventory, true);
        }
    }
Ejemplo n.º 2
0
    public void UpdateValues()
    {
        if (crafter != null)
        {
            for (int i = 0; i < crafter.myCraftingProcesses.Length; i++)
            {
                CraftingProcess curProcess = crafter.myCraftingProcesses[i] as CraftingProcess;
                if (curProcess != null)
                {
                    craftingProcesses[i].GetComponentInChildren <Slider>().value = (float)curProcess.curCraftingProgress / (float)curProcess.craftingProgressTickReq;
                    int totalItemCount = 0;
                    for (int input = 0; input < curProcess.inputItems.Length; input++)
                    {
                        // Manually set madness
                        craftingProcesses[i].GetComponent <MiniGUI_CraftingProcess>().InputsParent.GetChild(input).GetComponent <MiniGUI_InOutDisplay>().valueText.text
                                        = inventory.GetAmountOfItems(curProcess.inputItems[input]).ToString();
                        totalItemCount += inventory.GetAmountOfItems(curProcess.inputItems[input]);
                    }

                    for (int output = 0; output < curProcess.outputItems.Length; output++)
                    {
                        // Manually set madness
                        craftingProcesses[i].GetComponent <MiniGUI_CraftingProcess>().OutputsParent.GetChild(output).GetComponent <MiniGUI_InOutDisplay>().valueText.text
                                        = inventory.GetAmountOfItems(curProcess.outputItems[output]).ToString();
                        totalItemCount += inventory.GetAmountOfItems(curProcess.outputItems[output]);
                    }

                    if (curProcess.isCrafting)
                    {
                        totalItemCount += 1;
                    }

                    // Disable the crafting process display if there are no items
                    if (totalItemCount > 0)
                    {
                        timeoutCounters[i] = -1;
                        craftingProcesses[i].SetActive(true);
                    }
                    else
                    {
                        if (timeoutCounters[i] == -1)
                        {
                            timeoutCounters[i] = 0;
                        }
                        else if (timeoutCounters[i] < infoDisplayTimeoutTime)
                        {
                            timeoutCounters[i] += Time.deltaTime;
                        }
                        else
                        {
                            craftingProcesses[i].SetActive(false);
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Do the setup tasks, which means figuring out which crafting processes this building can do based on the BuildingData and the RecipeSet
    /// </summary>
    /// <param name="mydat"></param>
    public void SetUp(BuildingData mydat, BuildingInventoryController _inv)
    {
        inventory = _inv;
        myData    = mydat;

        CraftingNode[] ps = DataHolder.s.GetCraftingProcessesOfType(mydat.myType);
        if (ps != null)
        {
            if (mydat.myType == BuildingData.ItemType.Miner)
            {
                //myCraftingProcesses = new CraftingProcess[ps.Length];
                myCraftingProcesses = new CraftingProcess[ps.Length];

                for (int i = 0; i < ps.Length; i++)
                {
                    if (DataHolder.s.UniqueNameToOreId(DataHolder.s.GetConnections(ps[i], false)[0].itemUniqueName, out int oreId))
                    {
                        myCraftingProcesses[i] = new CraftingProcess(
                            new List <DataHolder.CountedItem>(),
                            DataHolder.s.GetConnections(ps[i], false),
                            ps[i].timeCost
                            );
                    }
                }
            }
            else
            {
                myCraftingProcesses = new CraftingProcess[ps.Length];

                for (int i = 0; i < ps.Length; i++)
                {
                    myCraftingProcesses[i] = new CraftingProcess(
                        DataHolder.s.GetConnections(ps[i], true),
                        DataHolder.s.GetConnections(ps[i], false),
                        ps[i].timeCost
                        );
                }
            }
        }
        else if (mydat.myType == BuildingData.ItemType.Base)
        {
            //myCraftingProcesses = new IProcess[1];
            //myCraftingProcesses[0] = new InputProcess(myBelts);

            // This logic is now handled by the BuildingInventoryController and the BuildingInOutController
        }

        if (myCraftingProcesses.Length > 0)
        {
            isActive = true;
        }
        else
        {
            stopAnimationsEvent?.Invoke();
        }
    }