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.

75 lines
2.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(int idx)
  20. {
  21. var cell = base.CellForIdx(idx) as LevelListTableCell;
  22. var nameText = cell.GetPrivateField<TextMeshProUGUI>("_songNameText");
  23. nameText.overflowMode = TextOverflowModes.Overflow;
  24. return cell;
  25. }
  26. internal ModListFlowCoordinator flow;
  27. #pragma warning disable CS0618
  28. public void Init(ModListFlowCoordinator flow, IEnumerable<PluginLoader.PluginMetadata> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)
  29. {
  30. Data.Clear();
  31. Logger.log.Debug("List Controller Init");
  32. DidActivateEvent = DidActivate;
  33. DidSelectRowEvent = DidSelectRow;
  34. rectTransform.anchorMin = new Vector2(0f, 0f);
  35. rectTransform.anchorMax = new Vector2(.4f, 1f);
  36. includePageButtons = true;
  37. this.flow = flow;
  38. reuseIdentifier = "BSIPAModListTableCell";
  39. foreach (var plugin in bsipaPlugins.Where(p => !p.IsBare))
  40. Data.Add(new BSIPAModCell(this, plugin));
  41. foreach (var plugin in ignoredPlugins)
  42. Data.Add(new BSIPAIgnoredModCell(this, plugin));
  43. foreach (var plugin in bsipaPlugins.Where(p => p.IsBare))
  44. Data.Add(new LibraryModCell(this, plugin));
  45. foreach (var plugin in ipaPlugins)
  46. Data.Add(new IPAModCell(this, plugin));
  47. }
  48. #pragma warning restore
  49. private void DidSelectRow(TableView view, int index)
  50. {
  51. Debug.Assert(ReferenceEquals(view.dataSource, this));
  52. (Data[index] as IClickableCell)?.OnSelect(this);
  53. }
  54. private new void DidActivate(bool first, ActivationType type)
  55. {
  56. var rt = _customListTableView.transform as RectTransform;
  57. rt.anchorMin = new Vector2(.1f, 0f);
  58. rt.anchorMax = new Vector2(.9f, 1f);
  59. _customListTableView.gameObject.GetComponent<ScrollRect>().scrollSensitivity = 0f;
  60. }
  61. }
  62. }