少年修仙传客户端代码仓库
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using CJ.Wait;
using System;
 
using System.Text.RegularExpressions;
using DG.Tweening;
namespace vnxbqy.UI
{
    
    public class MessageWin : Window
    {
        [SerializeField] RectTransform m_ContainerNormalHint;
        [SerializeField] RichText m_NormalHint;
        [SerializeField] RectTransform m_ContainerChatHint;
        [SerializeField] RichText m_NormalChatHint; //显示在聊天界面的位置
 
        [SerializeField] RectTransform m_ContainerServerTip;
        [SerializeField] ScaleTween m_ServerTipScaleTween;
        [SerializeField] PositionTween m_ServerTipPositionTween;
        [SerializeField] RichText m_ServerTip;
        [SerializeField, Header("全服广播停留时间")] float m_ServerTipKeepTime = 1.5f;
 
        [SerializeField] RectTransform m_ContainerGM;
        [SerializeField] Text m_GmRichText;
        [SerializeField] ScrollerController m_ScrollControl;
        [SerializeField] Toggle m_AutoPopToggle;
        [SerializeField] Toggle m_AutoRefreshToggle;
        [SerializeField] Button m_GMClose;
 
        bool m_ServerTipPrepared = true;
 
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_ContainerNormalHint.OnWaitCompelete(OnHintDisplayComplete);
            m_ContainerChatHint.OnWaitCompelete(OnHintDisplayComplete);
            m_ScrollControl.OnRefreshCell += OnRefreshGmCell;
            m_ScrollControl.OnGetDynamicSize += OnGetDynamicSize;
            m_ScrollControl.lockType = EnhanceLockType.LockVerticalBottom;
            m_GMClose.onClick.AddListener(OnGMClose);
        }
 
        protected override void OnPreOpen()
        {
            m_ServerTipPrepared = true;
 
#if UNITY_EDITOR
            m_ContainerGM.SetActive(VersionConfig.Get().debugVersion);
#else
            m_ContainerGM.SetActive(false);
#endif
            ServerTipDetails.normalHintRefresh += CheckNormalHint;
            ServerTipDetails.serverHintRefresh += CheckServerHint;
            ServerTipDetails.gmMessageRefresh += DisplayGM;
            ServerTipDetails.gmOpenEvent += GmOpenEvent;
            ServerTipDetails.chatHintRefresh += CheckChatHint;
            CheckNormalHint();
            CheckChatHint();
            CheckServerHint();
            DisplayGM(string.Empty);
 
            if (ServerTipDetails.requireOpenGM)
            {
                if (hasOnFrom)
                {
                    OnGMOpen();
                }
                ServerTipDetails.requireOpenGM = false;
            }
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            ServerTipDetails.normalHintRefresh -= CheckNormalHint;
            ServerTipDetails.serverHintRefresh -= CheckServerHint;
            ServerTipDetails.gmMessageRefresh -= DisplayGM;
            ServerTipDetails.gmOpenEvent -= GmOpenEvent;
            ServerTipDetails.chatHintRefresh -= CheckChatHint;
        }
 
        protected override void OnAfterClose()
        {
        }
 
        private void GmOpenEvent()
        {
            if (ServerTipDetails.requireOpenGM)
            {
                OnGMOpen();
                ServerTipDetails.requireOpenGM = false;
            }
        }
 
        void CheckNormalHint()
        {
            var hint = ServerTipDetails.RequireNormalHint();
            if (hint != null)
            {
                DisplayNormalHint(hint);
            }
        }
 
        void DisplayNormalHint(SystemHintData hint)
        {
            transform.SetAsLastSibling();
            m_NormalHint.SetExtenalData(hint.extentionData);
            m_NormalHint.text = hint.message;
            if (!m_ContainerNormalHint.gameObject.activeInHierarchy)
            {
                m_ContainerNormalHint.SetActive(true);
            }
            m_ContainerNormalHint.DoWaitRestart();
        }
 
        private void OnHintDisplayComplete(Component com)
        {
            com.DoWaitStop();
            com.SetActive(false);
        }
 
        void CheckServerHint()
        {
            if (!m_ServerTipPrepared)
            {
                return;
            }
            var hint = ServerTipDetails.RequireServerTip();
            if (hint != null && gameObject.activeInHierarchy)
            {
                DisplayServerHint(hint);
            }
            else
            {
                DisableServerTip();
            }
        }
 
        public void DisplayServerHint(SystemHintData hint)
        {
            transform.SetAsLastSibling();
            m_ServerTipPrepared = false;
            if (!m_ServerTipScaleTween.gameObject.activeSelf)
            {
                m_ServerTipScaleTween.SetActive(true);
            }
            m_ServerTipScaleTween.SetStartState();
            m_ServerTipPositionTween.SetStartState();
            m_ContainerServerTip.SetActive(true);
            m_ServerTip.SetExtenalData(hint.extentionData);
            m_ServerTip.text = hint.message;
            m_ServerTipScaleTween.Play();
            TimeMgr.Instance.Register(m_ServerTip, ServerTipStartHide, m_ServerTipKeepTime + m_ServerTipScaleTween.duration);
        }
 
        private void ServerTipStartHide(Component comp)
        {
            m_ServerTipPositionTween.Play();
            TimeMgr.Instance.Register(m_ServerTipPositionTween, ServerTipTweenComplete, m_ServerTipPositionTween.duration);
        }
 
        private void ServerTipTweenComplete(Component comp)
        {
            m_ServerTipPrepared = true;
            DisableServerTip();
            CheckServerHint();
        }
 
        private void DisableServerTip()
        {
            TimeMgr.Instance.UnRegister(m_ServerTip);
            TimeMgr.Instance.UnRegister(m_ServerTipPositionTween);
            m_ContainerServerTip.SetActive(false);
            m_ServerTipScaleTween.Stop();
            m_ServerTipPositionTween.Stop();
            m_ServerTipScaleTween.SetStartState();
            m_ServerTipPositionTween.SetStartState();
        }
 
 
        #region GM
        readonly Regex autoPopRegex = new Regex("参数错误|执行GM命令错误|^###");
        void DisplayGM(string latest)
        {
            if (!string.IsNullOrEmpty(latest))
            {
                if (m_AutoPopToggle.isOn && hasOnFrom)
                {
                    RectTransform rt = m_ContainerGM;
                    Vector3 pos = new Vector3(hasOnFrom ? -rt.sizeDelta.x / 2 : rt.sizeDelta.x / 2, 0, 0);
                    rt.DOLocalMove(pos, 1.0f);
                    hasOnFrom = !hasOnFrom;
                    m_GMClose.SetActive(!hasOnFrom);
                }
            }
            if (m_ScrollControl.GetNumberOfCells(m_ScrollControl.m_Scorller) >= 300)
            {
                m_ScrollControl.m_Scorller.RefreshActiveCellViews();
                return;
            }
            m_ScrollControl.Refresh();
            for (int i = 0; i < ServerTipDetails.gmMessages.Count; i++)
            {
                m_ScrollControl.AddCell(ScrollerDataType.Normal, i);
            }
            m_ScrollControl.Restart();
            if (autoPopRegex.IsMatch(latest))
            {
                if (hasOnFrom)
                {
                    OnGMOpen();
                }
            }
        }
 
        private void OnRefreshGmCell(ScrollerDataType type, CellView cell)
        {
            if (cell.index < ServerTipDetails.gmMessages.Count)
            {
                Text text = cell.transform.Find("Text").GetComponent<Text>();
                text.text = ServerTipDetails.gmMessages[cell.index];
            }
        }
 
        private bool OnGetDynamicSize(ScrollerDataType type, int index, out float height)
        {
            var msg = index < ServerTipDetails.gmMessages.Count ? ServerTipDetails.gmMessages[index] : string.Empty;
            height = m_GmRichText.cachedTextGeneratorForLayout.GetPreferredHeight(msg,
                m_GmRichText.GetGenerationSettings(new Vector2(m_GmRichText.rectTransform.rect.size.x, 0.0f)))
                / m_GmRichText.pixelsPerUnit;
            height += 5;
            return true;
        }
 
        private void OnGMClose()
        {
            if (!hasOnFrom)
            {
                RectTransform rt = m_ContainerGM;
                Vector3 pos = new Vector3(hasOnFrom ? -rt.sizeDelta.x / 2 : rt.sizeDelta.x / 2, 0, 0);
                rt.DOLocalMove(pos, 1.0f);
                hasOnFrom = !hasOnFrom;
                m_GMClose.SetActive(!hasOnFrom);
            }
        }
        #endregion
 
        private void OnDisable()
        {
            m_ContainerNormalHint.SetActive(false);
            m_ContainerChatHint.SetActive(false);
            DisableServerTip();
            StopAllCoroutines();
        }
 
        private Vector3 gmTo = new Vector3(442, 0, 0);
        private Vector3 gmFrom = new Vector3(892, 0, 0);
        private bool hasOnFrom = true;
        public void OnGMOpen()
        {
            RectTransform rt = m_ContainerGM;
            Vector3 pos = new Vector3(hasOnFrom ? -rt.sizeDelta.x / 2 : rt.sizeDelta.x / 2, 0, 0);
            rt.DOLocalMove(pos, 1.0f);
            hasOnFrom = !hasOnFrom;
            m_GMClose.SetActive(!hasOnFrom);
        }
 
        void CheckChatHint()
        {
            var hint = ServerTipDetails.RequireChatHint();
            if (hint != null)
            {
                DisplayChatHint(hint);
            }
        }
 
        void DisplayChatHint(SystemHintData hint)
        {
            if (!WindowCenter.Instance.IsOpen<ChatWin>())
            {
                return;
            }
            if (!m_ContainerChatHint.gameObject.activeInHierarchy)
            {
                m_ContainerChatHint.gameObject.SetActive(true);
            }
            m_NormalChatHint.SetExtenalData(hint.extentionData);
            m_NormalChatHint.text = hint.message;
            m_ContainerChatHint.DoWaitRestart();
        }
    }
}