public T AddIconSegmentsSetting <T>(string name, string hintText, IconSegmentedControl.DataItem[] icons) where T : SegmentedControlViewController { var volumeSettings = GetVolumeSettings(); GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform); newSettingsObject.name = name; ListSettingsController volume = newSettingsObject.GetComponent <ListSettingsController>(); T newTextSegmentsSettingsController = (T)ReflectionUtil.CopyComponent(volume, typeof(ListSettingsController), typeof(T), newSettingsObject); MonoBehaviour.DestroyImmediate(volume); GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("DecButton").gameObject); GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("ValueText").gameObject); GameObject.Destroy(newSettingsObject.transform.Find("Value").Find("IncButton").gameObject); IconSegmentedControl segmentedControl = BeatSaberUI.CreateIconSegmentedControl(newSettingsObject.transform.Find("Value") as RectTransform, new Vector2(0f, 0f), new Vector2(40f, 7f)); newTextSegmentsSettingsController.segmentedControl = segmentedControl; segmentedControl.SetData(icons); var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>(); tmpText.text = name; if (hintText != String.Empty) { BeatSaberUI.AddHintText(tmpText.rectTransform, hintText); } viewController?.AddSubmenuOption(newSettingsObject); AddHooks(newTextSegmentsSettingsController); return(newTextSegmentsSettingsController); }
public override GameObject CreateObject(Transform parent) { if (prefab == null) { PlatformLeaderboardViewController vc = Resources.FindObjectsOfTypeAll <PlatformLeaderboardViewController>().First(); prefab = vc.GetField <IconSegmentedControl, PlatformLeaderboardViewController>("_scopeSegmentedControl"); } IconSegmentedControl control = Object.Instantiate(prefab, parent, false); control.name = "BSMLVerticalIconSegmentedControl"; control.SetField("_container", prefab.GetField <DiContainer, IconSegmentedControl>("_container")); RectTransform rt = control.transform as RectTransform; rt.anchorMin = new Vector2(0.5f, 0.5f); rt.anchorMax = new Vector2(0.5f, 0.5f); rt.anchoredPosition = Vector2.zero; rt.pivot = new Vector2(0.5f, 0.5f); foreach (Transform transform in control.transform) { Object.Destroy(transform.gameObject); } return(control.gameObject); }
/// <summary> /// Create icon segmented control /// </summary> /// <param name="p_Parent">Parent game object transform</param> /// <param name="p_HideCellBackground">Should hide cell background</param> /// <returns>GameObject</returns> public static IconSegmentedControl CreateVerticalIconSegmentedControl(RectTransform p_Parent, bool p_HideCellBackground) { PlatformLeaderboardViewController l_PlatformLeaderboardViewController = Resources.FindObjectsOfTypeAll <PlatformLeaderboardViewController>().First(); var l_Prefab = l_PlatformLeaderboardViewController.GetField <IconSegmentedControl, PlatformLeaderboardViewController>("_scopeSegmentedControl"); IconSegmentedControl l_Control = MonoBehaviour.Instantiate(l_Prefab, p_Parent, false); l_Control.name = "BSMLVerticalIconSegmentedControl"; l_Control.SetField("_container", l_Prefab.GetField <DiContainer, IconSegmentedControl>("_container")); l_Control.SetField("_hideCellBackground", p_HideCellBackground); RectTransform l_RectTransform = l_Control.transform as RectTransform; l_RectTransform.anchorMin = Vector2.one * 0.5f; l_RectTransform.anchorMax = Vector2.one * 0.5f; l_RectTransform.anchoredPosition = Vector2.zero; l_RectTransform.pivot = Vector2.one * 0.5f; foreach (Transform l_Transform in l_Control.transform) { GameObject.Destroy(l_Transform.gameObject); } return(l_Control); }
/// <summary> /// Create icon segmented control /// </summary> /// <param name="p_Parent">Parent game object transform</param> /// <param name="p_HideCellBackground">Should hide cell background</param> /// <returns>GameObject</returns> public static IconSegmentedControl CreateHorizontalIconSegmentedControl(RectTransform p_Parent, bool p_HideCellBackground) { IconSegmentedControl l_Prefab = Resources.FindObjectsOfTypeAll <IconSegmentedControl>().First(x => x.name == "BeatmapCharacteristicSegmentedControl" && x.GetField <DiContainer, IconSegmentedControl>("_container") != null); IconSegmentedControl l_Control = MonoBehaviour.Instantiate(l_Prefab, p_Parent, false); l_Control.name = "BSMLIconSegmentedControl"; l_Control.SetField("_container", l_Prefab.GetField <DiContainer, IconSegmentedControl>("_container")); l_Control.SetField("_hideCellBackground", p_HideCellBackground); RectTransform l_RectTransform = l_Control.transform as RectTransform; l_RectTransform.anchorMin = Vector2.one * 0.5f; l_RectTransform.anchorMax = Vector2.one * 0.5f; l_RectTransform.anchoredPosition = Vector2.zero; l_RectTransform.pivot = Vector2.one * 0.5f; foreach (Transform l_Transform in l_Control.transform) { GameObject.Destroy(l_Transform.gameObject); } MonoBehaviour.Destroy(l_Control.GetComponent <BeatmapCharacteristicSegmentedControlController>()); return(l_Control); }
public DifficultyHighlighter(StandardLevelDetailViewController standardLevelDetailViewController) { StandardLevelDetailView standardLevelDetailView = Accessors.StandardLevelDetailViewAccessor(ref standardLevelDetailViewController); beatmapCharacteristicSegmentedControlController = Accessors.BeatmapCharacteristicSegmentedControlController(ref standardLevelDetailView); beatmapCharacteristicSegmentedControl = Accessors.BeatmapCharacteristicsSegmentedControlAccessor(ref beatmapCharacteristicSegmentedControlController); beatmapDifficultySegmentedControlController = Accessors.BeatmapDifficultySegmentedControlControllerAccessor(ref standardLevelDetailView); beatmapDifficultySegmentedControl = Accessors.BeatmapDifficultySegmentedControlAccessor(ref beatmapDifficultySegmentedControlController); }
public void SetSelectedCharateristic(IconSegmentedControl sender, int index) { _playerDataModel.playerData.SetLastSelectedBeatmapCharacteristic(_beatmapCharacteristics[index]); var diffBeatmaps = _selectedLevel.beatmapLevelData.GetDifficultyBeatmapSet(_beatmapCharacteristics[index]).difficultyBeatmaps; int diffIndex = CustomExtensions.GetClosestDifficultyIndex(diffBeatmaps, _playerDataModel.playerData.lastSelectedBeatmapDifficulty); difficultyControl.SetTexts(diffBeatmaps.Select(x => x.difficulty.ToString().Replace("Plus", "+")).ToArray()); difficultyControl.SelectCellWithNumber(diffIndex); SetSelectedDifficulty(null, diffIndex); }
public override GameObject CreateObject(Transform parent) { IconSegmentedControl prefab = Resources.FindObjectsOfTypeAll <IconSegmentedControl>().First(x => x.name == "BeatmapCharacteristicSegmentedControl" && x.GetField <DiContainer, IconSegmentedControl>("_container") != null); IconSegmentedControl iconSegmentedControl = MonoBehaviour.Instantiate(prefab, parent, false); iconSegmentedControl.name = "BSMLIconSegmentedControl"; iconSegmentedControl.SetField("_container", prefab.GetField <DiContainer, IconSegmentedControl>("_container")); (iconSegmentedControl.transform as RectTransform).anchoredPosition = new Vector2(0, 0); foreach (Transform transform in iconSegmentedControl.transform) { GameObject.Destroy(transform.gameObject); } MonoBehaviour.Destroy(iconSegmentedControl.GetComponent <BeatmapCharacteristicSegmentedControlController>()); return(iconSegmentedControl.gameObject); }
void SetupCharacteristicDisplay(IconSegmentedControl controller, Song song) { List <IconSegmentedControl.DataItem> characteristics = new List <IconSegmentedControl.DataItem>(); foreach (var c in song.metadata.characteristics) { BeatmapCharacteristicSO characteristic = SongCore.Loader.beatmapCharacteristicCollection.GetBeatmapCharacteristicBySerialiedName(c.name); if (characteristic.characteristicName == "Missing Characteristic") { characteristics.Add(new IconSegmentedControl.DataItem(characteristic.icon, $"Missing Characteristic: {c.name}")); } else { characteristics.Add(new IconSegmentedControl.DataItem(characteristic.icon, characteristic.hintText)); } } controller.SetData(characteristics.ToArray()); }
public void SetSelectedCharateristic(IconSegmentedControl sender, int index) { _playerDataModel.playerData.SetLastSelectedBeatmapCharacteristic(_beatmapCharacteristics[index]); var diffBeatmaps = _selectedLevel.beatmapLevelData.GetDifficultyBeatmapSet(_beatmapCharacteristics[index]).difficultyBeatmaps; int diffIndex = CustomExtensions.GetClosestDifficultyIndex(diffBeatmaps, _playerDataModel.playerData.lastSelectedBeatmapDifficulty); var extraData = Collections.RetrieveExtraSongData(Collections.hashForLevelID(_selectedLevel.levelID)); if (extraData != null) { string[] difficultyLabels = new string[diffBeatmaps.Length]; var extraDifficulties = extraData._difficulties.Where(x => x._beatmapCharacteristicName == _beatmapCharacteristics[index].serializedName || x._beatmapCharacteristicName == _beatmapCharacteristics[index].characteristicNameLocalizationKey); for (int i = 0; i < diffBeatmaps.Length; i++) { var customDiff = extraDifficulties.FirstOrDefault(x => x._difficulty == diffBeatmaps[i].difficulty); if (customDiff != null && !string.IsNullOrEmpty(customDiff._difficultyLabel)) { difficultyLabels[i] = customDiff._difficultyLabel; } else { difficultyLabels[i] = diffBeatmaps[i].difficulty.ToString().Replace("Plus", "+"); } } difficultyControl.SetTexts(difficultyLabels); } else { difficultyControl.SetTexts(diffBeatmaps.Select(x => x.difficulty.ToString().Replace("Plus", "+")).ToArray()); } difficultyControl.SelectCellWithNumber(diffIndex); SetSelectedDifficulty(null, diffIndex); }
public override void HandleType(ComponentTypeWithData componentType, BSMLParserParams parserParams) { IconSegmentedControl iconControl = componentType.component as IconSegmentedControl; if (componentType.data.TryGetValue("data", out string value)) { if (!parserParams.values.TryGetValue(value, out BSMLValue contents)) { throw new Exception("value '" + value + "' not found"); } iconControl.SetData((contents.GetValue() as List <IconSegmentedControl.DataItem>).ToArray()); } if (componentType.data.TryGetValue("selectCell", out string selectCell)) { iconControl.didSelectCellEvent += (SegmentedControl control, int index) => { if (!parserParams.actions.TryGetValue(selectCell, out BSMLAction action)) { throw new Exception("select-cell action '" + componentType.data["selectCell"] + "' not found"); } action.Invoke(control, index); }; } }
static bool Prefix(ref IDifficultyBeatmap ____difficultyBeatmap, ref List <LeaderboardTableView.ScoreData> ____scores, ref bool ____hasScoresData, ref LeaderboardTableView ____leaderboardTableView, ref int[] ____playerScorePos, ref PlatformLeaderboardsModel.ScoresScope ____scoresScope, ref IconSegmentedControl ____scopeSegmentedControl) { if (____difficultyBeatmap.level is CustomBeatmapLevel) { IconSegmentedControl.DataItem thirdCell = ____scopeSegmentedControl.GetPrivateField <IconSegmentedControl.DataItem[]>("_dataItems").Last(); thirdCell.SetPrivateProperty("hintText", "Platform: PC"); thirdCell.SetPrivateProperty("icon", BeatBoardsUIManager.Instance.PCIcon); ____hasScoresData = false; ____scores.Clear(); ____leaderboardTableView.SetScores(____scores, ____playerScorePos[(int)____scoresScope]); Events.Instance.leaderboardOpened.Invoke(____difficultyBeatmap, ____leaderboardTableView); return(false); } return(true); }
/// <summary> /// This code is run before the original code in MethodToPatch is run. /// </summary> /// <param name="__instance">The instance of ClassToPatch</param> /// <param name="arg1">The Parameter1Type arg1 that was passed to MethodToPatch</param> /// <param name="____privateFieldInClassToPatch">Reference to the private field in ClassToPatch named '_privateFieldInClassToPatch', /// added three _ to the beginning to reference it in the patch. Adding ref means we can change it.</param> static bool Prefix(ref SelectLevelCategoryViewController.LevelCategoryInfo[] ____levelCategoryInfos, ref IconSegmentedControl ____levelFilterCategoryIconSegmentedControl) { var con = ____levelFilterCategoryIconSegmentedControl; var col = ____levelCategoryInfos; Plugin.Log?.Debug($"Selected cell: {con.selectedCellNumber} / {col.Length} ({con.NumberOfCells()})"); if (con.selectedCellNumber < 0 || con.selectedCellNumber > col.Length) { con.SelectCellWithNumber(0); } foreach (var item in col) { Plugin.Log?.Debug($"{item.levelCategory}"); } return(true); }
static void Postfix(ref Sprite ____friendsLeaderboardIcon, ref Sprite ____globalLeaderboardIcon, ref Sprite ____aroundPlayerLeaderboardIcon, ref IconSegmentedControl ____scopeSegmentedControl, ref PlatformLeaderboardViewController __instance) {//LeaderboardUIManager.Instance.PCIcon; ____scopeSegmentedControl.didSelectCellEvent += __instance.HandleScopeSegmentedControlDidSelectCell; ____scopeSegmentedControl.SetData(new IconSegmentedControl.DataItem[] { new IconSegmentedControl.DataItem(____globalLeaderboardIcon, "Global"), new IconSegmentedControl.DataItem(____aroundPlayerLeaderboardIcon, "Around You"), new IconSegmentedControl.DataItem(BeatBoardsUIManager.Instance.PCIcon, "Platform: PC") }); var replayButton = __instance.CreateUIButton("OkButton", new Vector2(0f, -37f), new Vector2(9.0f, 5.0f)); replayButton.ToggleWordWrapping(false); replayButton.SetButtonText("Replays"); replayButton.SetButtonTextSize(3); //replayButton.onClick.AddListener(LeaderboardUIManager.Instance.ReplayMenu); BeatBoardsUIManager.Instance.replaysButton = replayButton; }
public void SetContent(MoreSongsFlowCoordinator sender, Song newSongInfo) { selectedCharacteristic = null; currentDifficulties = null; _currentSong = newSongInfo; songNameText.text = _currentSong.songName; if (_characteristicSegmentedDisplay == null) { _characteristicSegmentedDisplay = BeatSaberUI.CreateIconSegmentedControl(rectTransform, new Vector2(-40, .2f), new Vector2(70, 9f), delegate(int value) { SelectedCharacteristic(_currentSong.metadata.characteristics[value]); }); SetupCharacteristicDisplay(_characteristicSegmentedDisplay, _currentSong); } else { SetupCharacteristicDisplay(_characteristicSegmentedDisplay, _currentSong); } if (_difficultySegmentedDisplay == null) { _difficultySegmentedDisplay = BeatSaberUI.CreateTextSegmentedControl(rectTransform, new Vector2(-40, -9f), new Vector2(85, 8f), delegate(int value) { SelectedDifficulty(currentDifficulties[value]); }); _difficultySegmentedDisplay.transform.localScale = new Vector3(.8f, _difficultySegmentedDisplay.transform.localScale.y, _difficultySegmentedDisplay.transform.localScale.z); SetupDifficultyDisplay(_difficultySegmentedDisplay, _currentSong); } else { SetupDifficultyDisplay(_difficultySegmentedDisplay, _currentSong); } downloadsText.text = _currentSong.downloads.ToString(); _levelParams.bpm = (float)(_currentSong.plays); _levelParams.notesCount = (int)_currentSong.bpm; _levelParams.obstaclesCount = _currentSong.upVotes; _levelParams.bombsCount = _currentSong.downVotes; Polyglot.LocalizedTextMeshProUGUI localizer1 = difficulty1Title.GetComponentInChildren <Polyglot.LocalizedTextMeshProUGUI>(); if (localizer1 != null) { GameObject.Destroy(localizer1); } Polyglot.LocalizedTextMeshProUGUI localizer2 = difficulty2Title.GetComponentInChildren <Polyglot.LocalizedTextMeshProUGUI>(); if (localizer2 != null) { GameObject.Destroy(localizer2); } Polyglot.LocalizedTextMeshProUGUI localizer3 = difficulty3Title.GetComponentInChildren <Polyglot.LocalizedTextMeshProUGUI>(); if (localizer3 != null) { GameObject.Destroy(localizer3); } difficulty1Title.text = ""; difficulty2Title.text = ""; difficulty3Title.text = ""; difficulty1Text.text = ""; difficulty2Text.text = ""; difficulty3Text.text = ""; // difficulty1Text.text = (_currentSong.metadata.difficulties.expert || _currentSong.metadata.difficulties.expertPlus) ? "Yes" : "No"; // difficulty2Text.text = (_currentSong.metadata.difficulties.hard) ? "Yes" : "No"; // difficulty3Text.text = (_currentSong.metadata.difficulties.easy || _currentSong.metadata.difficulties.normal) ? "Yes" : "No"; StartCoroutine(LoadScripts.LoadSpriteCoroutine(_currentSong.coverURL, (cover) => { coverImage.texture = cover.texture; })); SetFavoriteState(PluginConfig.favoriteSongs.Any(x => x.Contains(_currentSong.hash))); SetDownloadState((SongDownloader.Instance.IsSongDownloaded(_currentSong) ? DownloadState.Downloaded : (sender.IsDownloadingSong(_currentSong) ? DownloadState.Downloading : DownloadState.NotDownloaded))); SetLoadingState(false); SelectedCharacteristic(_currentSong.metadata.characteristics[0]); }