Exemplo n.º 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();
    }
Exemplo n.º 2
0
    public void updateCredits()
    {
        string workshopCreditText = WORKSHOP_CREDIT.GetComponent <TextMeshProUGUI>().text;

        WORKSHOP_CREDIT.GetComponent <TextMeshProUGUI>().text = workshopCreditText.Substring(0, workshopCreditText.LastIndexOf(" ") + 1) + credits.ToString();
    }
Exemplo n.º 3
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();
     }
 }