| | |
| | | using EnhancedUI.EnhancedScroller; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | // using System; |
| | | // using System.Collections; |
| | | // using System.Collections.Generic; |
| | | // using UnityEngine; |
| | | // using UnityEngine.UI; |
| | | |
| | | namespace vnxbqy.UI |
| | | { |
| | | public class SortTable : MonoBehaviour |
| | | { |
| | | [SerializeField] SortType m_SortType; |
| | | public SortType sortType |
| | | { |
| | | get |
| | | { |
| | | return m_SortType; |
| | | } |
| | | set |
| | | { |
| | | m_SortType = value; |
| | | } |
| | | } |
| | | [SerializeField] List<SortElement> m_SortElements; |
| | | [SerializeField] ScrollerController m_Controller; |
| | | [SerializeField] ClickScreenOtherSpace m_ClickOtherSpace; |
| | | [SerializeField] Text m_TargetDisplay; |
| | | public event Action<SortType, int> onSelectSortEvent; |
| | | public event Action onSortCloseEvent; |
| | | private void Awake() |
| | | { |
| | | m_Controller.OnRefreshCell += OnRefreshCell; |
| | | } |
| | | // public class SortTable : MonoBehaviour |
| | | // { |
| | | // [SerializeField] SortType m_SortType; |
| | | // public SortType sortType |
| | | // { |
| | | // get |
| | | // { |
| | | // return m_SortType; |
| | | // } |
| | | // set |
| | | // { |
| | | // m_SortType = value; |
| | | // } |
| | | // } |
| | | // [SerializeField] List<SortElement> m_SortElements; |
| | | // [SerializeField] ScrollerController m_Controller; |
| | | // [SerializeField] ClickScreenOtherSpace m_ClickOtherSpace; |
| | | // [SerializeField] Text m_TargetDisplay; |
| | | // public event Action<SortType, int> onSelectSortEvent; |
| | | // public event Action onSortCloseEvent; |
| | | // 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(); |
| | | // 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; |
| | | if (onSelectSortEvent != null) |
| | | { |
| | | onSelectSortEvent(sortType,type); |
| | | } |
| | | if (onSortCloseEvent != null) |
| | | { |
| | | onSortCloseEvent(); |
| | | } |
| | | if (m_TargetDisplay != null) |
| | | { |
| | | m_TargetDisplay.text = Language.Get(m_SortElements[_index].textKey); |
| | | } |
| | | this.SetActive(false); |
| | | } |
| | | private void OnRefreshCell(ScrollerDataType type, CellView cell) |
| | | { |
| | | var _sortCell = cell as SortCell; |
| | | _sortCell.sortTypeTxt.text = Language.Get(m_SortElements[cell.index].textKey); |
| | | } |
| | | // 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; |
| | | // if (onSelectSortEvent != null) |
| | | // { |
| | | // onSelectSortEvent(sortType,type); |
| | | // } |
| | | // if (onSortCloseEvent != null) |
| | | // { |
| | | // onSortCloseEvent(); |
| | | // } |
| | | // if (m_TargetDisplay != null) |
| | | // { |
| | | // m_TargetDisplay.text = Language.Get(m_SortElements[_index].textKey); |
| | | // } |
| | | // this.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(int value = 0) |
| | | { |
| | | if(value == 0) |
| | | { |
| | | if (m_TargetDisplay != null && m_SortElements != null && m_SortElements.Count > 0) |
| | | { |
| | | m_TargetDisplay.text = Language.Get(m_SortElements[0].textKey); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (m_TargetDisplay != null && m_SortElements != null && m_SortElements.Count > 0) |
| | | { |
| | | foreach(var key in m_SortElements) |
| | | { |
| | | if(key.type == value) |
| | | { |
| | | m_TargetDisplay.text = Language.Get(key.textKey); |
| | | break; |
| | | } |
| | | } |
| | | // public void SetDefault(int value = 0) |
| | | // { |
| | | // if(value == 0) |
| | | // { |
| | | // if (m_TargetDisplay != null && m_SortElements != null && m_SortElements.Count > 0) |
| | | // { |
| | | // m_TargetDisplay.text = Language.Get(m_SortElements[0].textKey); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // if (m_TargetDisplay != null && m_SortElements != null && m_SortElements.Count > 0) |
| | | // { |
| | | // foreach(var key in m_SortElements) |
| | | // { |
| | | // if(key.type == value) |
| | | // { |
| | | // m_TargetDisplay.text = Language.Get(key.textKey); |
| | | // break; |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | } |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | } |
| | | // } |
| | | // } |
| | | |
| | | public enum SortType |
| | | { |
| | | EquipQuality, |
| | | EquipStar, |
| | | EquipLv, |
| | | } |
| | | [Serializable] |
| | | public struct SortElement |
| | | { |
| | | [Header("语言表key")] |
| | | public string textKey; |
| | | public int type; |
| | | } |
| | | } |
| | | |
| | | // public enum SortType |
| | | // { |
| | | // EquipQuality, |
| | | // EquipStar, |
| | | // EquipLv, |
| | | // } |
| | | // [Serializable] |
| | | // public struct SortElement |
| | | // { |
| | | // [Header("语言表key")] |
| | | // public string textKey; |
| | | // public int type; |
| | | // } |