using EnhancedUI.EnhancedScroller; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class SortTable : MonoBehaviour { [SerializeField] SortType m_SortType; public SortType sortType { get { return m_SortType; } set { m_SortType = value; } } [SerializeField] List m_SortElements; [SerializeField] ScrollerController m_Controller; [SerializeField] ClickScreenOtherSpace m_ClickOtherSpace; [SerializeField] Text m_TargetDisplay; public event Action onSelectSortEvent; public event Action onSortCloseEvent; DogzModel dogzModel { get { return ModelCenter.Instance.GetModel(); } } private void Awake() { m_Controller.OnRefreshCell += OnRefreshCell; } private void OnEnable() { m_Controller.Refresh(); if (m_SortElements != null) { for (int i = 0; i < m_SortElements.Count; i++) { m_Controller.AddCell(ScrollerDataType.Header, i, OnSortSelect); } } m_Controller.Restart(); if (m_ClickOtherSpace != null) { m_ClickOtherSpace.RemoveAllListeners(); m_ClickOtherSpace.AddListener(() => { if (onSortCloseEvent != null) { onSortCloseEvent(); } }); } } private void OnSortSelect(CellView _cell) { var _index = _cell.index; var type = m_SortElements[_index].type; switch (sortType) { case SortType.EquipQuality: dogzModel.SelectDogzItemQuality = type; break; case SortType.EquipStar: dogzModel.SelectDogzItemStart = type; break; } if (onSelectSortEvent != null) { onSelectSortEvent(type); } if (onSortCloseEvent != null) { onSortCloseEvent(); } if (m_TargetDisplay != null) { m_TargetDisplay.text = Language.Get(m_SortElements[_index].textKey); } this.gameObject.SetActive(false); } private void OnRefreshCell(ScrollerDataType type, CellView cell) { var _sortCell = cell as SortCell; _sortCell.sortTypeTxt.text = Language.Get(m_SortElements[cell.index].textKey); } public void SetDefault() { if (m_TargetDisplay != null && m_SortElements != null && m_SortElements.Count > 0) { m_TargetDisplay.text = Language.Get(m_SortElements[0].textKey); } } } public enum SortType { EquipQuality, EquipStar, } [Serializable] public struct SortElement { [Header("语言表key")] public string textKey; public int type; } }