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.

94 lines
3.5 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. public void Init(DownloadObject mod)
  16. {
  17. Destroy(GetComponent<LevelListTableCell>());
  18. reuseIdentifier = "DownloadCell";
  19. this.mod = mod;
  20. _authorText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "Author");
  21. _authorText.enableWordWrapping = false;
  22. _authorText.overflowMode = TextOverflowModes.Overflow;
  23. _songNameText = GetComponentsInChildren<TextMeshProUGUI>().First(x => x.name == "SongName");
  24. _songNameText.enableWordWrapping = false;
  25. _songNameText.overflowMode = TextOverflowModes.Overflow;
  26. _coverRawImage = GetComponentsInChildren<UnityEngine.UI.RawImage>().First(x => x.name == "CoverImage");
  27. _bgImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "BG");
  28. _highlightImage = GetComponentsInChildren<UnityEngine.UI.Image>().First(x => x.name == "Highlight");
  29. _beatmapCharacteristicAlphas = new float[0];
  30. _beatmapCharacteristicImages = new UnityEngine.UI.Image[0];
  31. _bought = true;
  32. foreach (var icon in GetComponentsInChildren<UnityEngine.UI.Image>().Where(x => x.name.StartsWith("LevelTypeIcon")))
  33. Destroy(icon.gameObject);
  34. _songNameText.text = $"{mod.Mod.Name} <size=60%>v{mod.Mod.ResolvedVersion}</size>";
  35. _authorText.text = "";
  36. _coverRawImage.texture = mod.Icon.texture;
  37. _bgImage.enabled = true;
  38. _bgImage.sprite = Sprite.Create(new Texture2D(1, 1), new Rect(0, 0, 1, 1), Vector2.one / 2f);
  39. _bgImage.type = UnityEngine.UI.Image.Type.Filled;
  40. _bgImage.fillMethod = UnityEngine.UI.Image.FillMethod.Horizontal;
  41. Update();
  42. }
  43. public void Update()
  44. {
  45. if (mod == null) return;
  46. _bgImage.enabled = true;
  47. switch (mod.State)
  48. {
  49. case DownloadObject.States.ToDownload:
  50. {
  51. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  52. _bgImage.fillAmount = 0;
  53. }
  54. break;
  55. case DownloadObject.States.Downloading:
  56. {
  57. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  58. _bgImage.fillAmount = (float)mod.Progress;
  59. }
  60. break;
  61. case DownloadObject.States.Installing:
  62. {
  63. _bgImage.color = new Color(0f, 1f, 1f, 0.35f);
  64. _bgImage.fillAmount = 1f;
  65. }
  66. break;
  67. case DownloadObject.States.Completed:
  68. {
  69. _bgImage.color = new Color(0f, 1f, 0f, 0.35f);
  70. _bgImage.fillAmount = 1f;
  71. }
  72. break;
  73. case DownloadObject.States.Failed:
  74. {
  75. _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
  76. _bgImage.fillAmount = 1f;
  77. }
  78. break;
  79. }
  80. }
  81. }
  82. }