/// <summary>
    /// Determinates what to do when action button is clicked
    /// </summary>
    public void actionButtonClick()
    {
        bool remove = true;

        if (selectedItem != null)
        {
            ItemInventoryBase item = new ItemInventoryBase();
            item = selectedItem;
            GameStateBase currentState = gameController.GetCurrentState();

            if (currentState.GetComponent <WorkBench> () != null)
            {
                remove = SendObjectToWorkbench(item);
            }

            if (currentState.GetComponent <LIAState> () != null)
            {
                remove = currentState.GetComponent <LIAState>().ReceiveProduct(item, GameObject.Find(item.index));
            }

            if (remove)
            {
                removeItem(GameObject.Find(selectedItem.gameObject.name));
            }
        }
    }
示例#2
0
 public bool ReceiveProduct(ItemInventoryBase item, GameObject obj)
 {
     if (currentIndex.Length == 0)
     {
         if (obj != null)
         {
             currentIndex     = item.index;
             glassware.sprite = item.icon.sprite;
             if (item.solid.IsActive())
             {
                 solid.sprite = item.solid.sprite;
                 solid.color  = new Color32(255, 255, 255, 255);
             }
             if (item.liquid.IsActive())
             {
                 liquid.sprite = item.liquid.sprite;
                 liquid.color  = new Color32(255, 255, 255, 255);
             }
             verifyButton.interactable = true;
             return(true);
         }
         else
         {
             Debug.Log("n recebi");
             return(false);
         }
     }
     else
     {
         gameController.sendAlert("Já tem um produto");
     }
     return(false);
 }
    /// <summary>
    /// Refreshs the tab with Item info.
    /// </summary>
    /// <param name="i">ItemInventoryBase to get info from.</param>
    /// <param name="val">If set to <c>true</c>, activates tab. Else, deactivates.</param>
    public void refreshTab(ItemInventoryBase i, bool val)
    {
        if (!val)
        {
            actionTab.SetActive(false);
            return;
        }
        //gets info from "i"
        switch (i.getItemType())
        {
        case ItemType.Glassware:
            tabValues[0].text = i.gl.name;
            break;

        case ItemType.Liquids:
        case ItemType.Solids:
            tabValues[0].text = i.reagent;
            tabValues[1].text = CompoundFactory.GetInstance().GetCupboardCompound(i.reagent).MolarMass + " g/mol";
            tabValues[2].text = CompoundFactory.GetInstance().GetCupboardCompound(i.reagent).Density + " g/ml";
            tabValues[3].text = CompoundFactory.GetInstance().GetCupboardCompound(i.reagent).Purity *100 + "%";
            tabValues[4].text = CompoundFactory.GetInstance().GetCupboardCompound(i.reagent).Solubility + " g/1g";
            break;
        }

        actionTab.SetActive(true);
    }
示例#4
0
    /// <summary>
    /// Sets the selected item.
    /// </summary>
    /// <param name="i">The item to be set.</param>
    public void setSelectedItem(ItemInventoryBase i)
    {
        //if there was a selected object, sets its background to default
        if (selectedObject != null)
        {
            selectedObject.GetComponentInChildren <Image> ().sprite = backgroundIcons [3];
        }
        //sets "i" as selected item and changes its background
        this.selectedItem = i;
        selectedObject    = GameObject.Find(selectedItem.gameObject.name);
        selectedObject.GetComponentInChildren <Image>().sprite = selectedIcon;

        refreshButtons();

        //Debug.Log("Chamar o clique do botão action interagir se estiver interagindo");
        if (interacting.Interacting)
        {
            actionButtonClick();
        }
        else
        {
            txtIntegarir.enabled = true;
            Debug.Log("Impossível interagir");
        }
    }
    /// <summary>
    /// Adds the reagent to inventory.
    /// </summary>
    /// <param name="reagent">Reagent to be added.</param>
    /// <param name="r">The component info.</param>
    public void AddReagentToInventory(ReagentPot reagent, Compound r)
    {
        ItemInventoryBase item = new ItemInventoryBase();

        item.HoldItem(reagent);
        item.addReagent(r);
        addItem(ref item);
    }
    /// <summary>
    /// Adds the glassware to inventory.
    /// </summary>
    /// <param name="gl">Glassware to be added.</param>
    public void AddGlasswareToInventory(Glassware gl)
    {
        ItemInventoryBase item = new ItemInventoryBase();

        item.addGlassware(gl);
        item.HoldItem(gl);
        addItem(ref item);
    }
    public void onClick(int index)
    {
        if (item is Glassware)
        {
            switch (actualIDs[index])
            {
            case 0:
                if (!item.GetComponent <Glassware>().hasReagents())
                {
                    GameObject temp = null;
                    for (int i = 0; i < prefabs.Count; i++)
                    {
                        if (((item as Glassware).gl.Contains(prefabs[i].GetComponent <Glassware>().name)))
                        {
                            temp = prefabs[i];
                        }
                    }
                    GameObject.Find("InventoryManager").GetComponent <InventoryManager>().AddGlasswareToInventory(temp.GetComponent <Glassware>());
                    Destroy(item.gameObject);
                }
                else
                {
                    if (GetComponentInParent <WorkBench>().equipmentController != null && item.transform.parent == GetComponentInParent <WorkBench>().positionGlassEquipament)
                    {
                        GetComponentInParent <WorkBench>().equipmentController.RemoveObjectInEquipament(item.gameObject);
                    }
                    GameObject.Find("InventoryManager").GetComponent <InventoryManager>().AddProductToInventory(item.gameObject);
                }
                break;

            case 1:
                GetComponentInParent <WorkBench>().PutGlassInEquip(item.gameObject);
                break;

            case 2:
                GetComponentInParent <WorkBench>().PutItemFromEquip(item.gameObject);
                break;
            }
        }

        if (item is ReagentPot)
        {
            switch (actualIDs[index])
            {
            case 0:
                ItemInventoryBase reagent = new ItemInventoryBase();
                Compound          r       = (item as ReagentPot).reagent.Clone() as Compound;
                reagent.addReagent(r);
                int prefabIndex = reagent.getItemType() == ItemType.Liquids?0:1;
                GameObject.Find("InventoryManager").GetComponent <InventoryManager>().AddReagentToInventory(prefabs[prefabIndex].GetComponent <ReagentPot>(), r);

                Destroy(item.gameObject);
                break;
            }
        }

        ui_manager.CloseAll();
    }
示例#8
0
    //! Put into workbench position an item from the inventory
    public bool PutItemFromInventory(ItemInventoryBase item)
    {
        bool worked = false;

        if (!item.physicalObject)
        {
            GameObject tempItem = Instantiate(item.itemBeingHeld.gameObject) as GameObject;
            if (!TryPutIntoPosition(tempItem))
            {
                Destroy(tempItem);
                worked = false;
            }
            else
            {
                if (tempItem.GetComponent <ReagentPot>() != null)
                {
                    if (item.reagent.Length != 0)
                    {
                        Compound reagent = CompoundFactory.GetInstance().GetCupboardCompound(item.reagent);

                        if (tempItem.GetComponent <ReagentPot>().isSolid)
                        {
                            tempItem.GetComponent <ReagentPot>().reagent.setValues(reagent as Compound);
                        }
                        else
                        {
                            tempItem.GetComponent <ReagentPot>().reagent.setValues(reagent as Compound);
                        }
                    }
                }
                worked = true;
            }
        }
        else
        {
            GameObject tempItem = GameObject.Find(item.index);
            if (TryPutIntoPosition(tempItem))
            {
                tempItem.SetActive(true);
                worked = true;
            }
            else
            {
                worked = false;
            }
        }

        if (worked)
        {
            soundBeaker.Play();
            return(true);
        }
        else
        {
            gameController.sendAlert("A Bancada está cheia!");
            return(false);
        }
    }
示例#9
0
 public void copyData(ItemInventoryBase item)
 {
     this.name           = item.name;
     this.gl             = item.gl;
     this.reagent        = item.reagent;
     this.stackable      = item.stackable;
     this.itemType       = item.itemType;
     this.itemBeingHeld  = item.itemBeingHeld;
     this.index          = item.index;
     this.underText      = item.underText;
     this.physicalObject = item.physicalObject;
 }
    /// <summary>
    /// Adds the product to inventory.
    /// </summary>
    /// <param name="itm">Product to be added.</param>
    public void AddProductToInventory(GameObject itm)
    {
        ItemInventoryBase item = new ItemInventoryBase();

        item.physicalObject = true;
        item.itemType       = ItemType.Others;
        GenerateIndex(ref item);
        itm.name = item.index;

        addItem(ref item);
        //sends item to limbo
        itm.transform.SetParent(limbo, false);
    }
    /// <summary>
    /// Adds the item to the inventory.
    /// </summary>
    /// <returns>The item or null .</returns>
    /// <param name="item">Item.</param>
    public GameObject addItem(ref ItemInventoryBase item)
    {
        GenerateIndex(ref item);
        //If the item added is of current list type, adds it to the grid
        if (item.getItemType() == itemType[0] || item.getItemType() == itemType[1])
        {
            GameObject aux = instantiateObject(item);

            switch (item.getItemType())
            {
            case ItemType.Glassware:
                Glassware.Add(item);
                break;

            case ItemType.Liquids:
            case ItemType.Solids:
                Reagents.Add(item);
                break;

            case ItemType.Others:
                Products.Add(item);
                break;
            }
            refreshGrid();

            return(aux);
            //else, adds it to the List directly and changes the list
        }
        else
        {
            switch (item.getItemType())
            {
            case ItemType.Glassware:
                Glassware.Add(item);
                changeList(2);
                break;

            case ItemType.Liquids:
            case ItemType.Solids:
                Reagents.Add(item);
                changeList(1);
                break;

            case ItemType.Others:
                Products.Add(item);
                changeList(0);
                break;
            }
            return(null);
        }
    }
    /// <summary>
    /// Generates the index for an ItemInventoryBase.
    /// </summary>
    /// <returns>The index generated.</returns>
    /// <param name="item">Item to generate index.</param>
    public string GenerateIndex(ref ItemInventoryBase item)
    {
        if (item.index == null)
        {
            StringBuilder sb;
            do
            {
                sb = new StringBuilder();
                for (int i = 0; i < 6; i++)
                {
                    char aux = (char)Random.Range(65, 126);
                    sb.Append(aux);
                }
            }while(listOfIndexes.Contains(sb.ToString()));
            item.index = sb.ToString();
            listOfIndexes.Add(sb.ToString());
        }

        return(item.index);
    }
    /// <summary>
    /// Changes the list to the index sent.
    /// </summary>
    /// <param name="index">Index.</param>
    public void changeList(int index)
    {
        selectedItem = null;
        //cleans the grid
        for (int i = ObjectList.Count - 1; i >= 0; i--)
        {
            ObjectList.Remove(ObjectList[i]);
            Destroy(content.GetChild(i).gameObject);
        }

        selectedObject = null;
        refreshActionButton();
        count = 0;
        //changes the current list and instantiantes the objects from the list
        selectList(index);
        foreach (ItemInventoryBase item in getCurrentList())
        {
            instantiateObject(item);
        }
        refreshGrid();
    }
 /// <summary>
 /// Sends the object to workbench.
 /// </summary>
 /// <returns><c>true</c>, if object to workbench was sent, <c>false</c> otherwise.</returns>
 /// <param name="item">Item to be sent.</param>
 public bool SendObjectToWorkbench(ItemInventoryBase item)
 {
     return(gameController.GetCurrentState().GetComponent <WorkBench> ().PutItemFromInventory(item));
 }
    /// <summary>
    /// Instantiates the item on the grid.
    /// </summary>
    /// <returns>The GameObject.</returns>
    /// <param name="item">The Item to instantiate.</param>
    public GameObject instantiateObject(ItemInventoryBase item)
    {
        GameObject tempItem = Instantiate(itemPrefab) as GameObject;

        tempItem.transform.SetParent(content.transform, false);        //adds item as child of the grid
        tempItem.name = "InventoryItem" + count.ToString();
        count++;
        //copies the data from item to the ItemInventoryBase component
        tempItem.GetComponent <ItemInventoryBase>().copyData(item);
        ObjectList.Add(tempItem);
        changeImage(tempItem);
        tempItem.gameObject.GetComponent <Button> ().onClick.AddListener(() => this.setSelectedItem(tempItem.GetComponent <ItemInventoryBase>()));        //adds click listener on runtime


        if (item.getItemType() != ItemType.Glassware)
        {
            if (item.getItemType() == ItemType.Others)
            {
                //TODO: Implement the triggers for products
                EventTrigger       trigger = tempItem.gameObject.GetComponent <EventTrigger> ();
                EventTrigger.Entry enter   = new EventTrigger.Entry();
                enter.eventID = EventTriggerType.PointerEnter;
                //trigger for entering
                enter.callback.AddListener((eventData) => {
                    if (limbo.Find(item.index).GetComponent <Glassware>() != null)
                    {
                        if (limbo.Find(item.index).GetComponent <Glassware> ().label.Length != 0)
                        {
                            labelRect.gameObject.SetActive(true);
                            labelRect.rotation = Quaternion.Euler(0f, 0f, 0f);
                            labelRect.GetComponentInChildren <Text> ().rectTransform.localRotation = Quaternion.Euler(0f, 0f, 0f);
                            labelRect.GetComponentInChildren <Text> ().text = limbo.Find(item.index).GetComponent <Glassware> ().label;
                            labelRect.transform.position = new Vector2(tempItem.GetComponent <ItemInventoryBase> ().posTab.position.x,
                                                                       tempItem.GetComponent <ItemInventoryBase> ().posTab.position.y - 50.0f);
                        }
                    }

                    /*refreshLabel (item,true);
                     * glasswareLabel.transform.position = tempItem.GetComponent<ItemInventoryBase> ().posTab.position;*/
                });
                trigger.triggers.Add(enter);
                //trigger for leaving
                EventTrigger.Entry exit = new EventTrigger.Entry();
                exit.eventID = EventTriggerType.PointerExit;
                exit.callback.AddListener((eventData) => {
                    //refreshLabel (null,false);
                    labelRect.gameObject.SetActive(false);
                });
                trigger.triggers.Add(exit);
            }
            else
            {
                //if reagent, adds triggers for info tab
                EventTrigger       trigger = tempItem.gameObject.GetComponent <EventTrigger> ();
                EventTrigger.Entry enter   = new EventTrigger.Entry();
                enter.eventID = EventTriggerType.PointerEnter;
                //trigger for entering
                enter.callback.AddListener((eventData) => {
                    refreshTab(item, true);
                    actionTab.transform.position = tempItem.GetComponent <ItemInventoryBase> ().posTab.position;
                });
                trigger.triggers.Add(enter);
                //trigger for leaving
                EventTrigger.Entry exit = new EventTrigger.Entry();
                exit.eventID = EventTriggerType.PointerExit;
                exit.callback.AddListener((eventData) => {
                    refreshTab(null, false);
                });
                trigger.triggers.Add(exit);
            }
        }
        //returns the instantiated object
        return(tempItem);
    }
    /// <summary>
    /// Changes the background image of the selected item.
    /// </summary>
    /// <param name="obj">GameObject of the selected item.</param>
    public void changeImage(GameObject obj)
    {
        ItemInventoryBase item = obj.GetComponent <ItemInventoryBase> ();
        Image             icon = null;

        Image[] img = obj.GetComponentsInChildren <Image> ();
        //from images on obj, gets the Item Image
        for (int i = 0; i < img.Length; i++)
        {
            if (img[i].gameObject.name == "Item Image")
            {
                icon = img[i];
            }
        }

        Text txt = obj.GetComponentInChildren <Text> ();

        //chooses image depending on item
        //if reagent, sets underneath text to obj formula
        switch (item.getItemType())
        {
        case ItemType.Liquids:
            icon.sprite = icons[0];
            txt.text    = CompoundFactory.GetInstance().GetCupboardCompound(item.reagent).Formula;
            break;

        case ItemType.Solids:
            icon.sprite = icons[1];
            txt.text    = CompoundFactory.GetInstance().GetCupboardCompound(item.reagent).Formula;
            break;

        case ItemType.Glassware:
            txt.text = "";
            if (item.gl.name.Contains("Balão Vol."))
            {
                if (item.gl.name.Contains("25"))
                {
                    icon.sprite = icons[2];
                    break;
                }
                if (item.gl.name.Contains("50"))
                {
                    icon.sprite = icons[3];
                    break;
                }
                if (item.gl.name.Contains("100"))
                {
                    icon.sprite = icons[4];
                    break;
                }
            }
            if (item.gl.name.Contains("Béquer"))
            {
                icon.sprite = icons[5];
                break;
            }
            if (item.gl.name.Contains("Erlenmeyer"))
            {
                if (item.gl.name.Contains(" 50ml"))
                {
                    icon.sprite = icons[6];
                    break;
                }
                if (item.gl.name.Contains("125"))
                {
                    icon.sprite = icons[7];
                    break;
                }
                if (item.gl.name.Contains("250"))
                {
                    icon.sprite = icons[8];
                    break;
                }
            }
            break;

        case ItemType.Others:
            txt.text = "";
            string gl = GameObject.Find(item.index).GetComponent <Glassware>().gl;
            if (gl.Contains("Balão Vol."))
            {
                if (GameObject.Find(item.index).GetComponent <Glassware>().hasSolid)
                {
                    item.solid.sprite  = productsIcons[0];
                    item.solid.enabled = true;
                }
                if (GameObject.Find(item.index).GetComponent <Glassware>().hasLiquid)
                {
                    item.liquid.sprite  = productsIcons[1];
                    item.liquid.enabled = true;
                }

                if (gl.Contains("25"))
                {
                    icon.sprite = icons[2];
                    break;
                }
                if (gl.Contains("50"))
                {
                    icon.sprite = icons[3];
                    break;
                }
                if (gl.Contains("100"))
                {
                    icon.sprite = icons[4];
                    break;
                }
            }
            if (gl.Contains("Béquer"))
            {
                if (GameObject.Find(item.index).GetComponent <Glassware>().hasSolid)
                {
                    item.solid.sprite  = productsIcons[2];
                    item.solid.enabled = true;
                }
                if (GameObject.Find(item.index).GetComponent <Glassware>().hasLiquid)
                {
                    item.liquid.sprite  = productsIcons[3];
                    item.liquid.enabled = true;
                }
                icon.sprite = icons[5];
                break;
            }
            if (gl.Contains("Erlenmeyer"))
            {
                if (GameObject.Find(item.index).GetComponent <Glassware>().hasSolid)
                {
                    item.solid.sprite  = productsIcons[4];
                    item.solid.enabled = true;
                }
                if (GameObject.Find(item.index).GetComponent <Glassware>().hasLiquid)
                {
                    item.liquid.sprite  = productsIcons[5];
                    item.liquid.enabled = true;
                }
                if (gl.Contains(" 50ml"))
                {
                    icon.sprite = icons[6];
                    break;
                }
                if (gl.Contains("125"))
                {
                    icon.sprite = icons[7];
                    break;
                }
                if (gl.Contains("250"))
                {
                    icon.sprite = icons[8];
                    break;
                }
            }
            break;
        }
    }