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(); } }
public StoreCard(long credits, Part[] storeParts, Part[] humanParts, Part[] robotParts, Color colorScheme, bool enableCreditsSpentAnimation) { this.credits = credits; this.storeParts = storeParts; this.humanParts = humanParts; this.robotParts = robotParts; this.colorScheme = colorScheme; this.enableCreditsSpentAnimation = enableCreditsSpentAnimation; mode = MODES.VIEW_PART_STATS; partBeingPreviewed = null; partBeingBought = null; currentPartFilter = DEFAULT_STORE_FILTER; STORE_SORT = GameObject.Find("StoreSort"); currentSort = DEFAULT_SORT; PERFORMANCE_METRIC_CALCULATOR = new PerformanceMetricCalculator(); SCROLL_VIEW = GameObject.Find(STORE_CARD_NAME); GameObject storeContainerGameObject = GameObject.Find(STORE_CONTAINER_NAME); STORE_CONTAINER = storeContainerGameObject.GetComponent <RectTransform>(); SCROLL_RECT = SCROLL_VIEW.GetComponent <ScrollRect>(); STORE_PANEL = GameObject.Find(STORE_PANEL_NAME).GetComponent <RectTransform>(); SCROLLBAR = GameObject.Find(STORE_CARD_NAME).transform.Find(STORE_SCROLLBAR_NAME).gameObject; SCROLLBAR.SetActive(false); SCROLL_RECT.vertical = false; storeButtons = new List <GameObject>(); partInfo = GameObject.Find("Store").transform.Find(PART_INFO_NAME).gameObject; partType = partInfo.transform.Find(PART_TYPE_NAME).gameObject; partStats = partInfo.transform.Find(PART_STATS_NAME).gameObject; partInfo.SetActive(false); BUY_PART_BUTTON = GameObject.Find("Store").transform.Find("BuyPart").gameObject; BUY_PART_BUTTON.SetActive(false); STORE_CREDIT = GameObject.Find("StoreCredit"); STORE_CREDIT.GetComponent <TextMeshProUGUI>().color = colorScheme; updateCredits(); STORE_CREDITS_SPENT = GameObject.Find("Store").transform.Find("StoreCreditsSpent").gameObject; STORE_CREDITS_SPENT_HOME_POSITION = STORE_CREDITS_SPENT.transform.localPosition; STORE_CREDITS_SPENT.SetActive(false); partStatsList = new List <GameObject>(); ATTACHMENT_PARTS_ROWS_LABELS = new List <string>(); foreach (Part part in this.storeParts) { if (part is Attachment && !ATTACHMENT_PARTS_ROWS_LABELS.Contains(part.GetType().ToString())) { ATTACHMENT_PARTS_ROWS_LABELS.Add(part.GetType().ToString()); } GameObject storeButton = GameObject.Instantiate(Resources.Load("Prefabs/FeaturedPartButton") as GameObject); Texture2D partIcon = part.getIcon(); if (partIcon != null) { storeButton.transform.Find("Icon").GetComponent <UnityEngine.UI.Image>().sprite = Sprite.Create(partIcon, new Rect(0, 0, partIcon.width, partIcon.height), new Vector2(0.5f, 0.5f), 100); } storeButton.GetComponent <RectTransform>().localScale = Vector3.one; storeButton.transform.localPosition = new Vector3(storeButton.transform.localPosition.x, storeButton.transform.localPosition.y, 0); storeButton.transform.Find("CostLabel").GetComponent <TextMeshProUGUI>().text += PERFORMANCE_METRIC_CALCULATOR.calculateCost(part); storeButton.transform.Find("CostLabel").GetComponent <TextMeshProUGUI>().color = (PERFORMANCE_METRIC_CALCULATOR.calculateCost(part) <= this.credits ? AFFORDABLE_TEXT_COLOR : UNAFFORDABLE_TEXT_COLOR); storeButton.SetActive(false); storeButtons.Add(storeButton); } STORE_TABS = new List <GameObject>(); foreach (Transform childTransform in GameObject.Find("StoreTabs").transform.Find("StoreTabMask")) { if (childTransform.gameObject.name.Contains(STORE_TAB_SUFFIX)) { STORE_TABS.Add(childTransform.gameObject); } } FEATURED_PARTS_ROWS = new List <GameObject>(); foreach (string featuredPartsRowLabel in FEATURED_PARTS_ROWS_LABELS) { GameObject featuredPartsRow = GameObject.Instantiate(Resources.Load("Prefabs/FeaturedPartsRow") as GameObject); string featuredPartsRowLabelText = featuredPartsRow.transform.Find("AllParts").Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text; featuredPartsRow.transform.Find("AllParts").Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = featuredPartsRowLabelText.Substring(0, featuredPartsRowLabelText.IndexOf(" ") + 1) + featuredPartsRowLabel + featuredPartsRowLabelText.Substring(featuredPartsRowLabelText.IndexOf(" ")); featuredPartsRow.transform.localPosition = new Vector3(featuredPartsRow.transform.localPosition.x, featuredPartsRow.transform.localPosition.y, 0); featuredPartsRow.SetActive(false); FEATURED_PARTS_ROWS.Add(featuredPartsRow); } ATTACHMENT_PARTS_ROWS = new List <GameObject>(); foreach (string attachmentPartsRowLabel in ATTACHMENT_PARTS_ROWS_LABELS) { GameObject attachmentPartsRow = GameObject.Instantiate(Resources.Load("Prefabs/AttachmentPartsRow") as GameObject); string attachmentPartsRowLabelText = attachmentPartsRow.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text; attachmentPartsRow.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = attachmentPartsRowLabel; attachmentPartsRow.transform.localPosition = new Vector3(attachmentPartsRow.transform.localPosition.x, attachmentPartsRow.transform.localPosition.y, 0); attachmentPartsRow.SetActive(false); ATTACHMENT_PARTS_ROWS.Add(attachmentPartsRow); } filterFeaturedParts(); updateSorting(); }