//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, November 07, 2017
|
//--------------------------------------------------------
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class LocalMapTag : MonoBehaviour
|
{
|
[SerializeField] TextEx m_NpcName;
|
[SerializeField] TextEx m_Level;
|
[SerializeField] Button m_Moveto;
|
[SerializeField] Image m_TaskState;
|
[SerializeField] UIEffect m_Effect;
|
|
TagType m_TagType;
|
public TagType tagType {
|
get { return m_TagType; }
|
set { m_TagType = value; }
|
}
|
|
int npcId = 0;
|
int index = 0;
|
Vector3 jumpPoint = Vector3.zero;
|
|
MapModel mapModel { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
|
TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
|
FairyLeagueModel fairyLeagueModel { get { return ModelCenter.Instance.GetModel<FairyLeagueModel>(); } }
|
|
private void Start()
|
{
|
if (m_Moveto != null)
|
{
|
m_Moveto.SetListener(MoveTo);
|
}
|
}
|
|
public void Display(int npcId, TextColType colorType)
|
{
|
this.npcId = npcId;
|
var config = NPCConfig.Get(this.npcId);
|
switch (m_TagType)
|
{
|
case TagType.Function:
|
var status = this.taskModel.StatusLightQuery(this.npcId);
|
if (status > 0)
|
{
|
m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status));
|
}
|
else
|
{
|
m_TaskState.SetSprite("LocalMapTaskState_0");
|
}
|
|
m_TaskState.SetNativeSize();
|
TaskModel.Event_TaskResponse -= OnTaskStateChange;
|
TaskModel.Event_TaskResponse += OnTaskStateChange;
|
|
OnSelectEvent(mapModel.selectedMapEventPoint);
|
mapModel.selectMapEventPointEvent -= OnSelectEvent;
|
mapModel.selectMapEventPointEvent += OnSelectEvent;
|
break;
|
case TagType.WayPoint:
|
break;
|
case TagType.Boss:
|
m_NpcName.text = config.charName;
|
m_Level.text = Language.Get("HeadUpName_Monster", config.NPCLV);
|
m_NpcName.colorType = colorType;
|
var dangerous = PlayerDatas.Instance.baseData.LV <= config.NPCLV;
|
m_Level.color = UIHelper.GetUIColor(dangerous ? TextColType.Red : TextColType.Green, false);
|
break;
|
case TagType.Elite:
|
case TagType.Monster:
|
m_NpcName.text = config.charName;
|
m_NpcName.colorType = colorType;
|
break;
|
case TagType.Crystal:
|
this.OnCrystalStateChange(this.npcId);
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
|
fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
|
fairyLeagueModel.UpdateWarCrystalEvent += OnCrystalStateChange;
|
break;
|
}
|
}
|
|
public void Display(Vector3 position)
|
{
|
jumpPoint = position;
|
}
|
|
public void Display(int index)
|
{
|
this.index = index;
|
}
|
|
public void Dispose()
|
{
|
mapModel.selectMapEventPointEvent += OnSelectEvent;
|
TaskModel.Event_TaskResponse -= OnTaskStateChange;
|
fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
|
}
|
|
private void OnSelectEvent(int eventId)
|
{
|
var config = MapEventPointConfig.Get(eventId);
|
|
var isFunctionNpc = false;
|
if (config != null && config.NPCID == this.npcId)
|
{
|
var npcConfig = NPCConfig.Get(config.NPCID);
|
if (npcConfig.NPCType == 0)
|
{
|
isFunctionNpc = true;
|
}
|
}
|
|
if (isFunctionNpc)
|
{
|
if (!m_Effect.IsPlaying)
|
{
|
m_Effect.Play();
|
}
|
}
|
else
|
{
|
if (m_Effect.IsPlaying)
|
{
|
m_Effect.Stop();
|
}
|
}
|
}
|
|
private void MoveTo()
|
{
|
switch (m_TagType)
|
{
|
case TagType.FairyLeagueBuff:
|
{
|
var buffPos = fairyLeagueModel.crystalPosList[index];
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null)
|
{
|
hero.MoveToPosition(new Vector3(buffPos.x, hero.Pos.y, buffPos.y));
|
}
|
}
|
break;
|
case TagType.JumpPoint:
|
MapTransferUtility.Instance.MoveToLocalMapPosition(new Vector3(jumpPoint.x, jumpPoint.z, 0) );
|
break;
|
default:
|
{
|
WindowCenter.Instance.Close<WorldMapWin>();
|
WindowCenter.Instance.Close<LocalMapWin>();
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
MapTransferUtility.Instance.MoveToNPC(npcId);
|
mapModel.selectedMapEventPoint = -1;
|
}
|
break;
|
}
|
}
|
|
private void OnTaskStateChange(int nowNpcId, int npcLamp, Dictionary<int, int> dic)
|
{
|
if (npcId == nowNpcId)
|
{
|
var status = taskModel.StatusLightQuery(npcId);
|
if (status > 0)
|
{
|
m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status));
|
}
|
else
|
{
|
m_TaskState.SetSprite("LocalMapTaskState_0");
|
}
|
m_TaskState.SetNativeSize();
|
}
|
}
|
|
private void OnCrystalStateChange()
|
{
|
OnCrystalStateChange(npcId);
|
}
|
|
private void PlayerDataRefreshEvent(PlayerDataType type)
|
{
|
if (type == PlayerDataType.Faction)
|
{
|
OnCrystalStateChange();
|
}
|
}
|
|
private void OnCrystalStateChange(int npcId)
|
{
|
if (this.npcId != npcId)
|
{
|
return;
|
}
|
|
var index = fairyLeagueModel.GetCrystalIndex(npcId);
|
m_NpcName.text = (index + 1).ToString();
|
var camp = fairyLeagueModel.fairyLeagueHelp.GetCrystalBelongCamp(npcId);
|
if (camp == 0)
|
{
|
m_TaskState.SetSprite("GrayCrystal");
|
m_Moveto.image.SetSprite("GreyBottom");
|
return;
|
}
|
|
var isBlue = (FairyCampType)camp == FairyCampType.Blue;
|
m_TaskState.SetSprite(isBlue ? "BlueCrystal" : "RedCrystal");
|
m_Moveto.image.SetSprite(isBlue ? "BlueBottom" : "RedBottom");
|
}
|
|
public enum TagType
|
{
|
Boss = 1,
|
Elite = 2,
|
Monster = 3,
|
Function = 4,
|
WayPoint = 5,
|
Crystal = 6,
|
FairyLeagueBuff = 7,
|
JumpPoint = 8
|
}
|
|
}
|
|
public class LocalMapTagPool
|
{
|
static Dictionary<int, GameObjectPoolManager.GameObjectPool> pools = new Dictionary<int, GameObjectPoolManager.GameObjectPool>();
|
|
public static LocalMapTag Require(LocalMapTag.TagType pattern)
|
{
|
GameObjectPoolManager.GameObjectPool pool = null;
|
var poolKey = (int)pattern;
|
if (!pools.ContainsKey(poolKey))
|
{
|
var prefab = UILoader.LoadPrefab(StringUtility.Contact("LocalMap_", pattern));
|
if (prefab != null)
|
{
|
pool = GameObjectPoolManager.Instance.RequestPool(prefab);
|
pools[poolKey] = pool;
|
}
|
}
|
else
|
{
|
pool = pools[poolKey];
|
}
|
|
if (pool != null)
|
{
|
var instance = pool.Request();
|
var npcBehaviour = instance.GetComponent<LocalMapTag>();
|
npcBehaviour.tagType = pattern;
|
npcBehaviour.enabled = true;
|
return npcBehaviour;
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
public static void Recycle(LocalMapTag behaviour)
|
{
|
var pattern = behaviour.tagType;
|
GameObjectPoolManager.GameObjectPool pool;
|
if (pools.TryGetValue((int)pattern, out pool))
|
{
|
behaviour.enabled = false;
|
pool.Release(behaviour.gameObject);
|
}
|
}
|
|
public static void Clear()
|
{
|
foreach (var key in pools.Keys)
|
{
|
var pool = pools[key];
|
if (pool != null)
|
{
|
pool.Clear();
|
}
|
}
|
pools.Clear();
|
}
|
}
|
|
}
|