You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using TMPro;
  6. using System.Threading.Tasks;
  7. using IPA.Updating.BeatMods;
  8. using UnityEngine;
  9. namespace BSIPA_ModList.UI
  10. {
  11. // originally ripped verbatim from Andruzz's BeatSaverDownloader
  12. internal class DownloadProgressCell : LevelListTableCell
  13. {
  14. private DownloadObject mod;
  15. protected override void Awake()
  16. {
  17. base.Awake();
  18. }
  19. public void Init(DownloadObject mod)
  20. {
  21. Destroy(GetComponent<LevelListTableCell>());
  22. reuseIdentifier = "DownloadCell";
  23. this.mod = mod;
  24. _authorText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "Author");
  25. _authorText.enableWordWrapping = false;
  26. _authorText.overflowMode = TextOverflowModes.Overflow;
  27. _songNameText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "SongName");
  28. _songNameText.enableWordWrapping = false;
  29. _songNameText.overflowMode = TextOverflowModes.Overflow;
  30. _coverRawImage = GetComponentsInChildren<UnityEngine.UI.RawImage>().First(x => x.name == "CoverImage");
  31. _bgImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "BG");
  32. _highlightImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "Highlight");
  33. _beatmapCharacteristicAlphas = new float[0];
  34. _beatmapCharacteristicImages = new UnityEngine.UI.Image[0];
  35. _bought = true;
  36. foreach (var icon in GetComponentsInChildren<UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
  37. Destroy(icon.gameObject);
  38. _songNameText.text = $"{mod.Mod.Name} <size=60%>v{mod.Mod.ResolvedVersion}</size>";
  39. _authorText.text = "";
  40. _coverRawImage.texture = mod.Icon.texture;
  41. _bgImage.enabled = true;
  42. _bgImage.sprite = Sprite.Create(new Texture2D(1, 1), new Rect(0, 0, 1, 1), Vector2.one / 2f);
  43. _bgImage.type = UnityEngine.UI.Image.Type.Filled;
  44. _bgImage.fillMethod = UnityEngine.UI.Image.FillMethod.Horizontal;
  45. Update();
  46. }
  47. public void Update()
  48. {
  49. if (mod == null) return;
  50. _bgImage.enabled = true;
  51. switch (mod.State)
  52. {
  53. case DownloadObject.States.ToDownload:
  54. {
  55. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  56. _bgImage.fillAmount = 0;
  57. }
  58. break;
  59. case DownloadObject.States.Downloading:
  60. {
  61. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  62. _bgImage.fillAmount = (float)mod.Progress;
  63. }
  64. break;
  65. case DownloadObject.States.Installing:
  66. {
  67. _bgImage.color = new Color(0f, 1f, 1f, 0.35f);
  68. _bgImage.fillAmount = 1f;
  69. }
  70. break;
  71. case DownloadObject.States.Completed:
  72. {
  73. _bgImage.color = new Color(0f, 1f, 0f, 0.35f);
  74. _bgImage.fillAmount = 1f;
  75. }
  76. break;
  77. case DownloadObject.States.Failed:
  78. {
  79. _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
  80. _bgImage.fillAmount = 1f;
  81. }
  82. break;
  83. }
  84. }
  85. }
  86. }