少年修仙传客户端代码仓库
client_Wu Xijin
2018-09-04 d9e6e5aac14261fad5bd18053b600bd513b45509
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using CJ.Wait;
using System;
using TableConfig;
using System.Text.RegularExpressions;
using DG.Tweening;
namespace Snxxz.UI
{
    public class MessageWin : Window
    {
        private static MessageWin _inst = null;
        public static MessageWin Inst
        {
            get
            {
                if (_inst == null)
                {
                    _inst = WindowCenter.Instance.Open<MessageWin>(true);
                }
                return _inst;
            }
        }
        [SerializeField] RectTransform m_ContianerFixedTip0;
        [SerializeField] RichText m_FixedTip0;
 
        [SerializeField] List<RectTransform> m_ContianerFixedTips;
        [SerializeField] List<RichText> m_FixedTips;
        List<bool> m_FixedTipDisplays = new List<bool>();
 
        #region GM
        [SerializeField] GameObject gmPanel;
        [SerializeField] ScrollerController gmCtrl;
        [SerializeField] Toggle gmToggle;
        [SerializeField] Toggle gmUpdateToggle;
        [SerializeField] Button gmClose;
        #endregion
 
        public void ShowFixedTip(string tip, ArrayList infoList = null)
        {
            m_FixedTip0.SetExtenalData(infoList);
            m_FixedTip0.text = tip;
            if (!m_ContianerFixedTip0.gameObject.activeInHierarchy)
            {
                m_ContianerFixedTip0.gameObject.SetActive(true);
            }
            m_ContianerFixedTip0.DoWaitRestart();
        }
 
        public void ShowFixedTips(string tip, ArrayList infoList = null)
        {
            var _index = m_FixedTipDisplays.FindIndex((x) =>
             {
                 return !x;
             });
            _index = _index == -1 ? 0 : _index;
            m_FixedTips[_index].SetExtenalData(infoList);
            m_FixedTips[_index].text = tip;
            m_FixedTipDisplays[_index] = true;
            if (!m_ContianerFixedTips[_index].gameObject.activeInHierarchy)
            {
                m_ContianerFixedTips[_index].gameObject.SetActive(true);
            }
            m_ContianerFixedTips[_index].DoWaitRestart();
        }
 
        private void OnHideFixedTip(Component com)
        {
            com.DoWaitStop();
            com.gameObject.SetActive(false);
 
            var _index = m_ContianerFixedTips.FindIndex((x) =>
             {
                 return x.Equals(com);
             });
            if (_index != -1)
            {
                m_FixedTipDisplays[_index] = false;
            }
        }
 
        [SerializeField] RectTransform m_ContainerServerTip;
        [SerializeField] ScaleTween m_ServerTipScaleTween;
        [SerializeField] PositionTween m_ServerTipPositionTween;
        [SerializeField] RichText m_ServerTip;
        [SerializeField, Header("全服广播停留时间")] float m_ServerTipKeepTime = 1.5f;
 
        private bool serverTipPrepared = true;
        public void ShowServerTip()
        {
            if (!serverTipPrepared)
            {
                return;
            }
            var _hint = ServerTipDetails.RequireServerTip();
            if (_hint != null)
            {
                serverTipPrepared = false;
                m_ServerTipScaleTween.SetStartState();
                m_ServerTipPositionTween.SetStartState();
                m_ContainerServerTip.gameObject.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);
            }
            else
            {
                DisableServerTip();
            }
        }
        private void ServerTipStartHide(Component comp)
        {
            m_ServerTipPositionTween.Play();
            TimeMgr.Instance.Register(m_ServerTipPositionTween, ServerTipTweenComplete, m_ServerTipPositionTween.duration);
        }
 
        private void ServerTipTweenComplete(Component comp)
        {
            serverTipPrepared = true;
            DisableServerTip();
            ShowServerTip();
        }
 
        private void DisableServerTip()
        {
            m_ContainerServerTip.gameObject.SetActive(false);
            m_ServerTipScaleTween.Stop();
            m_ServerTipPositionTween.Stop();
            m_ServerTipScaleTween.SetStartState();
            m_ServerTipPositionTween.SetStartState();
        }
 
 
        #region GM
        private const int MAX_GM = 300;
        private List<string> gmList = new List<string>();
        public readonly Regex autoPopRegex = new Regex("参数错误|执行GM命令错误|^###");
        public void RevGMMsg(string msg)
        {
            if (gmList.Count >= MAX_GM)
            {
                gmList.RemoveAt(0);
            }
            msg.Replace("###", string.Empty);
            gmList.Add(msg);
            if (gmToggle.isOn && hasOnFrom)
            {
                RectTransform rt = gmPanel.transform as RectTransform;
                Vector3 pos = new Vector3(hasOnFrom ? -rt.sizeDelta.x / 2 : rt.sizeDelta.x / 2, 0, 0);
                rt.DOLocalMove(pos, 1.0f);
                hasOnFrom = !hasOnFrom;
                gmClose.gameObject.SetActive(!hasOnFrom);
            }
            if (gmCtrl.GetNumberOfCells(gmCtrl.m_Scorller) >= MAX_GM)
            {
                gmCtrl.m_Scorller.RefreshActiveCellViews();
                return;
            }
            gmCtrl.Refresh();
            for (int i = 0; i < gmList.Count; i++)
            {
                gmCtrl.AddCell(ScrollerDataType.Normal, i);
            }
            gmCtrl.Restart();
            if (autoPopRegex.IsMatch(msg))
            {
                if (hasOnFrom)
                {
                    OnGMOpen();
                }
            }
        }
 
        private void OnRefreshGmCell(ScrollerDataType type, CellView cell)
        {
            if (cell.index < gmList.Count)
            {
                Text text = cell.transform.Find("Text").GetComponent<Text>();
                text.text = gmList[cell.index];
            }
        }
 
        private void OnGMClose()
        {
            if (!hasOnFrom)
            {
                RectTransform rt = gmPanel.transform as RectTransform;
                Vector3 pos = new Vector3(hasOnFrom ? -rt.sizeDelta.x / 2 : rt.sizeDelta.x / 2, 0, 0);
                rt.DOLocalMove(pos, 1.0f);
                hasOnFrom = !hasOnFrom;
                gmClose.gameObject.SetActive(!hasOnFrom);
            }
        }
        #endregion
 
        private void OnDisable()
        {
            m_ContianerFixedTip0.gameObject.SetActive(false);
            for (int i = 0; i < m_ContianerFixedTips.Count; i++)
            {
                m_ContianerFixedTips[i].gameObject.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 = gmPanel.transform as RectTransform;
            Vector3 pos = new Vector3(hasOnFrom ? -rt.sizeDelta.x / 2 : rt.sizeDelta.x / 2, 0, 0);
            rt.DOLocalMove(pos, 1.0f);
            hasOnFrom = !hasOnFrom;
            gmClose.gameObject.SetActive(!hasOnFrom);
        }
 
        protected override void LateUpdate()
        {
#if UNITY_EDITOR
            if (Input.GetKeyDown(KeyCode.F3))
            {
                OnGMOpen();
            }
#endif
        }
 
        protected override void BindController()
        {
        }
        protected override void AddListeners()
        {
            m_ContianerFixedTip0.OnWaitCompelete(OnHideFixedTip);
            for (int i = 0; i < m_ContianerFixedTips.Count; i++)
            {
                m_ContianerFixedTips[i].OnWaitCompelete(OnHideFixedTip);
                m_FixedTipDisplays.Add(false);
            }
            gmCtrl.OnRefreshCell += OnRefreshGmCell;
            gmCtrl.lockType = EnhanceLockType.LockVerticalBottom;
            gmClose.onClick.AddListener(OnGMClose);
        }
 
        protected override void OnPreOpen()
        {
#if UNITY_EDITOR
            gmPanel.SetActive(VersionConfig.Get().debugVersion);
#else
           gmPanel.SetActive(false);
#endif
            serverTipPrepared = true;
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
            _inst = null;
        }
    }
}