private void OptionSelected(TableView view, CountersPlusListTableCell cell) { selectedGroup.OnCellSelect(view, cell.CellIdx); }
protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { rectTransform.anchorMax = new Vector2(1, 0.7f); try { if (firstActivation) { //Largely unchanged from CustomListController. Keep all of this. levelPackTableCellInstance = Resources.FindObjectsOfTypeAll <AnnotatedBeatmapLevelCollectionTableCell>().First(x => x.name == "AnnotatedBeatmapLevelCollectionTableCell"); RectTransform container = new GameObject("HorizontalListContainer", typeof(RectTransform)).transform as RectTransform; container.SetParent(rectTransform, false); container.sizeDelta = Vector2.zero; container.anchorMin = new Vector2(0.1f, 0); //Squish the list container a little bit container.anchorMax = new Vector2(0.9f, 1); //To make room for the forward/backward buttons var go = new GameObject("CustomListTableView", typeof(RectTransform), typeof(Touchable), typeof(EventSystemListener), typeof(ScrollRect)); go.SetActive(false); //Disable GameObject to not have scripts run. customListTableView = go.AddComponent <TableView>(); //Add TableView customListTableView.gameObject.AddComponent <RectMask2D>(); //Add Mask customListTableView.transform.SetParent(container, false); TVTableType(ref customListTableView) = TableView.TableType.Horizontal; (customListTableView.transform as RectTransform).anchorMin = Vector2.zero; (customListTableView.transform as RectTransform).anchorMax = Vector2.one; (customListTableView.transform as RectTransform).sizeDelta = Vector2.zero; (customListTableView.transform as RectTransform).anchoredPosition = Vector2.zero; TVPreallocCells(ref customListTableView) = new TableView.CellsGroup[0]; TVIsInitialized(ref customListTableView) = false; // Code copied from monkeymanboy's Beat Saber Custom Campaigns mod. Keep these too. PageLeftButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => x.name == "PageLeftButton"), transform); RectTransform buttonTransform = PageLeftButton.transform.Find("BG") as RectTransform; /*RectTransform glow = Instantiate(Resources.FindObjectsOfTypeAll<GameObject>().Last(x => (x.name == "GlowContainer")), PageLeftButton.transform).transform as RectTransform; * glow.localPosition = buttonTransform.localPosition; * glow.anchoredPosition = buttonTransform.anchoredPosition; * glow.anchorMin = buttonTransform.anchorMin; * glow.anchorMax = buttonTransform.anchorMax; * glow.sizeDelta = buttonTransform.sizeDelta;*/ PageLeftButton.transform.localPosition = new Vector3(-80, 2.5f, -5); (PageLeftButton.transform as RectTransform).anchoredPosition = Vector3.up * 2.5f; PageLeftButton.interactable = true; PageLeftButton.gameObject.SetActive(false); foreach (Transform child in PageLeftButton.transform) // These child transforms are offset from the actual hitbox; need to fix. { child.localPosition = new Vector3(7.5f, 0, 0); } PageRightButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => x.name == "PageRightButton"), transform); buttonTransform = PageRightButton.transform.Find("BG") as RectTransform; /*glow = Instantiate(Resources.FindObjectsOfTypeAll<GameObject>().Last(x => (x.name == "GlowContainer")), PageRightButton.transform).transform as RectTransform; * glow.localPosition = buttonTransform.localPosition; * glow.anchoredPosition = buttonTransform.anchoredPosition; * glow.anchorMin = buttonTransform.anchorMin; * glow.anchorMax = buttonTransform.anchorMax; * glow.sizeDelta = buttonTransform.sizeDelta;*/ PageRightButton.transform.localPosition = new Vector3(80, 2.5f, -5); (PageRightButton.transform as RectTransform).anchoredPosition = Vector3.up * 2.5f; PageRightButton.interactable = true; PageRightButton.gameObject.SetActive(false); foreach (Transform child in PageRightButton.transform) // These child transforms are offset from the actual hitbox; need to fix. { child.localPosition = new Vector3(-7.5f, 0, 0); } RectTransform viewport = new GameObject("Viewport").AddComponent <RectTransform>(); //Make a Viewport RectTransform viewport.SetParent(customListTableView.transform as RectTransform, false); //It expects one from a ScrollRect, so we have to make one ourselves. viewport.sizeDelta = Vector2.zero; //Important to set this to zero so the TableView can scroll through all available cells. TVPageUpButton(ref customListTableView) = PageLeftButton; // Set Up button to Left TVPageDownButton(ref customListTableView) = PageRightButton; // Set Down button to Right go.GetComponent <ScrollRect>().viewport = viewport; // Set it with our hot-out-of-the-oven Viewport. customListTableView.LazyInit(); customListTableView.SetDataSource(this, true); //Add data source go.SetActive(true); customListTableView.Show(); //Finally, reset some anchors of each child so that all of the available cells are shown. for (int i = 0; i < customListTableView.transform.childCount; i++) { (customListTableView.transform.GetChild(i).transform as RectTransform).anchoredPosition = Vector3.zero; (customListTableView.transform.GetChild(i).transform as RectTransform).anchorMin = Vector3.zero; (customListTableView.transform.GetChild(i).transform as RectTransform).anchorMax = Vector3.one; } HandleSettingsGroupChanged(0); } selectedSettingsGroup?.OnEnable(); if (lastClickedCellsPerGroup.TryGetValue(selectedSettingsGroup, out int idx)) { selectedSettingsGroup.OnCellSelect(customListTableView, idx); } } catch (Exception e) { //Edit this with your logging system of choice, or delete it altogether (As this shouldn't really cause Exceptions) Plugin.Logger.Error(e); } customListTableView.didSelectCellWithIdxEvent += OnCellSelect; sectionSelection.Value.OnSettingsGroupChanged += HandleSettingsGroupChanged; (transform as RectTransform).anchoredPosition = Vector3.zero; }
private void OnCellSelect(TableView view, int row) => selectedSettingsGroup?.OnCellSelect(view, row);
private void OnCellSelect(TableView view, int idx) { lastClickedCellsPerGroup[selectedSettingsGroup] = idx; selectedSettingsGroup?.OnCellSelect(view, idx); }