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.

98 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. _coverImage = GetComponentsInChildren<UnityEngine.UI.Image>().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. _coverImage.sprite = mod.Icon;
  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. _bgImage.enabled = true;
  50. switch (mod.State)
  51. {
  52. case DownloadObject.States.ToDownload:
  53. {
  54. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  55. _bgImage.fillAmount = 0;
  56. }
  57. break;
  58. case DownloadObject.States.Downloading:
  59. {
  60. _bgImage.color = new Color(1f, 1f, 1f, 0.35f);
  61. _bgImage.fillAmount = (float)mod.Progress;
  62. }
  63. break;
  64. case DownloadObject.States.Installing:
  65. {
  66. _bgImage.color = new Color(0f, 1f, 1f, 0.35f);
  67. _bgImage.fillAmount = 1f;
  68. }
  69. break;
  70. case DownloadObject.States.Completed:
  71. {
  72. _bgImage.color = new Color(0f, 1f, 0f, 0.35f);
  73. _bgImage.fillAmount = 1f;
  74. }
  75. break;
  76. case DownloadObject.States.Failed:
  77. {
  78. _bgImage.color = new Color(1f, 0f, 0f, 0.35f);
  79. _bgImage.fillAmount = 1f;
  80. }
  81. break;
  82. }
  83. }
  84. }
  85. }