Example #1
0
        /// <summary>
        /// Create Settings UI using UnityEngine.UI
        /// </summary>
        public void CreateSettingsUI()
        {
            GameObject settingsView = ModUI.CreateParent("MSCLoader Settings", true);

            settingsView.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 450);
            settingsView.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
            settingsView.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
            settingsView.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);

            settings = settingsView.AddComponent <SettingsView>();
            settingsView.GetComponent <SettingsView>().settingView = settingsView;

            GameObject settingsViewC = ModUI.CreateUIBase("MSCLoader SettingsContainer", settingsView);

            settingsViewC.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 450);
            settingsViewC.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
            settingsViewC.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
            settingsViewC.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            settingsViewC.AddComponent <Image>().color             = Color.black;

            settingsView.GetComponent <SettingsView>().settingViewContainer = settingsViewC;

            GameObject title = ModUI.CreateTextBlock("Title", "Loaded Mods:", settingsViewC, TextAnchor.MiddleCenter, Color.white, false);

            title.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 20);
            title.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1);
            title.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1);
            title.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 1);
            title.GetComponent <Text>().fontSize           = 16;
            title.GetComponent <Text>().fontStyle          = FontStyle.Bold;

            GameObject goBack = ModUI.CreateUIBase("GoBackButton", title);

            goBack.GetComponent <RectTransform>().sizeDelta = new Vector2(80, 20);
            goBack.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0.5f);
            goBack.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0.5f);
            goBack.GetComponent <RectTransform>().pivot     = new Vector2(0, 0.5f);
            goBack.AddComponent <Image>();
            goBack.AddComponent <Button>().targetGraphic = goBack.GetComponent <Image>();
            ColorBlock cb = goBack.GetComponent <Button>().colors;

            cb.normalColor      = Color.black;
            cb.highlightedColor = Color.red;
            goBack.GetComponent <Button>().colors        = cb;
            goBack.GetComponent <Button>().targetGraphic = goBack.GetComponent <Image>();
            goBack.GetComponent <Button>().onClick.AddListener(() => settingsView.GetComponent <SettingsView>().goBack());

            settingsView.GetComponent <SettingsView>().goBackBtn = goBack;

            GameObject BtnTxt = ModUI.CreateTextBlock("Text", " < Back", goBack, TextAnchor.MiddleLeft, Color.white);

            BtnTxt.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            BtnTxt.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            BtnTxt.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
            BtnTxt.GetComponent <RectTransform>().sizeDelta = new Vector2(80, 20);
            BtnTxt.GetComponent <Text>().fontSize           = 16;
            goBack.SetActive(false);
            //modList
            GameObject modList = ModUI.CreateUIBase("ModList", settingsViewC);

            modList.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0);
            modList.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0);
            modList.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0);
            modList.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 430);
            modList.AddComponent <Image>().color             = Color.black;
            modList.AddComponent <Mask>().showMaskGraphic    = true;

            settingsView.GetComponent <SettingsView>().modList = modList;

            //ModView
            GameObject scrollbar = ModUI.CreateScrollbar(settingsViewC, 450, 10, 90);

            scrollbar.GetComponent <RectTransform>().anchorMin = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().pivot     = new Vector2(1, 1);

            GameObject modView = ModListS(modList, scrollbar, "ModView");

            settingsView.GetComponent <SettingsView>().modView = modView;

            GameObject modSettings = ModUI.CreateUIBase("ModSettings", settingsViewC);

            modSettings.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0);
            modSettings.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0);
            modSettings.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0);
            modSettings.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 430);
            modSettings.AddComponent <Image>().color             = Color.black;
            modSettings.AddComponent <Mask>().showMaskGraphic    = true;

            GameObject modSettingsView = ModListS(modSettings, scrollbar, "ModSettingsView");

            settingsView.GetComponent <SettingsView>().modSettings     = modSettings;
            settingsView.GetComponent <SettingsView>().ModSettingsView = modSettingsView;
            settingsView.GetComponent <SettingsView>().IDtxt           = ModUI.CreateTextBlock("ID", "", modSettingsView).GetComponent <Text>();
            settingsView.GetComponent <SettingsView>().Nametxt         = ModUI.CreateTextBlock("Name", "", modSettingsView).GetComponent <Text>();
            settingsView.GetComponent <SettingsView>().Versiontxt      = ModUI.CreateTextBlock("Version", "", modSettingsView).GetComponent <Text>();
            settingsView.GetComponent <SettingsView>().Authortxt       = ModUI.CreateTextBlock("Author", "", modSettingsView).GetComponent <Text>();

            //keybinds
            ModUI.Separator(modSettingsView, "Key Bindings");

            GameObject keybinds = ModUI.CreateUIBase("Keybinds", modSettingsView);

            keybinds.AddComponent <VerticalLayoutGroup>().spacing   = 5;
            settingsView.GetComponent <SettingsView>().keybindsList = keybinds;

            ModUI.Separator(modSettingsView);

            modSettings.SetActive(false);
        }