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.

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