private async void SetDataFromLevelAsync(SongRequest request, LevelListTableCell _tableCell, int row) { bool highlight = (request.requestInfo.Length > 0) && (request.requestInfo[0] == '!'); string msg = highlight ? "MSG" : ""; var hasMessage = (request.requestInfo.Length > 0) && (request.requestInfo[0] == '!'); var isChallenge = request.requestInfo.IndexOf("!challenge", StringComparison.OrdinalIgnoreCase) >= 0; var beatmapCharacteristicImages = _tableCell.GetPrivateField <UnityEngine.UI.Image[]>("_beatmapCharacteristicImages"); // NEW VERSION foreach (var i in beatmapCharacteristicImages) { i.enabled = false; } _tableCell.SetPrivateField("_beatmapCharacteristicAlphas", new float[3] { 0f, 1f, 1f }); // set message icon if request has a message // NEW VERSION if (hasMessage) { beatmapCharacteristicImages.Last().sprite = Base64Sprites.InfoIcon; beatmapCharacteristicImages.Last().enabled = true; } // set challenge icon if song is a challenge if (isChallenge) { var el = beatmapCharacteristicImages.ElementAt(1); el.sprite = Base64Sprites.VersusChallengeIcon; el.enabled = true; } string pp = ""; int 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 songName = _tableCell.GetPrivateField <TextMeshProUGUI>("_songNameText"); //songName.text = $"{request.song["songName"].Value} <size=50%>{RequestBot.GetRating(ref request.song)} <color=#3fff3f>{pp}</color></size> <color=#ff00ff>{msg}</color>"; songName.text = $"{request.song["songName"].Value} <size=50%>{RequestBot.GetRating(ref request.song)} <color=#3fff3f>{pp}</color></size>"; // NEW VERSION var author = _tableCell.GetPrivateField <TextMeshProUGUI>("_authorText"); author.text = dt.Parse(RequestBot.QueueListRow2); var image = _tableCell.GetPrivateField <RawImage>("_coverRawImage"); var imageSet = false; if (SongCore.Loader.AreSongsLoaded) { CustomPreviewBeatmapLevel level = CustomLevelForRow(row); if (level != null) { Plugin.Log("custom level found"); // set image from song's cover image var tex = await level.GetCoverImageTexture2DAsync(System.Threading.CancellationToken.None); image.texture = tex; imageSet = true; } } if (!imageSet) { string url = request.song["coverURL"].Value; var s = GetSongCoverArt(url, (sprite) => { _cachedSprites[url] = sprite; _customListTableView.ReloadData(); }); image.texture = s.texture; } BeatSaberUI.AddHintText(_tableCell.transform as RectTransform, dt.Parse(RequestBot.SongHintText)); }
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)); }
private async void SetDataFromLevelAsync(SongRequest request, LevelListTableCell _tableCell, int row) { var favouritesBadge = _tableCell.GetField <RawImage, LevelListTableCell>("_favoritesBadgeImage"); favouritesBadge.enabled = false; bool highlight = (request.requestInfo.Length > 0) && (request.requestInfo[0] == '!'); string msg = highlight ? "MSG" : ""; var hasMessage = (request.requestInfo.Length > 0) && (request.requestInfo[0] == '!'); var isChallenge = request.requestInfo.IndexOf("!challenge", StringComparison.OrdinalIgnoreCase) >= 0; var beatmapCharacteristicImages = _tableCell.GetField <UnityEngine.UI.Image[], LevelListTableCell>("_beatmapCharacteristicImages"); // NEW VERSION foreach (var i in beatmapCharacteristicImages) { i.enabled = false; } // causing a nullex? //_tableCell.SetField("_beatmapCharacteristicAlphas", new float[5] { 1f, 1f, 1f, 1f, 1f }); // set message icon if request has a message // NEW VERSION if (hasMessage) { beatmapCharacteristicImages.Last().sprite = Base64Sprites.InfoIcon; beatmapCharacteristicImages.Last().enabled = true; } // set challenge icon if song is a challenge if (isChallenge) { var el = beatmapCharacteristicImages.ElementAt(beatmapCharacteristicImages.Length - 2); el.sprite = Base64Sprites.VersusChallengeIcon; el.enabled = true; } string pp = ""; int 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 songName = _tableCell.GetField <TextMeshProUGUI, LevelListTableCell>("_songNameText"); //songName.text = $"{request.song["songName"].Value} <size=50%>{RequestBot.GetRating(ref request.song)} <color=#3fff3f>{pp}</color></size> <color=#ff00ff>{msg}</color>"; songName.text = $"{request.song["songName"].Value} <size=50%>{RequestBot.GetRating(ref request.song)} <color=#3fff3f>{pp}</color></size>"; // NEW VERSION var author = _tableCell.GetField <TextMeshProUGUI, LevelListTableCell>("_authorText"); author.text = dt.Parse(RequestBot.QueueListRow2); var image = _tableCell.GetField <RawImage, LevelListTableCell>("_coverRawImage"); var imageSet = false; if (SongCore.Loader.AreSongsLoaded) { CustomPreviewBeatmapLevel level = CustomLevelForRow(row); if (level != null) { //Plugin.Log("custom level found"); // set image from song's cover image var tex = await level.GetCoverImageTexture2DAsync(System.Threading.CancellationToken.None); image.texture = tex; imageSet = true; } } if (!imageSet) { string url = request.song["coverURL"].Value; if (!_cachedTextures.TryGetValue(url, out var tex)) { var b = await Plugin.WebClient.DownloadImage($"https://beatsaver.com{url}", System.Threading.CancellationToken.None); tex = new Texture2D(2, 2); tex.LoadImage(b); try { _cachedTextures.Add(url, tex); } catch (Exception) { } } image.texture = tex; } UIHelper.AddHintText(_tableCell.transform as RectTransform, dt.Parse(RequestBot.SongHintText)); }