//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, September 06, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
public class LocalMapWin : Window, SecondWindowInterface
|
{
|
[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;
|
|
int dataMapId = 0;
|
int lineId = 0;
|
MapModel model { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
|
|
public Button close { get; set; }
|
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
}
|
|
protected override void AddListeners()
|
{
|
m_WorldMap.AddListener(GotoWorldMap);
|
m_AutoHangUp.AddListener(GotoHangUp);
|
m_MapLineSwitch.AddListener(GetMapLines);
|
close.AddListener(CloseClick);
|
}
|
|
protected override void OnPreOpen()
|
{
|
dataMapId = model.wannaLookLocalMap == 0 ? MapUtility.GetDataMapId() : model.wannaLookLocalMap;
|
lineId = MapUtility.GetDataMapId() == dataMapId ? PlayerDatas.Instance.baseData.dungeonLineId : 0;
|
if (PlayerDatas.Instance.baseData.MapID == BossHomeModel.BOSSHOME_MAPID)
|
lineId = PlayerDatas.Instance.baseData.FBID;
|
m_MapLineContainer.SetActive(false);
|
m_MapLineSwitch.SetActive(false);
|
|
var config = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
|
m_WorldMap.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<MainInterfaceWin>();
|
}
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
m_MapLineSwitch.isOn = false;
|
Init();
|
|
CheckAchievementGuide();
|
}
|
|
public override void CloseClick()
|
{
|
base.CloseClick();
|
}
|
|
void Init()
|
{
|
ShowMapEventPoints();
|
m_LocalMap.Init(dataMapId, lineId);
|
var mapResourceConfig = MapResourcesConfig.GetConfig(dataMapId, lineId);
|
m_MapName.text = mapResourceConfig.Name;
|
|
var showLineSwitch = false;
|
if (!CrossServerUtility.IsCrossServer() && dataMapId == MapUtility.GetDataMapId())
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var mapConfig = MapConfig.Get(mapId);
|
if (mapConfig.MapFBType == 0 && mapId != BossHomeModel.BOSSHOME_MAPID)
|
{
|
showLineSwitch = true;
|
}
|
}
|
|
m_MapLineSwitch.SetActive(showLineSwitch);
|
if (showLineSwitch)
|
{
|
if (BossJiaLineUtility.Instance.showJiaLine)
|
{
|
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<int>();
|
var eventPoints = model.GetMapEventPoints(dataMapId, lineId);
|
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(dataMapId, lineId);
|
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.SetActive(false);
|
m_MapLineSwitch.isOn = false;
|
}
|
else
|
{
|
var mapId = MapUtility.GetMapId(dataMapId, lineId);
|
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<WorldMapWin>();
|
WindowCenter.Instance.Close<LocalMapWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
MapTransferUtility.Instance.MoveToNPC(config.NPCID);
|
}
|
|
model.selectedMapEventPoint = -1;
|
}
|
|
private void GotoWorldMap()
|
{
|
WindowCenter.Instance.Close<LocalMapWin>();
|
WindowCenter.Instance.Open<WorldMapWin>();
|
}
|
|
private void OnMapLinesUpdate(int _mapId)
|
{
|
var mapId = MapUtility.GetMapId(dataMapId, lineId);
|
if (mapId != _mapId)
|
{
|
return;
|
}
|
|
var lines = model.GetMapLines(mapId);
|
if (lines != null)
|
{
|
DisplayLines(lines);
|
}
|
}
|
|
private void UnSelectedEventPoint()
|
{
|
model.selectedMapEventPoint = -1;
|
}
|
|
private void DisplayLines(List<MapLine> _mapLines)
|
{
|
m_MapLineContainer.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);
|
}
|
}
|
}
|
|
}
|
|
}
|
|
|
|