少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, September 06, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
 
 
namespace vnxbqy.UI
{
 
    public class WorldMapWin : Window
    {
        [SerializeField] Button m_LocalMap;
        [SerializeField] Button m_Close;
        [SerializeField] BoundedDrag m_BoudedDrag;
        [SerializeField] AreaBehaviourTable[] m_AreaBehaviours;
        [SerializeField] ScaleTween m_ScaleTween;
        [SerializeField] Transform m_ContainerPlayerHead;
        [SerializeField] AvatarCell m_AvatarCell;
        [SerializeField] ScreenMoveTo m_UnLockBehaviour;
        [SerializeField] Transform m_EffectMask;
        [SerializeField] Transform m_ContainerNewUnLock;
        [SerializeField] Image m_BackGround;
 
        MapModel model { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
 
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            m_LocalMap.AddListener(OpenLocalMap);
            m_Close.AddListener(CloseClick);
        }
 
        protected override void OnPreOpen()
        {
            m_EffectMask.SetActive(false);
            m_UnLockBehaviour.SetActive(false);
            m_ContainerNewUnLock.SetActive(false);
        }
 
        protected override void OnAfterOpen()
        {
            WindowCenter.Instance.Close<MainInterfaceWin>();
            WindowCenter.Instance.Close<KnapSackWin>();
        }
 
        protected override void OnPreClose()
        {
            model.wannaLookLocalMap = 0;
        }
 
        protected override void OnAfterClose()
        {
            if (!WindowJumpMgr.Instance.IsJumpState)
            {
                WindowCenter.Instance.Open<MainInterfaceWin>();
            }
        }
 
        protected override void OnActived()
        {
            base.OnActived();
 
            var backGroundSize = m_BackGround.rectTransform.rect;
            var viewAreaSize = m_BoudedDrag.rectTransform.rect;
            var xLimit = (backGroundSize.width - viewAreaSize.width) * 0.5f;
            var moveArea = m_BoudedDrag.moveArea;
 
            m_BoudedDrag.moveArea = new BoundedDrag.MoveArea()
            {
                Left = -xLimit,
                Right = xLimit,
                Bottom = moveArea.Bottom,
                Top = moveArea.Top
            };
 
            Init();
        }
 
        public override void CloseClick()
        {
            base.CloseClick();
        }
 
        void Init()
        {
            var worldMapAreaKeys = model.GetWorldMapAreas();
            var mapAreas = new List<WorldMapArea>();
            for (int i = 0; i < worldMapAreaKeys.Count; i++)
            {
                var key = worldMapAreaKeys[i];
                WorldMapArea area;
                if (model.TryGetWorldMapArea(key, out area))
                {
                    mapAreas.Add(area);
                }
            }
 
            m_AvatarCell.InitUI(AvatarHelper.GetMyAvatarModel());
 
            WorldMapAreaBehaviour playerAtBehaviour = null;
            var currentMapId = PlayerDatas.Instance.baseData.MapID;
            m_ContainerPlayerHead.SetActive(false);
            for (int i = 0; i < m_AreaBehaviours.Length; i++)
            {
                var behaviourTable = m_AreaBehaviours[i];
                WorldMapArea area;
                if (FindData(int.Parse(behaviourTable.id), mapAreas, out area))
                {
                    behaviourTable.areaBehaviour.SetActive(true);
                    behaviourTable.areaBehaviour.container.SetActive(true);
                    behaviourTable.areaBehaviour.Init(area);
                    if (behaviourTable.id == currentMapId.ToString())
                    {
                        m_ContainerPlayerHead.SetActive(true);
                        playerAtBehaviour = behaviourTable.areaBehaviour;
                        m_ContainerPlayerHead.SetParentEx(behaviourTable.areaBehaviour.playerHead, Vector3.zero, Vector3.zero, Vector3.one);
                    }
                }
                else
                {
                    behaviourTable.areaBehaviour.SetActive(false);
                    behaviourTable.areaBehaviour.container.SetActive(false);
                }
            }
 
            if (model.newUnlockedMap != 0)
            {
                StopCoroutine("Co_MapUnLockShow");
                StartCoroutine("Co_MapUnLockShow", model.newUnlockedMap);
                model.newUnlockedMap = 0;
            }
            else
            {
                EffectMgr.Instance.PlayUIEffect(1143, 3500, this.transform, false);
 
                if (playerAtBehaviour != null)
                {
                    var localPosition = -playerAtBehaviour.container.transform.localPosition.SetZ(0);
                    localPosition = new Vector3(Mathf.Clamp(localPosition.x, m_BoudedDrag.moveArea.Left, m_BoudedDrag.moveArea.Right),
                      Mathf.Clamp(localPosition.y, m_BoudedDrag.moveArea.Bottom, m_BoudedDrag.moveArea.Top));
 
                    m_BoudedDrag.currentPosition = m_BoudedDrag.destPosition = localPosition;
                }
                else
                {
                    m_BoudedDrag.currentPosition = m_BoudedDrag.destPosition = Vector3.zero;
                }
 
                m_BoudedDrag.actionable = false;
                m_ScaleTween.SetStartState();
                m_ScaleTween.Play(() =>
                {
                    m_BoudedDrag.currentScale = m_BoudedDrag.destScale = m_BoudedDrag.defaultScale;
                    m_BoudedDrag.actionable = true;
                });
            }
        }
 
        bool FindData(int _id, List<WorldMapArea> _areas, out WorldMapArea _area)
        {
            for (int i = 0; i < _areas.Count; i++)
            {
                var area = _areas[i];
                if (area.id == _id)
                {
                    _area = area;
                    return true;
                }
            }
 
            _area = default(WorldMapArea);
            return false;
        }
 
        IEnumerator Co_MapUnLockShow(int _mapId)
        {
            windowInfo.raycastTarget = false;
            var mapId = _mapId;
            WorldMapAreaBehaviour areaBehaviour = null;
            for (int i = 0; i < m_AreaBehaviours.Length; i++)
            {
                var behaviourTable = m_AreaBehaviours[i];
                if (behaviourTable.id == mapId.ToString())
                {
                    areaBehaviour = behaviourTable.areaBehaviour;
                }
            }
 
            if (areaBehaviour == null)
            {
                yield break;
            }
 
            m_EffectMask.SetActive(true);
            EffectMgr.Instance.PlayUIEffect(1143, 3500, this.transform, false);
            areaBehaviour.SetMaterial("Lerp");
            var localPosition = -areaBehaviour.transform.localPosition.SetZ(0);
            localPosition = new Vector3(Mathf.Clamp(localPosition.x, m_BoudedDrag.moveArea.Left, m_BoudedDrag.moveArea.Right),
              Mathf.Clamp(localPosition.y, m_BoudedDrag.moveArea.Bottom, m_BoudedDrag.moveArea.Top));
            m_BoudedDrag.currentPosition = m_BoudedDrag.destPosition = localPosition;
 
            yield return WaitingForSecondConst.WaitMS2000;
 
            var config = MapResourcesConfig.Get(MapUtility.GetMapResourceId(mapId, 0));
            if (config != null && !config.Effect.IsNullOrEmpty())
            {
                var unLockEffectId = config.Effect[0];
                var effect = EffectMgr.Instance.PlayUIEffect(unLockEffectId, 3500, this.transform, false);
                var timer = 0f;
                while (timer < 5f)
                {
                    timer += Time.deltaTime;
                    yield return null;
                }
 
                if (effect.gameObject != null)
                {
                    EffectMgr.Instance.RecyleUIEffect(unLockEffectId, effect.gameObject);
                }
            }
 
            EffectMgr.Instance.PlayUIEffect(3053, 3500, areaBehaviour.transform, false);
            yield return WaitingForSecondConst.WaitMS1000;
 
            m_EffectMask.SetActive(false);
 
            areaBehaviour.BeginUnLockShow();
            m_ContainerNewUnLock.SetActive(true);
            m_ContainerNewUnLock.SetParentEx(areaBehaviour.newUnLockArrowPoint != null ? areaBehaviour.newUnLockArrowPoint : areaBehaviour.transform,
                Vector3.zero, Vector3.zero, Vector3.one);
 
            windowInfo.raycastTarget = true;
        }
 
        public void TestMapUnLockShow(int _mapId)
        {
            StopCoroutine("Co_MapUnLockShow");
            StartCoroutine("Co_MapUnLockShow", _mapId);
        }
 
        private void OpenLocalMap()
        {
            WindowCenter.Instance.Close<WorldMapWin>();
            WindowCenter.Instance.Open<LocalMapWin>();
        }
 
        [System.Serializable]
        class AreaBehaviourTable
        {
            public string id;
            public WorldMapAreaBehaviour areaBehaviour;
        }
 
    }
 
}