少年修仙传客户端代码仓库
hch
2 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using EnhancedUI.EnhancedScroller;
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;
        }
 
        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);
        }
 
        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;
    }
}