DownloadQueueTableCell.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using SongBrowser.DataAccess;
  2. using SongBrowser.DataAccess.BeatSaverApi;
  3. using System.Linq;
  4. using System.Reflection;
  5. using TMPro;
  6. using UnityEngine;
  7. using Logger = SongBrowser.Logging.Logger;
  8. // From: https://github.com/andruzzzhka/BeatSaverDownloader
  9. namespace SongBrowser.UI.DownloadQueue
  10. {
  11. class DownloadQueueTableCell : LevelListTableCell
  12. {
  13. Song song;
  14. public void Init(Song _song)
  15. {
  16. Destroy(GetComponent<LevelListTableCell>());
  17. reuseIdentifier = "DownloadCell";
  18. song = _song;
  19. _authorText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "Author");
  20. _songNameText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "SongName");
  21. _coverRawImage = GetComponentsInChildren<UnityEngine.UI.RawImage>().First(x => x.name == "CoverImage");
  22. _bgImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "BG");
  23. _highlightImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "Highlight");
  24. _beatmapCharacteristicAlphas = new float[0];
  25. _beatmapCharacteristicImages = new UnityEngine.UI.Image[0];
  26. _bought = true;
  27. foreach (var icon in GetComponentsInChildren<UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
  28. {
  29. Destroy(icon.gameObject);
  30. }
  31. _songNameText.text = string.Format("{0}\n<size=80%>{1}</size>", song.songName, song.songSubName);
  32. _authorText.text = song.levelAuthorName;
  33. StartCoroutine(LoadScripts.LoadSpriteCoroutine(song.coverURL, (cover) => { if (cover != null) _coverRawImage.texture = cover.texture ; }));
  34. _bgImage.enabled = true;
  35. _bgImage.sprite = Sprite.Create((new Texture2D(1, 1)), new Rect(0, 0, 1, 1), Vector2.one / 2f);
  36. _bgImage.type = UnityEngine.UI.Image.Type.Filled;
  37. _bgImage.fillMethod = UnityEngine.UI.Image.FillMethod.Horizontal;
  38. switch (song.songQueueState)
  39. {
  40. case SongQueueState.Queued:
  41. case SongQueueState.Downloading:
  42. {
  43. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  44. _bgImage.fillAmount = song.downloadingProgress;
  45. }
  46. break;
  47. case SongQueueState.Downloaded:
  48. {
  49. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  50. _bgImage.fillAmount = 1f;
  51. }
  52. break;
  53. case SongQueueState.Error:
  54. {
  55. _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
  56. _bgImage.fillAmount = 1f;
  57. }
  58. break;
  59. }
  60. }
  61. public void Update()
  62. {
  63. _bgImage.enabled = true;
  64. switch (song.songQueueState)
  65. {
  66. case SongQueueState.Queued:
  67. case SongQueueState.Downloading:
  68. {
  69. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  70. _bgImage.fillAmount = song.downloadingProgress;
  71. }
  72. break;
  73. case SongQueueState.Downloaded:
  74. {
  75. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  76. _bgImage.fillAmount = 1f;
  77. }
  78. break;
  79. case SongQueueState.Error:
  80. {
  81. _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
  82. _bgImage.fillAmount = 1f;
  83. }
  84. break;
  85. }
  86. }
  87. }
  88. }