Ejemplo n.º 1
0
        //======================
        //ScrollMenu
        //======================
        public UIScrollMenu CreateScrollMenu(float posX, float posY, Transform parent, string name = "ScrollMenu")
        {
            //Create parent GO and set it up
            GameObject uiParent = new GameObject("ModScrollMenu");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localScale    = Vector3.one;
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);

            //Create Canvas
            GameObject canvas = new GameObject("Canvas");

            canvas.transform.SetParent(uiParent.transform, false);
            canvas.transform.localScale    = Vector3.one;
            canvas.transform.localPosition = new Vector3(0f, UIScrollMenu.initialY, 0f);

            //Create ScrollBar
            UIScrollBar scrollBar = CreateScrollBar(4f, -0.5f, uiParent.transform);

            //Create title
            UITextFrame title = UIFactory.Instance.CreateTextFrame(0f, 3f, uiParent.transform, name);

            //Assign component
            UIScrollMenu output = uiParent.AddComponent <UIScrollMenu>();

            output.Initialize();
            output.UIName        = name;
            output.CanvasWindow  = 8.5f;
            output.EmptySpace    = 2f;
            output.DynamicHeight = true;

            return(output);
        }
Ejemplo n.º 2
0
        public UISlider CreateSlider(float posX, float posY, Transform parent, string name = "")
        {
            //Search for slider to spawn
            GameObject objectToCopy;

            if (sliderOriginal == null)
            {
                sliderOriginal = SearchGO("ListLevel", "List");
                if (sliderOriginal == null)
                {
                    return(null);
                }
            }
            objectToCopy = sliderOriginal;

            //Create parent GO and set it up
            GameObject uiParent = new GameObject("ModSlider");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localScale    = Vector3.one;
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);

            //Instantiate GO
            GameObject elementCreated = Instantiate(objectToCopy, uiParent.transform);

            elementCreated.name = "ModUIElement";
            elementCreated.transform.localPosition = ZFixVector;

            //Set TextFrame
            UITextFrame display = UIFactory.Instance.CreateTextFrame(0f, 0f, elementCreated.transform);

            display.transform.localPosition = new Vector3(-2.35f, 0f, -0.2f);
            display.ScaleBackground(new Vector2(0.3f, 0.8f));

            //Remove slider icon, hider icon/component and arrows. Reposition title name
            Destroy(elementCreated.GetComponent <GuiFloatHiderApplier>());
            Destroy(elementCreated.transform.Find("Sound").gameObject);
            elementCreated.transform.Find("Arrows").localScale  = Vector3.zero;
            elementCreated.transform.Find("Name").localPosition = new Vector3(0f, 0.32f, -0.2f);
            Destroy(elementCreated.transform.Find("OffIcon").gameObject);

            //Assign component
            UISlider output = uiParent.AddComponent <UISlider>();

            output.Initialize();
            output.UIName = name;

            return(output);
        }
Ejemplo n.º 3
0
        //======================
        //2D List
        //======================
        public UI2DList Create2DList(float posX, float posY, Vector2 arraySize, Vector2 btnScale, Vector2 btnBackground, Vector2 separation, Transform parent, string name = "2D List")
        {
            //Create parent GO and set it up
            GameObject uiParent = new GameObject("Mod2DList");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localScale    = Vector3.one;
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);

            //Create ScrollBar
            UIScrollBar scrollBar = CreateScrollBar(4f, 0f, uiParent.transform);

            //Create title
            UITextFrame title = UIFactory.Instance.CreateTextFrame(0f, 3.2f, uiParent.transform, name);

            //Buttons array
            //--------------
            //Initialize array variables
            UIButton[] buttonsArray    = new UIButton[(int)(arraySize.x * arraySize.y)];
            float      xSeparation     = 3.4f * btnScale.x * btnBackground.x * separation.x;
            float      yScale          = btnScale.y * btnBackground.y;
            float      ySeparation     = -1.6f * yScale * separation.y;
            float      initialX        = xSeparation * (-0.5f) * (arraySize.x - 1);
            float      initialY        = 1.6f;
            Vector2    backgroundScale = new Vector2(0.75f * btnBackground.x, 1.5f * btnBackground.y);
            //Instantiate array
            UIButton createdButton;

            for (int i = 0; i < (int)(arraySize.x * arraySize.y); i++)
            {
                float buttonXPos = initialX + ((float)(i % (int)arraySize.x)) * xSeparation;
                float buttonYPos = initialY + ((float)(i / ((int)arraySize.x))) * ySeparation;
                createdButton = UIFactory.Instance.CreateButton(UIButton.ButtonType.Default, buttonXPos, buttonYPos, uiParent.transform, "2DLIST" + i.ToString());
                createdButton.ScaleBackground(backgroundScale, btnScale);
                buttonsArray[i] = createdButton;
            }

            //Assign component
            UI2DList output = uiParent.AddComponent <UI2DList>();

            output.Initialize();
            output.AssignButtonsArray(buttonsArray, (int)arraySize.x);
            output.UIName = name;

            return(output);
        }
Ejemplo n.º 4
0
        //======================
        //Utility functions
        //======================
        //Popup frame
        //Only works with UIButton, UIGfxButton, UICheckbox, UISlider and UIListExplorer
        public UITextFrame CreatePopupFrame(float x, float y, UIElement hover, Transform parent, string text)
        {
            if (!(hover is UIButton) && !(hover is UIGFXButton) && !(hover is UICheckBox) && !(hover is UISlider) && !(hover is UIListExplorer))
            {
                return(null);
            }

            UITextFrame textFrame = UIFactory.Instance.CreateTextFrame(x, y, parent.transform, text);

            textFrame.gameObject.SetActive(false);
            List <UIElement> applyTo = new List <UIElement>();

            if (hover is UIListExplorer)
            {
                UIListExplorer explorer = (UIListExplorer)hover;
                applyTo.Add(explorer.LeftArrow);
                applyTo.Add(explorer.RightArrow);
            }
            else
            {
                applyTo.Add(hover);
            }

            for (int i = 0; i < applyTo.Count; i++)
            {
                GuiSelectionObject hoverSelection = applyTo[i].gameObject.GetComponentInChildren <GuiSelectionObject>();

                bool oldState = false;
                applyTo[i].onUpdate += delegate()
                {
                    if (hoverSelection.IsSelected == oldState)
                    {
                        return;
                    }
                    oldState = hoverSelection.IsSelected;
                    textFrame.gameObject.SetActive(oldState);
                };
            }

            return(textFrame);
        }
Ejemplo n.º 5
0
        public UITextFrame CreateTextFrame(float posX, float posY, Transform parent, string name = "")
        {
            //Create parent GO and set it up
            GameObject uiParent = new GameObject("ModTextFrame");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localScale    = Vector3.one;
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);

            //Instantiate GOs
            GameObject elementCreated = Instantiate(TextFrameOriginal, uiParent.transform);

            elementCreated.name = "ModUIElement";
            elementCreated.transform.localPosition = ZFixVector;

            //Assign component
            UITextFrame output = uiParent.AddComponent <UITextFrame>();

            output.Initialize();
            output.UIName = name;

            return(output);
        }
Ejemplo n.º 6
0
        public void Initialize()
        {
            //Set TextMesh, slidable and textframe
            nameTextMesh = gameObject.GetComponentInChildren <TextMesh>();
            slidable     = gameObject.GetComponentInChildren <GuiSlidable>();
            _display     = gameObject.GetComponentInChildren <UITextFrame>();
            UpdateDisplayValue();

            //Find existing GUI node
            GuiNode node = gameObject.GetComponentInChildren <GuiNode>(true);

            if (node == null)
            {
                return;
            }

            //Link this component to the node
            GuiBindInData inData      = new GuiBindInData(null, null);
            GuiBindData   guiBindData = GuiNode.Connect(this.gameObject, inData);
            string        trackerID   = "Slider" + UIElement.GetNewTrackerID();

            guiBindData.AddTracker(trackerID, node);

            //Set delegate function
            IGuiOnchangeFloat tryfind = guiBindData.GetTrackerEvent <IGuiOnchangeFloat>(trackerID);

            if (tryfind == null)
            {
                return;
            }
            tryfind.onchange = new GuiNode.OnFloatFunc(SliderMoved);

            //Text resizing
            DefLineSize      = 200f;
            OriginalTextSize = nameTextMesh.transform.localScale;
            AutoTextResize   = true;
        }
Ejemplo n.º 7
0
        //======================
        //ListExplorer
        //======================
        public UIListExplorer CreateListExplorer(float posX, float posY, Transform parent, string name = "")
        {
            //Create parent GO and set it up
            GameObject uiParent = new GameObject("ModListExplorer");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localScale    = Vector3.one;
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);

            //Create display
            UITextFrame display = CreateTextFrame(0, 0, uiParent.transform);

            display.name = "Display";
            display.transform.localPosition = ZFixVector;

            //Left  arrow
            //--------------
            //Create arrow button, position and name it
            UIButton leftArrow = CreateButton(UIButton.ButtonType.Default, 0, 0, uiParent.transform, "");

            leftArrow.name = "LeftArrow";
            leftArrow.transform.localScale    = new Vector3(0.4f, 0.8f, 1f);
            leftArrow.transform.localPosition = new Vector3(-1.8f, 0f, -0.2f);
            //Replace gfx and position it
            SearchArrows(); //Search for arrows gfx
            Destroy(leftArrow.transform.Find("ModUIElement").Find("Root").Find("Background").gameObject);
            GameObject lArrow = Instantiate(leftArrowOriginal, leftArrow.transform.Find("ModUIElement").Find("Root"));

            lArrow.transform.localScale    = new Vector3(2f, 1f, 1f);
            lArrow.transform.localPosition = new Vector3(-0.5f, 0f, 0f);
            //Remove logic components from the gfx
            Destroy(lArrow.GetComponent <GuiClickable>());
            Destroy(lArrow.GetComponent <GuiClickRect>());
            Destroy(lArrow.GetComponent <GuiChangeEffect_ClickUpdSlider>());

            //Right arrow
            //--------------
            //Create arrow button, position and name it
            UIButton rightArrow = CreateButton(UIButton.ButtonType.Default, 0, 0, uiParent.transform, "");

            rightArrow.name = "RightArrow";
            rightArrow.transform.localScale    = new Vector3(0.4f, 0.8f, 1f);
            rightArrow.transform.localPosition = new Vector3(1.8f, 0f, -0.2f);
            //Replace gfx and position it
            Destroy(rightArrow.transform.Find("ModUIElement").Find("Root").Find("Background").gameObject);
            GameObject rArrow = Instantiate(rightArrowOriginal, rightArrow.transform.Find("ModUIElement").Find("Root"));

            rArrow.transform.localScale       = new Vector3(-2f, 1f, 1f); //The -2 flips the gfx horizontally
            rArrow.transform.localPosition    = new Vector3(0.5f, 0f, 0f);
            rArrow.transform.localEulerAngles = Vector3.zero;
            //Remove logic components from the gfx
            Destroy(rArrow.GetComponent <GuiClickable>());
            Destroy(rArrow.GetComponent <GuiClickRect>());
            Destroy(rArrow.GetComponent <GuiChangeEffect_ClickUpdSlider>());

            //Create title
            UITextFrame title = CreateTextFrame(0f, 0f, uiParent.transform);

            title.name = "UIName";
            title.transform.localPosition = new Vector3(0f, 0.65f, 0.6f);
            title.transform.localScale   *= 0.8f;
            title.ScaleText(1.25f);
            title.ScaleBackground(new Vector2(0.625f, 1f));

            //Assign component
            UIListExplorer output = uiParent.AddComponent <UIListExplorer>();

            output.Initialize();
            output.UIName = name;

            return(output);
        }