123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using SongBrowser.DataAccess;
- using SongBrowser.DataAccess.BeatSaverApi;
- using System.Linq;
- using System.Reflection;
- using TMPro;
- using UnityEngine;
- using Logger = SongBrowser.Logging.Logger;
- // From: https://github.com/andruzzzhka/BeatSaverDownloader
- namespace SongBrowser.UI.DownloadQueue
- {
- class DownloadQueueTableCell : LevelListTableCell
- {
- Song song;
- public void Init(Song _song)
- {
- Destroy(GetComponent<LevelListTableCell>());
- reuseIdentifier = "DownloadCell";
- song = _song;
- _authorText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "Author");
- _songNameText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "SongName");
- _coverRawImage = GetComponentsInChildren<UnityEngine.UI.RawImage>().First(x => x.name == "CoverImage");
- _bgImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "BG");
- _highlightImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "Highlight");
- _beatmapCharacteristicAlphas = new float[0];
- _beatmapCharacteristicImages = new UnityEngine.UI.Image[0];
- _bought = true;
- foreach (var icon in GetComponentsInChildren<UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
- {
- Destroy(icon.gameObject);
- }
- _songNameText.text = string.Format("{0}\n<size=80%>{1}</size>", song.songName, song.songSubName);
- _authorText.text = song.levelAuthorName;
- StartCoroutine(LoadScripts.LoadSpriteCoroutine(song.coverURL, (cover) => { if (cover != null) _coverRawImage.texture = cover.texture ; }));
- _bgImage.enabled = true;
- _bgImage.sprite = Sprite.Create((new Texture2D(1, 1)), new Rect(0, 0, 1, 1), Vector2.one / 2f);
- _bgImage.type = UnityEngine.UI.Image.Type.Filled;
- _bgImage.fillMethod = UnityEngine.UI.Image.FillMethod.Horizontal;
- switch (song.songQueueState)
- {
- case SongQueueState.Queued:
- case SongQueueState.Downloading:
- {
- _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
- _bgImage.fillAmount = song.downloadingProgress;
- }
- break;
- case SongQueueState.Downloaded:
- {
- _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
- _bgImage.fillAmount = 1f;
- }
- break;
- case SongQueueState.Error:
- {
- _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
- _bgImage.fillAmount = 1f;
- }
- break;
- }
- }
- public void Update()
- {
- _bgImage.enabled = true;
- switch (song.songQueueState)
- {
- case SongQueueState.Queued:
- case SongQueueState.Downloading:
- {
- _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
- _bgImage.fillAmount = song.downloadingProgress;
- }
- break;
- case SongQueueState.Downloaded:
- {
- _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
- _bgImage.fillAmount = 1f;
- }
- break;
- case SongQueueState.Error:
- {
- _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
- _bgImage.fillAmount = 1f;
- }
- break;
- }
- }
- }
- }
|