using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.UI; using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Widgets { public class ButtonListSource : IPoolDataSource { public int GetRealIndexOfTempIndex(int index) => throw new NotImplementedException("TODO"); internal ScrollPool Scroller; public int ItemCount => currentEntries.Count; public readonly List currentEntries = new List(); public Func> GetEntries; public Action, int> SetICell; public Func ShouldDisplay; public Action OnCellClicked; public string CurrentFilter { get => currentFilter; set => currentFilter = value?.ToLower() ?? ""; } private string currentFilter; public ButtonListSource(ScrollPool scrollPool, Func> getEntriesMethod, Action, int> setICellMethod, Func shouldDisplayMethod, Action onCellClickedMethod) { Scroller = scrollPool; GetEntries = getEntriesMethod; SetICell = setICellMethod; ShouldDisplay = shouldDisplayMethod; OnCellClicked = onCellClickedMethod; } public void Init() { var proto = ButtonCell.CreatePrototypeCell(Scroller.UIRoot); RefreshData(); Scroller.DataSource = this; Scroller.Initialize(this, proto); } public void RefreshData() { var allEntries = GetEntries.Invoke(); currentEntries.Clear(); foreach (var entry in allEntries) { if (!string.IsNullOrEmpty(currentFilter)) { if (!ShouldDisplay.Invoke(entry, currentFilter)) continue; currentEntries.Add(entry); } else currentEntries.Add(entry); } } public ICell CreateCell(RectTransform rect) { var button = rect.GetComponentInChildren