Beispiel #1
0
    public BoxProductReturnResults BoxPackagedProduct(Order.Order_Product productOrder)
    {
        int singleWeight       = productOrder.GetProduct().boxWeight;
        int productOrderWeight = productOrder.GetQuantity() * singleWeight;
        Box currentBox         = CreateBox(productOrderWeight);

        Box.PackagedProduct newPackagedProduct = new Box.PackagedProduct(currentBox, productOrder.GetProduct(), productOrder.GetQuantity());
        //currentBox.AddProduct(newPackagedProduct);
        float randomRed   = UnityEngine.Random.value;
        float randomGreen = UnityEngine.Random.value;
        float randomBlue  = UnityEngine.Random.value;

        if (productOrderWeight > currentBox.maxWeight)
        {
            int difference = currentBox.maxWeight - productOrderWeight;
            int val        = difference / singleWeight;
            val = Mathf.Abs(val);

            Order.Order_Product leftoverOrder = new Order.Order_Product(val, newPackagedProduct.productReference);
            newPackagedProduct.quantity -= val;
            currentBox.AddProduct(newPackagedProduct);
            return(new BoxProductReturnResults(currentBox, leftoverOrder));
        }
        else
        {
            currentBox.AddProduct(newPackagedProduct);
            return(new BoxProductReturnResults(currentBox, null));
        }
    }
 public void DisplayProduct(Order.Order_Product productOrder)
 {
     displayType       = DisplayType.Product;
     displayedBud      = null;
     displayedProduct  = productOrder;
     itemNameText.text = productOrder.GetProduct().productName;
     quantityText.text = productOrder.GetQuantity().ToString();
 }
Beispiel #3
0
 public void CreateOrderFormList()
 {
     if (currentOrder != null)
     {
         if (currentOrder.productList != null || currentOrder.budList != null)
         {
             orderFormScrollbar.value = 1;
             foreach (OrderFormDisplayObject disp in orderFormDisplayedObjects)
             {
                 Destroy(disp.gameObject);
             }
             orderFormDisplayedObjects.Clear();
             //staff = SortList(panel.sortMode, staff);
             RectTransform rectTransform      = orderFormContentPanel.GetComponent <RectTransform>();
             float         prefabHeight       = orderFormPrefab.gameObject.GetComponent <RectTransform>().rect.height;
             float         contentPanelHeight = (currentOrder.productList.Count + currentOrder.budList.Count) * prefabHeight + (prefabHeight * .5f);
             rectTransform.sizeDelta = new Vector2(orderFormContentPanel.rectTransform.sizeDelta.x, contentPanelHeight);
             int productCounter = 0;
             int budCounter     = 0;
             for (int i = 0; i < (currentOrder.productList.Count + currentOrder.budList.Count); i++)
             {
                 Image newItem = null;
                 bool  product = false; // true if product, false if bud (this iteration)
                 if (currentOrder.productList != null && productCounter < currentOrder.productList.Count)
                 {
                     newItem = Instantiate(orderFormPrefab);
                     product = true;
                 }
                 else if (currentOrder.budList != null && budCounter < currentOrder.budList.Count)
                 {
                     newItem = Instantiate(orderFormPrefab);
                     product = false;
                 }
                 Text[]   textComponents   = newItem.GetComponentsInChildren <Text>();
                 Button[] buttonComponents = newItem.GetComponentsInChildren <Button>();
                 OrderFormDisplayObject newOrderFormDisplayObject = newItem.gameObject.GetComponent <OrderFormDisplayObject>();
                 if (product)
                 {
                     int temp = productCounter;
                     Order.Order_Product productOrder = currentOrder.productList[temp];
                     newOrderFormDisplayObject.product = productOrder;
                     textComponents[0].text            = productOrder.GetProduct().productName;
                     textComponents[1].text            = "$0";
                     StoreObjectReference reference = productOrder.GetProduct();
                     buttonComponents[0].onClick.AddListener(() => DecreaseQuantity(reference));
                     buttonComponents[1].onClick.AddListener(() => IncreaseQuantity(reference));
                     newOrderFormDisplayObject.product = productOrder;
                     newOrderFormDisplayObject.SetQuantity(productOrder.GetQuantity().ToString());
                     productCounter++;
                 }
                 else
                 {
                     int             temp     = budCounter;
                     Order.Order_Bud budOrder = currentOrder.budList[temp];
                     textComponents[0].text = budOrder.GetStrain().name;
                     textComponents[1].text = "$0";
                     Strain reference = budOrder.GetStrain();
                     buttonComponents[0].onClick.AddListener(() => DecreaseQuantity(reference));
                     buttonComponents[1].onClick.AddListener(() => IncreaseQuantity(reference));
                     newOrderFormDisplayObject.bud = budOrder;
                     newOrderFormDisplayObject.SetQuantity(budOrder.GetWeight().ToString());
                     budCounter++;
                 }
                 newOrderFormDisplayObject.SetQuantity(quantityMode);
                 newItem.transform.SetParent(orderFormContentPanel.transform.parent, false);
                 newItem.gameObject.SetActive(true);
                 newItem.rectTransform.anchoredPosition = new Vector2(0, -prefabHeight * i);
                 orderFormDisplayedObjects.Add(newOrderFormDisplayObject);
             }
             foreach (OrderFormDisplayObject obj in orderFormDisplayedObjects)
             {
                 obj.transform.SetParent(orderFormContentPanel.transform);
             }
         }
     }
 }