public override GameObject CreateObject(Transform parent) { if (pageTemplate == null) { pageTemplate = Resources.FindObjectsOfTypeAll <ReleaseInfoViewController>().First().GetField <TextPageScrollView, ReleaseInfoViewController>("_textPageScrollView"); } TextPageScrollView scrollView = Object.Instantiate(pageTemplate, parent); scrollView.name = "BSMLTextPageScrollView"; scrollView.enabled = true; TextMeshProUGUI textMesh = scrollView.GetField <TextMeshProUGUI, TextPageScrollView>("_text"); textMesh.text = "Default Text"; LocalizableText localizedText = CreateLocalizableText(textMesh.gameObject); textMesh.gameObject.AddComponent <TextPageScrollViewRefresher>().scrollView = scrollView; List <Component> components = scrollView.gameObject.AddComponent <ExternalComponents>().components; components.Add(textMesh); components.Add(localizedText); return(scrollView.gameObject); }
public override GameObject CreateObject(Transform parent) { TextPageScrollView scrollView = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <ReleaseInfoViewController>().First().GetField <TextPageScrollView, ReleaseInfoViewController>("_textPageScrollView"), parent); scrollView.name = "BSMLTextPageScrollView"; scrollView.enabled = true; TextMeshProUGUI textMesh = scrollView.GetField <TextMeshProUGUI, TextPageScrollView>("_text"); textMesh.gameObject.AddComponent <TextPageScrollViewRefresher>().scrollView = scrollView; scrollView.gameObject.AddComponent <ExternalComponents>().components.Add(textMesh); return(scrollView.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); }
public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams) { CustomListTableData tableData = componentType.component as CustomListTableData; ScrollView scrollView = tableData.tableView.GetField <ScrollView, TableView>("_scrollView"); if (componentType.data.TryGetValue("selectCell", out string selectCell)) { tableData.tableView.didSelectCellWithIdxEvent += delegate(TableView table, int index) { if (!parserParams.actions.TryGetValue(selectCell, out BSMLAction action)) { throw new Exception("select-cell action '" + componentType.data["onClick"] + "' not found"); } action.Invoke(table, index); }; } bool verticalList = true; if (componentType.data.TryGetValue("listDirection", out string listDirection)) { tableData.tableView.SetField <TableView, TableType>("_tableType", (TableType)Enum.Parse(typeof(TableType), listDirection)); scrollViewDirectionField.SetValue(scrollView, Enum.Parse(scrollViewDirectionField.FieldType, listDirection)); verticalList = listDirection.ToLower() != "horizontal"; } if (componentType.data.TryGetValue("listStyle", out string listStyle)) { tableData.Style = (ListStyle)Enum.Parse(typeof(ListStyle), listStyle); } if (componentType.data.TryGetValue("cellSize", out string cellSize)) { tableData.cellSize = Parse.Float(cellSize); } if (componentType.data.TryGetValue("expandCell", out string expandCell)) { tableData.expandCell = Parse.Bool(expandCell); } if (componentType.data.TryGetValue("alignCenter", out string alignCenter)) { tableData.tableView.SetField <TableView, bool>("_alignToCenter", Parse.Bool(alignCenter)); } if (componentType.data.TryGetValue("stickScrolling", out string stickScrolling)) { if (Parse.Bool(stickScrolling)) { scrollView.SetField("_platformHelper", BeatSaberUI.PlatformHelper); } } // We can only show the scroll bar for vertical lists if (verticalList && componentType.data.TryGetValue("showScrollbar", out string showScrollbar)) { if (Parse.Bool(showScrollbar)) { TextPageScrollView textScrollView = UnityEngine.Object.Instantiate(ScrollViewTag.ScrollViewTemplate, componentType.component.transform); Button pageUpButton = textScrollView.GetField <Button, ScrollView>("_pageUpButton"); Button pageDownButton = textScrollView.GetField <Button, ScrollView>("_pageDownButton"); VerticalScrollIndicator verticalScrollIndicator = textScrollView.GetField <VerticalScrollIndicator, ScrollView>("_verticalScrollIndicator"); RectTransform scrollBar = verticalScrollIndicator.transform.parent as RectTransform; scrollView.SetField("_pageUpButton", pageUpButton); scrollView.SetField("_pageDownButton", pageDownButton); scrollView.SetField("_verticalScrollIndicator", verticalScrollIndicator); scrollBar.SetParent(componentType.component.transform); GameObject.Destroy(textScrollView.gameObject); // Need to adjust scroll bar positioning scrollBar.anchorMin = new Vector2(1, 0); scrollBar.anchorMax = Vector2.one; scrollBar.offsetMin = Vector2.zero; scrollBar.offsetMax = new Vector2(8, 0); } } if (componentType.data.TryGetValue("data", out string value)) { if (!parserParams.values.TryGetValue(value, out BSMLValue contents)) { throw new Exception("value '" + value + "' not found"); } var tableDataValue = contents.GetValue(); if (!(tableDataValue is List <CustomCellInfo> tableDataList)) { throw new Exception($"Value '{value}' is not a List<CustomCellInfo>, which is required for custom-list"); } tableData.data = tableDataList; tableData.tableView.ReloadData(); } switch (tableData.tableView.tableType) { case TableType.Vertical: (componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(componentType.data.TryGetValue("listWidth", out string vListWidth) ? Parse.Float(vListWidth) : 60, tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string vVisibleCells) ? Parse.Float(vVisibleCells) : 7)); break; case TableType.Horizontal: (componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string hVisibleCells) ? Parse.Float(hVisibleCells) : 4), componentType.data.TryGetValue("listHeight", out string hListHeight) ? Parse.Float(hListHeight) : 40); break; } componentType.component.gameObject.GetComponent <LayoutElement>().preferredHeight = (componentType.component.gameObject.transform as RectTransform).sizeDelta.y; componentType.component.gameObject.GetComponent <LayoutElement>().preferredWidth = (componentType.component.gameObject.transform as RectTransform).sizeDelta.x; tableData.tableView.gameObject.SetActive(true); tableData.tableView.LazyInit(); if (componentType.data.TryGetValue("id", out string id)) { parserParams.AddEvent(id + "#PageUp", scrollView.PageUpButtonPressed); parserParams.AddEvent(id + "#PageDown", scrollView.PageDownButtonPressed); } }
public override GameObject CreateObject(Transform parent) { TextPageScrollView textScrollView = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <ReleaseInfoViewController>().First().GetField <TextPageScrollView, ReleaseInfoViewController>("_textPageScrollView"), parent); textScrollView.name = "BSMLScrollableSettingsContainer"; Button pageUpButton = textScrollView.GetField <Button, TextPageScrollView>("_pageUpButton"); Button pageDownButton = textScrollView.GetField <Button, TextPageScrollView>("_pageDownButton"); VerticalScrollIndicator verticalScrollIndicator = textScrollView.GetField <VerticalScrollIndicator, TextPageScrollView>("_verticalScrollIndicator"); RectTransform viewport = textScrollView.GetField <RectTransform, TextPageScrollView>("_viewport"); 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); RectTransform scrollTransform = scrollView.transform as RectTransform; scrollTransform.anchoredPosition = new Vector2(2, 6); scrollTransform.sizeDelta = new Vector2(0, -20); viewport.anchorMin = new Vector2(0.5f, 0.5f); viewport.anchorMax = new Vector2(0.5f, 0.5f); viewport.sizeDelta = new Vector2(90, 40); GameObject parentObj = new GameObject(); parentObj.name = "BSMLScrollableSettingsContent"; parentObj.transform.SetParent(viewport, false); VerticalLayoutGroup verticalLayout = parentObj.AddComponent <VerticalLayoutGroup>(); verticalLayout.childForceExpandHeight = false; verticalLayout.childForceExpandWidth = false; RectTransform rectTransform = parentObj.transform as RectTransform; rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(1, 1); rectTransform.sizeDelta = new Vector2(0, 0); parentObj.AddComponent <LayoutElement>(); GameObject child = new GameObject(); child.name = "BSMLScrollableSettingsContentContainer"; child.transform.SetParent(rectTransform, false); VerticalLayoutGroup layoutGroup = child.AddComponent <VerticalLayoutGroup>(); layoutGroup.childControlHeight = false; layoutGroup.childForceExpandHeight = false; layoutGroup.childAlignment = TextAnchor.MiddleCenter; layoutGroup.spacing = 0.5f; child.AddComponent <ContentSizeFitter>(); child.AddComponent <LayoutElement>(); child.AddComponent <ScrollViewContent>().scrollView = scrollView; (child.transform as RectTransform).sizeDelta = new Vector2(0, -1); scrollView.SetField <ScrollView, RectTransform>("_contentRectTransform", parentObj.transform as RectTransform); gameObject.SetActive(true); return(child); }
void OnEnable() { scrollView?.SetText(scrollView.GetField <TextMeshProUGUI, TextPageScrollView>("_text").text); scrollView?.RefreshButtons(); }