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.

101 lines
3.3 KiB

  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using CustomUI.BeatSaber;
  5. using CustomUI.Utilities;
  6. using HMUI;
  7. using IPA.Loader;
  8. using IPA.Old;
  9. using UnityEngine;
  10. using VRUI;
  11. using IPA.Loader.Features;
  12. using TMPro;
  13. using BSIPA_ModList.UI.ViewControllers;
  14. using UnityEngine.UI;
  15. namespace BSIPA_ModList.UI
  16. {
  17. internal class ModListController : CustomListViewController
  18. {
  19. public override TableCell CellForIdx(int idx)
  20. {
  21. var cell = base.CellForIdx(idx) as LevelListTableCell;
  22. var nameText = cell.GetPrivateField<TextMeshProUGUI>("_songNameText");
  23. nameText.overflowMode = TextOverflowModes.Overflow;
  24. var authorText = cell.GetPrivateField<TextMeshProUGUI>("_authorText");
  25. authorText.overflowMode = TextOverflowModes.Overflow;
  26. return cell;
  27. }
  28. internal ModListFlowCoordinator flow;
  29. #pragma warning disable CS0618
  30. public void Init(ModListFlowCoordinator flow, IEnumerable<PluginLoader.PluginMetadata> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)
  31. {
  32. Data.Clear();
  33. Logger.log.Debug("List Controller Init");
  34. DidActivateEvent = DidActivate;
  35. DidSelectRowEvent = DidSelectRow;
  36. rectTransform.anchorMin = new Vector2(0f, 0f);
  37. rectTransform.anchorMax = new Vector2(.4f, 1f);
  38. includePageButtons = true;
  39. this.flow = flow;
  40. reuseIdentifier = "BSIPAModListTableCell";
  41. foreach (var plugin in bsipaPlugins.Where(p => !p.IsBare))
  42. Data.Add(new BSIPAModCell(this, plugin));
  43. foreach (var plugin in ignoredPlugins)
  44. Data.Add(new BSIPAIgnoredModCell(this, plugin));
  45. foreach (var plugin in bsipaPlugins.Where(p => p.IsBare))
  46. Data.Add(new LibraryModCell(this, plugin));
  47. foreach (var plugin in ipaPlugins)
  48. Data.Add(new IPAModCell(this, plugin));
  49. }
  50. #pragma warning restore
  51. public void Reload()
  52. {
  53. var cells = _customListTableView.GetPrivateField<List<TableCell>>("_visibleCells");
  54. foreach (var c in cells)
  55. {
  56. if (c == null) continue;
  57. c.gameObject?.SetActive(false);
  58. _customListTableView.AddCellToReusableCells(c);
  59. }
  60. cells.Clear();
  61. _customListTableView.RefreshCells(true);
  62. }
  63. private void DidSelectRow(TableView view, int index)
  64. {
  65. Debug.Assert(ReferenceEquals(view.dataSource, this));
  66. (Data[index] as IClickableCell)?.OnSelect(this);
  67. }
  68. private new void DidActivate(bool first, ActivationType type)
  69. {
  70. var rt = _customListTableView.transform as RectTransform;
  71. rt.anchorMin = new Vector2(.1f, 0f);
  72. rt.anchorMax = new Vector2(.9f, 1f);
  73. _customListTableView.gameObject.GetComponent<ScrollRect>().scrollSensitivity = 0f;
  74. }
  75. protected override void OnDestroy()
  76. {
  77. base.OnDestroy();
  78. foreach (var cell in Data)
  79. {
  80. if (cell is IDisposable disp)
  81. disp.Dispose();
  82. }
  83. }
  84. }
  85. }