Example #1
0
 public void OnSubModelClick(StoreObjectReference reference)
 {
     if (reference.subID != storeObject.subID)
     {
         StoreObject obj = objectSelectionPanel.selectedObject;
         objectSelectionPanel.actionManager.StartNewAction(obj, reference.subID, reference.price);
     }
     else
     {
         ActionManager.DispensaryAction       currentAction = objectSelectionPanel.actionManager.currentAction;
         ActionManager.ChangeStoreObjectModel changeStoreObjectModelAction = (ActionManager.ChangeStoreObjectModel)currentAction;
         if (changeStoreObjectModelAction != null)
         {
             if (!changeStoreObjectModelAction.OriginalActive())
             {
                 objectSelectionPanel.actionManager.CancelAction(true);
             }
         }
     }
     CreateModelsList();
 }
Example #2
0
    public void CreateModelsList() // panel 1
    {
        foreach (Image img in currentModelsList)
        {
            Destroy(img.gameObject);
        }
        currentModelsList.Clear();
        List <StoreObjectReference> siblingModels = new List <StoreObjectReference>();
        int  ID              = storeObject.objectID;
        int  subID           = 0;
        int  originalSubID   = storeObject.subID;
        bool gettingSiblings = true;

        while (gettingSiblings)
        {
            StoreObjectReference newReference = storeObject.dm.database.GetStoreObject(ID, subID);
            if (newReference != null)
            {
                siblingModels.Add(newReference);
            }
            else
            {
                gettingSiblings = false;
                break;
            }
            subID++;
        }
        RectTransform rectTransform      = panel1Content.GetComponent <RectTransform>();
        float         prefabHeight       = subModelPrefab.gameObject.GetComponent <RectTransform>().rect.height;
        float         contentPanelHeight = siblingModels.Count * prefabHeight;

        rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, contentPanelHeight);
        for (int i = 0; i < siblingModels.Count; i++)
        {
            StoreObjectReference reference = siblingModels[i];
            int     quantity      = storeObject.modifierHandler.GetAddonsModifier().inventory.GetQuantityOwned(reference.objectID, reference.subID);
            Image   newSubModelGO = Instantiate(subModelPrefab);
            Image[] imgComponents = newSubModelGO.GetComponentsInChildren <Image>();
            imgComponents[1].sprite = reference.objectScreenshot;
            Button[] buttonComponents = newSubModelGO.GetComponentsInChildren <Button>();
            buttonComponents[0].onClick.AddListener(() => OnSubModelClick(reference));
            Text[] textComponents = newSubModelGO.GetComponentsInChildren <Text>();
            textComponents[0].text = reference.ToString();
            string quantityText = string.Empty;
            ActionManager.DispensaryAction currentAction = objectSelectionPanel.actionManager.currentAction;
            if (currentAction != null)
            {
                if (currentAction.GetType() == ActionManager.ActionType.changeStoreObject)
                {
                    ActionManager.ChangeStoreObjectModel action = (ActionManager.ChangeStoreObjectModel)objectSelectionPanel.actionManager.currentAction;
                    StoreObject originalStoreObject             = action.originalStoreObject;
                    StoreObject newStoreObject = action.newStoreObject;
                    if (reference.subID == originalStoreObject.subID)
                    {
                        quantityText = "Current Model";
                    }
                    else if (reference.subID == newStoreObject.subID)
                    {
                        quantityText = "Currently Previewing";
                    }
                    else
                    {
                        quantityText = quantity.ToString() + " Owned";
                    }
                }
                else
                {
                    print("unknown error - ModifierPanel.cs : CreateModelsList()");
                }
            }
            else
            {
                if (reference.subID == originalSubID)
                {
                    quantityText = "Current Model";
                }
                else
                {
                    quantityText = quantity.ToString() + " Owned";
                }
            }
            textComponents[1].text = quantityText;
            textComponents[2].text = "$" + reference.price.ToString();
            newSubModelGO.transform.SetParent(panel1Content.transform.parent, false);
            newSubModelGO.gameObject.SetActive(true);
            newSubModelGO.rectTransform.anchoredPosition = new Vector2(0, -prefabHeight * i);
            currentModelsList.Add(newSubModelGO);
            newSubModelGO.transform.SetParent(panel1Content.transform);

            // Event Triggers
            float        yPos    = newSubModelGO.transform.position.y;
            EventTrigger trigger = imgComponents[1].GetComponent <EventTrigger>();
            SetupMouseEnterScreenshotTrigger(trigger, reference, yPos);
            SetupMouseExitScreenshotTrigger(trigger);
        }
    }