Example #1
0
        /*__________________________________________________________________________________________________________*/

        protected static void Create(Transform parent, Picker colorGrid, int buttonCount, GameObject lockerPrefab = null)
        {
#if SUBNAUTICA
            lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <Text>());
#elif BELOWZERO
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <TextMeshProUGUI>());
#endif

            textPrefab.fontSize = 12;
            textPrefab.color    = ScreenContentColor;

            float padding  = 10;
            float width    = padding + colorGrid.ButtonSize + (colorGrid.ButtonsPerRow * colorGrid.Spacing);
            int   rowCount = Mathf.CeilToInt(colorGrid.ButtonsPerPage / (float)colorGrid.ButtonsPerRow);
            float height   = 20 + colorGrid.ButtonSize + ((rowCount - 0.5f) * colorGrid.Spacing);

            var rt = colorGrid.rectTransform;
            // The first Vector2 positions the colorGrid on the locker horz / vert.
            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.6f), parent);
            RectTransformExtensions.SetSize(rt, width, height);

            colorGrid.background        = colorGrid.gameObject.AddComponent <Image>();
            colorGrid.background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("Background.png"));
            colorGrid.background.color  = new Color(1, 1, 1);

            for (int i = 0; i < buttonCount; ++i)
            {
                var colorButton = ColorPickerButton.Create(colorGrid.transform, colorGrid.ButtonSize, colorGrid.ButtonSize * 0.7f);
                colorGrid.buttons.Add(colorButton);
            }
        }
        public static CheckboxButton CreateCheckbox(Transform parent, Color color, TextMeshProUGUI textPrefab, string label, float width = 100)
        {
#endif
            var checkboxButton = new GameObject("Checkbox", typeof(RectTransform));
            var rt             = checkboxButton.transform as RectTransform;
            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, width, 20);
            rt.anchoredPosition = new Vector2(0, 0);

            var iconWidth = 20;
            var checkbox  = LockerPrefabShared.CreateIcon(rt, color, 0);
            RectTransformExtensions.SetSize(checkbox.rectTransform, iconWidth, iconWidth);
            checkbox.rectTransform.anchoredPosition = new Vector2(-width / 2 + iconWidth / 2, 0);

            var spacing = 5;
            var text    = LockerPrefabShared.CreateText(rt, textPrefab, color, 0, 10, label);
            RectTransformExtensions.SetSize(text.rectTransform, width - iconWidth - spacing, iconWidth);
            text.rectTransform.anchoredPosition = new Vector2(iconWidth / 2 + spacing, 0);
#if SN1
            text.alignment = TextAnchor.MiddleLeft;
#elif BZ
            text.alignment = TextAlignmentOptions.MidlineLeft;
#endif
            checkboxButton.AddComponent <BoxCollider2D>();

            var button = checkboxButton.AddComponent <CheckboxButton>();
            button.image   = checkbox;
            button.text    = text;
            button.UpColor = color;

            return(button);
        }
Example #3
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static PingColorButton Create(Transform parent, Color color, float iconWidth = 60, float editIconWidth = 30)
        {
            var button = new GameObject("ColorButton", typeof(RectTransform));
            var rt     = button.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, iconWidth, iconWidth);
            rt.anchoredPosition = new Vector2(0, 0);

            var icon = LockerPrefabShared.CreateIcon(rt, color, 0);

            icon.gameObject.name = "ColorIcon";
            RectTransformExtensions.SetSize(icon.rectTransform, iconWidth, iconWidth);
            icon.rectTransform.anchoredPosition = new Vector2(0, 0);

            var editIcon = LockerPrefabShared.CreateIcon(rt, color, 0);

            editIcon.gameObject.name = "EditIcon";
            RectTransformExtensions.SetSize(editIcon.rectTransform, editIconWidth, editIconWidth);
            editIcon.rectTransform.anchoredPosition = new Vector2(0, 0);
            editIcon.gameObject.SetActive(false);

            button.AddComponent <BoxCollider2D>();

            var pingColorButton = button.AddComponent <PingColorButton>();

            pingColorButton.image     = icon;
            pingColorButton.editImage = editIcon;

            var layout = pingColorButton.gameObject.AddComponent <LayoutElement>();

            layout.ignoreLayout = true;

            return(pingColorButton);
        }
        public void Initialize(Text textPrefab, GameObject batteryUI)
        {
            text = GameObject.Instantiate(textPrefab);
            text.gameObject.name = "PercentText";
            text.rectTransform.SetParent(transform, false);
            RectTransformExtensions.SetSize(text.rectTransform, 100, 100);

            float scale = 1 / 4.0f;

            var rt = batteryUI.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), transform);
            RectTransformExtensions.SetSize(rt, 136 * scale, 256 * scale);
            rt.anchoredPosition = new Vector2(0, 0);
            rt.localEulerAngles = new Vector3(0, 0, -90);
            bar          = batteryUI.transform.Find("Bar").GetComponent <Image>();
            bar.material = new Material(bar.material);
            Destroy(batteryUI.transform.Find("Text").gameObject);
            Destroy(batteryUI.transform.Find("Label").gameObject);

            bar.gameObject.SetActive(true);
            bar.transform.localScale = new Vector3(scale, scale, 1);

            text.transform.SetAsLastSibling();

            UpdateNoBattery();
        }
        internal static TextMeshProUGUI CreateText(Transform parent, TextMeshProUGUI prefab, Color color, int y, int size, string initial, string lockerType)
        {
            var text = new GameObject("TextMeshProUGUI", typeof(RectTransform)).AddComponent <TextMeshProUGUI>();
#endif
            var rt = text.rectTransform;

            // Positions the "Locker" label on the locker
            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);

            // The size of the Filter rectangle for each locker type
            if (lockerType == "Locker(Clone)")
            {
                RectTransformExtensions.SetSize(rt, 138, 200);
            }
            else
            {
                RectTransformExtensions.SetSize(rt, 112, 200);
            }

            rt.anchoredPosition = new Vector2(0, y);

            text.font     = prefab.font;
            text.fontSize = size;
            text.color    = color;
            text.text     = initial;

            return(text);
        }
        public static GameObject CreateNewText(string name, Transform parent, TextAnchor anchor)
        {
            Text prefab = GameObject.FindObjectOfType <HandReticle>().interactPrimaryText;

            if (prefab == null)
            {
                Logger.Log("Could not find text prefab! (HandReticle.interactPrimaryText)");
                return(null);
            }

            Text text = GameObject.Instantiate(prefab);

            text.gameObject.layer = parent.gameObject.layer;
            text.gameObject.name  = name;
            text.transform.SetParent(parent, false);
            text.transform.localScale = new Vector3(1, 1, 1);
            text.gameObject.SetActive(true);
            text.enabled  = true;
            text.text     = "";
            text.fontSize = 20;
            RectTransformExtensions.SetParams(text.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            text.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 700);
            text.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30);
            text.rectTransform.anchoredPosition = new Vector3(0, 0);
            text.alignment     = anchor;
            text.raycastTarget = false;

            return(text.gameObject);
        }
Example #7
0
        protected static void Create(Transform parent, Picker instance, int buttonCount)
        {
            var lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab   = Instantiate(lockerPrefab.GetComponentInChildren <Text>());

            textPrefab.fontSize = 12;
            textPrefab.color    = HabitatControlPanel.ScreenContentColor;

            var rt = instance.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, 1000 / 5.0f, (buttonCount <= 10 ? 400 : 900) / 5.0f);

            instance.background = instance.gameObject.AddComponent <Image>();

            for (int i = 0; i < buttonCount; ++i)
            {
                var colorButton = PickerButton.Create(instance.transform, ButtonSize, ButtonSize * 0.7f);
                instance.buttons.Add(colorButton);
            }

            instance.prevPageButton = PickerPageButton.Create(instance.transform, Color.white);
            (instance.prevPageButton.transform as RectTransform).anchoredPosition = new Vector2(-20, -70);

            instance.nextPageButton = PickerPageButton.Create(instance.transform, Color.white);
            (instance.nextPageButton.transform as RectTransform).anchoredPosition = new Vector2(20, -70);

            instance.pageText = LockerPrefabShared.CreateText(instance.transform, textPrefab, Color.white, 0, 10, "X/X");
            RectTransformExtensions.SetSize(instance.pageText.rectTransform, 20, 20);
            instance.pageText.rectTransform.anchoredPosition = new Vector2(0, -70);
        }
        private void Awake()
        {
            var buttonPositionCenter = new Vector2(0, 0);
            var buttonSpacing        = 104;

            var parent = GetComponentInChildren <Canvas>().transform;
            var color  = new Color32(189, 255, 255, 255);

            var text = new GameObject("label", typeof(RectTransform)).AddComponent <Text>();

            RectTransformExtensions.SetParams(text.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(text.rectTransform, 500, 140);
            text.rectTransform.anchoredPosition = buttonPositionCenter + new Vector2(0, 80);
            text.color         = GetComponentInChildren <Text>().color;
            text.text          = "Position";
            text.fontSize      = Mathf.FloorToInt(GetComponentInChildren <Text>().fontSize * 1.8f);
            text.font          = GetComponentInChildren <Text>().font;
            text.alignment     = TextAnchor.MiddleCenter;
            text.raycastTarget = false;

            for (int i = 0; i < 4; ++i)
            {
                var button = CheckboxButton.CreateCheckboxNoText(parent, color, 100);
                button.Initialize();
                button.toggled = false;
                button.rectTransform.anchoredPosition = buttonPositionCenter + new Vector2((-1.5f + i) * buttonSpacing, 0);
                var buttonIndex = i;
                button.onToggled = (bool toggled) => {
                    SetPosition(buttonIndex);
                };
                positionButtons.Add(button);
            }

            OnProtoDeserialize(null);
        }
        private void Init(TechType techType, bool first, bool last)
        {
            this.techType = techType;

            var quickSlots = GameObject.FindObjectOfType <uGUI_QuickSlots>();
            var bgSprite   = first ? quickSlots.spriteLeft : last ? quickSlots.spriteRight : quickSlots.spriteCenter;

            (transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, bgSprite.rect.width);
            (transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, bgSprite.rect.height);

            layout           = gameObject.AddComponent <LayoutElement>();
            layout.minWidth  = bgSprite.rect.width;
            layout.minHeight = bgSprite.rect.height;

            background               = gameObject.AddComponent <Image>();
            background.color         = new Color(1, 1, 1, 0.5f);
            background.raycastTarget = false;
            background.material      = quickSlots.materialBackground;
            background.sprite        = bgSprite;

            button = new GameObject(name, typeof(RectTransform)).AddComponent <PinButton>();
            var brt = button.transform as RectTransform;

            RectTransformExtensions.SetParams(brt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), transform);
            brt.anchoredPosition = new Vector2(0, 0);
            RectTransformExtensions.SetSize(brt, 30, 30);

            button.SetMode(PinButton.Mode.Cross);
            button.onClick += OnButtonClick;
        }
Example #10
0
        public static PickerButton Create(Transform parent, Text textPrefab, Action <AutosorterFilter> action, int width = 100, int height = 18)
        {
            var button = new GameObject("PickerButton", typeof(RectTransform)).AddComponent <PickerButton>();

            button.transform.SetParent(parent, false);

            button.background = new GameObject("Background", typeof(RectTransform)).AddComponent <Image>();
            RectTransformExtensions.SetParams(button.background.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), button.transform);
            RectTransformExtensions.SetSize(button.background.rectTransform, width * 10, height * 10);
            button.background.rectTransform.localScale = new Vector3(0.1f, 0.1f, 1);
            button.background.sprite = ImageUtils.Load9SliceSprite(Mod.GetAssetPath("MainMenuStandardSprite.png"), new RectOffset(Slice, Slice, Slice, Slice));
            button.background.color  = upColor;
            button.background.type   = Image.Type.Sliced;

            button.text = new GameObject("Text", typeof(RectTransform)).AddComponent <Text>();
            RectTransformExtensions.SetParams(button.text.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), button.transform);
            RectTransformExtensions.SetSize(button.text.rectTransform, width, height);
            button.text.color     = new Color(1, 1, 1);
            button.text.font      = textPrefab.font;
            button.text.fontSize  = 10;
            button.text.alignment = TextAnchor.MiddleCenter;

            button.onClick += action;

            return(button);
        }
Example #11
0
        internal static Canvas CreateCanvas(Transform parent)
        {
            var canvas = new GameObject("Canvas", typeof(RectTransform)).AddComponent <Canvas>();
            var t      = canvas.transform;

            t.SetParent(parent, false);
            canvas.sortingLayerID = 1;

            var raycaster = canvas.gameObject.AddComponent <uGUI_GraphicRaycaster>();

            var rt = t as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
            RectTransformExtensions.SetSize(rt, 1.7f, 3.0f);

            t.localPosition = new Vector3(0, 0, 0.345f);
            t.localRotation = new Quaternion(0, 1, 0, 0);
            t.localScale    = new Vector3(0.5f, 0.5f, 0.5f);

            canvas.scaleFactor            = 0.01f;
            canvas.renderMode             = RenderMode.WorldSpace;
            canvas.referencePixelsPerUnit = 100;

            var scaler = canvas.gameObject.AddComponent <CanvasScaler>();

            scaler.dynamicPixelsPerUnit = 20;

            return(canvas);
        }
Example #12
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static ColoredIconButton Create(Transform parent, Color color, Text textPrefab = null, string label = "", float width = 100, float iconWidth = 20)
        {
            var checkboxButton = new GameObject("Checkbox", typeof(RectTransform));
            var rt             = checkboxButton.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, width, 20);
            rt.anchoredPosition = new Vector2(0, 0);

            var checkbox = LockerPrefabShared.CreateIcon(rt, color, 0);

            RectTransformExtensions.SetSize(checkbox.rectTransform, iconWidth, iconWidth);
            checkbox.rectTransform.anchoredPosition = new Vector2(textPrefab != null ? -width / 2 + 10 : 0, 0);

            Text text = null;

            if (textPrefab != null)
            {
                var spacing = 5;
                text = LockerPrefabShared.CreateText(rt, textPrefab, color, 0, 10, label);
                RectTransformExtensions.SetSize(text.rectTransform, width - 20 - spacing, 20);
                text.rectTransform.anchoredPosition = new Vector2(10 + spacing, 0);
                text.alignment = TextAnchor.MiddleLeft;
            }

            checkboxButton.AddComponent <BoxCollider2D>();

            var button = checkboxButton.AddComponent <ColoredIconButton>();

            button.image   = checkbox;
            button.text    = text ?? null;
            button.UpColor = color;

            return(button);
        }
Example #13
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        protected static void Create(Transform parent, Picker instance, int buttonCount)
        {
            var lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab   = Instantiate(lockerPrefab.GetComponentInChildren <Text>());

            textPrefab.fontSize = 16;
            textPrefab.color    = ScreenContentColor;

            float padding  = 30;
            float width    = padding + instance.ButtonSize + ((instance.ButtonsPerRow - 1) * instance.Spacing) - 20;
            int   rowCount = Mathf.CeilToInt(instance.ButtonsPerPage / (float)instance.ButtonsPerRow);
            float height   = padding + instance.ButtonSize + ((rowCount - 0.5f) * instance.Spacing);

            var rt = instance.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, width, height);

            instance.background      = instance.gameObject.AddComponent <Image>();
            instance.background.type = Image.Type.Sliced;
            instance.background.rectTransform.anchoredPosition = new Vector2(0, -20);

            instance.pageText = LockerPrefabShared.CreateText(instance.transform, textPrefab, Color.white, 0, 10, "X/X");
            RectTransformExtensions.SetSize(instance.pageText.rectTransform, 30, 20);

            for (int i = 0; i < buttonCount; ++i)
            {
                var colorButton = ColorPickerButton.Create(instance.transform, instance.ButtonSize, instance.ButtonSize * 0.7f);
                instance.buttons.Add(colorButton);
            }

            instance.prevPageButton = ColorPickerPageButton.Create(instance.transform, Color.white);
            instance.nextPageButton = ColorPickerPageButton.Create(instance.transform, Color.white);
        }
Example #14
0
        private GameObject CreateModuleDisplay(Vector3 position, Quaternion rotation)
        {
            const float scale = 0.215f;

            Canvas    canvas = new GameObject("Canvas", typeof(RectTransform)).AddComponent <Canvas>();
            Transform t      = canvas.transform;

            t.SetParent(this.transform, false);
            canvas.sortingLayerID = 1;

            uGUI_GraphicRaycaster raycaster = canvas.gameObject.AddComponent <uGUI_GraphicRaycaster>();

            var rt = t as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
            RectTransformExtensions.SetSize(rt, 0.5f, 0.5f);

            t.localPosition = position;
            t.localRotation = rotation;
            t.localScale    = new Vector3(scale, scale, scale);

            canvas.scaleFactor            = 0.01f;
            canvas.renderMode             = RenderMode.WorldSpace;
            canvas.referencePixelsPerUnit = 100;

            CanvasScaler scaler = canvas.gameObject.AddComponent <CanvasScaler>();

            scaler.dynamicPixelsPerUnit = 20;

            uGUI_Icon icon = canvas.gameObject.AddComponent <uGUI_Icon>();

            return(canvas.gameObject);
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static CustomizeScreen Create(Transform parent, SaveDataEntry data, GameObject lockerPrefab = null)
        {
#if SUBNAUTICA
            lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <Text>());
#elif BELOWZERO
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <TextMeshProUGUI>());
#endif
            textPrefab.fontSize = 12;
            textPrefab.color    = CustomizeScreen.ScreenContentColor;

            var screen = new GameObject("CustomizeScreen", typeof(RectTransform)).AddComponent <CustomizeScreen>();
            RectTransformExtensions.SetParams(screen.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(screen.rectTransform, 114, 241);

            screen.background        = new GameObject("Background").AddComponent <Image>();
            screen.background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("CustomizeScreen.png"));
            RectTransformExtensions.SetParams(screen.background.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), screen.transform);
            RectTransformExtensions.SetSize(screen.background.rectTransform, 114, 241);

            screen.labelLabel = LockerPrefabShared.CreateText(screen.background.transform, textPrefab, ScreenContentColor, 100, 9, "Label:");
            RectTransformExtensions.SetSize(screen.labelLabel.rectTransform, 90, 40);
#if SUBNAUTICA
            screen.labelLabel.alignment = TextAnchor.MiddleLeft;
#elif BELOWZERO
            screen.labelLabel.alignment = TextAlignmentOptions.MidlineLeft;
#endif

            screen.label = LabelController.Create(data, screen.background.transform, lockerPrefab);
            screen.label.rectTransform.anchoredPosition = new Vector2(0, 80);

            screen.exitButton = ConfigureButton.Create(screen.background.transform, Color.white, 40);

            var startX = 0;
            var startY = 30;
            screen.labelColorSetting = ColorSetting.Create(screen.background.transform, "Label Color", lockerPrefab);
            screen.labelColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY);

            screen.iconColorSetting = ColorSetting.Create(screen.background.transform, "Icon Color", lockerPrefab);
            screen.iconColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - 19);

            screen.textColorSetting = ColorSetting.Create(screen.background.transform, "Filters Color", lockerPrefab);
            screen.textColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 2));

            screen.buttonsColorSetting = ColorSetting.Create(screen.background.transform, "Misc Color", lockerPrefab);
            screen.buttonsColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 3));

            screen.lockerColorSetting = ColorSetting.Create(screen.background.transform, "Locker Color", lockerPrefab);
            screen.lockerColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 4));

            screen.colorPicker = ColorPicker.Create(screen.background.transform, lockerPrefab);
            screen.colorPicker.gameObject.SetActive(false);
            screen.colorPicker.rectTransform.anchoredPosition = new Vector2(0, 30);

            return(screen);
        }
            private static bool Prefix(uGUI_SeamothHUD __instance)
            {
                var t = __instance.root.transform.parent.Find("TorpedoHud");

                if (t == null)
                {
                    var torpedoRoot = new GameObject("TorpedoHud", typeof(RectTransform)).AddComponent <TorpedoHudController>();
                    RectTransformExtensions.SetParams(torpedoRoot.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), __instance.root.transform.parent);
                }
                return(true);
            }
        private static Image CreateUnderline(Transform parent, int x)
        {
            var underline = new GameObject("Underline", typeof(RectTransform)).AddComponent <Image>();

            RectTransformExtensions.SetParams(underline.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(underline.rectTransform, 272 / 3, 78 / 3);
            underline.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("TitleUnderline.png"));
            underline.rectTransform.anchoredPosition = new Vector2(x, 90);

            return(underline);
        }
Example #18
0
        private void AddBrick(Color c, float x, float y)
        {
            var brick = new GameObject("Brick").AddComponent <Image>();

            RectTransformExtensions.SetParams(brick.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), transform);
            RectTransformExtensions.SetSize(brick.rectTransform, BrickWidth, BrickHeight);
            brick.rectTransform.anchoredPosition = new Vector2(x, y);
            brick.color = c;

            bricks.Add(brick.gameObject);
        }
        private static GameObject CreatePowerDisplay(string name, Transform parent, int x)
        {
            var go = new GameObject(name, typeof(RectTransform));
            var rt = go.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 1), new Vector2(0.5f, 0.5f), parent);
            rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 700);
            rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 800);
            rt.anchoredPosition = new Vector3(x, -425);

            return(go);
        }
        public static PickerCloseButton AddCloseButton(Transform parent)
        {
            var closeImage = new GameObject("CloseButton", typeof(RectTransform)).AddComponent <Image>();

            RectTransformExtensions.SetParams(closeImage.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(closeImage.rectTransform, 20, 20);
            closeImage.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("Close.png"));
            closeImage.rectTransform.anchoredPosition = new Vector2(0, -90);

            var closeButton = closeImage.gameObject.AddComponent <PickerCloseButton>();

            return(closeButton);
        }
Example #21
0
        public static SecretButton Create(Transform parent)
        {
            var button = new GameObject("SecretButton", typeof(RectTransform)).AddComponent <SecretButton>();

            RectTransformExtensions.SetParams(button.transform as RectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(button.transform as RectTransform, 15, 15);

            var image = button.gameObject.AddComponent <Image>();

            image.color = new Color(0, 0, 0, 0.0001f);

            return(button);
        }
Example #22
0
        internal static Image CreateIcon(Transform parent, Color color, int y)
        {
            var icon = new GameObject("Text", typeof(RectTransform)).AddComponent <Image>();
            var rt   = icon.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, 40, 40);

            rt.anchoredPosition = new Vector2(0, y);
            icon.color          = color;

            return(icon);
        }
Example #23
0
        internal static Image CreateBackground(Transform parent)
        {
            var background = new GameObject("Background", typeof(RectTransform)).AddComponent <Image>();
            var rt         = background.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, 114, 241);
            background.color = new Color(0, 0, 0);

            background.transform.localScale = new Vector3(0.01f, 0.01f, 1);
            background.type = Image.Type.Sliced;

            return(background);
        }
Example #24
0
        /*_____________________________________________________________________________________________________*/

        public static CustomizeScreen Create(Transform parent, SaveDataEntry data, GameObject lockerPrefab = null)
        {
#if SUBNAUTICA
            lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <Text>());
#elif BELOWZERO
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <TextMeshProUGUI>());
#endif
            textPrefab.fontSize = 12;
            textPrefab.color    = CustomizeScreen.ScreenContentColor;
            // The color picker settings
            var screen = new GameObject("CustomizeScreen", typeof(RectTransform)).AddComponent <CustomizeScreen>();
            RectTransformExtensions.SetParams(screen.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(screen.rectTransform, 114, 241);

            screen.background        = new GameObject("Background").AddComponent <Image>();
            screen.background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("CustomizeScreen.png"));
            // 1st = 2nd = 3rd = horizontal 4th = vertical positon of the color settings
            RectTransformExtensions.SetParams(screen.background.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.41f, 0.4f), screen.transform);
            RectTransformExtensions.SetSize(screen.background.rectTransform, 114, 220);

            screen.label = LabelController.Create(data, screen.background.transform, lockerPrefab);
            // The position of the LOCKER label
            screen.label.rectTransform.anchoredPosition = new Vector2(0, 70);
            // The position of the close (X) button on the color settings
            screen.exitButton = ConfigureButton.Create(screen.background.transform, Color.white, 0, -85);

            var startX = 0;
            var startY = 30;
            screen.lockerColorSetting = ColorSetting.Create(screen.background.transform, "Locker Color", lockerPrefab);
            screen.lockerColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY);

            screen.iconColorSetting = ColorSetting.Create(screen.background.transform, "Icon Color", lockerPrefab);
            screen.iconColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - 19);

            screen.textColorSetting = ColorSetting.Create(screen.background.transform, "Filters Color", lockerPrefab);
            screen.textColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 2));

            screen.buttonsColorSetting = ColorSetting.Create(screen.background.transform, "Misc Color", lockerPrefab);
            screen.buttonsColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 3));

            screen.labelColorSetting = ColorSetting.Create(screen.background.transform, "Label Color", lockerPrefab);
            screen.labelColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 4));

            screen.colorPicker = ColorPicker.Create(screen.background.transform, lockerPrefab);
            screen.colorPicker.gameObject.SetActive(false);
            screen.colorPicker.rectTransform.anchoredPosition = new Vector2(0, 30);

            return(screen);
        }
Example #25
0
        public static Text InstantiateNewText(string name, Transform parent)
        {
            var text = GameObject.Instantiate(GetTextPrefab());

            text.gameObject.layer = parent.gameObject.layer;
            text.gameObject.name  = name;
            text.transform.SetParent(parent, false);
            text.transform.localScale = new Vector3(1, 1, 1);
            text.gameObject.SetActive(true);
            text.enabled = true;

            RectTransformExtensions.SetParams(text.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            text.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
            text.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);
            return(text);
        }
Example #26
0
        /*_____________________________________________________________________________________________________*/

        public static ColorSetting Create(Transform parent, string label, GameObject lockerPrefab = null)
        {
#if SUBNAUTICA
            lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <Text>());
#elif BELOWZERO
            var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren <TextMeshProUGUI>());
#endif

            var beaconController = new GameObject("ColorSettings", typeof(RectTransform)).AddComponent <ColorSetting>();
            var rt = beaconController.gameObject.transform as RectTransform;
            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            beaconController.Initialize(textPrefab, label);

            return(beaconController);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        public static ColorSetting Create(Transform parent, string label)
        {
            var lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab   = Instantiate(lockerPrefab.GetComponentInChildren <Text>());

            textPrefab.fontSize = 12;
            textPrefab.color    = new Color32(66, 134, 244, 255);

            var beaconController = new GameObject("ColorSettings", typeof(RectTransform)).AddComponent <ColorSetting>();
            var rt = beaconController.gameObject.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            beaconController.Initialize(textPrefab, label);

            return(beaconController);
        }
Example #28
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        public static HabitatNameController Create(HabitatControlPanel controlPanel, Transform parent)
        {
            var lockerPrefab = Resources.Load <GameObject>("Submarine/Build/SmallLocker");
            var textPrefab   = Instantiate(lockerPrefab.GetComponentInChildren <Text>());

            textPrefab.fontSize = 12;
            textPrefab.color    = HabitatControlPanel.ScreenContentColor;

            var habitatNameController = new GameObject("HabitatNameController", typeof(RectTransform)).AddComponent <HabitatNameController>();
            var rt = habitatNameController.gameObject.transform as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            habitatNameController.Initialize(controlPanel, textPrefab);

            return(habitatNameController);
        }
Example #29
0
        internal static Text CreateText(Transform parent, Text prefab, Color color, int y, int size, string initial)
        {
            var text = new GameObject("Text", typeof(RectTransform)).AddComponent <Text>();
            var rt   = text.rectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent);
            RectTransformExtensions.SetSize(rt, 120, 200);
            rt.anchoredPosition = new Vector2(0, y);

            text.font      = prefab.font;
            text.fontSize  = size;
            text.color     = color;
            text.alignment = TextAnchor.MiddleCenter;
            text.text      = initial;

            return(text);
        }
Example #30
0
        internal static Canvas CreateModuleDisplay(GameObject anchor, Vector3 position, Quaternion rotation, TechType startingState)
        {
            const float scale = 0.215f;

            Canvas    canvas = new GameObject("Canvas", typeof(RectTransform)).AddComponent <Canvas>();
            Transform t      = canvas.transform;

            t.SetParent(anchor.transform, false);
            canvas.sortingLayerID = 1;

            uGUI_GraphicRaycaster raycaster = canvas.gameObject.AddComponent <uGUI_GraphicRaycaster>();

            var rt = t as RectTransform;

            RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
            RectTransformExtensions.SetSize(rt, 0.5f, 0.5f);

            t.localPosition = position;
            t.localRotation = rotation;
            t.localScale    = new Vector3(scale, scale, scale);

            canvas.scaleFactor            = 0.01f;
            canvas.renderMode             = RenderMode.WorldSpace;
            canvas.referencePixelsPerUnit = 100;

            CanvasScaler scaler = canvas.gameObject.AddComponent <CanvasScaler>();

            scaler.dynamicPixelsPerUnit = 20;

            uGUI_Icon icon = canvas.gameObject.AddComponent <uGUI_Icon>();

            if (startingState > TechType.None)
            {
                icon.sprite  = SpriteManager.Get(startingState);
                icon.enabled = true;
                canvas.gameObject.SetActive(true);
            }
            else
            {
                canvas.gameObject.SetActive(false);
                icon.enabled = false;
            }

            return(canvas);
        }