Esempio n. 1
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();
        }
    }
Esempio n. 2
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();
            }
        }
    }