Exemple #1
0
 public void ExpandCategory(CategoryDisplayObject displayObjectExpanded, float containerSize, bool instant)
 {
     if (currentActiveList != null)
     {
         bool moveDown = false;
         foreach (CategoryDisplayObject obj in currentActiveList.categoriesDisplayed)
         {
             if (!moveDown)
             {
                 if (obj.categoryReference.category == displayObjectExpanded.categoryReference.category)
                 {
                     moveDown = true;
                 }
             }
             else
             {
                 obj.MoveDown(containerSize, instant);
                 //obj.GetComponent<RectTransform>().anchoredPosition -= new Vector2(0, containerSize);
             }
         }
     }
 }
 public void SetupButton(CategoryDisplayObject parentObject_)
 {
     parentObject = parentObject_;
     parentItem   = null;
 }
Exemple #3
0
    public List <CategoryDisplayObject> CreateProductCategoriesList(Inventory.ProductCategoryVisibleData visibleData)
    {
        scrollbar.value = 1;
        List <CategoryDisplayObject>   newList    = new List <CategoryDisplayObject>();
        List <Product.ProductCategory> categories = Product.GetProductCategories();
        int     counter = 0;
        Vector2 previousContentPanelSize = Vector2.zero;
        Vector2 previousPos = Vector2.zero;
        float   previousCategoryObjectHeight = 0;

        foreach (Product.ProductCategory category in categories)
        {
            List <Product.type_> categoryTypes = Product.GetProductsInCategory(category);
            Inventory.ProductCategoryVisibleData.Category categoryData = visibleData.GetCategory(category);

            // Create category panel
            CategoryDisplayObject categoryDisplayObject = Instantiate(categoryPrefab);
            categoryDisplayObject.categoryReference = categoryData;
            categoryDisplayObject.parentPanel       = inventoryUIPanel;
            categoryDisplayObject.gameObject.SetActive(true);
            categoryDisplayObject.transform.SetParent(contentPanel.transform.parent, false);
            categoryDisplayObject.titlePanel.SetText(category.ToString());
            categoryDisplayObject.SetVisibility(categoryData.visibleState, true);

            // Size new panel
            float         titlePanelHeight       = categoryDisplayObject.titlePanel.mainImage.rectTransform.rect.height;
            float         titlePanelWidth        = categoryDisplayObject.titlePanel.mainImage.rectTransform.rect.width;
            float         subItemHeight          = categoryItemPrefab.GetComponent <Image>().rectTransform.rect.height;
            RectTransform containerRectTransform = categoryDisplayObject.containerPanel.rectTransform;
            Vector2       newContainerSize       = new Vector2(titlePanelWidth, subItemHeight * categoryTypes.Count);
            categoryDisplayObject.containerPanel.rectTransform.sizeDelta = newContainerSize;
            categoryDisplayObject.maskImage.rectTransform.sizeDelta      = newContainerSize;
            Vector2 newContainerPos = new Vector2(0, -newContainerSize.y / 2);
            categoryDisplayObject.containerPanel.rectTransform.anchoredPosition = newContainerPos;
            categoryDisplayObject.maskImage.rectTransform.anchoredPosition      = newContainerPos;
            Vector2 newCategoryObjectPos = new Vector2(previousPos.x, previousPos.y - previousCategoryObjectHeight);
            if (previousContentPanelSize == Vector2.zero)
            {
                newCategoryObjectPos = Vector2.zero;
            }
            categoryDisplayObject.GetComponent <RectTransform>().anchoredPosition = newCategoryObjectPos;
            newList.Add(categoryDisplayObject);

            //Setup previous info
            previousPos = newCategoryObjectPos;
            previousCategoryObjectHeight = (titlePanelHeight + newContainerSize.y);

            // Resize content panel
            if (previousContentPanelSize == Vector2.zero)
            {
                contentPanel.rectTransform.sizeDelta = new Vector2(titlePanelWidth, previousCategoryObjectHeight);
            }
            else
            {
                contentPanel.rectTransform.sizeDelta = new Vector2(previousContentPanelSize.x, previousContentPanelSize.y + previousCategoryObjectHeight);
            }
            previousContentPanelSize = contentPanel.rectTransform.sizeDelta;


            // Create sub panels
            for (int i = 0; i < categoryTypes.Count; i++)
            {
                Product.type_ type = categoryTypes[i];
                Inventory.ProductCategoryVisibleData.CategorySubType subData = visibleData.GetSubType(type);

                // Create product types inside category panel
                CategoryDisplayItem categoryDisplayItem = Instantiate(categoryItemPrefab);
                categoryDisplayItem.categorySubTypeReference = subData;
                categoryDisplayItem.parentDisplayObject      = categoryDisplayObject;
                categoryDisplayItem.textString = Product.ProductTypeToString(type, true);
                categoryDisplayItem.gameObject.SetActive(true);
                categoryDisplayItem.transform.SetParent(categoryDisplayObject.maskImage.transform, false);
                categoryDisplayItem.typeText.text = categoryDisplayItem.textString;
                categoryDisplayItem.SetVisibility(subData.visibleState, false);

                RectTransform categoryDisplayItemRectTransform = categoryDisplayItem.GetComponent <RectTransform>();
                Vector2       newPos = new Vector2(0, (-i * subItemHeight) - subItemHeight / 2);
                categoryDisplayItemRectTransform.anchoredPosition = newPos;
                categoryDisplayObject.displayedItems.Add(categoryDisplayItem);
                categoryDisplayItem.transform.SetParent(categoryDisplayObject.maskImage.transform, true);
                categoryDisplayItemRectTransform.sizeDelta = new Vector2(titlePanelWidth, subItemHeight);
            }

            if (categoryData.collapsed)
            {
                //categoryDisplayObject.Collapse();
                //previousContentPanelSize = new Vector2(titlePanelWidth, titlePanelHeight);
            }
            // Increase category object counter
            counter++;
        }
        foreach (CategoryDisplayObject obj in newList)
        {
            obj.transform.SetParent(contentPanel.transform, true);
        }
        return(newList);
    }