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.

187 lines
6.7 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. internal PluginLoader.PluginInfo Plugin;
  21. private ModListController list;
  22. public BSIPAModCell(ModListController list, PluginLoader.PluginInfo plugin)
  23. : base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
  24. {
  25. Plugin = plugin;
  26. this.list = list;
  27. if (string.IsNullOrWhiteSpace(subtext))
  28. subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
  29. icon = plugin.Metadata.GetIcon();
  30. }
  31. private ModInfoViewController infoView;
  32. public void OnSelect(ModListController cntrl)
  33. {
  34. Logger.log.Debug($"Selected BSIPAModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
  35. if (infoView == null)
  36. {
  37. var desc = Plugin.Metadata.Manifest.Description;
  38. if (string.IsNullOrWhiteSpace(desc))
  39. desc = "<color=#BFBFBF><i>No description</i>";
  40. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  41. infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
  42. desc, Plugin.Metadata, Plugin.Metadata.Manifest.Links);
  43. }
  44. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  45. }
  46. }
  47. internal class BSIPAIgnoredModCell : CustomCellInfo, IClickableCell
  48. {
  49. internal PluginLoader.PluginMetadata Plugin;
  50. private ModListController list;
  51. private const string authorFormat = "{0} <color=#BFBFBF>- <i>Not loaded</i>";
  52. private string authorText;
  53. public BSIPAIgnoredModCell(ModListController list, PluginLoader.PluginMetadata plugin)
  54. : base($"<color=#878787>{plugin.Name} <size=60%>v{plugin.Version}", "", Utilities.DefaultBSIPAIcon)
  55. {
  56. Plugin = plugin;
  57. this.list = list;
  58. if (string.IsNullOrWhiteSpace(plugin.Manifest.Author))
  59. authorText = "<color=#BFBFBF><i>Unspecified Author</i>";
  60. else
  61. authorText = plugin.Manifest.Author;
  62. subtext = string.Format(authorFormat, authorText);
  63. }
  64. private ModInfoViewController infoView;
  65. public void OnSelect(ModListController cntrl)
  66. {
  67. Logger.log.Debug($"Selected BSIPAIgnoredModCell {Plugin.Name} {Plugin.Version}");
  68. if (infoView == null)
  69. {
  70. var desc = Plugin.Manifest.Description;
  71. if (string.IsNullOrWhiteSpace(desc))
  72. desc = "<color=#BFBFBF><i>No description</i>";
  73. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  74. infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText,
  75. desc, Plugin, Plugin.Manifest.Links);
  76. }
  77. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  78. }
  79. }
  80. internal class LibraryModCell : CustomCellInfo, IClickableCell
  81. {
  82. internal PluginLoader.PluginInfo Plugin;
  83. private ModListController list;
  84. public LibraryModCell(ModListController list, PluginLoader.PluginInfo plugin)
  85. : base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
  86. {
  87. Plugin = plugin;
  88. this.list = list;
  89. if (string.IsNullOrWhiteSpace(subtext))
  90. subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
  91. icon = Utilities.DefaultLibraryIcon;
  92. }
  93. private ModInfoViewController infoView;
  94. public void OnSelect(ModListController cntrl)
  95. {
  96. Logger.log.Debug($"Selected LibraryModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
  97. if (infoView == null)
  98. {
  99. var desc = Plugin.Metadata.Manifest.Description;
  100. if (string.IsNullOrWhiteSpace(desc))
  101. desc = "<color=#BFBFBF><i>No description</i>";
  102. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  103. infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
  104. desc, Plugin.Metadata, Plugin.Metadata.Manifest.Links);
  105. }
  106. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  107. }
  108. }
  109. #pragma warning disable CS0618
  110. internal class IPAModCell : CustomCellInfo, IClickableCell
  111. {
  112. internal IPlugin Plugin;
  113. private ModListController list;
  114. public IPAModCell(ModListController list, IPlugin plugin)
  115. : base($"{plugin.Name} <size=60%>{plugin.Version}", "<color=#BFBFBF><i>Legacy</i>", Utilities.DefaultIPAIcon)
  116. {
  117. Plugin = plugin;
  118. this.list = list;
  119. }
  120. private ModInfoViewController infoView;
  121. public void OnSelect(ModListController cntrl)
  122. {
  123. Logger.log.Debug($"Selected IPAModCell {Plugin.Name} {Plugin.Version}");
  124. if (infoView == null)
  125. {
  126. PluginLoader.PluginMetadata updateInfo = null;
  127. try
  128. {
  129. updateInfo = new PluginLoader.PluginMetadata
  130. {
  131. Name = Plugin.Name,
  132. Id = Plugin.Name,
  133. Version = new SemVer.Version(Plugin.Version)
  134. };
  135. }
  136. catch (Exception e)
  137. {
  138. Logger.log.Warn($"Could not generate fake update info for {Plugin.Name}");
  139. Logger.log.Warn(e);
  140. }
  141. infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
  142. infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), "<color=#BFBFBF><i>Unknown Author</i>",
  143. "<color=#A0A0A0>This mod was written for IPA Reloaded. No metadata is avaliable for this mod. " +
  144. "Please contact the mod author and ask them to port it to BSIPA to provide more information.", updateInfo);
  145. }
  146. list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
  147. }
  148. }
  149. #pragma warning restore
  150. }