Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
        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);
        }
Esempio n. 5
0
        private static void PatchSmallLocker(uGUI_SignInput __instance)
        {
            __instance.inputField.lineType = InputField.LineType.MultiLineNewline;
            //__instance.inputField.lineType = TMPro.TMP_InputField.LineType.MultiLineNewline;
            //The Multiline Feature seems to be broken. It was switched to the TextMeshPro Libary and after this it worked agein.
            //For now waiting for the experimental Branch to get Stable to see if this can be fixed on SN too like BZ.
            __instance.inputField.characterLimit = Mod.Config.SmallLockerTextLimit;

            var rt = __instance.inputField.transform as RectTransform;

            RectTransformExtensions.SetSize(rt, rt.rect.width, TextFieldHeight);

            GameObject.Destroy(__instance.inputField.textComponent.GetComponent <ContentSizeFitter>());
            rt = __instance.inputField.textComponent.transform as RectTransform;
            RectTransformExtensions.SetSize(rt, rt.rect.width, TextFieldHeight);

            __instance.inputField.textComponent.alignment = TextAnchor.MiddleCenter;
            //__instance.inputField.textComponent.alignment = TMPro.TextAlignmentOptions.Center;
            //The TextAnchor Feature seems to be broken. It was switched to the TextMeshPro Libary and after this it worked agein.
            //For now waiting for the experimental Branch to get Stable to see if this can be fixed on SN too like BZ.

            if (Mod.Config.ColorPickerOnLockers)
            {
                var currentButton = __instance.transform.GetChild(1).GetComponent <Button>();
                var height        = Mod.Config.ExtraColorsOnLockers ? 1200 : 210;
                AddColorPickerSystem(__instance, currentButton, "LOCKER", -20, height);
            }
        }
Esempio n. 6
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);
        }
        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);
        }
Esempio n. 8
0
    GameObject PlayerBar(Entity playerMapEntity)
    {
        GameObject barObject = new GameObject("Player HP Bar");

        RectTransform rectTransform = barObject.AddComponent <RectTransform>();

        RectTransformExtensions.SetSize(rectTransform, new Vector2(70, 10));

        Sprite spriteBar = Resources.Load <Sprite>("simple_1_bar");
        Sprite spriteFg  = Resources.Load <Sprite>("simple_1_fg");

        EnergyBarUGUIBase.SpriteTex spriteFgTex = new EnergyBarUGUIBase.SpriteTex();
        spriteFgTex.sprite = spriteFg;

        List <EnergyBarUGUIBase.SpriteTex> foregroundSprites = new List <EnergyBarUGUIBase.SpriteTex>();

        foregroundSprites.Add(spriteFgTex);

        FilledRendererUGUI renderer = barObject.AddComponent <FilledRendererUGUI>();

        renderer.spriteBar         = spriteBar;
        renderer.spriteBarColor    = Color.green;
        renderer.spritesForeground = foregroundSprites;

        EnergyBar bar = barObject.AddComponent <EnergyBar>();

        EnergyBarFollowObject barFollow = barObject.AddComponent <EnergyBarFollowObject>();

        barFollow.followObject = playerMapEntity.gameObject.transform.Find("HP Bar Anchor").gameObject;

        return(barObject);
    }
Esempio n. 9
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);
        }
Esempio n. 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);
        }
Esempio n. 11
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);
        }
        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();
        }
        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;
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
    GameObject PlayerBar()
    {
        GameObject barObject = new GameObject("Player HP Bar");

        RectTransform rectTransform = barObject.AddComponent <RectTransform>();

        RectTransformExtensions.SetSize(rectTransform, new Vector2(150, 20));
        rectTransform.localPosition = new Vector3(Screen.width - 110, (Screen.height - (Screen.height - 65)), 0);

        Sprite spriteBar = Resources.Load <Sprite>("simple_1_bar");
        Sprite spriteFg  = Resources.Load <Sprite>("simple_1_fg");

        EnergyBarUGUIBase.SpriteTex spriteFgTex = new EnergyBarUGUIBase.SpriteTex();
        spriteFgTex.sprite = spriteFg;

        List <EnergyBarUGUIBase.SpriteTex> foregroundSprites = new List <EnergyBarUGUIBase.SpriteTex>();

        foregroundSprites.Add(spriteFgTex);

        FilledRendererUGUI renderer = barObject.AddComponent <FilledRendererUGUI>();

        renderer.spriteBar         = spriteBar;
        renderer.spriteBarColor    = Color.green;
        renderer.spritesForeground = foregroundSprites;

        EnergyBar bar = barObject.AddComponent <EnergyBar>();

        return(barObject);
    }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        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 void Init(IIngredient ingredient, Atlas.Sprite sprite, bool first, bool last)
        {
            this.ingredient = ingredient;
            bool mainIcon = ingredient == null;

            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, Mod.config.BackgroundAlpha);
            background.raycastTarget = false;
            background.material      = quickSlots.materialBackground;
            background.sprite        = bgSprite;

            icon = new GameObject("Icon").AddComponent <uGUI_ItemIcon>();
            icon.transform.SetParent(transform, false);
            icon.SetForegroundSprite(sprite);
            if (mainIcon)
            {
                icon.SetSize(Width, Width);
            }
            else
            {
                icon.SetSize(IconWidth, IconWidth);
            }
            icon.rectTransform.anchorMin        = new Vector2(0.5f, 0.5f);
            icon.rectTransform.anchorMax        = new Vector2(0.5f, 0.5f);
            icon.rectTransform.pivot            = new Vector2(0.5f, 0.5f);
            icon.rectTransform.anchoredPosition = new Vector2(0, 0);
            icon.raycastTarget = false;

            if (!mainIcon)
            {
                text = ModUtils.InstantiateNewText("Text", transform);
                RectTransformExtensions.SetSize(text.rectTransform, Width, Width);
                text.rectTransform.anchorMin        = new Vector2(0.5f, 0);
                text.rectTransform.anchorMax        = new Vector2(0.5f, 0);
                text.rectTransform.pivot            = new Vector2(0.5f, 0);
                text.rectTransform.anchoredPosition = new Vector2(0, 0);
                text.alignment     = TextAnchor.LowerCenter;
                text.fontSize      = Mod.config.FontSize;
                text.raycastTarget = false;

                ColorUtility.TryParseHtmlString(Mod.config.ColorblindMode ? IngredientColorGoodColorblind : IngredientColorGood, out goodColor);
                ColorUtility.TryParseHtmlString(Mod.config.ColorblindMode ? IngredientColorBadColorblind : IngredientColorBad, out badColor);
            }

            UpdateText();
        }
        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);
        }
Esempio n. 20
0
 public void initialize(TaskPanelItemType type, Content content)
 {
     this.ActiveContent = content;
     this.Type          = type;
     this.IconRectTransform.anchoredPosition = this.ActiveContent.IconOffset;
     RectTransformExtensions.SetSize(this.IconRectTransform, this.ActiveContent.IconSize);
     this.Sparkles.startColor = this.ActiveContent.SparklesColor;
     this.Sparkles.gameObject.SetActive(ConfigDevice.DeviceQuality() >= DeviceQualityType.Med);
     this.Glow.SetActive(ConfigDevice.DeviceQuality() >= DeviceQualityType.Med);
     this.refresh(null, null, 1, content.IconSprite);
 }
Esempio n. 21
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 void Initialize(SaveDataEntry data, Text textPrefab)
        {
            target = data;

            text                 = GameObject.Instantiate(textPrefab);
            text.fontSize        = 16;
            text.gameObject.name = "Text";
            text.rectTransform.SetParent(transform, false);
            RectTransformExtensions.SetSize(text.rectTransform, 140, 50);

            text.text = target.Label;
        }
Esempio n. 23
0
        private void Initialize(HabitatControlPanel controlPanel, Text textPrefab)
        {
            target = controlPanel;

            habitatNameText                 = GameObject.Instantiate(textPrefab);
            habitatNameText.fontSize        = 16;
            habitatNameText.gameObject.name = "HabitatNameText";
            habitatNameText.rectTransform.SetParent(transform, false);
            RectTransformExtensions.SetSize(habitatNameText.rectTransform, 140, 50);

            habitatNameText.text = target.HabitatLabel;
        }
Esempio n. 24
0
        public static ConfigureButton Create(Transform parent, Color color, float x)
        {
            var config = LockerPrefabShared.CreateIcon(parent, color, 0);

            RectTransformExtensions.SetSize(config.rectTransform, 20, 20);
            config.rectTransform.anchoredPosition = new Vector2(x, -104);

            config.gameObject.AddComponent <BoxCollider2D>();
            var button = config.gameObject.AddComponent <ConfigureButton>();

            return(button);
        }
Esempio n. 25
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);
        }
        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);
        }
Esempio n. 27
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);
        }
Esempio n. 28
0
        private static ConfigureButton CreateConfigureButton(Transform parent, Color color, AutosortTarget target)
        {
            var config = LockerPrefabShared.CreateIcon(parent, color, 0);

            RectTransformExtensions.SetSize(config.rectTransform, 20, 20);
            config.rectTransform.anchoredPosition = new Vector2(40, -104);

            config.gameObject.AddComponent <BoxCollider2D>();
            var button = config.gameObject.AddComponent <ConfigureButton>();

            button.target = target;

            return(button);
        }
Esempio n. 29
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);
        }
Esempio n. 30
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);
        }