少年修仙传客户端代码仓库
client_linchunjie
2018-09-19 aecb6a5a62d8a4cfc7b924ce957a9c7ea90c235d
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Saturday, September 23, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class FitterWin : Window
    {
        private ScrollerController fitterCtrl;
        private RectTransform fitterFrame;
 
        public static Dictionary<int, string> fitterTypes;
 
        public static RectTransform target;
 
        private static Action<int> fitterAction;
        public static Action<int> FitterAction
        {
            set
            {
                fitterAction = value;
            }
        }
 
        public static Action fitterClose;
 
        private ClickScreenOtherSpace spaceClick;
        #region Built-in
        protected override void BindController()
        {
            fitterFrame = transform.Find("FitterFrame") as RectTransform;
            fitterCtrl = this.GetComponent<ScrollerController>("FitterFrame/Controller");
            spaceClick = this.GetComponent<ClickScreenOtherSpace>("FitterFrame");
        }
 
        protected override void AddListeners()
        {
            fitterCtrl.OnRefreshCell += OnRefreshFitterCell;
            spaceClick.AddListener(CloseClick);
        }
 
        protected override void OnPreOpen()
        {
            fitterFrame.gameObject.SetActive(false);
            InitFitter();
        }
 
        protected override void OnActived()
        {
            base.OnActived();
            SnxxzGame.Instance.StartCoroutine(Co_DelayDisplay());
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
 
        }
 
        protected override void OnAfterClose()
        {
            fitterFrame.gameObject.SetActive(false);
            if (fitterClose != null)
            {
                fitterClose();
            }
        }
        #endregion
 
        private void OnRefreshFitterCell(ScrollerDataType type, CellView cell)
        {
            int index = cell.index;
            if (fitterTypes != null && fitterTypes.ContainsKey(index))
            {
                Text text = cell.GetComponent<Text>("Text");
                text.text = fitterTypes[index];
            }
        }
 
        private void InitFitter()
        {
            Vector2 nSize = fitterFrame.sizeDelta;
            if (fitterTypes != null && fitterTypes.Count < 6)
            {
                nSize.y = fitterTypes.Count * fitterCtrl.m_CellHeaderPrefab.height + (fitterTypes.Count - 1) * fitterCtrl.m_Scorller.spacing + 24;
                fitterCtrl.maxCellCnt = fitterTypes.Count;
            }
            else
            {
                nSize.y = 5 * fitterCtrl.m_CellHeaderPrefab.height + 4 * fitterCtrl.m_Scorller.spacing + 24;
                fitterCtrl.maxCellCnt = 5;
            }
            fitterFrame.sizeDelta = nSize;
            fitterCtrl.Refresh();
            if (fitterTypes != null && fitterTypes.Count > 0)
            {
                foreach (int key in fitterTypes.Keys)
                {
                    fitterCtrl.AddCell(ScrollerDataType.Header, key, OnFitterCellClick);
                }
            }
            fitterCtrl.Restart();
        }
 
        private void OnFitterCellClick(CellView cell)
        {
            int index = cell.index;
            if (fitterAction != null)
            {
                fitterAction(index);
                CloseImmediately();
            }
        }
 
        private void SetPos()
        {
            fitterFrame.gameObject.SetActive(true);
            Transform rt = target.parent;
            Vector3 pos = target.localPosition;
            pos.y -= target.sizeDelta.y / 2;
            if (rt != null)
            {
                pos = rt.TransformPoint(pos);
            }
            fitterFrame.localPosition = transform.InverseTransformPoint(pos);
        }
 
        IEnumerator Co_DelayDisplay()
        {
            yield return null;
            SetPos();
        }
    }
 
}