public TableCell CellForIdx(int row) { LevelListTableCell cell = Instantiate(_serverTableCellInstance); cell.reuseIdentifier = "ServerHubCell"; ServerHubClient client = _serverHubClients[row]; cell.GetComponentsInChildren <UnityEngine.UI.Image>(true).First(x => x.name == "CoverImage").enabled = false; cell.SetText($"{(!client.serverHubCompatible ? (client.serverHubAvailable ? "<color=yellow>" : "<color=red>") : "")}{client.ip}:{client.port} (PING: {Mathf.RoundToInt(client.ping*1000)})"); if (client.serverHubCompatible) { cell.SetSubText($"{client.playersCount} players, {client.availableRoomsCount} rooms"); } else { cell.SetSubText($"{(client.serverHubAvailable ? "VERSION MISMATCH" : "SERVER DOWN")}"); } cell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); cell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); cell.SetPrivateField("_bought", true); foreach (var icon in cell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } return(cell); }
public TableCell CellForIdx(TableView sender, int row) { LevelListTableCell cell = Instantiate(_serverTableCellInstance); cell.reuseIdentifier = "ServerTableCell"; RoomInfo room = availableRooms[row].roomInfo; if (room.usePassword) { cell.SetIcon(Sprites.lockedRoomIcon.texture); } else { cell.GetComponentsInChildren <UnityEngine.UI.RawImage>(true).First(x => x.name == "CoverImage").enabled = false; } cell.SetText($"({room.players}/{((room.maxPlayers == 0)? "INF":room.maxPlayers.ToString())})" + room.name); cell.SetSubText($"{room.roomState.ToString()}"); cell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); cell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); cell.SetPrivateField("_bought", true); foreach (var icon in cell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } return(cell); }
public TableCell CellForIdx(int row) { LevelListTableCell _tableCell = Instantiate(_songListTableCellInstance); _tableCell.reuseIdentifier = "PlaylistTableCell"; _tableCell.GetPrivateField <TextMeshProUGUI>("_songNameText").text = playlistList[row].playlistTitle; _tableCell.GetPrivateField <TextMeshProUGUI>("_authorText").text = playlistList[row].playlistAuthor; _tableCell.GetPrivateField <UnityEngine.UI.Image>("_coverImage").sprite = playlistList[row].icon; _tableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); _tableCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); _tableCell.SetPrivateField("_bought", true); foreach (var icon in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } if (highlightDownloadedPlaylists) { if (PlaylistsCollection.loadedPlaylists.Any(x => x.PlaylistEqual(playlistList[row]))) { foreach (UnityEngine.UI.Image img in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>()) { img.color = new Color(1f, 1f, 1f, 0.2f); } foreach (TextMeshProUGUI text in _tableCell.GetComponentsInChildren <TextMeshProUGUI>()) { text.faceColor = new Color(1f, 1f, 1f, 0.2f); } } } return(_tableCell); }
public override TableCell CellForIdx(int row) { LevelListTableCell _tableCell = GetTableCell(false); _tableCell.reuseIdentifier = "MoreSongsTableCell"; _tableCell.GetPrivateField <TextMeshProUGUI>("_songNameText").text = string.Format("{0} <size=80%>{1}</size>", songsList[row].songName, songsList[row].songSubName); _tableCell.GetPrivateField <TextMeshProUGUI>("_authorText").text = songsList[row].songAuthorName + " <size=80%>[" + songsList[row].levelAuthorName + "]</size>"; _tableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); _tableCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); _tableCell.SetPrivateField("_bought", true); StartCoroutine(LoadScripts.LoadSpriteCoroutine(songsList[row].coverURL, (cover) => { _tableCell.GetPrivateField <UnityEngine.UI.RawImage>("_coverRawImage").texture = cover.texture; })); bool alreadyDownloaded = SongDownloader.Instance.IsSongDownloaded(songsList[row]); if (alreadyDownloaded) { foreach (UnityEngine.UI.Image img in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>()) { img.color = new Color(1f, 1f, 1f, 0.2f); } foreach (TextMeshProUGUI text in _tableCell.GetComponentsInChildren <TextMeshProUGUI>()) { text.faceColor = new Color(1f, 1f, 1f, 0.2f); } } return(_tableCell); }
public TableCell CellForRow(int row) { LevelListTableCell _tableCell = Instantiate(_songListTableCellInstance); _tableCell.reuseIdentifier = "PlaylistTableCell"; _tableCell.songName = playlistList[row].playlistTitle; _tableCell.author = playlistList[row].playlistAuthor; _tableCell.coverImage = playlistList[row].icon; if (highlightDownloadedPlaylists) { if (PlaylistsCollection.loadedPlaylists.Any(x => x.PlaylistEqual(playlistList[row]))) { foreach (UnityEngine.UI.Image img in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>()) { img.color = new Color(1f, 1f, 1f, 0.2f); } foreach (TextMeshProUGUI text in _tableCell.GetComponentsInChildren <TextMeshProUGUI>()) { text.faceColor = new Color(1f, 1f, 1f, 0.2f); } } } return(_tableCell); }
public TableCell CellForIdx(int row) { LevelListTableCell _tableCell = Instantiate(_songListTableCellInstance); _tableCell.reuseIdentifier = "MoreSongsTableCell"; _tableCell.GetPrivateField <TextMeshProUGUI>("_songNameText").text = string.Format("{0} <size=80%>{1}</size>", songsList[row].songName, songsList[row].songSubName); _tableCell.GetPrivateField <TextMeshProUGUI>("_authorText").text = songsList[row].authorName; _tableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); _tableCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); _tableCell.SetPrivateField("_bought", true); foreach (var icon in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } StartCoroutine(LoadScripts.LoadSpriteCoroutine(songsList[row].coverUrl, (cover) => { _tableCell.GetPrivateField <UnityEngine.UI.Image>("_coverImage").sprite = cover; })); bool alreadyDownloaded = SongDownloader.Instance.IsSongDownloaded(songsList[row]); if (alreadyDownloaded) { foreach (UnityEngine.UI.Image img in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>()) { img.color = new Color(1f, 1f, 1f, 0.2f); } foreach (TextMeshProUGUI text in _tableCell.GetComponentsInChildren <TextMeshProUGUI>()) { text.faceColor = new Color(1f, 1f, 1f, 0.2f); } } return(_tableCell); }
public static void Postfix(LevelListTableCell __instance, bool ____selected, bool ____highlighted, Color ____beatmapCharacteristicImagesNormalColor, Color ____selectedHighlightElementsColor) { foreach (var image in __instance.GetComponentsInChildren <Image>()) { // Fork ====== if (image.name.IndexOf(ClearedLevelPrefix) >= 0) { image.color = ____selected ? ____selectedHighlightElementsColor : Color.yellow; continue; } // =========== // For performance reason, avoid using Linq. if (image.name != "Vote") { continue; } if (____selected) { image.color = ____highlighted ? ____selectedHighlightElementsColor : Color.black; } else { image.color = ____beatmapCharacteristicImagesNormalColor; } break; } }
public static void Postfix(LevelListTableCell __instance, IPreviewBeatmapLevel level, bool isFavorite, Image ____favoritesBadgeImage, TextMeshProUGUI ____songBpmText) { if (float.TryParse(____songBpmText?.text, out float bpm)) { ____songBpmText.text = bpm.ToString("0"); } Image voteIcon = null; foreach (var image in __instance.GetComponentsInChildren <Image>()) { // For performance reason, avoid using Linq. if (image.name == "Vote") { voteIcon = image; break; } } if (voteIcon == null) { voteIcon = Instantiate(____favoritesBadgeImage, __instance.transform); voteIcon.name = "Vote"; voteIcon.rectTransform.sizeDelta = new Vector2(2.5f, 2.5f); voteIcon.color = new Color(1f, 1f, 1f, 0.3f); } voteIcon.enabled = false; if (!isFavorite && SPHModel.Votes.TryGetValue(level.levelID.Replace("custom_level_", "").ToLower(), out var vote)) { voteIcon.sprite = vote.voteType == "Upvote" ? _thumbsUp : _thumbsDown; voteIcon.enabled = true; } }
public TableCell CellForIdx(TableView tableView, int row) { LevelListTableCell cell = Instantiate(_songTableCellInstance); IPreviewBeatmapLevel song = availableSongs[row]; song.GetCoverImageTexture2DAsync(new CancellationToken()).ContinueWith((tex) => { if (!tex.IsFaulted) { cell.SetIcon(tex.Result); } }).ConfigureAwait(false); cell.SetText($"{song.songName} <size=80%>{song.songSubName}</size>"); cell.SetSubText(song.songAuthorName + " <size=80%>[" + song.levelAuthorName + "]</size>"); cell.reuseIdentifier = "SongCell"; cell.SetPrivateField("_beatmapCharacteristicAlphas", new float[3] { song.beatmapCharacteristics.Any(x => x.serializedName == "Standard") ? 1f : 0.1f, song.beatmapCharacteristics.Any(x => x.serializedName == "NoArrows") ? 1f : 0.1f, song.beatmapCharacteristics.Any(x => x.serializedName == "OneSaber") ? 1f : 0.1f }); cell.SetPrivateField("_beatmapCharacteristicImages", cell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")).ToArray()); cell.SetPrivateField("_bought", true); return(cell); }
public TableCell CellForIdx(int row) { LevelListTableCell cell = Instantiate(_presetsTableCellInstance); RoomPreset preset = availablePresets[row]; cell.GetComponentsInChildren <UnityEngine.UI.Image>(true).First(x => x.name == "CoverImage").enabled = false; cell.SetText($"{preset.GetName()}"); cell.SetSubText($"{preset.settings.Name}"); cell.reuseIdentifier = "PresetCell"; cell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); cell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); cell.SetPrivateField("_bought", true); foreach (var icon in cell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } return(cell); }
public TableCell CellForRow(int row) { LevelListTableCell cell = Instantiate(_serverTableCellInstance); cell.reuseIdentifier = "ServerHubCell"; ServerHubClient client = _serverHubClients[row]; cell.GetComponentsInChildren <UnityEngine.UI.Image>(true).First(x => x.name == "CoverImage").enabled = false; cell.songName = $"{client.ip}:{client.port}"; cell.author = $"{client.availableRooms.Count} rooms"; return(cell); }
public TableCell CellForRow(int row) { LevelListTableCell cell = Instantiate(_presetsTableCellInstance); RoomPreset preset = availablePresets[row]; cell.GetComponentsInChildren <UnityEngine.UI.Image>(true).First(x => x.name == "CoverImage").enabled = false; cell.songName = $"{preset.GetName()}"; cell.author = $"{preset.settings.Name}"; cell.reuseIdentifier = "PresetCell"; return(cell); }
public TableCell CellForRow(int row) { LevelListTableCell _tableCell = Instantiate(_songListTableCellInstance); _tableCell.reuseIdentifier = "MoreSongsTableCell"; _tableCell.songName = string.Format("{0}\n<size=80%>{1}</size>", songsList[row].songName, songsList[row].songSubName); _tableCell.author = songsList[row].authorName; StartCoroutine(LoadScripts.LoadSprite(songsList[row].coverUrl, _tableCell)); bool alreadyDownloaded = SongDownloader.Instance.IsSongDownloaded(songsList[row]); if (alreadyDownloaded) { foreach (UnityEngine.UI.Image img in _tableCell.GetComponentsInChildren <UnityEngine.UI.Image>()) { img.color = new Color(1f, 1f, 1f, 0.2f); } foreach (TextMeshProUGUI text in _tableCell.GetComponentsInChildren <TextMeshProUGUI>()) { text.faceColor = new Color(1f, 1f, 1f, 0.2f); } } return(_tableCell); }
public TableCell CellForIdx(int row) { LevelListTableCell cell = Instantiate(_songTableCellInstance); BeatmapLevelSO song = availableSongs[row]; cell.SetIcon(song.coverImage); cell.SetText($"{song.songName} <size=80%>{song.songSubName}</size>"); cell.SetSubText(song.songAuthorName); cell.reuseIdentifier = "SongCell"; cell.SetPrivateField("_beatmapCharacteristicAlphas", new float[3] { song.beatmapCharacteristics.Any(x => x.serializedName == "Standard") ? 1f : 0.1f, song.beatmapCharacteristics.Any(x => x.serializedName == "NoArrows") ? 1f : 0.1f, song.beatmapCharacteristics.Any(x => x.serializedName == "OneSaber") ? 1f : 0.1f }); cell.SetPrivateField("_beatmapCharacteristicImages", cell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")).ToArray()); cell.SetPrivateField("_bought", true); return(cell); }
public TableCell CellForRow(int row) { LevelListTableCell cell = Instantiate(_serverTableCellInstance); cell.reuseIdentifier = "ServerTableCell"; RoomInfo room = availableRooms[row].roomInfo; if (room.usePassword) { cell.coverImage = Sprites.lockedRoomIcon; } else { cell.GetComponentsInChildren <UnityEngine.UI.Image>(true).First(x => x.name == "CoverImage").enabled = false; } cell.songName = $"({room.players}/{((room.maxPlayers == 0)? "INF":room.maxPlayers.ToString())})" + room.name; cell.author = $"{room.roomState.ToString()}{(room.noFail ? ", No Fail" : "")}"; return(cell); }
public override TableCell CellForIdx(TableView tablewView, int idx) { // adapted from CustomUI's CustomListViewController LevelListTableCell tableCell = (LevelListTableCell)_customListTableView.DequeueReusableCellForIdentifier(reuseIdentifier); TextMeshProUGUI cellText; UEImage statusImg; if (!tableCell) { tableCell = Instantiate(_songListTableCellInstance); // remove unused elements Destroy(tableCell.GetPrivateField <RawImage>("_coverRawImage").gameObject); Destroy(tableCell.GetPrivateField <TextMeshProUGUI>("_authorText").gameObject); cellText = tableCell.GetPrivateField <TextMeshProUGUI>("_songNameText"); cellText.fontSize = 5f; cellText.alignment = TextAlignmentOptions.Left; cellText.rectTransform.anchorMin = new Vector2(0.15f, 0f); cellText.rectTransform.anchorMax = Vector2.one; cellText.rectTransform.pivot = new Vector2(0.5f, 0.5f); cellText.rectTransform.sizeDelta = Vector2.zero; cellText.rectTransform.anchoredPosition = Vector2.zero; UEImage bgImg = tableCell.GetComponentsInChildren <UEImage>().First(x => x.name == "BG"); bgImg.rectTransform.anchorMin = Vector2.zero; bgImg.rectTransform.anchorMax = Vector2.one; bgImg.rectTransform.pivot = new Vector2(0.5f, 0.5f); bgImg.rectTransform.anchoredPosition = Vector2.zero; bgImg.rectTransform.sizeDelta = Vector2.zero; UEImage highlightImg = tableCell.GetComponentsInChildren <UEImage>().First(x => x.name == "Highlight"); highlightImg.rectTransform.anchorMin = Vector2.zero; highlightImg.rectTransform.anchorMax = Vector2.one; highlightImg.rectTransform.pivot = new Vector2(0.5f, 0.5f); highlightImg.rectTransform.anchoredPosition = Vector2.zero; highlightImg.rectTransform.sizeDelta = Vector2.zero; statusImg = new GameObject("StatusImage").AddComponent <UEImage>(); statusImg.transform.SetParent(tableCell.transform, false); statusImg.rectTransform.anchorMin = Vector2.zero; statusImg.rectTransform.anchorMax = new Vector2(0.03f, 1f); statusImg.rectTransform.pivot = new Vector2(0.5f, 0.5f); statusImg.rectTransform.sizeDelta = new Vector2(0.5f, 0.5f); statusImg.rectTransform.anchoredPosition = Vector2.zero; statusImg.sprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 1f, 1f), Vector2.zero); statusImg.color = DefaultFilterColor; statusImg.material = Utilities.NoGlowMaterial; foreach (UEImage i in tableCell.GetPrivateField <UEImage[]>("_beatmapCharacteristicImages")) { i.enabled = false; } tableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); tableCell.SetPrivateField("_beatmapCharacteristicImages", new UEImage[0]); tableCell.reuseIdentifier = reuseIdentifier; } IFilter filter = FilterList[idx]; cellText = tableCell.GetPrivateField <TextMeshProUGUI>("_songNameText"); statusImg = tableCell.GetComponentsInChildren <UEImage>().First(x => x.name == "StatusImage"); if (filter.IsAvailable) { cellText.text = filter.FilterName; } else { cellText.text = $"<color=#FF8888><i>{filter.FilterName}</i></color>"; } if (filter.Status == FilterStatus.NotAppliedAndDefault) { statusImg.color = DefaultFilterColor; } else if (filter.Status == FilterStatus.NotAppliedAndChanged) { statusImg.color = PendingFilterColor; } else if (filter.Status == FilterStatus.AppliedAndChanged) { statusImg.color = AppliedPendingFilterColor; } else { statusImg.color = AppliedFilterColor; } return(tableCell); }
protected override void DidActivate(bool firstActivation, ActivationType activationType) { if (firstActivation && activationType == ActivationType.AddedToHierarchy) { _beatmapCharacteristics = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>(); _standardCharacteristic = _beatmapCharacteristics.First(x => x.serializedName == "Standard"); bool isHost = Client.Instance.isHost; _selectedSongCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")), rectTransform, false); (_selectedSongCell.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f); (_selectedSongCell.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f); (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(-25f, 7.5f); _selectedSongCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); _selectedSongCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); _selectedSongCell.SetPrivateField("_bought", true); foreach (var icon in _selectedSongCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } _playersReadyText = BeatSaberUI.CreateText(rectTransform, "0/0 players ready", new Vector2(0f, 5f)); _playersReadyText.rectTransform.anchorMin = new Vector2(0.5f, 0f); _playersReadyText.rectTransform.anchorMax = new Vector2(0.5f, 0f); _playersReadyText.alignment = TextAlignmentOptions.Center; _playersReadyText.fontSize = 5.5f; _cancelButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton"); (_cancelButton.transform as RectTransform).anchoredPosition = new Vector2(-30f, -25f); (_cancelButton.transform as RectTransform).sizeDelta = new Vector2(28f, 12f); _cancelButton.SetButtonText("CANCEL"); _cancelButton.ToggleWordWrapping(false); _cancelButton.SetButtonTextSize(5.5f); _cancelButton.onClick.AddListener(delegate() { discardPressed?.Invoke(); }); _cancelButton.gameObject.SetActive(isHost); _playButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton"); (_playButton.transform as RectTransform).anchoredPosition = new Vector2(30f, -25f); (_playButton.transform as RectTransform).sizeDelta = new Vector2(28f, 12f); _playButton.SetButtonText("PLAY"); _playButton.ToggleWordWrapping(false); _playButton.SetButtonTextSize(5.5f); _playButton.onClick.AddListener(delegate() { playPressed?.Invoke(_selectedSong, selectedCharacteristic, selectedDifficulty); }); var playGlow = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => x.name == "PlayButton").GetComponentsInChildren <RectTransform>().First(x => x.name == "GlowContainer"), _playButton.transform); //Let's add some glow! playGlow.transform.SetAsFirstSibling(); playGlow.GetComponentInChildren <UnityEngine.UI.Image>().color = new Color(0f, 0.7058824f, 1f, 0.7843137f); _playButton.gameObject.SetActive(isHost); _characteristicControl = BeatSaberUI.CreateTextSegmentedControl(rectTransform, new Vector2(0f, 34f), new Vector2(110f, 7f), _characteristicControl_didSelectCellEvent); _characteristicControl.SetTexts(new string[] { "Standard", "No Arrows", "One Saber" }); _characteristicControlBlocker = new GameObject("CharacteristicControlBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid" _characteristicControlBlocker.SetParent(rectTransform, false); _characteristicControlBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f); _characteristicControlBlocker.anchorMin = new Vector2(0f, 1f); _characteristicControlBlocker.anchorMax = new Vector2(1f, 1f); _characteristicControlBlocker.sizeDelta = new Vector2(-30f, 7f); _characteristicControlBlocker.anchoredPosition = new Vector2(0f, -6f); _difficultyControl = BeatSaberUI.CreateTextSegmentedControl(rectTransform, new Vector2(0f, 24f), new Vector2(110f, 7f), _difficultyControl_didSelectCellEvent); _difficultyControl.SetTexts(new string[] { "Easy", "Normal", "Hard", "Expert", "Expert+" }); _difficultyControlBlocker = new GameObject("DifficultyControlBlocker", typeof(RectTransform)).GetComponent <RectTransform>(); //"If it works it's not stupid" _difficultyControlBlocker.SetParent(rectTransform, false); _difficultyControlBlocker.gameObject.AddComponent <UnityEngine.UI.Image>().color = new Color(0f, 0f, 0f, 0f); _difficultyControlBlocker.anchorMin = new Vector2(0f, 1f); _difficultyControlBlocker.anchorMax = new Vector2(1f, 1f); _difficultyControlBlocker.sizeDelta = new Vector2(-30f, 7f); _difficultyControlBlocker.anchoredPosition = new Vector2(0f, -16f); _progressBarRect = new GameObject("ProgressBar", typeof(RectTransform)).GetComponent <RectTransform>(); _progressBarRect.SetParent(rectTransform, false); _progressBarRect.anchorMin = new Vector2(0.5f, 0.5f); _progressBarRect.anchorMax = new Vector2(0.5f, 0.5f); _progressBarRect.anchoredPosition = new Vector2(0f, -7.5f); _progressBarRect.sizeDelta = new Vector2(46f, 5f); _progressBackground = new GameObject("Background", typeof(RectTransform), typeof(UnityEngine.UI.Image)).GetComponent <UnityEngine.UI.Image>(); _progressBackground.rectTransform.SetParent(_progressBarRect, false); _progressBackground.rectTransform.anchorMin = new Vector2(0f, 0f); _progressBackground.rectTransform.anchorMax = new Vector2(1f, 1f); _progressBackground.rectTransform.anchoredPosition = new Vector2(0f, 0f); _progressBackground.rectTransform.sizeDelta = new Vector2(0f, 0f); _progressBackground.sprite = Sprites.whitePixel; _progressBackground.material = Sprites.NoGlowMat; _progressBackground.color = new Color(1f, 1f, 1f, 0.075f); _progressBarImage = new GameObject("ProgressImage", typeof(RectTransform), typeof(UnityEngine.UI.Image)).GetComponent <UnityEngine.UI.Image>(); _progressBarImage.rectTransform.SetParent(_progressBarRect, false); _progressBarImage.rectTransform.anchorMin = new Vector2(0f, 0f); _progressBarImage.rectTransform.anchorMax = new Vector2(1f, 1f); _progressBarImage.rectTransform.anchoredPosition = new Vector2(0f, 0f); _progressBarImage.rectTransform.sizeDelta = new Vector2(0f, 0f); _progressBarImage.sprite = Sprites.whitePixel; _progressBarImage.material = Sprites.NoGlowMat; _progressBarImage.type = UnityEngine.UI.Image.Type.Filled; _progressBarImage.fillMethod = UnityEngine.UI.Image.FillMethod.Horizontal; _progressBarImage.fillAmount = 0.5f; _progressText = BeatSaberUI.CreateText(rectTransform, "0.0%", new Vector2(55f, -10f)); _progressText.rectTransform.SetParent(_progressBarRect, true); } _playButton.interactable = false; _progressBarRect.gameObject.SetActive(false); }
public static void Postfix(LevelListTableCell __instance, IPreviewBeatmapLevel level, bool isFavorite, Image[] ____beatmapCharacteristicImages, BeatmapCharacteristicSO[] ____beatmapCharacteristics, TextMeshProUGUI ____songNameText, TextMeshProUGUI ____authorText) { if (level == null || ____songNameText == null || ____authorText == null) { return; } Image voteIcon = null; foreach (var image in __instance.GetComponentsInChildren <Image>()) { // Forked ===== if (image.name == "LevelTypeIcon0" || image.name.IndexOf(ClearedLevelPrefix) >= 0) { if (SPHModel.BestRecords != null && SPHModel.BestRecords.TryGetValue(level.levelID, out var record)) { // Plugin.Log?.Info(level.levelID); var mostDifficulty = level.previewDifficultyBeatmapSets .Where(d => d.beatmapCharacteristic.serializedName == "Standard") .First()? .beatmapDifficulties .Select(b => b.SerializedName().BeatmapDifficultyFromSerializedName(out var difficulty) ? (int)difficulty : -100) .OrderByDescending(x => x) .First(); if (mostDifficulty.HasValue && mostDifficulty.Value == record.Difficulty && record.IsCleared) { image.name = ClearedLevelPrefix + level.levelID; image.color = Color.yellow; } } else { image.name = "LevelTypeIcon0"; } continue; } // =========== // For performance reason, avoid using Linq. if (image.name == "Vote") { voteIcon = image; break; } } if (voteIcon == null) { voteIcon = UnityEngine.Object.Instantiate(____beatmapCharacteristicImages[0], __instance.transform); voteIcon.name = "Vote"; voteIcon.rectTransform.sizeDelta = new Vector2(3f, 3f); voteIcon.color = new Color(1f, 1f, 1f, 0.5f); } voteIcon.enabled = false; if (SPHModel.Votes.TryGetValue(level.levelID.Replace("custom_level_", "").ToLower(), out var vote)) { float pos = -1f; foreach (var d in level.previewDifficultyBeatmapSets) { if (Array.IndexOf(____beatmapCharacteristics, d.beatmapCharacteristic) >= 0) { pos -= d.beatmapCharacteristic.serializedName == "90Degree" ? 3.125f : 4f; } } voteIcon.enabled = true; voteIcon.sprite = vote.voteType == "Upvote" ? _thumbsUp : _thumbsDown; voteIcon.rectTransform.anchoredPosition = new Vector2(pos, 0f); pos -= 3.5f; ____songNameText.rectTransform.offsetMax = new Vector2(pos, ____songNameText.rectTransform.offsetMax.y); ____songNameText.SetText(____songNameText.text); // Force refresh. ____authorText.rectTransform.offsetMax = new Vector2(pos, ____authorText.rectTransform.offsetMax.y); ____authorText.SetText(____authorText.text); // Force refresh. } }
private async void SetDataFromLevelAsync(SongRequest request, LevelListTableCell _tableCell, int row) { var favouritesBadge = _tableCell.GetField <Image, LevelListTableCell>("_favoritesBadgeImage"); favouritesBadge.enabled = false; var highlight = (request.requestInfo.Length > 0) && (request.requestInfo[0] == '!'); var msg = highlight ? "MSG" : ""; var hasMessage = (request.requestInfo.Length > 0) && (request.requestInfo[0] == '!'); var isChallenge = request.requestInfo.IndexOf("!challenge", StringComparison.OrdinalIgnoreCase) >= 0; var pp = ""; var ppvalue = request.song["pp"].AsInt; if (ppvalue > 0) { pp = $" {ppvalue} PP"; } var dt = new RequestBot.DynamicText().AddSong(request.song).AddUser(ref request.requestor); // Get basic fields dt.Add("Status", request.status.ToString()); dt.Add("Info", (request.requestInfo != "") ? " / " + request.requestInfo : ""); dt.Add("RequestTime", request.requestTime.ToLocalTime().ToString("hh:mm")); var songDurationText = _tableCell.GetField <TextMeshProUGUI, LevelListTableCell>("_songDurationText"); songDurationText.text = request.song["songlength"].Value; var songBpm = _tableCell.GetField <TextMeshProUGUI, LevelListTableCell>("_songBpmText"); (songBpm.transform as RectTransform).anchoredPosition = new Vector2(-2.5f, -1.8f); (songBpm.transform as RectTransform).sizeDelta += new Vector2(15f, 0f); var k = new List <string>(); if (hasMessage) { k.Add("MSG"); } if (isChallenge) { k.Add("VS"); } k.Add(request.song["id"]); songBpm.text = string.Join(" - ", k); var songBmpIcon = _tableCell.GetComponentsInChildren <Image>().LastOrDefault(c => string.Equals(c.name, "BpmIcon", StringComparison.OrdinalIgnoreCase)); if (songBmpIcon != null) { Destroy(songBmpIcon); } var songName = _tableCell.GetField <TextMeshProUGUI, LevelListTableCell>("_songNameText"); songName.richText = true; songName.text = $"{request.song["songName"].Value} <size=50%>{RequestBot.GetRating(ref request.song)} <color=#3fff3f>{pp}</color></size>"; var author = _tableCell.GetField <TextMeshProUGUI, LevelListTableCell>("_songAuthorText"); author.richText = true; author.text = dt.Parse(RequestBot.QueueListRow2); var image = _tableCell.GetField <Image, LevelListTableCell>("_coverImage"); var imageSet = false; if (SongCore.Loader.AreSongsLoaded) { var level = CustomLevelForRow(row); if (level != null) { // set image from song's cover image var sprite = await level.GetCoverImageAsync(System.Threading.CancellationToken.None); image.sprite = sprite; imageSet = true; } } if (!imageSet) { var url = request.song["coverURL"].Value; if (!_cachedTextures.TryGetValue(url, out var tex)) { var b = await Plugin.WebClient.DownloadImage($"{url}", System.Threading.CancellationToken.None); tex = new Texture2D(2, 2); tex.LoadImage(b); try { _cachedTextures.Add(url, tex); } catch (Exception) { // ignored } } image.sprite = Base64Sprites.Texture2DToSprite(tex); } UIHelper.AddHintText(_tableCell.transform as RectTransform, dt.Parse(RequestBot.SongHintText)); }
protected override void DidActivate(bool firstActivation, ActivationType activationType) { if (firstActivation) { _timerText = BeatSaberUI.CreateText(rectTransform, "0:30", new Vector2(0f, 35f)); _timerText.alignment = TextAlignmentOptions.Top; _timerText.fontSize = 8f; _nextSongText = BeatSaberUI.CreateText(rectTransform, "Next song:", new Vector2(0f, 15.5f)); _nextSongText.alignment = TextAlignmentOptions.Top; _nextSongText.fontSize = 6f; _currentSongCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")), rectTransform, false); (_currentSongCell.transform as RectTransform).anchoredPosition = new Vector2(55f, -27f); _currentSongCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); _currentSongCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); _currentSongCell.SetPrivateField("_bought", true); foreach (var icon in _currentSongCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } _progressBarRect = new GameObject("ProgressBar", typeof(RectTransform)).GetComponent <RectTransform>(); _progressBarRect.SetParent(rectTransform, false); _progressBarRect.anchorMin = new Vector2(0.5f, 0.5f); _progressBarRect.anchorMax = new Vector2(0.5f, 0.5f); _progressBarRect.anchoredPosition = new Vector2(0f, -7.5f); _progressBarRect.sizeDelta = new Vector2(46f, 5f); _progressBackground = new GameObject("Background", typeof(RectTransform), typeof(Image)).GetComponent <Image>(); _progressBackground.rectTransform.SetParent(_progressBarRect, false); _progressBackground.rectTransform.anchorMin = new Vector2(0f, 0f); _progressBackground.rectTransform.anchorMax = new Vector2(1f, 1f); _progressBackground.rectTransform.anchoredPosition = new Vector2(0f, 0f); _progressBackground.rectTransform.sizeDelta = new Vector2(0f, 0f); _progressBackground.sprite = Sprites.whitePixel; _progressBackground.material = Sprites.NoGlowMat; _progressBackground.color = new Color(1f, 1f, 1f, 0.075f); _progressBarImage = new GameObject("ProgressImage", typeof(RectTransform), typeof(Image)).GetComponent <Image>(); _progressBarImage.rectTransform.SetParent(_progressBarRect, false); _progressBarImage.rectTransform.anchorMin = new Vector2(0f, 0f); _progressBarImage.rectTransform.anchorMax = new Vector2(1f, 1f); _progressBarImage.rectTransform.anchoredPosition = new Vector2(0f, 0f); _progressBarImage.rectTransform.sizeDelta = new Vector2(0f, 0f); _progressBarImage.sprite = Sprites.whitePixel; _progressBarImage.material = Sprites.NoGlowMat; _progressBarImage.type = Image.Type.Filled; _progressBarImage.fillMethod = Image.FillMethod.Horizontal; _progressBarImage.fillAmount = 0.5f; _progressText = BeatSaberUI.CreateText(rectTransform, "0.0%", new Vector2(55f, -10f)); _progressText.rectTransform.SetParent(_progressBarRect, true); _progressBarRect.gameObject.SetActive(false); _skipButton = BeatSaberUI.CreateUIButton(rectTransform, "CancelButton", new Vector2(-12.5f, -25f), new Vector2(20f, 8.8f), () => { skipPressedEvent?.Invoke(); }, "Skip"); _skipButton.ToggleWordWrapping(false); _skipText = BeatSaberUI.CreateText(rectTransform, " this song", new Vector2(8.5f, -21f)); _skipText.alignment = TextAlignmentOptions.Top; _skipText.fontSize = 6f; _skipText.rectTransform.sizeDelta = new Vector2(0f, 0f); _skipText.overflowMode = TextOverflowModes.Overflow; _skipText.enableWordWrapping = false; } _progressBarRect.gameObject.SetActive(false); SetSkipState(false); }
protected override void DidActivate(bool firstActivation, ActivationType type) { if (firstActivation && type == ActivationType.AddedToHierarchy) { _songTableCell = Instantiate(Resources.FindObjectsOfTypeAll <LevelListTableCell>().First(x => (x.name == "LevelListTableCell")), rectTransform); (_songTableCell.transform as RectTransform).anchoredPosition = new Vector2(100f, -1.5f); _songTableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[0]); _songTableCell.SetPrivateField("_beatmapCharacteristicImages", new UnityEngine.UI.Image[0]); _songTableCell.SetPrivateField("_bought", true); foreach (var icon in _songTableCell.GetComponentsInChildren <UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon"))) { Destroy(icon.gameObject); } _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageUpButton")), rectTransform, 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, -12.5f); (_pageUpButton.transform as RectTransform).sizeDelta = new Vector2(40f, 6f); _pageUpButton.interactable = true; _pageUpButton.onClick.AddListener(delegate() { _leaderboardTableView.PageScrollUp(); }); _pageUpButton.interactable = false; _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, 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() { _leaderboardTableView.PageScrollDown(); }); _pageDownButton.interactable = false; _playNowButton = this.CreateUIButton("QuitButton", new Vector2(-39f, 34.5f), new Vector2(28f, 8.8f), () => { playNowButtonPressed?.Invoke(); }, "Play now"); _playNowButton.ToggleWordWrapping(false); _progressText = BeatSaberUI.CreateText(rectTransform, "0.0%", new Vector2(8f, 32f)); _progressText.gameObject.SetActive(false); _leaderboardTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(x => (x.name == "LeaderboardTableCell")); RectTransform container = new GameObject("Content", typeof(RectTransform)).transform as RectTransform; container.SetParent(rectTransform, false); container.anchorMin = new Vector2(0.15f, 0.5f); container.anchorMax = new Vector2(0.85f, 0.5f); container.sizeDelta = new Vector2(0f, 56f); container.anchoredPosition = new Vector2(0f, -3f); _leaderboardTableView = new GameObject("CustomTableView").AddComponent <TableView>(); _leaderboardTableView.gameObject.AddComponent <RectMask2D>(); _leaderboardTableView.transform.SetParent(container, false); _leaderboardTableView.SetPrivateField("_isInitialized", false); _leaderboardTableView.SetPrivateField("_preallocatedCells", new TableView.CellsGroup[0]); _leaderboardTableView.Init(); RectMask2D viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <RectMask2D>().First(), _leaderboardTableView.transform, false); viewportMask.transform.DetachChildren(); _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false); (_leaderboardTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0f); (_leaderboardTableView.transform as RectTransform).anchorMax = new Vector2(1f, 1f); (_leaderboardTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 0f); (_leaderboardTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f); ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageUpButton", _pageUpButton); ReflectionUtil.SetPrivateField(_leaderboardTableView, "_pageDownButton", _pageDownButton); _leaderboardTableView.dataSource = this; _timerText = BeatSaberUI.CreateText(rectTransform, "", new Vector2(0f, 34f)); _timerText.fontSize = 8f; _timerText.alignment = TextAlignmentOptions.Center; _timerText.rectTransform.sizeDelta = new Vector2(30f, 6f); } }