RequirementsUI.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using BeatSaberMarkupLanguage;
  2. using BeatSaberMarkupLanguage.Attributes;
  3. using BeatSaberMarkupLanguage.Components;
  4. using BS_Utils.Utilities;
  5. using SongCore.Utilities;
  6. using System.Linq;
  7. using System.Reflection;
  8. using UnityEngine;
  9. using static BeatSaberMarkupLanguage.Components.CustomListTableData;
  10. namespace SongCore.UI
  11. {
  12. public class RequirementsUI : NotifiableSingleton<RequirementsUI>
  13. {
  14. private StandardLevelDetailViewController standardLevel;
  15. internal static BS_Utils.Utilities.Config ModPrefs = new BS_Utils.Utilities.Config("SongCore/SongCore");
  16. internal Sprite HaveReqIcon;
  17. internal Sprite MissingReqIcon;
  18. internal Sprite HaveSuggestionIcon;
  19. internal Sprite MissingSuggestionIcon;
  20. internal Sprite WarningIcon;
  21. internal Sprite InfoIcon;
  22. //Currently selected song data
  23. public CustomPreviewBeatmapLevel level;
  24. public Data.ExtraSongData songData;
  25. public Data.ExtraSongData.DifficultyData diffData;
  26. public bool wipFolder;
  27. [UIComponent("list")]
  28. public CustomListTableData customListTableData;
  29. private bool _buttonGlow = false;
  30. [UIValue("button-glow")]
  31. public bool ButtonGlowColor
  32. {
  33. get => _buttonGlow;
  34. set
  35. {
  36. _buttonGlow = value;
  37. NotifyPropertyChanged();
  38. }
  39. }
  40. private bool buttonInteractable = false;
  41. [UIValue("button-interactable")]
  42. public bool ButtonInteractable
  43. {
  44. get => buttonInteractable;
  45. set
  46. {
  47. buttonInteractable = value;
  48. NotifyPropertyChanged();
  49. }
  50. }
  51. [UIComponent("info-button")]
  52. private Transform infoButtonTransform;
  53. internal void Setup()
  54. {
  55. GetIcons();
  56. standardLevel = Resources.FindObjectsOfTypeAll<StandardLevelDetailViewController>().First();
  57. BSMLParser.instance.Parse(BeatSaberMarkupLanguage.Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "SongCore.UI.requirements.bsml"), standardLevel.transform.Find("LevelDetail").gameObject, this);
  58. infoButtonTransform.localScale *= 0.7f;//no scale property in bsml as of now so manually scaling it
  59. (standardLevel.transform.Find("LevelDetail").Find("FavoriteToggle")?.transform as RectTransform).anchoredPosition = new Vector2(3, -2);
  60. }
  61. internal void GetIcons()
  62. {
  63. if (!MissingReqIcon)
  64. MissingReqIcon = Utilities.Utils.LoadSpriteFromResources("SongCore.Icons.RedX.png");
  65. if (!HaveReqIcon)
  66. HaveReqIcon = Utilities.Utils.LoadSpriteFromResources("SongCore.Icons.GreenCheck.png");
  67. if (!HaveSuggestionIcon)
  68. HaveSuggestionIcon = Utilities.Utils.LoadSpriteFromResources("SongCore.Icons.YellowCheck.png");
  69. if (!MissingSuggestionIcon)
  70. MissingSuggestionIcon = Utilities.Utils.LoadSpriteFromResources("SongCore.Icons.YellowX.png");
  71. if (!WarningIcon)
  72. WarningIcon = Utilities.Utils.LoadSpriteFromResources("SongCore.Icons.Warning.png");
  73. if (!InfoIcon)
  74. InfoIcon = Utilities.Utils.LoadSpriteFromResources("SongCore.Icons.Info.png");
  75. }
  76. [UIAction("button-click")]
  77. internal void ShowRequirements()
  78. {
  79. // suggestionsList.text = "";
  80. customListTableData.data.Clear();
  81. //Requirements
  82. if (diffData != null)
  83. {
  84. if (diffData.additionalDifficultyData._requirements.Count() > 0)
  85. {
  86. foreach (string req in diffData.additionalDifficultyData._requirements)
  87. {
  88. // Console.WriteLine(req);
  89. if (!Collections.capabilities.Contains(req))
  90. customListTableData.data.Add(new CustomCellInfo("<size=75%>" + req, "Missing Requirement", MissingReqIcon));
  91. else
  92. customListTableData.data.Add(new CustomCellInfo("<size=75%>" + req, "Requirement", HaveReqIcon));
  93. }
  94. }
  95. }
  96. //Contributors
  97. if (songData.contributors.Count() > 0)
  98. {
  99. foreach (Data.ExtraSongData.Contributor author in songData.contributors)
  100. {
  101. if (author.icon == null)
  102. if (!string.IsNullOrWhiteSpace(author._iconPath))
  103. {
  104. author.icon = Utilities.Utils.LoadSpriteFromFile(level.customLevelPath + "/" + author._iconPath);
  105. customListTableData.data.Add(new CustomCellInfo(author._name, author._role, author.icon ?? InfoIcon));
  106. }
  107. else
  108. customListTableData.data.Add(new CustomCellInfo(author._name, author._role, InfoIcon));
  109. else
  110. customListTableData.data.Add(new CustomCellInfo(author._name, author._role, author.icon));
  111. }
  112. }
  113. //WIP Check
  114. if (wipFolder)
  115. customListTableData.data.Add(new CustomCellInfo("<size=70%>" + "WIP Song. Please Play in Practice Mode", "Warning", WarningIcon));
  116. //Additional Diff Info
  117. if (diffData != null)
  118. {
  119. if (diffData.additionalDifficultyData._warnings.Count() > 0)
  120. {
  121. foreach (string req in diffData.additionalDifficultyData._warnings)
  122. {
  123. // Console.WriteLine(req);
  124. customListTableData.data.Add(new CustomCellInfo("<size=75%>" + req, "Warning", WarningIcon));
  125. }
  126. }
  127. if (diffData.additionalDifficultyData._information.Count() > 0)
  128. {
  129. foreach (string req in diffData.additionalDifficultyData._information)
  130. {
  131. // Console.WriteLine(req);
  132. customListTableData.data.Add(new CustomCellInfo("<size=75%>" + req, "Info", InfoIcon));
  133. }
  134. }
  135. if (diffData.additionalDifficultyData._suggestions.Count() > 0)
  136. {
  137. foreach (string req in diffData.additionalDifficultyData._suggestions)
  138. {
  139. // Console.WriteLine(req);
  140. if (!Collections.capabilities.Contains(req))
  141. customListTableData.data.Add(new CustomCellInfo("<size=75%>" + req, "Missing Suggestion", MissingSuggestionIcon));
  142. else
  143. customListTableData.data.Add(new CustomCellInfo("<size=75%>" + req, "Suggestion", HaveSuggestionIcon));
  144. }
  145. }
  146. }
  147. customListTableData.tableView.ReloadData();
  148. customListTableData.tableView.ScrollToCellWithIdx(0, HMUI.TableViewScroller.ScrollPositionType.Beginning, false);
  149. }
  150. }
  151. }