//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 06, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; namespace Snxxz.UI { public class LocalMapWin : Window { [SerializeField] CyclicScroll m_EventPointToggleGroup; [SerializeField] Text m_MapName; [SerializeField] Button m_AutoHangUp; [SerializeField] LocalMapFindPath m_LocalMap; [SerializeField] ToggleButton m_MapLineSwitch; [SerializeField] Transform m_MapLineContainer; [SerializeField] Text m_CurrentLine; [SerializeField] DynamicCyclicScroll m_LinesScroll; [SerializeField] Button m_WorldMap; [SerializeField] Button m_Close; int mapId = 0; MapModel model { get { return ModelCenter.Instance.GetModel(); } } FairyGrabBossModel fairyGrabBossModel { get { return ModelCenter.Instance.GetModel(); } } protected override void BindController() { } protected override void AddListeners() { m_WorldMap.AddListener(GotoWorldMap); m_AutoHangUp.AddListener(GotoHangUp); m_MapLineSwitch.AddListener(GetMapLines); m_Close.AddListener(CloseClick); } protected override void OnPreOpen() { mapId = model.wannaLookLocalMap == 0 ? PlayerDatas.Instance.baseData.MapID : model.wannaLookLocalMap; m_MapLineContainer.gameObject.SetActive(false); m_MapLineSwitch.gameObject.SetActive(false); var config = MapConfig.Get(PlayerDatas.Instance.baseData.MapID); m_WorldMap.gameObject.SetActive(!CrossServerUtility.IsCrossServer() && config.MapFBType == (int)MapType.OpenCountry); } protected override void OnAfterOpen() { model.mapLinesUpdateEvent += OnMapLinesUpdate; } protected override void OnPreClose() { model.wannaLookLocalMap = 0; m_LocalMap.UnInit(); model.mapLinesUpdateEvent -= OnMapLinesUpdate; } protected override void OnAfterClose() { if (!WindowJumpMgr.Instance.IsJumpState) { WindowCenter.Instance.Open(); } } protected override void OnActived() { base.OnActived(); m_MapLineSwitch.isOn = false; Init(); CheckAchievementGuide(); } public override void CloseClick() { base.CloseClick(); } void Init() { ShowMapEventPoints(); m_LocalMap.Init(mapId); var mapConfig = MapConfig.Get(mapId); m_MapName.text = mapConfig.Name; m_MapLineSwitch.gameObject.SetActive(!CrossServerUtility.IsCrossServer() && mapId == PlayerDatas.Instance.baseData.MapID); var grabBossLine = 0; fairyGrabBossModel.TryGetFairyGrabBossLine(out grabBossLine); if (grabBossLine != 0 && PlayerDatas.Instance.baseData.FBID == grabBossLine) { m_CurrentLine.text = Language.Get("FairyGrabBossLine"); } else { if (BossFakeLineUtility.Instance.showFakeLine) { m_CurrentLine.text = Language.Get("line", 1); } else { m_CurrentLine.text = Language.Get("line", PlayerDatas.Instance.baseData.FBID + 1); } } } private void ShowMapEventPoints() { var visableEventPoints = new List(); var eventPoints = model.GetMapEventPoints(mapId); for (int i = 0; i < eventPoints.Count; i++) { var config = MapEventPointConfig.Get(eventPoints[i]); if (config.IsShowInfo == 1) { visableEventPoints.Add(eventPoints[i]); } } visableEventPoints.Sort((int a, int b) => { var configA = MapEventPointConfig.Get(a); var configB = MapEventPointConfig.Get(b); if (configA.LowLV != configB.LowLV) { return configA.LowLV < configB.LowLV ? -1 : 1; } else { return configA.Key < configB.Key ? -1 : 1; } }); m_EventPointToggleGroup.Init(visableEventPoints); var recommendHangPoint = model.GetRecommendHangPoint(mapId); if (recommendHangPoint == 0) { model.selectedMapEventPoint = -1; } else { model.selectedMapEventPoint = recommendHangPoint; m_EventPointToggleGroup.MoveToCenter(visableEventPoints.IndexOf(model.selectedMapEventPoint)); } } private void GetMapLines() { if (m_MapLineContainer.gameObject.activeInHierarchy) { m_MapLineContainer.gameObject.SetActive(false); m_MapLineSwitch.isOn = false; } else { var lines = model.GetMapLines(mapId); if (lines != null) { DisplayLines(lines); } else { model.RequestQueryMapLineState(mapId); } } } private void GotoHangUp() { if (model.selectedMapEventPoint != -1) { var config = MapEventPointConfig.Get(this.model.selectedMapEventPoint); WindowCenter.Instance.Close(); WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); MapTransferUtility.Instance.MoveToNPC(config.NPCID); } model.selectedMapEventPoint = -1; } private void GotoWorldMap() { WindowCenter.Instance.Close(); WindowCenter.Instance.Open(); } private void OnMapLinesUpdate(int _mapId) { if (mapId != _mapId) { return; } var lines = model.GetMapLines(mapId); if (lines != null) { DisplayLines(lines); } } private void UnSelectedEventPoint() { model.selectedMapEventPoint = -1; } private void DisplayLines(List _mapLines) { m_MapLineContainer.gameObject.SetActive(true); m_MapLineSwitch.isOn = true; m_LinesScroll.Init(_mapLines); } private void CheckAchievementGuide() { if (AchievementGoto.guideAchievementId != 0) { var config = SuccessConfig.Get(AchievementGoto.guideAchievementId); var condition = config.Type == 4; if (condition) { var guideEffect = AchievementGuideEffectPool.Require(1); guideEffect.transform.SetParentEx(m_AutoHangUp.transform, Vector3.zero, Vector3.zero, Vector3.one); } } } } }