public override GameObject CreateObject(Transform parent) { GameObject gameObject = MonoBehaviour.Instantiate(safePrefab, parent, false); gameObject.name = "BSMLDropdownList"; SimpleTextDropdown dropdown = gameObject.GetComponentInChildren <SimpleTextDropdown>(); dropdown.gameObject.SetActive(false); dropdown.name = "Dropdown"; dropdown.GetComponentInChildren <VRGraphicRaycaster>(true).SetField("_physicsRaycaster", BeatSaberUI.PhysicsRaycasterWithCache); dropdown.GetComponentInChildren <ModalView>(true).SetField("_container", BeatSaberUI.DiContainer); ExternalComponents externalComponents = dropdown.gameObject.AddComponent <ExternalComponents>(); GameObject labelObject = gameObject.transform.Find("Label").gameObject; MonoBehaviour.Destroy(labelObject.GetComponent <LocalizedTextMeshProUGUI>()); externalComponents.components.Add(gameObject.transform.Find("Label").GetComponent <CurvedTextMeshPro>()); LayoutElement layoutElement = gameObject.AddComponent <LayoutElement>(); layoutElement.preferredHeight = 8; layoutElement.preferredWidth = 90; externalComponents.components.Add(layoutElement); DropDownListSetting dropDownListSetting = dropdown.gameObject.AddComponent <DropDownListSetting>(); dropDownListSetting.dropdown = dropdown; dropdown.gameObject.SetActive(true); gameObject.SetActive(true); return(dropdown.gameObject); }
public override GameObject CreateObject(Transform parent) { GameObject gameObject = base.CreateObject(parent); ExternalComponents externalComponents = gameObject.GetComponent <ExternalComponents>(); RectTransform windowTransform = externalComponents.Get <RectTransform>(); windowTransform.name = "BSMLModalKeyboard"; windowTransform.sizeDelta = new Vector2(135, 75); RectTransform parentTransform = new GameObject("KeyboardParent").AddComponent <RectTransform>(); parentTransform.SetParent(gameObject.transform, false); KEYBOARD keyboard = new KEYBOARD(parentTransform, KEYBOARD.QWERTY, true, 4, -12); parentTransform.localScale *= 1.4f; ModalKeyboard modalKeyboard = gameObject.AddComponent <ModalKeyboard>(); modalKeyboard.keyboard = keyboard; modalKeyboard.modalView = externalComponents.Get <ModalView>(); keyboard.EnterPressed += delegate(string value) { modalKeyboard.OnEnter(value); }; return(gameObject); }
public override GameObject CreateObject(Transform parent) { if (buttonPrefab == null) { buttonPrefab = Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == PrefabButton)); } Button button = Object.Instantiate(buttonPrefab, parent, false); button.name = "BSMLButton"; button.interactable = true; button.GetComponentInChildren <Polyglot.LocalizedTextMeshProUGUI>(true).TryDestroy(); ExternalComponents externalComponents = button.gameObject.AddComponent <ExternalComponents>(); TextMeshProUGUI textMesh = button.GetComponentInChildren <TextMeshProUGUI>(); textMesh.richText = true; externalComponents.components.Add(textMesh); Object.Destroy(button.transform.Find("Content").GetComponent <LayoutElement>()); var bgImage = button.transform.Find("BG").gameObject.GetComponent <ImageView>(); button.gameObject.GetComponent <ButtonStaticAnimations>().TryDestroy(); var buttonStateColors = button.gameObject.AddComponent <ButtonStateColors>(); buttonStateColors.Image = bgImage; buttonStateColors.NormalColor = _defaultNormalColor; buttonStateColors.HoveredColor = _defaultHoveredColor; buttonStateColors.SelectionDidChange(NoTransitionsButton.SelectionState.Normal); button.gameObject.GetComponent <NoTransitionsButton>().selectionStateDidChangeEvent += buttonStateColors.SelectionDidChange; var buttonImageController = button.gameObject.AddComponent <ButtonImageController>(); buttonImageController.BackgroundImage = bgImage; buttonImageController.LineImage = button.transform.Find("Underline").gameObject.GetComponent <ImageView>(); buttonImageController.ShowLine(false); ContentSizeFitter buttonSizeFitter = button.gameObject.AddComponent <ContentSizeFitter>(); buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; // miss me with those small ass buttons button.gameObject.GetComponent <LayoutElement>().preferredHeight = 10; LayoutGroup stackLayoutGroup = button.GetComponentInChildren <LayoutGroup>(); if (stackLayoutGroup != null) { externalComponents.components.Add(stackLayoutGroup); } return(button.gameObject); }
public override GameObject CreateObject(Transform parent) { if (buttonPrefab == null) { buttonPrefab = Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == PrefabButton)); } Button button = MonoBehaviour.Instantiate(buttonPrefab, parent, false); button.name = "BSMLButton"; button.interactable = true; ExternalComponents externalComponents = button.gameObject.AddComponent <ExternalComponents>(); GameObject textObject = button.transform.Find("Content/Text").gameObject; LocalizedTextMeshProUGUI localizedText = ConfigureLocalizedText(textObject); externalComponents.components.Add(localizedText); TextMeshProUGUI textMesh = textObject.GetComponent <TextMeshProUGUI>(); textMesh.text = "Default Text"; textMesh.richText = true; externalComponents.components.Add(textMesh); GameObject.Destroy(button.transform.Find("Content").GetComponent <LayoutElement>()); ContentSizeFitter buttonSizeFitter = button.gameObject.AddComponent <ContentSizeFitter>(); buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; LayoutGroup stackLayoutGroup = button.GetComponentInChildren <LayoutGroup>(); if (stackLayoutGroup != null) { externalComponents.components.Add(stackLayoutGroup); } /* * Image glowImage = button.gameObject.GetComponentsInChildren<Image>(true).Where(x => x.gameObject.name == "Glow").FirstOrDefault(); * if (glowImage != null) * { * Glowable glowable = button.gameObject.AddComponent<Glowable>(); * glowable.image = glowImage; * glowable.SetGlow("none"); * } * * Image strokeImage = button.gameObject.GetComponentsInChildren<Image>(true).Where(x => x.gameObject.name == "Stroke").FirstOrDefault(); * if (strokeImage != null) * { * Strokable strokable = button.gameObject.AddComponent<Strokable>(); * strokable.image = strokeImage; * strokable.SetType(StrokeType.Regular); * }*/ return(button.gameObject); }
public override GameObject CreateObject(Transform parent) { GameObject content = base.CreateObject(parent); ExternalComponents externalComponents = content.GetComponent <ExternalComponents>(); RectTransform scrollTransform = externalComponents.Get <RectTransform>(); scrollTransform.anchoredPosition = new Vector2(2, 6); scrollTransform.sizeDelta = new Vector2(0, -20); scrollTransform.gameObject.name = "BSMLScrollableSettingsContainer"; return(content); }
public override GameObject CreateObject(Transform parent) { GameObject gameObject = new GameObject(); gameObject.SetActive(false); gameObject.name = "BSMLModalView"; RectTransform rectTransform = gameObject.AddComponent <RectTransform>(); rectTransform.SetParent(parent, false); rectTransform.anchorMin = new Vector2(0.5f, 0.5f); rectTransform.anchorMax = new Vector2(0.5f, 0.5f); rectTransform.sizeDelta = new Vector2(0, 0); ModalView modalView = gameObject.AddComponent <ModalView>(); ModalView yoinkFromView = Resources.FindObjectsOfTypeAll <ModalView>().First(x => x.name == "TableView"); modalView.SetPrivateField("_presentPanelAnimations", yoinkFromView.GetPrivateField <PanelAnimationSO>("_presentPanelAnimations")); modalView.SetPrivateField("_dismissPanelAnimation", yoinkFromView.GetPrivateField <PanelAnimationSO>("_dismissPanelAnimation")); GameObject child = new GameObject(); child.transform.SetParent(rectTransform, false); child.name = "Shadow"; RectTransform shadowTransform = child.gameObject.AddComponent <RectTransform>(); shadowTransform.anchorMin = new Vector2(0, 0); shadowTransform.anchorMax = new Vector2(1, 1); shadowTransform.sizeDelta = new Vector2(10, 10); child.gameObject.AddComponent <Backgroundable>().ApplyBackground("round-rect-panel-shadow"); child = new GameObject(); child.transform.SetParent(rectTransform, false); child.name = "Content"; RectTransform backgroundTransform = child.gameObject.AddComponent <RectTransform>(); backgroundTransform.anchorMin = new Vector2(0, 0); backgroundTransform.anchorMax = new Vector2(1, 1); backgroundTransform.sizeDelta = new Vector2(0, 0); Backgroundable backgroundable = child.gameObject.AddComponent <Backgroundable>(); backgroundable.ApplyBackground("round-rect-panel"); backgroundable.background.color = new Color(0.706f, 0.706f, 0.706f, 1); backgroundable.background.material = Resources.FindObjectsOfTypeAll <Material>().First(x => x.name == "UIFogBG"); ExternalComponents externalComponents = child.AddComponent <ExternalComponents>(); externalComponents.components.Add(modalView); externalComponents.components.Add(rectTransform); return(child); }
public override GameObject CreateObject(Transform parent) { GameObject gameObj = new GameObject("BSMLSubmenu"); gameObj.SetActive(false); ClickableText clickableText = gameObj.AddComponent <ClickableText>(); clickableText.font = BeatSaberUI.MainTextFont; clickableText.fontSharedMaterial = BeatSaberUI.MainUIFontMaterial; clickableText.rectTransform.SetParent(parent, false); clickableText.text = "Default Text"; clickableText.fontSize = 4; clickableText.fontStyle = FontStyles.Italic; clickableText.color = Color.white; clickableText.rectTransform.sizeDelta = new Vector2(90, 8); LocalizableText localizedText = CreateLocalizableText(gameObj); ViewController submenuController = BeatSaberUI.CreateViewController <ViewController>(); SettingsMenu.SetupViewControllerTransform(submenuController); clickableText.OnClickEvent += delegate { if (flow == null) { flow = Resources.FindObjectsOfTypeAll <ModSettingsFlowCoordinator>().FirstOrDefault(); } if (flow) { flow.OpenMenu(submenuController, true, false); } }; ExternalComponents externalComponents = submenuController.gameObject.AddComponent <ExternalComponents>(); externalComponents.components.Add(clickableText); externalComponents.components.Add(clickableText.rectTransform); externalComponents.components.Add(localizedText); gameObj.SetActive(true); return(submenuController.gameObject); }
public override GameObject CreateObject(Transform parent) { GameObject gameObject = base.CreateObject(parent); ExternalComponents externalComponents = gameObject.GetComponent <ExternalComponents>(); RectTransform windowTransform = externalComponents.Get <RectTransform>(); windowTransform.name = "BSMLModalColorPicker"; windowTransform.sizeDelta = new Vector2(135, 75); ModalColorPicker colorPicker = gameObject.AddComponent <ModalColorPicker>(); colorPicker.modalView = externalComponents.Get <ModalView>(); RGBPanelController rgbController = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <RGBPanelController>().First(x => x.name == "RGBColorPicker"), gameObject.transform, false); rgbController.name = "BSMLRGBPanel"; (rgbController.gameObject.transform as RectTransform).anchoredPosition = new Vector2(0, 3); (rgbController.gameObject.transform as RectTransform).anchorMin = new Vector2(0.1f, 0.73f); (rgbController.gameObject.transform as RectTransform).anchorMax = new Vector2(0.1f, 0.73f); colorPicker.rgbPanel = rgbController; rgbController.colorDidChangeEvent += colorPicker.OnChange; HSVPanelController hsvController = Object.Instantiate(Resources.FindObjectsOfTypeAll <HSVPanelController>().First(x => x.name == "HSVColorPicker"), gameObject.transform, false); hsvController.name = "BSMLHSVPanel"; (hsvController.gameObject.transform as RectTransform).anchoredPosition = new Vector2(0, 3); (hsvController.gameObject.transform as RectTransform).anchorMin = new Vector2(0.75f, 0.5f); (hsvController.gameObject.transform as RectTransform).anchorMax = new Vector2(0.75f, 0.5f); colorPicker.hsvPanel = hsvController; hsvController.colorDidChangeEvent += colorPicker.OnChange; Image colorImage = Object.Instantiate(Resources.FindObjectsOfTypeAll <Image>().First(x => x.gameObject.name == "ColorImage" && x.sprite?.name == "NoteCircle"), gameObject.transform, false); colorImage.name = "BSMLCurrentColor"; (colorImage.gameObject.transform as RectTransform).anchoredPosition = new Vector2(0, 0); (colorImage.gameObject.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f); (colorImage.gameObject.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f); colorPicker.colorImage = colorImage; BSMLParser.instance.Parse(@"<horizontal anchor-pos-y='-30' spacing='2' horizontal-fit='PreferredSize'><button text='Cancel' on-click='cancel' pref-width='30'/><button text='Done' on-click='done' pref-width='30'/></horizontal>", gameObject, colorPicker); return(gameObject); }
public override GameObject CreateObject(Transform parent) { Button button = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == (parent.GetComponent <StartMiddleEndButtonsGroup>() == null ? "PlayButton" : "CreditsButton"))), parent, false); button.name = "BSMLButton"; button.interactable = true; Polyglot.LocalizedTextMeshProUGUI localizer = button.GetComponentInChildren <Polyglot.LocalizedTextMeshProUGUI>(); if (localizer != null) { GameObject.Destroy(localizer); } ExternalComponents externalComponents = button.gameObject.AddComponent <ExternalComponents>(); externalComponents.components.Add(button.GetComponentInChildren <TextMeshProUGUI>()); HorizontalLayoutGroup horiztonalLayoutGroup = button.GetComponentInChildren <HorizontalLayoutGroup>(); if (horiztonalLayoutGroup != null) { externalComponents.components.Add(horiztonalLayoutGroup); } Image glowImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Glow").FirstOrDefault(); if (glowImage != null) { Glowable glowable = button.gameObject.AddComponent <Glowable>(); glowable.image = glowImage; glowable.SetGlow("none"); } Image strokeImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Stroke").FirstOrDefault(); if (strokeImage != null) { Strokable strokable = button.gameObject.AddComponent <Strokable>(); strokable.image = strokeImage; strokable.SetType(StrokeType.Regular); } return(button.gameObject); }
public async Task<ExternalJsComponent> GetExternalComponent(string componentName, JsExecutionContext executionContext) { if (!await ExternalComponents.ContainsKeyAsync(componentName)) { var mes = $"Компонент не найден по указанному названию '{componentName}'"; executionContext.ExecutionLogs.Add(new JsExecutionLog { EventIdName = EventIds.JsExecutorComponents.GetExternalComponentNotFound, Message = mes }); throw new InvalidOperationException(mes); } executionContext.ExecutionLogs.Add(new JsExecutionLog { EventIdName = EventIds.JsExecutorComponents.GetJsWorkerFound, Message = $"Компонент найден по указанному названию '{componentName}'", }); return await ExternalComponents.GetValueAsync(componentName); }
public override GameObject CreateObject(Transform parent) { GameplayModifierToggle baseModifier = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifierToggle>().First(x => (x.name == "InstaFail")), parent, false); baseModifier.name = "BSMLModifier"; GameObject gameObject = baseModifier.gameObject; MonoBehaviour.Destroy(baseModifier); MonoBehaviour.Destroy(gameObject.GetComponent <HoverHint>()); ExternalComponents externalComponents = gameObject.AddComponent <ExternalComponents>(); externalComponents.components.Add(gameObject.GetComponentInChildren <TextMeshProUGUI>()); externalComponents.components.Add(gameObject.transform.Find("Icon").GetComponent <Image>()); CheckboxSetting checkboxSetting = gameObject.AddComponent <CheckboxSetting>(); checkboxSetting.checkbox = gameObject.GetComponent <Toggle>(); return(gameObject); }
private Component GetExternalComponent(GameObject gameObject, Type type) { Component component = null; ExternalComponents externalComponents = gameObject.GetComponent <ExternalComponents>(); if (externalComponents != null) { foreach (Component externalComponent in externalComponents.components) { if (type.IsAssignableFrom(externalComponent.GetType())) { component = externalComponent; } } } if (component == null) { component = gameObject.GetComponent(type); } return(component); }
public override GameObject CreateObject(Transform parent) { GameObject gameObj = new GameObject("BSMLSubmenu"); gameObj.SetActive(false); ClickableText clickableText = gameObj.AddComponent <ClickableText>(); clickableText.font = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF No Glow")); clickableText.rectTransform.SetParent(parent, false); clickableText.text = "Default Text"; clickableText.fontSize = 4; clickableText.fontStyle = FontStyles.Italic; clickableText.color = Color.white; clickableText.rectTransform.sizeDelta = new Vector2(90, 8); ViewController submenuController = BeatSaberUI.CreateViewController <ViewController>(); SettingsMenu.SetupViewControllerTransform(submenuController); clickableText.OnClickEvent += delegate { ModSettingsFlowCoordinator settingsFlowCoordinator = Resources.FindObjectsOfTypeAll <ModSettingsFlowCoordinator>().FirstOrDefault(); if (settingsFlowCoordinator) { settingsFlowCoordinator.OpenMenu(submenuController, true, false); } }; ExternalComponents externalComponents = submenuController.gameObject.AddComponent <ExternalComponents>(); externalComponents.components.Add(clickableText); externalComponents.components.Add(clickableText.rectTransform); gameObj.SetActive(true); return(submenuController.gameObject); }
public override GameObject CreateObject(Transform parent) { TextPageScrollView textScrollView = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <ReleaseInfoViewController>().First().GetField <TextPageScrollView, ReleaseInfoViewController>("_textPageScrollView"), parent); textScrollView.name = "BSMLScrollView"; Button pageUpButton = textScrollView.GetField <Button, ScrollView>("_pageUpButton"); Button pageDownButton = textScrollView.GetField <Button, ScrollView>("_pageDownButton"); VerticalScrollIndicator verticalScrollIndicator = textScrollView.GetField <VerticalScrollIndicator, ScrollView>("_verticalScrollIndicator"); RectTransform viewport = textScrollView.GetField <RectTransform, ScrollView>("_viewport"); viewport.gameObject.AddComponent <VRGraphicRaycaster>().SetField("_physicsRaycaster", BeatSaberUI.PhysicsRaycasterWithCache); GameObject.Destroy(textScrollView.GetField <TextMeshProUGUI, TextPageScrollView>("_text").gameObject); GameObject gameObject = textScrollView.gameObject; MonoBehaviour.Destroy(textScrollView); gameObject.SetActive(false); BSMLScrollView scrollView = gameObject.AddComponent <BSMLScrollView>(); scrollView.SetField <ScrollView, Button>("_pageUpButton", pageUpButton); scrollView.SetField <ScrollView, Button>("_pageDownButton", pageDownButton); scrollView.SetField <ScrollView, VerticalScrollIndicator>("_verticalScrollIndicator", verticalScrollIndicator); scrollView.SetField <ScrollView, RectTransform>("_viewport", viewport); viewport.anchorMin = new Vector2(0, 0); viewport.anchorMax = new Vector2(1, 1); GameObject parentObj = new GameObject(); parentObj.name = "BSMLScrollViewContent"; parentObj.transform.SetParent(viewport, false); ContentSizeFitter contentSizeFitter = parentObj.AddComponent <ContentSizeFitter>(); contentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; VerticalLayoutGroup verticalLayout = parentObj.AddComponent <VerticalLayoutGroup>(); verticalLayout.childForceExpandHeight = false; verticalLayout.childForceExpandWidth = false; verticalLayout.childControlHeight = true; verticalLayout.childControlWidth = true; verticalLayout.childAlignment = TextAnchor.UpperCenter; RectTransform rectTransform = parentObj.transform as RectTransform; rectTransform.anchorMin = new Vector2(0, 1); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.sizeDelta = new Vector2(0, 0); rectTransform.pivot = new Vector2(0.5f, 1); //parentObj.AddComponent<LayoutElement>(); parentObj.AddComponent <ScrollViewContent>().scrollView = scrollView; GameObject child = new GameObject(); child.name = "BSMLScrollViewContentContainer"; child.transform.SetParent(rectTransform, false); VerticalLayoutGroup layoutGroup = child.AddComponent <VerticalLayoutGroup>(); layoutGroup.childControlHeight = false; layoutGroup.childForceExpandHeight = false; layoutGroup.childAlignment = TextAnchor.LowerCenter; layoutGroup.spacing = 0.5f; //parentObj.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; //child.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize; //child.AddComponent<LayoutElement>(); ExternalComponents externalComponents = child.AddComponent <ExternalComponents>(); externalComponents.components.Add(scrollView); externalComponents.components.Add(scrollView.transform); externalComponents.components.Add(gameObject.AddComponent <LayoutElement>()); (child.transform as RectTransform).sizeDelta = new Vector2(0, -1); scrollView.SetField <ScrollView, RectTransform>("_contentRectTransform", parentObj.transform as RectTransform); gameObject.SetActive(true); return(child); }