Example #1
0
        public void CreateConsoleUI()
        {
            //Create parent gameobject for console.
            consoleObj = ModUI.CreateParent("MSCLoader Console", false);
            consoleObj.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().sizeDelta = new Vector2(346, 150);
            console = consoleObj.AddComponent <ConsoleView>();

            //Create console container
            GameObject consoleObjc = ModUI.CreateUIBase("MSCLoader ConsoleContainer", consoleObj);

            consoleObjc.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleObjc.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            consoleObjc.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            consoleObjc.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);

            consoleObj.GetComponent <ConsoleView>().viewContainer = consoleObjc; //set viewContainer in ConsoleView.cs
            //console = consoleObj.GetComponent<ConsoleView>();

            //Create input field
            GameObject consoleInput = ModUI.CreateInputField("InputField", "Enter command...", consoleObjc, 322, 30);

            consoleInput.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleInput.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            consoleInput.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            consoleInput.GetComponent <InputField>().onEndEdit.AddListener(delegate { consoleObj.GetComponent <ConsoleView>().runCommand(); });

            consoleObj.GetComponent <ConsoleView>().inputField = consoleInput.GetComponent <InputField>();

            //Submit button
            GameObject enterBtn = ModUI.CreateButton("SubmitBtn", ">", consoleObjc, 24, 30);

            enterBtn.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
            enterBtn.GetComponent <RectTransform>().anchorMax = new Vector2(1, 0);
            enterBtn.GetComponent <RectTransform>().pivot     = new Vector2(1, 0);
            enterBtn.GetComponent <Button>().onClick.AddListener(() => consoleObj.GetComponent <ConsoleView>().runCommand());

            //Log view text
            logView = ModUI.CreateUIBase("LogView", consoleObjc);
            logView.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().sizeDelta = new Vector2(333, 120);
            logView.AddComponent <Image>().color             = Color.black;
            logView.AddComponent <Mask>().showMaskGraphic    = true;

            GameObject logViewTxt = ModUI.CreateTextBlock("LogText", ">", logView, TextAnchor.LowerLeft, Color.white, false);

            logViewTxt.GetComponent <RectTransform>().anchorMin       = new Vector2(0, 0);
            logViewTxt.GetComponent <RectTransform>().anchorMax       = new Vector2(1, 0);
            logViewTxt.GetComponent <RectTransform>().pivot           = new Vector2(0.5f, 0);
            logViewTxt.GetComponent <RectTransform>().sizeDelta       = new Vector2(0, 1425);
            logViewTxt.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            consoleObj.GetComponent <ConsoleView>().logTextArea   = logViewTxt.GetComponent <Text>();
            logView.AddComponent <ScrollRect>().content           = logViewTxt.GetComponent <RectTransform>();
            logView.GetComponent <ScrollRect>().horizontal        = false;
            logView.GetComponent <ScrollRect>().inertia           = false;
            logView.GetComponent <ScrollRect>().movementType      = ScrollRect.MovementType.Clamped;
            logView.GetComponent <ScrollRect>().scrollSensitivity = 30f;

            //Scrollbar
            scrollbar = ModUI.CreateScrollbar(consoleObjc, 13, 120, Scrollbar.Direction.BottomToTop);
            scrollbar.GetComponent <RectTransform>().anchorMin        = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().anchorMax        = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().pivot            = new Vector2(0, 1);
            scrollbar.GetComponent <RectTransform>().anchoredPosition = new Vector2(-13, 0);

            logView.GetComponent <ScrollRect>().verticalScrollbar = scrollbar.GetComponent <Scrollbar>();
        }
Example #2
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);
        }