少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 11997ece0dc4980eba3dd8889d37adb8376e14cb
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Snxxz.UI
{
    public class ReikiRootPointBehaviour : MonoBehaviour
    {
        [SerializeField] Text m_PropertyName;
        [SerializeField] Text m_Point;
        [SerializeField] Button m_Add;
        [SerializeField] Button m_Sub;
        [SerializeField] Button m_OpenKeyboard;
 
        public int id { get; private set; }
 
        int m_CachePoint = 0;
        public int point
        {
            get { return m_CachePoint; }
            set
            {
                if (m_CachePoint != value)
                {
                    m_CachePoint = value;
                    DisplayPoint();
                }
            }
        }
 
        public RectTransform openKeyboardBottom
        {
            get { return m_OpenKeyboard.transform as RectTransform; }
        }
 
        ReikiRootWin parent = null;
 
        Coroutine m_Coroutine = null;
 
        bool isPointAdd = false;
        bool isPointSub = false;
 
        int cacheQuality = 0;
 
        int coroutineCount = 0;
 
        static WaitForSeconds waitSpeedFaster = new WaitForSeconds(0.05f);
        static WaitForSeconds waitSpeedSlow = new WaitForSeconds(0.2f);
 
        ReikiRootModel model { get { return ModelCenter.Instance.GetModel<ReikiRootModel>(); } }
 
        private void Awake()
        {
            UIEventTrigger.Get(m_Sub.gameObject).OnDown = OnSubDown;
            UIEventTrigger.Get(m_Sub.gameObject).OnUp = OnSubUp;
            UIEventTrigger.Get(m_Add.gameObject).OnDown = OnAddDown;
            UIEventTrigger.Get(m_Add.gameObject).OnUp = OnAddUp;
            m_OpenKeyboard.AddListener(OpenKeyboard);
        }
 
        public void Display(ReikiRootWin win, int id)
        {
            parent = win;
            this.id = id;
 
            cacheQuality = 0;
 
            DisplayPoint();
 
            model.onReikiRootPointRefresh += OnReikiRootPointRefresh;
        }
 
        void DisplayPoint()
        {
            var original = model.GetReikiRootPoint(id);
            var addLabel = point == 0 ? string.Empty : UIHelper.AppendColor(TextColType.Green, "+" + point, true);
            var quality = model.GetReikiRootQuality(id, original + point);
            var areaPoint = model.GetQualityPoint(id, quality + 1);
            if (areaPoint == 0)
            {
                m_Point.text = StringUtility.Contact(original, addLabel);
            }
            else
            {
                m_Point.text = StringUtility.Contact(original, addLabel, "/", areaPoint);
            }
 
            if (cacheQuality != quality)
            {
                var propertyConfig = PlayerPropertyConfig.Get(id);
                m_PropertyName.text = StringUtility.Contact(propertyConfig.Name, ReikiRootModel.GetQualityLabel(quality));
                m_PropertyName.color = UIHelper.GetUIColor(model.GetQualityColor(quality), true);
                cacheQuality = quality;
            }
        }
 
        private void OnAddDown(GameObject go)
        {
            isPointAdd = true;
            coroutineCount = 0;
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
            m_Coroutine = StartCoroutine(Co_PointRefresh(true));
        }
 
        private void OnAddUp(GameObject go)
        {
            isPointAdd = false;
        }
 
        private void OnSubDown(GameObject go)
        {
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
            coroutineCount = 0;
            isPointSub = true;
            m_Coroutine = StartCoroutine(Co_PointRefresh(false));
        }
 
        private void OnSubUp(GameObject go)
        {
            isPointSub = false;
        }
 
        IEnumerator Co_PointRefresh(bool pointUp)
        {
            while (pointUp ? isPointAdd : isPointSub)
            {
                if (pointUp && model.cacheFreePoint > 0)
                {
                    point += 1;
                    model.cacheFreePoint -= 1;
                }
                else if (!pointUp && point > 0)
                {
                    point -= 1;
                    model.cacheFreePoint += 1;
                }
                if (coroutineCount == 0)
                {
                    yield return waitSpeedSlow;
                }
                else
                {
                    yield return waitSpeedFaster;
                }
                coroutineCount++;
            }
        }
 
        private void OnReikiRootPointRefresh()
        {
            if (point == 0)
            {
                DisplayPoint();
            }
            else
            {
                point = 0;
            }
        }
 
        private void OpenKeyboard()
        {
            if (parent != null)
            {
                parent.OpenKeyboard(this);
            }
        }
 
        public void Dispose()
        {
            model.onReikiRootPointRefresh -= OnReikiRootPointRefresh;
 
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
            isPointAdd = false;
            isPointSub = false;
            point = 0;
        }
    }
}