コード例 #1
0
    public ConfigurationCard(string robotName, long credits, double durability, double remainingDurability, string[] robotStatStrings, bool maxForceExceeded, Part[] parts, Color colorScheme, bool enableCreditsSpentAnimation)
    {
        this.robotName           = robotName;
        this.credits             = credits;
        this.durability          = durability;
        this.remainingDurability = remainingDurability;
        this.robotStatStrings    = robotStatStrings;
        this.maxForceExceeded    = maxForceExceeded;
        this.parts       = new List <Part>();
        attachments      = new List <Attachment>();
        this.colorScheme = colorScheme;
        this.enableCreditsSpentAnimation = enableCreditsSpentAnimation;
        foreach (Part part in parts)
        {
            if (!(part is Attachment))
            {
                this.parts.Add(part);
            }
            else
            {
                this.attachments.Add((Attachment)part);
            }
        }
        mode = InventoryCard.MODES.VIEW_PART_STATS;
        MASKED_ROBOT_WIDGET = GameObject.Find("Workshop").transform.Find("MaskedRobotWidget").gameObject;
        MASKED_ROBOT_WIDGET.SetActive(false);
        partBeingPreviewed            = null;
        partToEquipt                  = null;
        PERFORMANCE_METRIC_CALCULATOR = new PerformanceMetricCalculator();
        SCROLL_VIEW = GameObject.Find(CONFIGURATION_CARD_NAME);
        GameObject partsContainerGameObject = GameObject.Find(WIDGETS_CONTAINER_NAME);

        WIDGETS_CONTAINER = partsContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT       = SCROLL_VIEW.GetComponent <ScrollRect>();
        WIDGETS_PANEL     = GameObject.Find(WIDGETS_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR_OBJECT  = GameObject.Find(WIDGETS_CARD_NAME).transform.Find(CONFIGURATION_SCROLLBAR_NAME).gameObject;
        SCROLLBAR         = SCROLLBAR_OBJECT.GetComponent <Scrollbar>();
        SCROLLBAR_OBJECT.SetActive(false);
        SCROLL_RECT.vertical        = false;
        robotWidget                 = GameObject.Find(CONFIGURATION_CARD_NAME).transform.Find(ROBOT_WIDGET_NAME).gameObject;
        robotWidgetLabel            = robotWidget.transform.Find(ROBOT_WIDGET_LABEL_NAME).gameObject;
        robotWidgetLabelPlaceholder = robotWidgetLabel.transform.Find("Text Area").Find(ROBOT_WIDGET_LABEL_PLACEHOLDER_NAME).gameObject;
        robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().enabled = false;
        robotWidgetLabelText          = robotWidgetLabel.transform.Find("Text Area").Find(ROBOT_WIDGET_LABEL_TEXT_NAME).gameObject;
        robotWidgetDurabilityBar      = robotWidget.transform.Find(ROBOT_WIDGET_DURABILITY_BAR_NAME).gameObject;
        robotWidgetDurabilityBarLabel = robotWidget.transform.Find(ROBOT_WIDGET_DURABILITY_BAR_LABEL_NAME).gameObject;
        robotWidgetStats = robotWidget.transform.Find(ROBOT_WIDGET_STATS_NAME).gameObject;
        WORKSHOP_CREDIT  = GameObject.Find("WorkshopCredit");
        updateCredits();
        WORKSHOP_CREDITS_SPENT = GameObject.Find("Workshop").transform.Find("WorkshopCreditsSpent").gameObject;
        WORKSHOP_CREDITS_SPENT_HOME_POSITION = WORKSHOP_CREDITS_SPENT.transform.localPosition;
        WORKSHOP_CREDITS_SPENT.SetActive(false);
        WORKSHOP_CREDIT.GetComponent <TextMeshProUGUI>().color = colorScheme;
        initialize();
    }
コード例 #2
0
    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();
    }
コード例 #3
0
    public MyRobotsCard(Robot[] myRobots, Part[] humanRobotParts, long credits, Color colorScheme)
    {
        this.myRobots = new List <Robot>();
        this.myRobots.AddRange(myRobots);
        this.humanRobotParts = new List <Part>();
        this.humanRobotParts.AddRange(humanRobotParts);
        this.credits                 = credits;
        this.colorScheme             = colorScheme;
        robotBeingPreviewed          = null;
        robotBeingPicked             = null;
        robotsToRemove               = new List <Robot>();
        selectedRobotIndicesToRemove = new List <int>();
        newRobot       = null;
        mode           = MODES.VIEW_MY_ROBOTS_STATS;
        MY_ROBOTS_SORT = GameObject.Find("MyRobotsSort");
        currentSort    = DEFAULT_SORT;
        SCROLL_VIEW    = GameObject.Find(MY_ROBOTS_CARD_NAME);
        GameObject storeContainerGameObject = GameObject.Find(MY_ROBOTS_CONTAINER_NAME);

        MY_ROBOTS_CONTAINER = storeContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT         = SCROLL_VIEW.GetComponent <ScrollRect>();
        MY_ROBOTS_PANEL     = GameObject.Find(MY_ROBOTS_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR_OBJECT    = GameObject.Find(MY_ROBOTS_CARD_NAME).transform.Find(MY_ROBOTS_SCROLLBAR_NAME).gameObject;
        SCROLLBAR           = SCROLLBAR_OBJECT.GetComponent <Scrollbar>();
        SCROLLBAR_OBJECT.SetActive(false);
        SCROLL_RECT.vertical          = false;
        myRobotsButtons               = new List <GameObject>();
        myRobotsInfo                  = GameObject.Find("MyRobots").transform.Find(MY_ROBOTS_INFO_NAME).gameObject;
        myRobotsName                  = myRobotsInfo.transform.Find(MY_ROBOTS_NAME).gameObject;
        myRobotsStats                 = myRobotsInfo.transform.Find(MY_ROBOTS_STATS_NAME).gameObject;
        robotWidgetDurabilityBar      = myRobotsInfo.transform.transform.Find("DurabilityBar").gameObject;
        robotWidgetDurabilityBarLabel = myRobotsInfo.transform.transform.Find("DurabilityBarLabel").gameObject;
        myRobotsInfo.SetActive(false);
        NEW_ROBOT_BUTTON = GameObject.Find("NewRobot");
        NEW_ROBOT_BUTTON.GetComponent <UnityEngine.UI.Image>().color = this.colorScheme;
        REMOVE_ROBOTS_BUTTON        = GameObject.Find("MyRobots").transform.Find("RemoveRobots").gameObject;
        CANCEL_REMOVE_ROBOTS_BUTTON = GameObject.Find("MyRobots").transform.Find("CancelRemoveRobots").gameObject;
        if (myRobots.Length == 0)
        {
            REMOVE_ROBOTS_BUTTON.SetActive(false);
        }
        CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(false);
        MY_ROBOTS_CREDIT = GameObject.Find("MyRobotsCredit");
        MY_ROBOTS_CREDIT.GetComponent <TextMeshProUGUI>().color = this.colorScheme;
        updateCredits();
        myRobotsStatsList = new List <GameObject>();
        foreach (Robot robot in this.myRobots)
        {
            GameObject robotButton = GameObject.Instantiate(Resources.Load("Prefabs/RobotButton") as GameObject);
            Texture2D  robotIcon   = robot.getHead().getIcon();
            if (robotIcon != null)
            {
                robotButton.transform.Find("Icon").GetComponent <UnityEngine.UI.Image>().sprite = Sprite.Create(robotIcon, new Rect(0, 0, robotIcon.width, robotIcon.height), new Vector2(0.5f, 0.5f), 100);
            }
            robotButton.GetComponent <RectTransform>().localScale = Vector3.one;
            robotButton.transform.localPosition = new Vector3(robotButton.transform.localPosition.x, robotButton.transform.localPosition.y, 0);
            robotButton.transform.Find("NameLabel").GetComponent <TextMeshProUGUI>().text = robot.getName();
            robotButton.transform.SetParent(MY_ROBOTS_PANEL);
            robotButton.transform.localPosition = new Vector3(robotButton.transform.localPosition.x, robotButton.transform.localPosition.y, 0);
            robotButton.transform.Find("SelectionIndicator").gameObject.SetActive(false);
            myRobotsButtons.Add(robotButton);
        }
        if (this.myRobots.Count > 0)
        {
            updateSorting();
        }
    }
コード例 #4
0
    public void update(Robot[] myRobots, Part[] humanRobotParts, long credits, Color colorScheme)
    {
        this.credits = credits;
        if (this.colorScheme != colorScheme)
        {
            this.colorScheme = colorScheme;
            NEW_ROBOT_BUTTON.GetComponent <UnityEngine.UI.Image>().color = this.colorScheme;
            MY_ROBOTS_CREDIT.GetComponent <TextMeshProUGUI>().color      = this.colorScheme;
        }
        if (this.myRobots.Count != myRobots.Length)
        {
            this.myRobots.Clear();
            this.myRobots.AddRange(myRobots);
        }
        if (this.humanRobotParts.Count != humanRobotParts.Length)
        {
            this.humanRobotParts.Clear();
            this.humanRobotParts.AddRange(humanRobotParts);
        }
        if (base.enabled)
        {
            if ((mode != MODES.NEW_ROBOT && (myRobots == null || myRobots.Length == 0)) || (NEW_ROBOT_BUTTON.activeSelf && NEW_ROBOT_BUTTON.GetComponent <ButtonListener>().isClicked()))
            {
                NEW_ROBOT_BUTTON.GetComponent <ButtonListener>().resetClick();
                mode = MODES.NEW_ROBOT;
                Part[] parts = null;
                if (myRobots != null && myRobots.Length > 0)
                {
                    parts = myRobots[0].getParts();
                }
                else
                {
                    List <Part> defaultParts = new List <Part>();
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Head)));
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Body)));
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Mobility)));
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Blaster)));
                    parts = defaultParts.ToArray();
                }
                List <Part> newParts = new List <Part>();
                foreach (Part part in parts)
                {
                    newParts.Add(part.clone(true));
                }
                newRobot            = new Robot("", true, true, newParts.ToArray());
                robotBeingPreviewed = null;
            }
            else if (CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().isClicked())
            {
                mode = MODES.VIEW_MY_ROBOTS_STATS;
                CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().resetClick();
                REMOVE_ROBOTS_BUTTON.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = REMOVE_ROBOTS_TEXT;
                CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(false);
                robotsToRemove = new List <Robot>();
                selectedRobotIndicesToRemove = new List <int>();
                foreach (GameObject robotButton in myRobotsButtons)
                {
                    robotButton.transform.Find("SelectionIndicator").gameObject.SetActive(false);
                }
            }
            else if (REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().isClicked())
            {
                REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().resetClick();
                switch (mode)
                {
                case MODES.REMOVE_ROBOTS:
                    if (selectedRobotIndicesToRemove.Count > 0)
                    {
                        mode = MODES.VIEW_MY_ROBOTS_STATS;
                        REMOVE_ROBOTS_BUTTON.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = REMOVE_ROBOTS_TEXT;
                        CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(false);
                        robotsToRemove = new List <Robot>();
                        foreach (int robotIndex in selectedRobotIndicesToRemove)
                        {
                            robotsToRemove.Add(this.myRobots[robotIndex]);
                            this.myRobots.RemoveAt(robotIndex);
                            GameObject.Destroy(myRobotsButtons[robotIndex]);
                            myRobotsButtons.RemoveAt(robotIndex);
                        }
                        selectedRobotIndicesToRemove = new List <int>();
                    }
                    break;

                default:
                    mode = MODES.REMOVE_ROBOTS;
                    REMOVE_ROBOTS_BUTTON.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = REMOVE_SELECTED_ROBOTS_TEXT;
                    REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color;
                    CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(true);
                    robotsToRemove = new List <Robot>();
                    selectedRobotIndicesToRemove = new List <int>();
                    break;
                }
            }
            if ((MY_ROBOTS_PANEL.offsetMax.y - MY_ROBOTS_PANEL.offsetMin.y) > (MY_ROBOTS_CONTAINER.offsetMax.y - MY_ROBOTS_CONTAINER.offsetMin.y))
            {
                SCROLLBAR_OBJECT.SetActive(true);
                SCROLL_RECT.vertical = true;
            }
            else
            {
                SCROLLBAR_OBJECT.SetActive(false);
                SCROLL_RECT.vertical = false;
            }
            for (int myRobotsButtonIndex = 0; myRobotsButtonIndex < myRobotsButtons.Count; ++myRobotsButtonIndex)
            {
                ButtonListener buttonListener = myRobotsButtons[myRobotsButtonIndex].GetComponent <ButtonListener>();
                if (buttonListener.isClicked())
                {
                    buttonListener.resetClick();
                    switch (mode)
                    {
                    case MODES.VIEW_MY_ROBOTS_STATS:
                        mode = MODES.PICK_ROBOT;
                        myRobotsInfo.SetActive(false);
                        robotBeingPicked = myRobots[myRobotsButtonIndex];
                        break;

                    case MODES.REMOVE_ROBOTS:
                        if (!selectedRobotIndicesToRemove.Contains(myRobotsButtonIndex))
                        {
                            selectedRobotIndicesToRemove.Add(myRobotsButtonIndex);
                            myRobotsButtons[myRobotsButtonIndex].transform.Find("SelectionIndicator").gameObject.SetActive(true);
                            REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = REMOVE_ROBOTS_BUTTON_COLOR;
                        }
                        else
                        {
                            selectedRobotIndicesToRemove.Remove(myRobotsButtonIndex);
                            myRobotsButtons[myRobotsButtonIndex].transform.Find("SelectionIndicator").gameObject.SetActive(false);
                            if (selectedRobotIndicesToRemove.Count == 0)
                            {
                                REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    break;
                }
                if (buttonListener.isMouseOver() && mode == MODES.VIEW_MY_ROBOTS_STATS)
                {
                    robotBeingPreviewed = myRobots[myRobotsButtonIndex];
                    Vector2 position;
                    RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>(), Input.mousePosition, Camera.main, out position);
                    position.x += myRobotsInfo.GetComponent <RectTransform>().sizeDelta.x / 2;
                    myRobotsInfo.transform.localPosition = position;
                    myRobotsName.GetComponent <TextMeshProUGUI>().text = myRobots[myRobotsButtonIndex].getName();
                    foreach (GameObject partStat in myRobotsStatsList)
                    {
                        GameObject.Destroy(partStat);
                    }
                    myRobotsStatsList.Clear();
                    robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale  = new Vector3((float)(myRobots[myRobotsButtonIndex].getRemainingDurability() / myRobots[myRobotsButtonIndex].getDurability()), robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale.y, 0);
                    robotWidgetDurabilityBarLabel.GetComponent <TextMeshProUGUI>().text = DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(myRobots[myRobotsButtonIndex].getRemainingDurability()) + " / " + StringTools.formatString(myRobots[myRobotsButtonIndex].getDurability());
                    string[] myRobotsStatStrings = myRobots[myRobotsButtonIndex].getRobotStatStrings();
                    for (int myRobotsStatIndex = 0; myRobotsStatIndex < myRobotsStatStrings.Length; ++myRobotsStatIndex)
                    {
                        GameObject myRobotsStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                        myRobotsStat.GetComponent <TextMeshProUGUI>().text = myRobotsStatStrings[myRobotsStatIndex];
                        myRobotsStat.transform.SetParent(myRobotsStats.GetComponent <RectTransform>());
                        myRobotsStat.transform.localPosition = new Vector3(myRobotsStat.transform.localPosition.x, myRobotsStat.transform.localPosition.y, 0);
                        myRobotsStatsList.Add(myRobotsStat);
                    }
                    myRobotsInfo.SetActive(true);
                    break;
                }
                else
                {
                    myRobotsInfo.SetActive(false);
                }
            }
            if (currentSort != MY_ROBOTS_SORT.GetComponent <TMP_Dropdown>().value)
            {
                currentSort = MY_ROBOTS_SORT.GetComponent <TMP_Dropdown>().value;
                applySorting();
            }
        }
    }
コード例 #5
0
 public void update(string robotName, long credits, double durability, double remainingDurability, string[] robotStatStrings, bool maxForceExceeded, Part[] parts, Color colorScheme, bool enableCreditsSpentAnimation)
 {
     this.colorScheme = colorScheme;
     this.enableCreditsSpentAnimation = enableCreditsSpentAnimation;
     if (WORKSHOP_CREDIT.GetComponent <TextMeshProUGUI>().color != this.colorScheme)
     {
         WORKSHOP_CREDIT.GetComponent <TextMeshProUGUI>().color = this.colorScheme;
     }
     if (this.robotName != robotName)
     {
         this.robotName = robotName;
         robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().text    = (!((robotName.Length == 1 && ((int)robotName[0]) == 8203) || this.robotName == default || this.robotName == "" || this.robotName == Robot.DEFAULT_NAME) ? this.robotName : ROBOT_NAME_PLACEHOLDER);
         robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().enabled = robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().text == ROBOT_NAME_PLACEHOLDER;
     }
     this.credits = credits;
     updateCredits();
     this.durability          = durability;
     this.remainingDurability = remainingDurability;
     this.maxForceExceeded    = maxForceExceeded;
     if (this.parts.Count + attachments.Count != parts.Length)
     {
         this.parts       = new List <Part>();
         this.attachments = new List <Attachment>();
         foreach (Part part in parts)
         {
             if (!(part is Attachment))
             {
                 this.parts.Add(part);
             }
             else
             {
                 this.attachments.Add((Attachment)part);
             }
         }
         initialize();
     }
     if (base.enabled && mode != InventoryCard.MODES.PREVIEW_PART)
     {
         robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().text    = (!(((int)robotName[0]) == 8203 || robotName == default || robotName == "" || robotName == Robot.DEFAULT_NAME) ? robotName : ROBOT_NAME_PLACEHOLDER);
         robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().enabled = robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().text == ROBOT_NAME_PLACEHOLDER;
         robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale   = new Vector3((float)(this.remainingDurability / this.durability), robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale.y, 0);
         robotWidgetDurabilityBarLabel.GetComponent <TextMeshProUGUI>().text  = DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(this.remainingDurability) + " / " + StringTools.formatString(this.durability);
         for (int robotStatStringIndex = 0; robotStatStringIndex < robotStatStrings.Length; ++robotStatStringIndex)
         {
             string robotStatString = robotStatStrings[robotStatStringIndex];
             if (this.robotStatStrings[robotStatStringIndex] != robotStatString)
             {
                 this.robotStatStrings[robotStatStringIndex] = robotStatString;
                 GameObject.Destroy(robotStatStringLabels[robotStatStringIndex]);
                 GameObject partStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                 partStat.GetComponent <TextMeshProUGUI>().text = robotStatString;
                 if (robotStatString.Contains(WEIGHT_STRING) && this.maxForceExceeded)
                 {
                     partStat.GetComponent <TextMeshProUGUI>().color = BAD_COLOR;
                 }
                 partStat.transform.SetParent(robotWidgetStats.GetComponent <RectTransform>());
                 robotStatStringLabels[robotStatStringIndex] = partStat;
             }
         }
         if ((WIDGETS_PANEL.offsetMax.y - WIDGETS_PANEL.offsetMin.y) > (WIDGETS_CONTAINER.offsetMax.y - WIDGETS_CONTAINER.offsetMin.y))
         {
             SCROLLBAR_OBJECT.SetActive(true);
             SCROLL_RECT.vertical = true;
         }
         else
         {
             SCROLLBAR_OBJECT.SetActive(false);
             SCROLL_RECT.vertical = false;
         }
         for (int widgetButtonIndex = 0; widgetButtonIndex < widgetButtons.Count; ++widgetButtonIndex)
         {
             Part part = (widgetButtonIndex < parts.Length ? parts[widgetButtonIndex] : attachments[widgetButtonIndex - parts.Length]);
             widgetStates[widgetButtonIndex] = widgetButtons[widgetButtonIndex].GetComponent <ButtonListener>().isClicked() || widgetButtons[widgetButtonIndex].GetComponent <ButtonListener>().isControlClicked();
             float widgetYScale = configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y;
             if (!widgetStates[widgetButtonIndex] && Math.Abs(currentWidgetHeights[widgetButtonIndex]) < WIDGET_EXPAND_HEIGHT && Math.Abs(currentWidgetHeights[widgetButtonIndex]) > WIDGET_HEIGHT)
             {
                 currentWidgetHeights[widgetButtonIndex] += WIDGET_EXPAND_RATE;
                 if (Math.Abs(currentWidgetHeights[widgetButtonIndex]) > WIDGET_EXPAND_HEIGHT)
                 {
                     currentWidgetHeights[widgetButtonIndex] = currentWidgetHeights[widgetButtonIndex] / Math.Abs(currentWidgetHeights[widgetButtonIndex]) * WIDGET_EXPAND_HEIGHT;
                 }
                 if (Math.Abs(currentWidgetHeights[widgetButtonIndex]) < WIDGET_HEIGHT)
                 {
                     currentWidgetHeights[widgetButtonIndex] = currentWidgetHeights[widgetButtonIndex] / Math.Abs(currentWidgetHeights[widgetButtonIndex]) * WIDGET_HEIGHT;
                 }
             }
             if (widgetStates[widgetButtonIndex])
             {
                 if (widgetButtons[widgetButtonIndex].GetComponent <ButtonListener>().isClicked())
                 {
                     currentWidgetHeights[widgetButtonIndex] *= -1;
                     ++currentWidgetHeights[widgetButtonIndex];
                 }
                 else if (widgetButtons[widgetButtonIndex].GetComponent <ButtonListener>().isControlClicked())
                 {
                     removeParts[widgetButtonIndex] = true;
                 }
                 widgetStates[widgetButtonIndex] = false;
                 widgetButtons[widgetButtonIndex].GetComponent <ButtonListener>().resetClick();
             }
             configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta = new Vector3(configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.x, Math.Abs(currentWidgetHeights[widgetButtonIndex]), 0);
             widgetButtons[widgetButtonIndex].GetComponent <ButtonListener>().resetClick();
             widgetDurabilityBars[widgetButtonIndex].SetActive(-widgetDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + widgetDurabilityBars[widgetButtonIndex].transform.position.y >= -configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + configurationPartWidgets[widgetButtonIndex].transform.position.y);
             widgetDurabilityBarLabels[widgetButtonIndex].SetActive(-widgetDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + widgetDurabilityBars[widgetButtonIndex].transform.position.y >= -configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + configurationPartWidgets[widgetButtonIndex].transform.position.y);
             repairDurabilityBars[widgetButtonIndex].SetActive(-widgetDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + widgetDurabilityBars[widgetButtonIndex].transform.position.y < -configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + configurationPartWidgets[widgetButtonIndex].transform.position.y);
             for (int widgetStatIndex = 0; widgetStatIndex < widgetStatsLabelList[widgetButtonIndex].Count; ++widgetStatIndex)
             {
                 widgetStatsLabelList[widgetButtonIndex][widgetStatIndex].SetActive(-widgetDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + widgetDurabilityBars[widgetButtonIndex].transform.position.y >= -configurationPartWidgets[widgetButtonIndex].GetComponent <RectTransform>().sizeDelta.y + configurationPartWidgets[widgetButtonIndex].transform.position.y && -widgetStatsLabelList[widgetButtonIndex][widgetStatIndex].GetComponent <RectTransform>().sizeDelta.y + widgetStatsLabelList[widgetButtonIndex][widgetStatIndex].transform.position.y >= -widgetStatsLabelList[widgetButtonIndex][widgetStatIndex].GetComponent <RectTransform>().sizeDelta.y + widgetStatsLabelList[widgetButtonIndex][widgetStatIndex].transform.position.y);
             }
             canAffordRepair[widgetButtonIndex] = credits >= repairCosts[widgetButtonIndex];
             buttonStates[widgetButtonIndex]    = widgetRepairButtons[widgetButtonIndex].GetComponent <ButtonListener>().isClicked() && canAffordRepair[widgetButtonIndex];
             widgetRepairButtons[widgetButtonIndex].GetComponent <UnityEngine.UI.Image>().color = (canAffordRepair[widgetButtonIndex] ? new Color(colorScheme.r, colorScheme.g - (float)((part.getDurability() - part.getRemainingDurability()) / part.getDurability()) * colorScheme.g, colorScheme.b, colorScheme.a) : REPAIR_UNAFFORDABLE_COLOR);
             widgetRepairButtons[widgetButtonIndex].GetComponent <ButtonListener>().resetClick();
             string repairButtonLabel = REPAIR_BUTTON_LABEL + " (<sprite=0> " + repairCosts[widgetButtonIndex].ToString() + ")";
             widgetRepairButtonLabels[widgetButtonIndex].GetComponent <TextMeshProUGUI>().text  = repairButtonLabel;
             repairDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().localScale  = new Vector3((part.getDurability() > 0 ? (float)(part.getRemainingDurability() / part.getDurability()) : 0), repairDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().localScale.y, 0);
             widgetDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().localScale  = new Vector3((part.getDurability() > 0 ? (float)(part.getRemainingDurability() / part.getDurability()) : 0), widgetDurabilityBars[widgetButtonIndex].GetComponent <RectTransform>().localScale.y, 0);
             widgetDurabilityBarLabels[widgetButtonIndex].GetComponent <TextMeshProUGUI>().text = DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(part.getRemainingDurability()) + " / " + StringTools.formatString(part.getDurability());
             if (part.getRemainingDurability() >= part.getDurability())
             {
                 widgetRepairButtons[widgetButtonIndex].SetActive(false);
                 widgetRepairButtonLabels[widgetButtonIndex].SetActive(false);
                 repairDurabilityBars[widgetButtonIndex].SetActive(false);
                 canAffordRepair[widgetButtonIndex] = false;
             }
             else if (buttonStates[widgetButtonIndex])
             {
                 widgetRepairButtons[widgetButtonIndex].SetActive(false);
                 widgetRepairButtonLabels[widgetButtonIndex].SetActive(false);
                 repairDurabilityBars[widgetButtonIndex].SetActive(false);
                 canAffordRepair[widgetButtonIndex] = false;
                 updateCredits();
                 if (enableCreditsSpentAnimation)
                 {
                     WORKSHOP_CREDITS_SPENT.SetActive(true);
                     WORKSHOP_CREDITS_SPENT.transform.localPosition = WORKSHOP_CREDITS_SPENT_HOME_POSITION;
                     Color storeCreditsSpentColor = WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color;
                     WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color = new Color(storeCreditsSpentColor.r, storeCreditsSpentColor.g, storeCreditsSpentColor.b, 1);
                     WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().text  = "-" + PERFORMANCE_METRIC_CALCULATOR.calculateCost(part).ToString();
                 }
             }
         }
         if (enableCreditsSpentAnimation && WORKSHOP_CREDITS_SPENT.activeSelf)
         {
             Vector3 position = WORKSHOP_CREDITS_SPENT.transform.localPosition;
             WORKSHOP_CREDITS_SPENT.transform.localPosition = new Vector3(position.x, position.y + WORKSHOP_CREDITS_SPENT_ANIMATION_POSITION_SPEED, position.z);
             Color storeCreditsSpentColor = WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color;
             WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color = new Color(storeCreditsSpentColor.r, storeCreditsSpentColor.g, storeCreditsSpentColor.b, storeCreditsSpentColor.a - WORKSHOP_CREDITS_SPENT_ANIMATION_COLOR_SPEED);
             if (WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color.a <= 0)
             {
                 WORKSHOP_CREDITS_SPENT.SetActive(false);
             }
         }
         else if (!enableCreditsSpentAnimation)
         {
             if (WORKSHOP_CREDITS_SPENT.transform.localPosition != WORKSHOP_CREDITS_SPENT_HOME_POSITION)
             {
                 WORKSHOP_CREDITS_SPENT.transform.localPosition = WORKSHOP_CREDITS_SPENT_HOME_POSITION;
             }
             Color storeCreditsSpentColor = WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color;
             if (WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color.a != 1)
             {
                 WORKSHOP_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color = new Color(storeCreditsSpentColor.r, storeCreditsSpentColor.g, storeCreditsSpentColor.b, 1);
             }
             if (WORKSHOP_CREDITS_SPENT.activeInHierarchy)
             {
                 WORKSHOP_CREDITS_SPENT.SetActive(false);
             }
         }
         checkRobotName();
     }
 }
コード例 #6
0
 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();
         }
     }
 }