public void modButton(string name, string version, string author, Mod mod) { GameObject modButton = ModUI.CreateUIBase("ModButton", modView); modButton.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); modButton.AddComponent <Image>().color = Color.white; modButton.AddComponent <LayoutElement>().minHeight = 50; modButton.AddComponent <Button>().targetGraphic = modButton.GetComponent <Image>(); ColorBlock cb = modButton.GetComponent <Button>().colors; cb.normalColor = new Color32(0x00, 0xB4, 0xFF, 0x64); //00B4FF64 cb.highlightedColor = new Color32(0x00, 0xFF, 0x2B, 0x64); //00FF2B64 modButton.GetComponent <Button>().colors = cb; modButton.AddComponent <ModInfo>().mod = mod; GameObject modName = ModUI.CreateTextBlock("Name", name, modButton, TextAnchor.UpperLeft, Color.green); modName.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1); modName.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1); modName.GetComponent <RectTransform>().pivot = new Vector2(0, 1); modName.GetComponent <RectTransform>().anchoredPosition = new Vector2(2, 0); modName.GetComponent <Text>().fontStyle = FontStyle.Bold; modName.GetComponent <Text>().fontSize = 18; modName.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize; modName.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; GameObject modVersion = ModUI.CreateTextBlock("Version", string.Format("v{0}", version), modButton, TextAnchor.LowerLeft, Color.yellow); modVersion.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); modVersion.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0); modVersion.GetComponent <RectTransform>().pivot = new Vector2(0, 0); modVersion.GetComponent <RectTransform>().anchoredPosition = new Vector2(2, 0); modVersion.GetComponent <Text>().fontSize = 16; modVersion.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize; modVersion.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; GameObject modAuthor = ModUI.CreateTextBlock("Author", author, modButton, TextAnchor.LowerRight, Color.yellow); modAuthor.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0); modAuthor.GetComponent <RectTransform>().anchorMax = new Vector2(1, 0); modAuthor.GetComponent <RectTransform>().pivot = new Vector2(1, 0); modAuthor.GetComponent <RectTransform>().anchoredPosition = new Vector2(-2, 0); modAuthor.GetComponent <Text>().fontSize = 16; modAuthor.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize; modAuthor.GetComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; modButton.GetComponent <Button>().onClick.AddListener(() => settingView.GetComponent <SettingsView>().selectMod()); }
/// <summary> /// Print information about ModLoader in MainMenu scene. /// </summary> private static void MainMenuInfo(bool destroy = false) { //Create parent gameobject in canvas for layout and text information. GameObject modInfo = ModUI.CreateUIBase("MSCLoader Info", GameObject.Find("MSCLoader Canvas")); modInfo.AddComponent <VerticalLayoutGroup>().childForceExpandHeight = false; modInfo.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1); modInfo.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1); modInfo.GetComponent <RectTransform>().pivot = new Vector2(0, 1); //check if new version is available if (!experimental) { try { string version; using (WebClient client = new WebClient()) { version = client.DownloadString("http://my-summer-car.ml/version.txt"); } int i = Version.CompareTo(version.Trim()); if (i != 0) { ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready! (<color=orange>New version available: <b>v{1}</b></color>)", Version, version.Trim()), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; } else if (i == 0) { ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready! (<color=lime>Up to date</color>)", Version, i.ToString()), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; } } catch (Exception e) { ModConsole.Error(string.Format("Check for new version failed with error: {0}", e.Message)); ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready!", Version), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; } } else { ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready! (<color=magenta>Experimental</color>)", Version), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; } ModUI.CreateTextBlock("MSCLoader Mod location Text", string.Format("Mods folder: {0}", ModsFolder), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow; }
private static GameObject ModListS(GameObject modList, GameObject scrollbar, string name) { GameObject modView = ModUI.CreateUIBase(name, modList); modView.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1); modView.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1); modView.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 1); modView.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 430); modView.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; modView.AddComponent <VerticalLayoutGroup>().padding = new RectOffset(5, 5, 5, 5); modView.GetComponent <VerticalLayoutGroup>().spacing = 5; modView.GetComponent <VerticalLayoutGroup>().childAlignment = TextAnchor.UpperCenter; modView.GetComponent <VerticalLayoutGroup>().childForceExpandHeight = false; modList.AddComponent <ScrollRect>().content = modView.GetComponent <RectTransform>(); modList.GetComponent <ScrollRect>().horizontal = false; modList.GetComponent <ScrollRect>().inertia = false; modList.GetComponent <ScrollRect>().movementType = ScrollRect.MovementType.Clamped; modList.GetComponent <ScrollRect>().scrollSensitivity = 30f; modList.GetComponent <ScrollRect>().verticalScrollbar = scrollbar.GetComponent <Scrollbar>(); return(modView); }
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>(); }
public void KeyBindsList(string name, KeyCode modifier, KeyCode key, string ID) { GameObject keyBind = ModUI.CreateUIBase("KeyBind", keybindsList); keyBind.AddComponent <LayoutElement>().preferredHeight = 35; keyBind.AddComponent <KeyBinding>(); GameObject keyName = ModUI.CreateTextBlock("Key Name", name, keyBind, TextAnchor.MiddleLeft); keyName.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1); keyName.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1); keyName.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 1); keyName.GetComponent <RectTransform>().sizeDelta = new Vector2(290, 17); GameObject keyButton = ModUI.CreateUIBase("Modifier Button", keyBind); keyButton.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0); keyButton.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0); keyButton.GetComponent <RectTransform>().pivot = new Vector2(0, 0); keyButton.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17); keyButton.AddComponent <Image>(); keyButton.AddComponent <Button>().targetGraphic = keyButton.GetComponent <Image>(); ColorBlock cb = keyButton.GetComponent <Button>().colors; cb.normalColor = new Color32(0x14, 0x14, 0x14, 0xFF); cb.highlightedColor = new Color32(0x50, 0x50, 0x50, 0xFF); cb.pressedColor = new Color32(0x64, 0x64, 0x64, 0xFF); keyButton.GetComponent <Button>().colors = cb; keyButton.GetComponent <Button>().targetGraphic = keyButton.GetComponent <Image>(); GameObject BtnTxt = ModUI.CreateTextBlock("Text", "", keyButton, TextAnchor.MiddleCenter, Color.white); BtnTxt.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f); BtnTxt.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f); BtnTxt.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); BtnTxt.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17); keyBind.GetComponent <KeyBinding>().modifierButton = keyButton; keyBind.GetComponent <KeyBinding>().modifierDisplay = BtnTxt.GetComponent <Text>(); GameObject plus = ModUI.CreateTextBlock("Text", "+", keyBind, TextAnchor.MiddleCenter, Color.white); plus.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0); plus.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0); plus.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0); plus.GetComponent <RectTransform>().sizeDelta = new Vector2(10, 17); plus.GetComponent <Text>().fontStyle = FontStyle.Bold; plus.GetComponent <Text>().resizeTextForBestFit = true; GameObject keyButton2 = ModUI.CreateUIBase("Keybind Button", keyBind); keyButton2.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0); keyButton2.GetComponent <RectTransform>().anchorMax = new Vector2(1, 0); keyButton2.GetComponent <RectTransform>().pivot = new Vector2(1, 0); keyButton2.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17); keyButton2.AddComponent <Image>(); keyButton2.AddComponent <Button>().targetGraphic = keyButton2.GetComponent <Image>(); keyButton2.GetComponent <Button>().colors = cb; keyButton2.GetComponent <Button>().targetGraphic = keyButton2.GetComponent <Image>(); GameObject BtnTxt2 = ModUI.CreateTextBlock("Text", "", keyButton2, TextAnchor.MiddleCenter, Color.white); BtnTxt2.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f); BtnTxt2.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f); BtnTxt2.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); BtnTxt2.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17); keyBind.GetComponent <KeyBinding>().keyButton = keyButton2; keyBind.GetComponent <KeyBinding>().keyDisplay = BtnTxt2.GetComponent <Text>(); keyBind.GetComponent <KeyBinding>().key = key; keyBind.GetComponent <KeyBinding>().modifierKey = modifier; keyBind.GetComponent <KeyBinding>().mod = selected; keyBind.GetComponent <KeyBinding>().id = ID; keyBind.GetComponent <KeyBinding>().LoadBind(); }
/// <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); }