Example #1
0
 void Start()
 {
     PersistentDataManager.LoadData();
     amount = PersistentDataManager.GetItemAmount((int)item);
     UpdateText();
     if (amount == 0)
     {
         item_button.interactable = false;
     }
 }
Example #2
0
 public void UpdateItemAmount(int currentItemID)
 {
     for (int i = 0; i < ItemHolderList.Count; i++)
     {
         ItemHolder holderScript = ItemHolderList[i].GetComponent <ItemHolder>();
         if (holderScript.itemID == currentItemID)
         {
             for (int j = 0; j < itemList.Count; j++)
             {
                 if (itemList[j].ItemID == currentItemID)
                 {
                     holderScript.amount.text = PersistentDataManager.GetItemAmount(currentItemID - 1).ToString();
                     if (holderScript.amount.text == "0")
                     {
                         holderScript.bar1.SetActive(false);
                         holderScript.bar2.SetActive(false);
                         holderScript.bar3.SetActive(false);
                         holderScript.bar4.SetActive(false);
                         holderScript.bar5.SetActive(false);
                     }
                     if (holderScript.amount.text == "1")
                     {
                         holderScript.bar1.SetActive(true);
                     }
                     if (holderScript.amount.text == "2")
                     {
                         holderScript.bar1.SetActive(false);
                         holderScript.bar2.SetActive(true);
                     }
                     if (holderScript.amount.text == "3")
                     {
                         holderScript.bar2.SetActive(false);
                         holderScript.bar3.SetActive(true);
                     }
                     if (holderScript.amount.text == "4")
                     {
                         holderScript.bar3.SetActive(false);
                         holderScript.bar4.SetActive(true);
                     }
                     if (holderScript.amount.text == "5")
                     {
                         holderScript.bar4.SetActive(false);
                         holderScript.bar5.SetActive(true);
                     }
                 }
             }
         }
     }
 }
Example #3
0
    void FillList() //Instantiates an itemholder object into the grid in the UI
    {
        //int[] loadData = PersistentDataManager.GetItemAmounts ();
        PersistentDataManager.LoadData();
        for (int i = 0; i < itemList.Count; i++)
        {
            GameObject holder       = Instantiate(ItemHolderPrefab, grid, false);
            ItemHolder holderScript = holder.GetComponent <ItemHolder>(); //Gain acces to the stuff in ItemHolder(the individual info of each item).

            holderScript.itemName.text  = itemList[i].ItemName;
            holderScript.itemPrice.text = itemList[i].ItemPrice.ToString();
            holderScript.itemID         = itemList[i].ItemID;
            holderScript.amount.text    = PersistentDataManager.GetItemAmount(i).ToString();

            if (holderScript.amount.text == "0")
            {
                holderScript.amount.text = "";
                holderScript.bar1.SetActive(false);
                holderScript.bar2.SetActive(false);
                holderScript.bar3.SetActive(false);
                holderScript.bar4.SetActive(false);
                holderScript.bar5.SetActive(false);
            }
            if (holderScript.amount.text == "1")
            {
                holderScript.bar1.SetActive(true);
            }
            if (holderScript.amount.text == "2")
            {
                holderScript.bar1.SetActive(false);
                holderScript.bar2.SetActive(true);
            }
            if (holderScript.amount.text == "3")
            {
                holderScript.bar2.SetActive(false);
                holderScript.bar3.SetActive(true);
            }
            if (holderScript.amount.text == "4")
            {
                holderScript.bar3.SetActive(false);
                holderScript.bar4.SetActive(true);
            }
            if (holderScript.amount.text == "5")
            {
                holderScript.bar4.SetActive(false);
                holderScript.bar5.SetActive(true);
            }
            //the buy button
            holderScript.buyButton.GetComponent <BuyButton>().itemID = itemList[i].ItemID;

            //The list to update the sprite
            ItemHolderList.Add(holder);
            buyButtonList.Add(holderScript.buyButton); //keeps track of whihc button.

            itemList [i].bought = PersistentDataManager.GetItemAmount(i) > 0?true:false;
            if (itemList[i].bought == true)
            {                                                                                                 //v----the sub directory.
                holderScript.itemImage.sprite = Resources.Load <Sprite>("Sprites/" + itemList[i].SpriteName); //Goes to the Resources directory to grab the right sprites.
            }
            else
            {
                holderScript.itemImage.sprite = Resources.Load <Sprite>("Sprites/" + "Lock" + itemList[i].SpriteName); //I manually change the sprite we getting by adding "Lock" to name
                                                                                                                       //Since all my locked versions are same name but Locked at start of string
                                                                                                                       //ex: Clock and LockClock
            }
        }
    }
Example #4
0
    public void BuyItem() //On click event
    {
        if (itemID == 0)
        {
            Debug.Log("Error: No weapon ID set"); //shouldnt see this.
            return;
        }

        for (int i = 0; i < ItemShop.itemShop.itemList.Count; i++)
        {
            if (ItemShop.itemShop.itemList[i].ItemID == itemID /*&& !ItemShop.itemShop.itemList[i].bought*/ && GameManager.gameManager.CheckMoney(ItemShop.itemShop.itemList[i].ItemPrice) && PersistentDataManager.GetItemAmount(i) < 5)
            {
                //We can buy item if hasnt been bought, have enough $$, and has same ID in the list.

                ItemShop.itemShop.itemList[i].bought = true;
                GameManager.gameManager.SubtractMoney(ItemShop.itemShop.itemList[i].ItemPrice);
                FindObjectOfType <AudioManager>().Play("CashBell");
                UpdateBuyButton();

                //item index = i, thus the save index for persistentdatamanager = i+itemstart;
                PersistentDataManager.PurchaseItem(i);
                ItemShop.itemShop.UpdateItemAmount(i + 1);
            }

            //if they do not have enough gold.
            else if (ItemShop.itemShop.itemList[i].ItemID == itemID && !ItemShop.itemShop.itemList[i].bought && !GameManager.gameManager.CheckMoney(ItemShop.itemShop.itemList[i].ItemPrice))
            {
                NotEnoughGoldWindow.SetActive(true);

                Debug.Log("NO Enough money");
            }

            else if (ItemShop.itemShop.itemList[i].ItemID == itemID && ItemShop.itemShop.itemList[i].bought)
            {
                Debug.Log("Has been bought");
            }
        }
        ItemShop.itemShop.UpdateSprite(itemID);
    }