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.6 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.PluginInfo> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)
  31. {
  32. Logger.log.Debug("List Controller Init");
  33. DidActivateEvent = DidActivate;
  34. DidSelectRowEvent = DidSelectRow;
  35. rectTransform.anchorMin = new Vector2(0f, 0f);
  36. rectTransform.anchorMax = new Vector2(.4f, 1f);
  37. includePageButtons = true;
  38. this.flow = flow;
  39. reuseIdentifier = "BSIPAModListTableCell";
  40. foreach (var plugin in bsipaPlugins.Where(p => !p.Metadata.IsBare))
  41. Data.Add(new BSIPAModCell(this, plugin));
  42. foreach (var plugin in ignoredPlugins)
  43. Data.Add(new BSIPAIgnoredModCell(this, plugin));
  44. foreach (var plugin in bsipaPlugins.Where(p => p.Metadata.IsBare))
  45. Data.Add(new LibraryModCell(this, plugin));
  46. foreach (var plugin in ipaPlugins)
  47. Data.Add(new IPAModCell(this, plugin));
  48. }
  49. #pragma warning restore
  50. private void DidSelectRow(TableView view, int index)
  51. {
  52. Debug.Assert(ReferenceEquals(view.dataSource, this));
  53. (Data[index] as IClickableCell)?.OnSelect(this);
  54. }
  55. private new void DidActivate(bool first, ActivationType type)
  56. {
  57. var rt = _customListTableView.transform as RectTransform;
  58. rt.anchorMin = new Vector2(.1f, 0f);
  59. rt.anchorMax = new Vector2(.9f, 1f);
  60. _customListTableView.gameObject.GetComponent<ScrollRect>().scrollSensitivity = 0f;
  61. }
  62. }
  63. }