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.

139 lines
4.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CustomUI.BeatSaber;
  4. using CustomUI.Utilities;
  5. using HMUI;
  6. using IPA.Loader;
  7. using IPA.Old;
  8. using UnityEngine;
  9. using VRUI;
  10. namespace BSIPA_ModList.UI
  11. {
  12. internal class ModListController : CustomListViewController
  13. {
  14. private interface IClickableCell
  15. {
  16. void OnSelect(ModListController cntrl);
  17. }
  18. private 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. public BSIPAModCell(PluginLoader.PluginInfo plugin)
  32. : base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
  33. {
  34. Plugin = plugin;
  35. if (plugin.Metadata.Manifest.IconPath != null)
  36. icon = UIUtilities.LoadSpriteRaw(UIUtilities.GetResource(plugin.Metadata.Assembly, plugin.Metadata.Manifest.IconPath));
  37. else
  38. icon = DefaultIcon;
  39. Logger.log.Debug($"BSIPAModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
  40. }
  41. public void OnSelect(ModListController cntrl)
  42. {
  43. Logger.log.Debug($"Selected BSIPAModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
  44. }
  45. }
  46. private class BSIPAIgnoredModCell : CustomCellInfo, IClickableCell
  47. {
  48. internal PluginLoader.PluginMetadata Plugin;
  49. public BSIPAIgnoredModCell(PluginLoader.PluginMetadata plugin)
  50. : base($"<color=#878787>{plugin.Name} <size=60%>v{plugin.Version}", $"{plugin.Manifest.Author} <color=#BFBFBF>- <i>Not loaded</i>", BSIPAModCell.DefaultIcon)
  51. {
  52. Plugin = plugin;
  53. Logger.log.Debug($"BSIPAIgnoredModCell {plugin.Name} {plugin.Version}");
  54. }
  55. public void OnSelect(ModListController cntrl)
  56. {
  57. Logger.log.Debug($"Selected BSIPAIgnoredModCell {Plugin.Name} {Plugin.Version}");
  58. }
  59. }
  60. #pragma warning disable CS0618
  61. private class IPAModCell : CustomCellInfo, IClickableCell
  62. {
  63. private static Sprite _defaultIcon;
  64. public static Sprite DefaultIcon
  65. {
  66. get
  67. {
  68. if (_defaultIcon == null)
  69. _defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_ipa.png");
  70. return _defaultIcon;
  71. }
  72. }
  73. internal IPlugin Plugin;
  74. public IPAModCell(IPlugin plugin)
  75. : base($"{plugin.Name} <size=60%>{plugin.Version}", "<color=#BFBFBF><i>Legacy</i>", DefaultIcon)
  76. {
  77. Plugin = plugin;
  78. Logger.log.Debug($"IPAModCell {plugin.Name} {plugin.Version}");
  79. }
  80. public void OnSelect(ModListController cntrl)
  81. {
  82. Logger.log.Debug($"Selected IPAModCell {Plugin.Name} {Plugin.Version}");
  83. }
  84. }
  85. #pragma warning restore
  86. private BackButtonNavigationController navigation;
  87. #pragma warning disable CS0618
  88. public void Init(BackButtonNavigationController navigation, IEnumerable<PluginLoader.PluginInfo> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)
  89. {
  90. Logger.log.Debug("List Controller Init");
  91. DidActivateEvent = DidActivate;
  92. DidSelectRowEvent = DidSelectRow;
  93. includePageButtons = true;
  94. this.navigation = navigation;
  95. reuseIdentifier = "BSIPAModListTableCell";
  96. foreach (var plugin in bsipaPlugins)
  97. Data.Add(new BSIPAModCell(plugin));
  98. foreach (var plugin in ignoredPlugins)
  99. Data.Add(new BSIPAIgnoredModCell(plugin));
  100. foreach (var plugin in ipaPlugins)
  101. Data.Add(new IPAModCell(plugin));
  102. }
  103. #pragma warning restore
  104. private void DidSelectRow(TableView view, int index)
  105. {
  106. Debug.Assert(ReferenceEquals(view.dataSource, this));
  107. (Data[index] as IClickableCell)?.OnSelect(this);
  108. }
  109. private new void DidActivate(bool first, ActivationType type)
  110. {
  111. }
  112. }
  113. }