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.

104 lines
3.4 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(TableView view, int idx)
  20. {
  21. var cell = base.CellForIdx(view, 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. var content = _customListTableView.contentTransform;
  75. content.anchoredPosition = new Vector2(7f, 0f);
  76. }
  77. protected override void OnDestroy()
  78. {
  79. base.OnDestroy();
  80. foreach (var cell in Data)
  81. {
  82. if (cell is IDisposable disp)
  83. disp.Dispose();
  84. }
  85. }
  86. }
  87. }