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.

228 lines
8.2 KiB

  1. using CustomUI.BeatSaber;
  2. using CustomUI.Utilities;
  3. using IPA.Loader;
  4. using IPA.Loader.Features;
  5. using IPA.Old;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using UnityEngine;
  12. namespace BSIPA_ModList.UI.ViewControllers
  13. {
  14. internal interface IClickableCell
  15. {
  16. void OnSelect(ModListController cntrl);
  17. }
  18. internal class BSIPAModCell : CustomCellInfo, IClickableCell
  19. {
  20. private static Sprite _defaultIcon;
  21. public static Sprite DefaultIcon
  22. {
  23. get
  24. {
  25. if (_defaultIcon == null)
  26. _defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_bsipa.png");
  27. return _defaultIcon;
  28. }
  29. }
  30. internal PluginLoader.PluginInfo Plugin;
  31. private ModListController list;
  32. public BSIPAModCell(ModListController list, PluginLoader.PluginInfo plugin)
  33. : base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
  34. {
  35. Plugin = plugin;
  36. this.list = list;
  37. if (string.IsNullOrWhiteSpace(subtext))
  38. subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
  39. if (plugin.Metadata.Manifest.IconPath != null)
  40. {
  41. try
  42. {
  43. icon = UIUtilities.LoadSpriteRaw(UIUtilities.GetResource(plugin.Metadata.Assembly, plugin.Metadata.Manifest.IconPath));
  44. }
  45. catch (Exception e)
  46. {
  47. Logger.log.Error($"Error loading icon for {plugin.Metadata.Name}");
  48. Logger.log.Error(e);
  49. }
  50. }
  51. if (icon == null)
  52. icon = DefaultIcon;
  53. Logger.log.Debug($"BSIPAModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
  54. }
  55. private ModInfoViewController infoView;
  56. public void OnSelect(ModListController cntrl)
  57. {
  58. Logger.log.Debug($"Selected BSIPAModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
  59. if (infoView == null)
  60. {
  61. var desc = Plugin.Metadata.Manifest.Description;
  62. if (string.IsNullOrWhiteSpace(desc))
  63. desc = "<color=#BFBFBF><i>No description</i>";
  64. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  65. infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
  66. desc, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin.Metadata : null,
  67. Plugin.Metadata.Manifest.Links);
  68. }
  69. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  70. }
  71. }
  72. internal class BSIPAIgnoredModCell : CustomCellInfo, IClickableCell
  73. {
  74. internal PluginLoader.PluginMetadata Plugin;
  75. private ModListController list;
  76. private const string authorFormat = "{0} <color=#BFBFBF>- <i>Not loaded</i>";
  77. private string authorText;
  78. public BSIPAIgnoredModCell(ModListController list, PluginLoader.PluginMetadata plugin)
  79. : base($"<color=#878787>{plugin.Name} <size=60%>v{plugin.Version}", "", BSIPAModCell.DefaultIcon)
  80. {
  81. Plugin = plugin;
  82. this.list = list;
  83. if (string.IsNullOrWhiteSpace(plugin.Manifest.Author))
  84. authorText = "<color=#BFBFBF><i>Unspecified Author</i>";
  85. else
  86. authorText = plugin.Manifest.Author;
  87. subtext = string.Format(authorFormat, authorText);
  88. Logger.log.Debug($"BSIPAIgnoredModCell {plugin.Name} {plugin.Version}");
  89. }
  90. private ModInfoViewController infoView;
  91. public void OnSelect(ModListController cntrl)
  92. {
  93. Logger.log.Debug($"Selected BSIPAIgnoredModCell {Plugin.Name} {Plugin.Version}");
  94. if (infoView == null)
  95. {
  96. var desc = Plugin.Manifest.Description;
  97. if (string.IsNullOrWhiteSpace(desc))
  98. desc = "<color=#BFBFBF><i>No description</i>";
  99. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  100. infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText,
  101. desc, Plugin.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin : null,
  102. Plugin.Manifest.Links);
  103. }
  104. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  105. }
  106. }
  107. internal class LibraryModCell : CustomCellInfo, IClickableCell
  108. {
  109. private static Sprite _defaultIcon;
  110. public static Sprite DefaultIcon
  111. {
  112. get
  113. {
  114. if (_defaultIcon == null)
  115. _defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.library.png");
  116. return _defaultIcon;
  117. }
  118. }
  119. internal PluginLoader.PluginInfo Plugin;
  120. private ModListController list;
  121. public LibraryModCell(ModListController list, PluginLoader.PluginInfo plugin)
  122. : base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
  123. {
  124. Plugin = plugin;
  125. this.list = list;
  126. if (string.IsNullOrWhiteSpace(subtext))
  127. subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
  128. icon = DefaultIcon;
  129. Logger.log.Debug($"LibraryModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
  130. }
  131. private ModInfoViewController infoView;
  132. public void OnSelect(ModListController cntrl)
  133. {
  134. Logger.log.Debug($"Selected LibraryModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
  135. if (infoView == null)
  136. {
  137. var desc = Plugin.Metadata.Manifest.Description;
  138. if (string.IsNullOrWhiteSpace(desc))
  139. desc = "<color=#BFBFBF><i>No description</i>";
  140. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  141. infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
  142. desc, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin.Metadata : null,
  143. Plugin.Metadata.Manifest.Links);
  144. }
  145. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  146. }
  147. }
  148. #pragma warning disable CS0618
  149. internal class IPAModCell : CustomCellInfo, IClickableCell
  150. {
  151. private static Sprite _defaultIcon;
  152. public static Sprite DefaultIcon
  153. {
  154. get
  155. {
  156. if (_defaultIcon == null)
  157. _defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_ipa.png");
  158. return _defaultIcon;
  159. }
  160. }
  161. internal IPlugin Plugin;
  162. private ModListController list;
  163. public IPAModCell(ModListController list, IPlugin plugin)
  164. : base($"{plugin.Name} <size=60%>{plugin.Version}", "<color=#BFBFBF><i>Legacy</i>", DefaultIcon)
  165. {
  166. Plugin = plugin;
  167. this.list = list;
  168. Logger.log.Debug($"IPAModCell {plugin.Name} {plugin.Version}");
  169. }
  170. private ModInfoViewController infoView;
  171. public void OnSelect(ModListController cntrl)
  172. {
  173. Logger.log.Debug($"Selected IPAModCell {Plugin.Name} {Plugin.Version}");
  174. if (infoView == null)
  175. {
  176. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  177. infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), "<color=#BFBFBF><i>Unknown Author</i>",
  178. "<color=#A0A0A0>This mod was written for IPA Reloaded. No metadata is avaliable for this mod. " +
  179. "Please contact the mod author and ask them to port it to BSIPA to provide more information.", null);
  180. }
  181. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  182. }
  183. }
  184. #pragma warning restore
  185. }