protected void SetupViewController() { modifiersPanelBlocker.type = Image.Type.Sliced; modifiersPanelBlocker.color = new Color(0f, 0f, 0f, 0.75f); modifiersPanel = Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifiersPanelController>().First(), rectTransform, false); modifiersPanel.gameObject.SetActive(true); modifiersPanel.transform.SetParent(modifiersTab, false); (modifiersPanel.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (modifiersPanel.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (modifiersPanel.transform as RectTransform).anchoredPosition = new Vector2(0f, -23f); (modifiersPanel.transform as RectTransform).sizeDelta = new Vector2(120f, -23f); HoverHintController hoverHintController = Resources.FindObjectsOfTypeAll <HoverHintController>().First(); foreach (var hint in modifiersPanel.GetComponentsInChildren <HoverHint>()) { hint.SetPrivateField("_hoverHintController", hoverHintController); } modifiersPanel.Awake(); modifiersPanel.SetData(GameplayModifiers.defaultModifiers); modifiersPanel.Refresh(); var modifierToggles = modifiersPanel.GetPrivateField <GameplayModifierToggle[]>("_gameplayModifierToggles"); foreach (var item in modifierToggles) { item.toggle.onValueChanged.AddListener((enabled) => { gameplayModifiersChanged?.Invoke(); }); } playersList.tableView.ReloadData(); }
protected override void DidActivate(bool firstActivation, ActivationType activationType) { if (firstActivation && activationType == ActivationType.AddedToHierarchy) { _downloadListTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(); _tabControl = CustomExtensions.CreateTextSegmentedControl(rectTransform, new Vector2(0f, -9f)); _tabControl.SetTexts(new string[] { "Players", "Modifiers" }); _tabControl.didSelectCellEvent += _tabControl_didSelectCellEvent; #region Modifiers tab _modifiersTab = new GameObject("ModifiersTab", typeof(RectTransform)).GetComponent <RectTransform>(); _modifiersTab.SetParent(rectTransform, false); _modifiersTab.anchorMin = new Vector2(0f, 0f); _modifiersTab.anchorMax = new Vector2(1f, 1f); _modifiersTab.anchoredPosition = new Vector2(0f, 0f); _modifiersTab.sizeDelta = new Vector2(0f, 0f); _modifiersPanel = Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifiersPanelController>().First(), rectTransform, false); _modifiersPanel.gameObject.SetActive(true); _modifiersPanel.transform.SetParent(_modifiersTab, false); (_modifiersPanel.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_modifiersPanel.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_modifiersPanel.transform as RectTransform).anchoredPosition = new Vector2(0f, -23f); (_modifiersPanel.transform as RectTransform).sizeDelta = new Vector2(120f, -23f); _modifiersPanel.Init(GameplayModifiers.defaultModifiers); _modifiersPanel.Awake(); var modifierToggles = _modifiersPanel.GetPrivateField <GameplayModifierToggle[]>("_gameplayModifierToggles"); foreach (var item in modifierToggles) { item.toggle.onValueChanged.AddListener((enabled) => { gameplayModifiersChanged?.Invoke(); }); } _modifiersPanelBlocker = new GameObject("ModifiersPanelBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid" _modifiersPanelBlocker.SetParent(_modifiersTab, false); _modifiersPanelBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f); _modifiersPanelBlocker.anchorMin = new Vector2(0f, 0f); _modifiersPanelBlocker.anchorMax = new Vector2(1f, 0f); _modifiersPanelBlocker.pivot = new Vector2(0.5f, 0f); _modifiersPanelBlocker.sizeDelta = new Vector2(-10f, 62f); _modifiersPanelBlocker.anchoredPosition = new Vector2(0f, 0f); #endregion #region Players tab _playersTab = new GameObject("PlayersTab", typeof(RectTransform)).GetComponent <RectTransform>(); _playersTab.SetParent(rectTransform, false); _playersTab.anchorMin = new Vector2(0f, 0f); _playersTab.anchorMax = new Vector2(1f, 1f); _playersTab.anchoredPosition = new Vector2(0f, 0f); _playersTab.sizeDelta = new Vector2(0f, 0f); _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), _playersTab, false); (_pageUpButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -18f); (_pageUpButton.transform as RectTransform).sizeDelta = new Vector2(40f, 6f); _pageUpButton.interactable = true; _pageUpButton.onClick.AddListener(delegate() { _playersTableView.PageScrollUp(); }); _pageUpButton.interactable = false; _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), _playersTab, false); (_pageDownButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 6f); (_pageDownButton.transform as RectTransform).sizeDelta = new Vector2(40f, 6f); _pageDownButton.interactable = true; _pageDownButton.onClick.AddListener(delegate() { _playersTableView.PageScrollDown(); }); _pageDownButton.interactable = false; RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform; container.SetParent(_playersTab, false); container.anchorMin = new Vector2(0.15f, 0.5f); container.anchorMax = new Vector2(0.85f, 0.5f); container.sizeDelta = new Vector2(0f, 49f); container.anchoredPosition = new Vector2(0f, -3f); _playersTableView = new GameObject("CustomTableView").AddComponent <TableView>(); _playersTableView.gameObject.AddComponent <RectMask2D>(); _playersTableView.transform.SetParent(container, false); _playersTableView.SetPrivateField("_isInitialized", false); _playersTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]); _playersTableView.Init(); (_playersTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0f); (_playersTableView.transform as RectTransform).anchorMax = new Vector2(1f, 1f); (_playersTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 0f); (_playersTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f); ReflectionUtil.SetPrivateField(_playersTableView, "_pageUpButton", _pageUpButton); ReflectionUtil.SetPrivateField(_playersTableView, "_pageDownButton", _pageDownButton); _playersTableView.dataSource = this; #endregion _pingText = this.CreateText("PING: 0", new Vector2(75f, 22.5f)); _pingText.alignment = TextAlignmentOptions.Left; _tabControl_didSelectCellEvent(null, 0); } if (activationType == ActivationType.AddedToHierarchy) { SetGameplayModifiers(GameplayModifiers.defaultModifiers); } }
protected override void DidActivate(bool firstActivation, ActivationType activationType) { if (firstActivation && activationType == ActivationType.AddedToHierarchy) { _downloadListTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(); _tabControl = BeatSaberUI.CreateTextSegmentedControl(rectTransform, new Vector2(0f, 31f), new Vector2(100f, 7f), _tabControl_didSelectCellEvent); _tabControl.SetTexts(new string[] { "Players", "Modifiers" }); #region Modifiers tab _modifiersTab = new GameObject("ModifiersTab", typeof(RectTransform)).GetComponent <RectTransform>(); _modifiersTab.SetParent(rectTransform, false); _modifiersTab.anchorMin = new Vector2(0f, 0f); _modifiersTab.anchorMax = new Vector2(1f, 1f); _modifiersTab.anchoredPosition = new Vector2(0f, 0f); _modifiersTab.sizeDelta = new Vector2(0f, 0f); _modifiersPanel = Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifiersPanelController>().First(), rectTransform, false); _modifiersPanel.SetData(GameplayModifiers.defaultModifiers); _modifiersPanel.gameObject.SetActive(true); _modifiersPanel.transform.SetParent(_modifiersTab, false); (_modifiersPanel.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_modifiersPanel.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_modifiersPanel.transform as RectTransform).anchoredPosition = new Vector2(0f, -23f); (_modifiersPanel.transform as RectTransform).sizeDelta = new Vector2(120f, -23f); HoverHintController hoverHintController = Resources.FindObjectsOfTypeAll <HoverHintController>().First(); foreach (var hint in _modifiersPanel.GetComponentsInChildren <HoverHint>()) { hint.SetPrivateField("_hoverHintController", hoverHintController); } _modifiersPanel.Awake(); var modifierToggles = _modifiersPanel.GetPrivateField <GameplayModifierToggle[]>("_gameplayModifierToggles"); foreach (var item in modifierToggles) { item.toggle.onValueChanged.AddListener((enabled) => { Plugin.log.Info("Toggle changed"); gameplayModifiersChanged?.Invoke(); }); } _modifiersPanelBlocker = new GameObject("ModifiersPanelBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid" _modifiersPanelBlocker.SetParent(_modifiersTab, false); _modifiersPanelBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f); _modifiersPanelBlocker.anchorMin = new Vector2(0f, 0f); _modifiersPanelBlocker.anchorMax = new Vector2(1f, 0f); _modifiersPanelBlocker.pivot = new Vector2(0.5f, 0f); _modifiersPanelBlocker.sizeDelta = new Vector2(-10f, 62f); _modifiersPanelBlocker.anchoredPosition = new Vector2(0f, 0f); #endregion #region Players tab _playersTab = new GameObject("PlayersTab", typeof(RectTransform)).GetComponent <RectTransform>(); _playersTab.SetParent(rectTransform, false); _playersTab.anchorMin = new Vector2(0f, 0f); _playersTab.anchorMax = new Vector2(1f, 1f); _playersTab.anchoredPosition = new Vector2(0f, 0f); _playersTab.sizeDelta = new Vector2(0f, 0f); _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageUpButton")), _playersTab, false); (_pageUpButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -18.5f); (_pageUpButton.transform as RectTransform).sizeDelta = new Vector2(40f, 6f); _pageUpButton.interactable = true; _pageUpButton.onClick.AddListener(delegate() { _playersTableViewScroller.PageScrollUp(); }); _pageUpButton.interactable = false; _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), _playersTab, false); (_pageDownButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 7f); (_pageDownButton.transform as RectTransform).sizeDelta = new Vector2(40f, 6f); _pageDownButton.interactable = true; _pageDownButton.onClick.AddListener(delegate() { _playersTableViewScroller.PageScrollDown(); }); _pageDownButton.interactable = false; RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform; container.SetParent(_playersTab, false); container.anchorMin = new Vector2(0.15f, 0.5f); container.anchorMax = new Vector2(0.85f, 0.5f); container.sizeDelta = new Vector2(0f, 49f); container.anchoredPosition = new Vector2(0f, -3f); var tableGameObject = new GameObject("CustomTableView"); tableGameObject.SetActive(false); _playersTableView = tableGameObject.AddComponent <TableView>(); _playersTableView.gameObject.AddComponent <RectMask2D>(); _playersTableView.transform.SetParent(container, false); _playersTableView.SetPrivateField("_isInitialized", false); _playersTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]); _playersTableView.SetPrivateField("_tableType", TableView.TableType.Vertical); var viewport = new GameObject("Viewport").AddComponent <RectTransform>(); viewport.SetParent(tableGameObject.GetComponent <RectTransform>(), false); (viewport.transform as RectTransform).sizeDelta = new Vector2(0f, 0f); (viewport.transform as RectTransform).anchorMin = new Vector2(0f, 0f); (viewport.transform as RectTransform).anchorMax = new Vector2(1f, 1f); tableGameObject.GetComponent <ScrollRect>().viewport = viewport; _playersTableView.Init(); (_playersTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0f); (_playersTableView.transform as RectTransform).anchorMax = new Vector2(1f, 1f); (_playersTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 0f); (_playersTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f); ReflectionUtil.SetPrivateField(_playersTableView, "_pageUpButton", _pageUpButton); ReflectionUtil.SetPrivateField(_playersTableView, "_pageDownButton", _pageDownButton); tableGameObject.SetActive(true); _playersTableViewScroller = _playersTableView.GetPrivateField <TableViewScroller>("_scroller"); //_playersTableViewScroller.SetPrivateField("position", zero); _playersTableView.dataSource = this; #endregion _pingText = this.CreateText("PING: 0", new Vector2(75f, 22.5f)); _pingText.alignment = TextAlignmentOptions.Left; _tabControl_didSelectCellEvent(0); } else { for (int i = 0; i < _tableCells.Count; i++) { Destroy(_tableCells[i].gameObject); } _tableCells.Clear(); _playersTableView.ReloadData(); } if (activationType == ActivationType.AddedToHierarchy) { StartCoroutine(ScrollWithDelay()); SetGameplayModifiers(GameplayModifiers.defaultModifiers); } }