public InventoryCard(long credits, Part[] humanParts, Part[] robotParts)
    {
        this.credits                 = credits;
        this.humanParts              = humanParts;
        this.robotParts              = robotParts;
        mode                         = MODES.VIEW_PART_STATS;
        partBeingPreviewed           = null;
        partBeingEquipt              = null;
        currentPartFilter            = DEFAULT_PART_FILTER;
        MASKED_INVENTORY_PART_BUTTON = GameObject.Find("Workshop").transform.Find("MaskedInventoryPartButton").gameObject;
        MASKED_INVENTORY_PART_BUTTON.SetActive(false);
        INVENTORY_SORT = GameObject.Find("InventorySort");
        currentSort    = DEFAULT_SORT;
        PERFORMANCE_METRIC_CALCULATOR = new PerformanceMetricCalculator();
        SCROLL_VIEW = GameObject.Find(INVENTORY_CARD_NAME);
        GameObject partsContainerGameObject = GameObject.Find(PARTS_CONTAINER_NAME);

        PARTS_CONTAINER  = partsContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT      = SCROLL_VIEW.GetComponent <ScrollRect>();
        PARTS_PANEL      = GameObject.Find(PARTS_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR_OBJECT = GameObject.Find(INVENTORY_CARD_NAME).transform.Find(INVENTORY_SCROLLBAR_NAME).gameObject;
        SCROLLBAR        = SCROLLBAR_OBJECT.GetComponent <Scrollbar>();
        SCROLLBAR_OBJECT.SetActive(false);
        SCROLL_RECT.vertical = false;
        partButtons          = new List <GameObject>();
        partInfo             = GameObject.Find("Workshop").transform.Find(PART_INFO_NAME).gameObject;
        partType             = partInfo.transform.Find(PART_TYPE_NAME).gameObject;
        durabilityBar        = partInfo.transform.Find(DURABILITY_BAR_NAME).gameObject;
        durabilityBarLabel   = partInfo.transform.Find(DURABILITY_BAR_LABEL_NAME).gameObject;
        partStats            = partInfo.transform.Find(PART_STATS_NAME).gameObject;
        partInfo.SetActive(false);
        partStatsList = new List <GameObject>();
        initialize();
        PART_TABS = new List <GameObject>();
        foreach (Transform childTransform in GameObject.Find("InventoryTabs").transform.Find("InventoryTabMask"))
        {
            if (childTransform.gameObject.name.Contains(PART_TAB_SUFFIX))
            {
                PART_TABS.Add(childTransform.gameObject);
            }
        }
        updateSorting();
    }
 public void exitPartPreview()
 {
     mode = MODES.VIEW_PART_STATS;
     partBeingPreviewed = null;
     MASKED_INVENTORY_PART_BUTTON.SetActive(false);
 }
 public void update(long credits, Part[] humanParts, Part[] robotParts)
 {
     this.credits = credits;
     if (this.humanParts.Length != humanParts.Length || this.robotParts.Length != robotParts.Length)
     {
         this.humanParts = humanParts;
         this.robotParts = robotParts;
         initialize();
     }
     if (base.enabled)
     {
         if (Input.GetMouseButton(0) && mode == MODES.PREVIEW_PART)
         {
             mode = MODES.VIEW_PART_STATS;
             partBeingPreviewed = null;
             partBeingEquipt    = null;
             MASKED_INVENTORY_PART_BUTTON.SetActive(false);
         }
         if ((PARTS_PANEL.offsetMax.y - PARTS_PANEL.offsetMin.y) > (PARTS_CONTAINER.offsetMax.y - PARTS_CONTAINER.offsetMin.y))
         {
             SCROLLBAR_OBJECT.SetActive(true);
             SCROLL_RECT.vertical = true;
         }
         else
         {
             SCROLLBAR_OBJECT.SetActive(false);
             SCROLL_RECT.vertical = false;
         }
         for (int partButtonIndex = 0; partButtonIndex < partButtons.Count; ++partButtonIndex)
         {
             ButtonListener buttonListener = partButtons[partButtonIndex].GetComponent <ButtonListener>();
             if ((buttonListener.isClicked() || buttonListener.isControlClicked()) && mode != MODES.PREVIEW_PART)
             {
                 bool ignoreClick = false;
                 foreach (Part part in robotParts)
                 {
                     if (humanParts[partButtonIndex].getID() == part.getID())
                     {
                         ignoreClick = true;
                         break;
                     }
                 }
                 if (!ignoreClick)
                 {
                     if (buttonListener.isClicked())
                     {
                         mode = MODES.PREVIEW_PART;
                         partInfo.SetActive(false);
                         partBeingPreviewed = humanParts[partButtonIndex];
                         Texture2D partIcon = humanParts[partButtonIndex].getIcon();
                         MASKED_INVENTORY_PART_BUTTON.transform.Find("Icon").gameObject.GetComponent <UnityEngine.UI.Image>().sprite = Sprite.Create(partIcon, new Rect(0, 0, partIcon.width, partIcon.height), new Vector2(0.5f, 0.5f), 100);
                         MASKED_INVENTORY_PART_BUTTON.GetComponent <RectTransform>().localScale = Vector3.one;
                         MASKED_INVENTORY_PART_BUTTON.transform.position = partButtons[partButtonIndex].transform.position;
                         MASKED_INVENTORY_PART_BUTTON.SetActive(true);
                     }
                     else if (buttonListener.isControlClicked())
                     {
                         mode            = MODES.EQUIPT_PART;
                         partBeingEquipt = humanParts[partButtonIndex];
                     }
                     buttonListener.resetClick();
                     break;
                 }
                 buttonListener.resetClick();
             }
             if (buttonListener.isMouseOver() && mode != MODES.PREVIEW_PART)
             {
                 Part robotPart = null;
                 foreach (Part part in robotParts)
                 {
                     if (part.GetType() == humanParts[partButtonIndex].GetType())
                     {
                         robotPart = part;
                         break;
                     }
                 }
                 float positionY = Input.mousePosition.y / (UnityEngine.Screen.height) * GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>().sizeDelta.y - partInfo.GetComponent <RectTransform>().sizeDelta.y * 2;
                 positionY = Mathf.Clamp(positionY, -partInfo.GetComponent <RectTransform>().sizeDelta.y * 2, GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>().sizeDelta.y - partInfo.GetComponent <RectTransform>().sizeDelta.y * 2);
                 partInfo.transform.localPosition = new Vector3(partInfo.transform.localPosition.x, positionY, partInfo.transform.localPosition.z);
                 partType.GetComponent <TextMeshProUGUI>().text = humanParts[partButtonIndex].GetType().ToString();
                 double[] differenceInStats = (robotPart != null ? robotPart.compareTo(humanParts[partButtonIndex]) : new double[0]);
                 durabilityBar.GetComponent <RectTransform>().localScale  = new Vector3((humanParts[partButtonIndex].getDurability() > 0 ? (float)(humanParts[partButtonIndex].getRemainingDurability() / humanParts[partButtonIndex].getDurability()) : 0), durabilityBar.GetComponent <RectTransform>().localScale.y, 0);
                 durabilityBarLabel.GetComponent <TextMeshProUGUI>().text = ConfigurationCard.DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(humanParts[partButtonIndex].getRemainingDurability()) + " / " + StringTools.formatString(humanParts[partButtonIndex].getDurability()) + (differenceInStats != null && differenceInStats.Length > 0 ? " (" + applyStatDifferenceFormatting(differenceInStats[0], false) + " / " + applyStatDifferenceFormatting(differenceInStats[1], false) + ")" : "");
                 foreach (GameObject partStat in partStatsList)
                 {
                     GameObject.Destroy(partStat);
                 }
                 partStatsList.Clear();
                 string[] partStatStrings = humanParts[partButtonIndex].getStatStrings();
                 for (int partStatIndex = 0; partStatIndex < partStatStrings.Length; ++partStatIndex)
                 {
                     GameObject partStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                     string     differenceInStatString = "";
                     int        differenceInStatsIndex = partStatIndex + 2;
                     if (!(humanParts[partButtonIndex] is Attachment))
                     {
                         differenceInStatString = applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], differenceInStatsIndex == 2);
                     }
                     else if (differenceInStats != null && differenceInStats.Length > 0)
                     {
                         if (differenceInStatsIndex == 3 || (differenceInStatsIndex >= 8 && differenceInStatsIndex < 11))
                         {
                             differenceInStatsIndex = -1;
                         }
                         else if (differenceInStatsIndex > 3 && differenceInStatsIndex < 8)
                         {
                             differenceInStatsIndex -= 1;
                         }
                         else if (differenceInStatsIndex == 11)
                         {
                             differenceInStatsIndex -= 4;
                         }
                         if (differenceInStatsIndex != -1)
                         {
                             if (differenceInStatsIndex >= 3 && differenceInStatsIndex <= 6)
                             {
                                 differenceInStats[differenceInStatsIndex] /= 1000;
                             }
                             differenceInStatString = applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], differenceInStatsIndex == 2 || differenceInStatsIndex == 3 || differenceInStatsIndex == 4 || differenceInStatsIndex == 6);
                         }
                     }
                     partStat.GetComponent <TextMeshProUGUI>().text = partStatStrings[partStatIndex] + (differenceInStatString != "" ? " (" + differenceInStatString + ")" : "");
                     partStat.transform.SetParent(partStats.GetComponent <RectTransform>());
                     partStat.transform.localPosition = new Vector3(partStat.transform.localPosition.x, partStat.transform.localPosition.y, 0);
                     partStatsList.Add(partStat);
                 }
                 partInfo.SetActive(true);
                 break;
             }
             else
             {
                 partInfo.SetActive(false);
             }
         }
         bool switchTabs = false;
         foreach (GameObject tab in PART_TABS)
         {
             if (tab.GetComponent <ButtonListener>().isClicked() && currentPartFilter != tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text)
             {
                 switchTabs = true;
                 filterParts(tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text);
                 updateSorting();
                 break;
             }
             else
             {
                 tab.GetComponent <ButtonListener>().resetClick();
             }
         }
         if (switchTabs)
         {
             foreach (GameObject tab in PART_TABS)
             {
                 if (tab.GetComponent <ButtonListener>().isClicked())
                 {
                     tab.GetComponent <ButtonListener>().resetClick();
                     tab.GetComponent <UnityEngine.UI.Image>().color = ACTIVE_TAB_COLOR;
                 }
                 else
                 {
                     tab.GetComponent <UnityEngine.UI.Image>().color = INACTIVE_TAB_COLOR;
                 }
             }
         }
         if (currentSort != INVENTORY_SORT.GetComponent <TMP_Dropdown>().value)
         {
             currentSort = INVENTORY_SORT.GetComponent <TMP_Dropdown>().value;
             applySorting();
         }
     }
 }