Example #1
0
    public void CreateVendorList(string search)
    {
        List <Vendor_s> vendors_s = dm.currentCompany.hiredVendors;
        List <Vendor>   vendors   = new List <Vendor>();

        if (vendors_s != null)
        {
            foreach (Vendor_s vendor_s in vendors_s)
            {
                vendors.Add(database.GetVendor(vendor_s.vendorName));
            }
            vendorScrollbar.value = 1;
            foreach (VendorDisplayObject disp in vendorDisplayedObjects)
            {
                Destroy(disp.gameObject);
            }
            vendorDisplayedObjects.Clear();
            if (search != null)
            {
                vendors = SearchVendorList(vendors, search);
            }
            if (!window.searchBar.ignoreFilters)
            {
                vendors = FilterVendorList(vendors);
            }
            vendors = SortVendorList(window.sortMode, vendors);
            RectTransform rectTransform      = vendorContentPanel.GetComponent <RectTransform>();
            float         prefabHeight       = vendorDisplayPrefab.gameObject.GetComponent <RectTransform>().rect.height;
            float         contentPanelHeight = vendors.Count * prefabHeight + (prefabHeight * .5f);
            rectTransform.sizeDelta = new Vector2(vendorContentPanel.rectTransform.sizeDelta.x, contentPanelHeight);
            for (int i = 0; i < vendors.Count; i++)
            {
                VendorDisplayObject vendorDisplayObject = Instantiate(vendorDisplayPrefab);
                int    temp   = i;
                Vendor vendor = vendors[temp];
                vendorDisplayObject.Setup(vendor);
                vendorDisplayObject.viewSelectionButton.onClick.AddListener(() => ViewSelection(vendor));
                vendorDisplayObject.hire_fireButton.onClick.AddListener(() => FireVendor(vendor));
                Text buttonText = vendorDisplayObject.hire_fireButton.GetComponentInChildren <Text>();
                buttonText.text = "Fire Vendor";
                vendorDisplayObject.transform.SetParent(vendorContentPanel.transform.parent, false);
                vendorDisplayObject.gameObject.SetActive(true);
                vendorDisplayObject.GetComponent <Image>().rectTransform.anchoredPosition = new Vector2(0, -prefabHeight * i);
                vendorDisplayedObjects.Add(vendorDisplayObject);
            }
            foreach (VendorDisplayObject obj in vendorDisplayedObjects)
            {
                obj.transform.SetParent(vendorContentPanel.transform);
            }
        }
    }
    public void CreateVendorList()
    {
        DispensaryManager dm        = GameObject.Find("DispensaryManager").GetComponent <DispensaryManager>();
        List <Vendor_s>   vendors_s = dm.currentCompany.hiredVendors;
        List <Vendor>     vendors   = new List <Vendor>();

        if (vendors_s != null)
        {
            foreach (Vendor_s vendor_s in vendors_s)
            {
                vendors.Add(database.GetVendor(vendor_s.vendorName));
            }
            vendorScrollbar.value = 1;
            foreach (VendorDisplayObject disp in vendorDisplayedObjects)
            {
                Destroy(disp.gameObject);
            }
            vendorDisplayedObjects.Clear();
            //vendors = SortList(panel.sortMode, vendors);
            RectTransform rectTransform = vendorContentPanel.GetComponent <RectTransform>();
            //rectTransform.sizeDelta = new Vector2(contentPanel.rectTransform.sizeDelta.x, 0);
            float prefabHeight       = vendorDisplayPrefab.gameObject.GetComponent <RectTransform>().rect.height;
            float contentPanelHeight = vendors.Count * prefabHeight + (prefabHeight * .5f);
            //print("Prefab Height: " + prefabHeight + "\nContent Panel Height(Old): " + contentPanel.rectTransform.sizeDelta.y
            //    + "\nContent Panel Height(New): " + contentPanelHeight + "\nPrefab Height, New: " + displayPrefab.gameObject.GetComponent<RectTransform>().rect.height);
            rectTransform.sizeDelta = new Vector2(vendorContentPanel.rectTransform.sizeDelta.x, contentPanelHeight);
            for (int i = 0; i < vendors.Count; i++)
            {
                Image    vendorDisplayGO  = Instantiate(vendorDisplayPrefab);
                Button[] buttonComponents = vendorDisplayGO.GetComponentsInChildren <Button>();
                Vendor   vendor           = vendors[i];
                buttonComponents[0].onClick.AddListener(() => ViewSelection(vendor));
                buttonComponents[1].onClick.AddListener(() => FireVendor(vendor));
                Text[] textComponents = vendorDisplayGO.GetComponentsInChildren <Text>();
                textComponents[0].text = vendors[i].vendorName;
                vendorDisplayGO.transform.SetParent(vendorContentPanel.transform.parent, false);
                vendorDisplayGO.gameObject.SetActive(true);
                vendorDisplayGO.rectTransform.anchoredPosition = new Vector2(0, -prefabHeight * i);
                VendorDisplayObject vendorDisplayObject = vendorDisplayGO.gameObject.AddComponent <VendorDisplayObject>();
                vendorDisplayedObjects.Add(vendorDisplayObject);
                //newStaffDisplayObject
            }
            foreach (VendorDisplayObject obj in vendorDisplayedObjects)
            {
                obj.transform.SetParent(vendorContentPanel.transform);
            }
        }
    }