Beispiel #1
0
    private void FillPlayerInventoryPanel()
    {
        //Get the player's inventory
        UIControllerScript uic            = otherCanvas.GetComponent <UIControllerScript>();
        List <Placeable>   inventoryData  = uic.getInventoryData();
        List <int>         inventoryCount = uic.getInventoryCount();

        //Get the panel to add to
        RectTransform pip = GameObject.Find("playerInventoryPanel").GetComponent <RectTransform>();

        for (int ii = 0; ii < fpc.inventorySize; ii++)
        {
            //Add item to player inventory rect
            //Build the slot regardless of whether or not it will be empty
            GameObject slotObject = Instantiate(playerInventorySlotPrefab, pip);
            MenuSlot   slot       = slotObject.GetComponent <MenuSlot>();
            slot.slotIndex = ii;

            //Add an item to the slot if it shouldn't be empty
            if (inventoryData[ii] != null && inventoryCount[ii] > 0)
            {
                //Add the slot item to the slot
                GameObject   itemObject = Instantiate(slotItemPrefab, slot.GetComponent <RectTransform>());
                MenuSlotItem item       = itemObject.GetComponent <MenuSlotItem>();
                item.setID(inventoryData[ii].id, inventoryData[ii].isFlower);
                item.setCount(inventoryCount[ii]);

                slot.GetComponent <MenuSlot>().setItem(item);
            }
        }
    }
Beispiel #2
0
    private void postSetDecorationsTab()
    {
        Transform grid     = currentPageObject.transform.Find("decorationInventoryHolder");
        Canvas    myCanvas = transform.GetComponentInParent <Canvas>();

        GetComponent <RectTransform>().ForceUpdateRectTransforms();

        float rectWidth  = grid.GetComponent <RectTransform>().rect.width *myCanvas.scaleFactor * .5f;
        float rectHeight = grid.GetComponent <RectTransform>().rect.height *myCanvas.scaleFactor * .5f;

        rectHeight = Mathf.Min(rectWidth * .75f, rectHeight);

        List <GameObject> slotList = new List <GameObject>();

        for (int ii = 0; ii < 4; ii += 1)
        {
            uint itemID = (uint)decorationTabIDs[decorationTab, ii];

            //GetComponent<RectTransform>().ForceUpdateRectTransforms();
            GameObject seller = Instantiate(decorationPurchasePrefab, grid);

            GameObject slot = Instantiate(homeInventorySlotPrefab, seller.GetComponent <RectTransform>());
            slotList.Add(slot);

            Text priceText = seller.GetComponentInChildren <Text>();
            slot.transform.SetAsFirstSibling();
            slot.GetComponent <MenuSlot>().slotIndex = 0;
            slot.GetComponent <MenuSlot>().type      = MenuSlot.SlotType.DecorationSlot;
            GameObject   item       = Instantiate(slotItemPrefab, slot.GetComponent <RectTransform>());
            MenuSlotItem itemObject = item.GetComponent <MenuSlotItem>();
            itemObject.setID(itemID, false);
            itemObject.setCount(getHomeInventoryCount(itemID, false));

            slot.GetComponent <MenuSlot>().setItemNoSort(itemObject);
            slot.GetComponent <MenuSlot>().getItem().updateModelScale(rectWidth * .5f, rectHeight);

            GameObject buyButtom = seller.transform.GetComponentInChildren <UnityEngine.UI.Button>().gameObject;

            priceText.text = "PRICE: " + decorationValue[(uint)decorationTabIDs[decorationTab, ii]];
            buyButtom.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(delegate { purchaseDecoration(itemID, slot.GetComponent <MenuSlot>()); });
            buyButtom.GetComponentInChildren <Text>().text = "BUY";
        }

        GameObject priceBreakdownButton = GameObject.Find("priceBreakdownButton");

        priceBreakdownButton.GetComponentInChildren <Text>().text = sellAllPrefix;
        grid.GetComponent <GridLayoutGroup>().cellSize            = new Vector2(rectWidth, rectHeight);

        //LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
        GetComponent <RectTransform>().ForceUpdateRectTransforms();
        updatePriceBreakdownButton(false);
        //Set up the sell display slot
        updateFlowerDisplaySlot(null);
    }
Beispiel #3
0
 private void purchaseDecoration(uint id, MenuSlot item)
 {
     if (grabbedSlot == null)
     {
         if (fpc.money >= decorationValue[(uint)id])
         {
             if (!homeDecorationsBought.ContainsKey(id))
             {
                 homeDecorationsBought.Add(id, 0);
             }
             homeDecorationsBought[id] += 1;
             fpc.money -= decorationValue[(uint)id];
             updateMoneyText();
             bool      pushedToInventory    = false;
             Transform playerInventoryPanel = GameObject.Find("playerInventoryPanel").transform;
             for (int i = 0; i < 10 && pushedToInventory == false; i++)
             {
                 if (playerInventoryPanel.GetChild(i).childCount != 0)
                 {
                     MenuSlotItem msi = playerInventoryPanel.GetChild(i).GetChild(0).GetComponent <MenuSlotItem>();
                     if (msi.isFlower == false && msi.id == id)
                     {
                         msi.setCount(msi.count + 1);
                         pushedToInventory = true;
                     }
                 }
             }
             if (!pushedToInventory)
             {
                 item.setCount(item.getCount() + 1);
                 addHomeInventoryItem(id, 1, false);
             }
             for (int i = 0; i < 10 && pushedToInventory == false; i++)
             {
                 if (playerInventoryPanel.GetChild(i).childCount == 0)
                 {
                     item.releaseItem(playerInventoryPanel.GetChild(i).GetComponent <MenuSlot>());
                     pushedToInventory = true;
                 }
             }
         }
     }
 }
Beispiel #4
0
    private void postSetFlowersTab()
    {
        //Fill in the display inventory
        if (searchMask != 0)
        {
            displayInventory = new Dictionary <uint, int>();

            for (int ii = 0; ii < homeFlowerInventory.Keys.Count; ii++)
            {
                if (shouldDisplayFlower(homeFlowerInventory.Keys.ElementAt(ii)))
                {
                    displayInventory.Add(homeFlowerInventory.Keys.ElementAt(ii), homeFlowerInventory.Values.ElementAt(ii));
                }
            }
        }
        else
        {
            displayInventory = homeFlowerInventory;
        }

        //Just add some slots and things
        GameObject flowerGridObject = GameObject.Find("flowerGrid");
        Transform  grid             = flowerGridObject.transform;

        //Figure out how many flowers to put on each page
        Canvas myCanvas   = transform.GetComponentInParent <Canvas>();
        float  rectWidth  = grid.GetComponent <RectTransform>().rect.width *myCanvas.scaleFactor;
        float  rectHeight = grid.GetComponent <RectTransform>().rect.height *myCanvas.scaleFactor;

        Debug.Log(rectWidth + "," + rectHeight + "  with a scale factor of " + myCanvas.scaleFactor);
        int gridWidth  = (int)Mathf.Floor(rectWidth / slotSize);
        int gridHeight = (int)Mathf.Floor(rectHeight / slotSize);

        flowersPerPage = (gridHeight * gridWidth) - 1;

        //Add an empty slot
        //Fill the screen with flowers and slots
        int startPosition = flowersPerPage * currentFlowerPage;

        Debug.Log("start position is: " + startPosition);

        //Loop and fill the page with the right flowers
        for (int ii = startPosition; ii <= Mathf.Min(startPosition + flowersPerPage - 1, displayInventory.Count - 1); ii += 1)
        {
            uint flowerID = displayInventory.Keys.ElementAt(ii);
            int  count    = displayInventory.Values.ElementAt(ii);

            if (shouldDisplayFlower(flowerID))
            {
                GameObject slot = Instantiate(homeInventorySlotPrefab, grid);
                slot.GetComponent <MenuSlot>().slotIndex = ii;
                GameObject   item       = Instantiate(slotItemPrefab, slot.GetComponent <RectTransform>());
                MenuSlotItem itemObject = item.GetComponent <MenuSlotItem>();
                itemObject.setID(flowerID, true);
                itemObject.setCount(count);

                slot.GetComponent <MenuSlot>().setItem(itemObject);
                homeFlowerSlots.Add(slot);
            }
        }

        //If there are more flowersPerPage than flowers in the home inventory then...
        //fill in the rest of the screen with blank slots
        int ss = homeFlowerSlots.Count; //this is just for setting indexes

        while (homeFlowerSlots.Count <= flowersPerPage)
        {
            GameObject slot = Instantiate(homeInventorySlotPrefab, grid);
            slot.GetComponent <MenuSlot>().slotIndex = ss;
            homeFlowerSlots.Add(slot);
            ss += 1;
        }

        setPageCountText();
        updatePriceBreakdownButton(true);
        //Set up the sell display slot
        updateFlowerDisplaySlot(null);
    }