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.

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