//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 06, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using TableConfig; namespace Snxxz.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] Image m_PlayerHead; [SerializeField] ScreenMoveTo m_UnLockBehaviour; [SerializeField] Transform m_EffectMask; [SerializeField] Transform m_ContainerNewUnLock; MapModel model { get { return ModelCenter.Instance.GetModel(); } } protected override void BindController() { } protected override void AddListeners() { m_LocalMap.AddListener(OpenLocalMap); m_Close.AddListener(CloseClick); } protected override void OnPreOpen() { m_EffectMask.gameObject.SetActive(false); m_UnLockBehaviour.gameObject.SetActive(false); m_ContainerNewUnLock.gameObject.SetActive(false); } protected override void OnAfterOpen() { WindowCenter.Instance.CloseImmediately(); WindowCenter.Instance.CloseImmediately(); } protected override void OnPreClose() { model.wannaLookLocalMap = 0; } protected override void OnAfterClose() { if (!WindowJumpMgr.Instance.IsJumpState) { WindowCenter.Instance.Open(); } } protected override void OnActived() { base.OnActived(); Init(); } public override void CloseClick() { base.CloseClick(); } void Init() { var worldMapAreaKeys = model.GetWorldMapAreas(); var mapAreas = new List(); for (int i = 0; i < worldMapAreaKeys.Count; i++) { var key = worldMapAreaKeys[i]; WorldMapArea area; if (model.TryGetWorldMapArea(key, out area)) { mapAreas.Add(area); } } var job = PlayerDatas.Instance.baseData.Job; m_PlayerHead.SetSprite(GeneralConfig.Instance.GetJobHeadPortrait(job, 0)); WorldMapAreaBehaviour playerAtBehaviour = null; var currentMapId = PlayerDatas.Instance.baseData.MapID; 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.gameObject.SetActive(true); behaviourTable.areaBehaviour.container.SetActive(true); behaviourTable.areaBehaviour.Init(area); if (behaviourTable.id == currentMapId.ToString()) { playerAtBehaviour = behaviourTable.areaBehaviour; m_ContainerPlayerHead.SetParentEx(behaviourTable.areaBehaviour.playerHead, Vector3.zero, Vector3.zero, Vector3.one); } } else { behaviourTable.areaBehaviour.gameObject.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 _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.gameObject.SetActive(true); EffectMgr.Instance.PlayUIEffect(1143, 3500, this.transform, false); yield return WaitingForSecondConst.WaitMS2000; 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; EffectMgr.Instance.PlayUIEffect(3053, 3500, areaBehaviour.transform, false); yield return WaitingForSecondConst.WaitMS1000; m_EffectMask.gameObject.SetActive(false); areaBehaviour.BeginUnLockShow(); m_ContainerNewUnLock.gameObject.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(); WindowCenter.Instance.Open(); } [System.Serializable] class AreaBehaviourTable { public string id; public WorldMapAreaBehaviour areaBehaviour; } } }