少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class AlchemySortBehaviour : MonoBehaviour
    {
        [SerializeField] AlchemySortType m_AlchemySortType;
        [SerializeField] Button m_Func;
        [SerializeField] Image m_Arrow;
        [SerializeField] Transform m_ContainerSort;
        [SerializeField] ScrollerController m_Controller;
 
        List<int> m_Sorts = new List<int>();
 
        Dictionary<int, bool> m_SortEnables = new Dictionary<int, bool>();
 
        bool m_OpenSort = false;
        bool openSort
        {
            get { return m_OpenSort; }
            set
            {
                if (m_OpenSort != value)
                {
                    m_OpenSort = value;
                    OnSortChange();
                }
            }
        }
 
        public static event Action onSortRefresh;
 
 
        AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
 
        private void Awake()
        {
            m_Controller.OnRefreshCell += OnRefreshCell;
            m_Func.SetListener(() =>
            {
                DisplaySorts();
            });
        }
 
        public void Display()
        {
            m_ContainerSort.SetActive(false);
            m_OpenSort = false;
 
            if (m_Sorts.Count == 0)
            {
                switch (m_AlchemySortType)
                {
                    case AlchemySortType.AlchemyType:
                        m_Sorts.Add((int)AlchemyType.Normal);
                        m_Sorts.Add((int)AlchemyType.Fairy);
                        break;
                    case AlchemySortType.Quality:
                        var qualities = model.GetDrugQualitys();
                        m_Sorts.AddRange(qualities);
                        break;
                }
                m_Sorts.RemoveAll((x) => { return x == 0; });
            }
 
            SetSortEnable(0, true);
            DisplaySortState();
        }
 
        void DisplaySortState()
        {
            m_Arrow.transform.localEulerAngles = new Vector3(0, 0, openSort ? 0 : 180);
        }
 
        void DisplaySorts()
        {
            m_ContainerSort.SetActive(true);
            if (m_Controller.GetNumberOfCells(m_Controller.m_Scorller) == 0)
            {
                m_Controller.Refresh();
                m_Controller.AddCell(ScrollerDataType.Header, 0);
                for (int i = 0; i < m_Sorts.Count; i++)
                {
                    m_Controller.AddCell(ScrollerDataType.Header, m_Sorts[i]);
                }
                m_Controller.Restart();
            }
            else
            {
                m_Controller.JumpIndex(0);
                m_Controller.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        public bool IsSortEnabled(int sort)
        {
            if (sort == 0)
            {
                var allEnabled = true;
                foreach (var _sort in m_Sorts)
                {
                    if (!IsSortEnabled(_sort))
                    {
                        allEnabled = false;
                        break;
                    }
                }
                return allEnabled;
            }
            return m_SortEnables.ContainsKey(sort) && m_SortEnables[sort];
        }
 
        public void SetSortEnable(int sort, bool enabled, bool single = true)
        {
            if (sort == 0)
            {
                foreach (var _sort in m_Sorts)
                {
                    SetSortEnable(_sort, enabled, false);
                }
                m_Controller.m_Scorller.RefreshActiveCellViews();
                return;
            }
            m_SortEnables[sort] = enabled;
            if (single)
            {
                m_Controller.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            var sortCell = cell as AlchemySortCell;
            sortCell.Display(this, m_AlchemySortType, cell.index);
        }
 
        private void OnSortChange()
        {
            DisplaySortState();
            if (!openSort)
            {
                if (onSortRefresh != null)
                {
                    onSortRefresh();
                }
            }
        }
 
        private void LateUpdate()
        {
            openSort = m_ContainerSort.gameObject.activeSelf;
        }
 
        public enum AlchemySortType
        {
            AlchemyType,
            Quality,
        }
    }
}