| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: 第二世界 |
| | | // [ Date ]: Tuesday, November 07, 2017 |
| | | //-------------------------------------------------------- |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using TableConfig; |
| | | 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; |
| | | |
| | | TagType m_TagType; |
| | | public TagType tagType { |
| | | get { |
| | | return m_TagType; |
| | | } |
| | | set { |
| | | m_TagType = value; |
| | | } |
| | | } |
| | | |
| | | LocalMapFindPath localMapFindPath; |
| | | Vector3 worldPosition = Vector3.zero; |
| | | int npcId = 0; |
| | | int index = 0; |
| | | PlayerTaskDatas taskmodel { |
| | | get { |
| | | return ModelCenter.Instance.GetModel<PlayerTaskDatas>(); |
| | | } |
| | | } |
| | | |
| | | FairyLeagueModel fairyLeagueModel { |
| | | get { |
| | | return ModelCenter.Instance.GetModel<FairyLeagueModel>(); |
| | | } |
| | | } |
| | | |
| | | public void Display(int _npcId, TextColType _colorType) |
| | | { |
| | | npcId = _npcId; |
| | | switch (m_TagType) |
| | | { |
| | | case TagType.Function: |
| | | var status = taskmodel.StatusLightQuery(npcId); |
| | | if (status > 0) |
| | | { |
| | | m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status)); |
| | | } |
| | | else |
| | | { |
| | | m_TaskState.SetSprite("LocalMapTaskState_0"); |
| | | } |
| | | |
| | | m_TaskState.SetNativeSize(); |
| | | PlayerTaskDatas.Event_TaskResponse -= OnTaskStateChange; |
| | | PlayerTaskDatas.Event_TaskResponse += OnTaskStateChange; |
| | | break; |
| | | case TagType.WayPoint: |
| | | break; |
| | | case TagType.Boss: |
| | | break; |
| | | case TagType.Elite: |
| | | case TagType.Monster: |
| | | var config = ConfigManager.Instance.GetTemplate<NPCConfig>(npcId); |
| | | m_NpcName.text = config.charName; |
| | | m_NpcName.colorType = _colorType; |
| | | break; |
| | | case TagType.Crystal: |
| | | OnCrystalStateChange(npcId); |
| | | m_Moveto.RemoveAllListeners(); |
| | | m_Moveto.AddListener(MoveTo); |
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent; |
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent; |
| | | fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange; |
| | | fairyLeagueModel.UpdateWarCrystalEvent += OnCrystalStateChange; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | public void Display(int _npcId, TextColType _colorType, Vector3 _position) |
| | | { |
| | | worldPosition = _position; |
| | | npcId = _npcId; |
| | | |
| | | switch (m_TagType) |
| | | { |
| | | case TagType.Boss: |
| | | var config = ConfigManager.Instance.GetTemplate<NPCConfig>(npcId); |
| | | 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); |
| | | m_Moveto.RemoveAllListeners(); |
| | | m_Moveto.AddListener(MoveTo); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | public void Display(int _index) |
| | | { |
| | | index = _index; |
| | | switch (m_TagType) |
| | | { |
| | | case TagType.FairyLeagueBuff: |
| | | m_Moveto.RemoveAllListeners(); |
| | | m_Moveto.AddListener(MoveTo); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | PlayerTaskDatas.Event_TaskResponse -= OnTaskStateChange; |
| | | fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange; |
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent; |
| | | } |
| | | |
| | | private void MoveTo() |
| | | { |
| | | switch (m_TagType) |
| | | { |
| | | case TagType.FairyLeagueBuff: |
| | | { |
| | | var _help = fairyLeagueModel.fairyLeagueHelp; |
| | | Vector2 _buffPos = fairyLeagueModel.crystalPosList[index]; |
| | | var _hero = PlayerDatas.Instance.hero; |
| | | if (_hero != null) |
| | | { |
| | | _hero.MoveToPosition(new Vector3(_buffPos.x, _hero.Pos.y, _buffPos.y)); |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | { |
| | | var model = ModelCenter.Instance.GetModel<MapModel>(); |
| | | WindowCenter.Instance.Close<WorldMapWin>(); |
| | | WindowCenter.Instance.Close<LocalMapWin>(); |
| | | WindowCenter.Instance.Open<MainInterfaceWin>(); |
| | | MapTransferUtility.Instance.MoveToNPC(npcId); |
| | | model.selectedLocalMapEventPoint = -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 PlayerDataRefreshInfoEvent(PlayerDataRefresh _type) |
| | | { |
| | | if (_type == PlayerDataRefresh.Faction) |
| | | { |
| | | OnCrystalStateChange(); |
| | | } |
| | | } |
| | | |
| | | private void OnCrystalStateChange(int _npcId) |
| | | { |
| | | if (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; |
| | | } |
| | | m_TaskState.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueCrystal" : "RedCrystal"); |
| | | m_Moveto.image.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueBottom" : "RedBottom"); |
| | | } |
| | | |
| | | public enum TagType |
| | | { |
| | | Boss = 1, |
| | | Elite = 2, |
| | | Monster = 3, |
| | | Function = 4, |
| | | WayPoint = 5, |
| | | Crystal = 6, |
| | | FairyLeagueBuff = 7, |
| | | } |
| | | |
| | | } |
| | | |
| | | 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 _npcBehaviour) |
| | | { |
| | | var pattern = _npcBehaviour.tagType; |
| | | GameObjectPoolManager.GameObjectPool pool; |
| | | if (pools.TryGetValue((int)pattern, out pool)) |
| | | { |
| | | _npcBehaviour.enabled = false; |
| | | pool.Release(_npcBehaviour.gameObject); |
| | | } |
| | | } |
| | | |
| | | public static void Clear() |
| | | { |
| | | foreach (var key in pools.Keys) |
| | | { |
| | | var pool = pools[key]; |
| | | if (pool != null) |
| | | { |
| | | pool.Clear(); |
| | | } |
| | | } |
| | | pools.Clear(); |
| | | } |
| | | } |
| | | |
| | | //--------------------------------------------------------
|
| | | // [Author]: 第二世界
|
| | | // [ Date ]: Tuesday, November 07, 2017
|
| | | //--------------------------------------------------------
|
| | | using System;
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using TableConfig;
|
| | | 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;
|
| | |
|
| | | TagType m_TagType;
|
| | | public TagType tagType {
|
| | | get {
|
| | | return m_TagType;
|
| | | }
|
| | | set {
|
| | | m_TagType = value;
|
| | | }
|
| | | }
|
| | |
|
| | | LocalMapFindPath localMapFindPath;
|
| | | Vector3 worldPosition = Vector3.zero;
|
| | | int npcId = 0;
|
| | | int index = 0;
|
| | | PlayerTaskDatas taskmodel {
|
| | | get {
|
| | | return ModelCenter.Instance.GetModel<PlayerTaskDatas>();
|
| | | }
|
| | | }
|
| | |
|
| | | FairyLeagueModel fairyLeagueModel {
|
| | | get {
|
| | | return ModelCenter.Instance.GetModel<FairyLeagueModel>();
|
| | | }
|
| | | }
|
| | |
|
| | | public void Display(int _npcId, TextColType _colorType)
|
| | | {
|
| | | npcId = _npcId;
|
| | | switch (m_TagType)
|
| | | {
|
| | | case TagType.Function:
|
| | | var status = taskmodel.StatusLightQuery(npcId);
|
| | | if (status > 0)
|
| | | {
|
| | | m_TaskState.SetSprite(StringUtility.Contact("LocalMapTaskState_", status));
|
| | | }
|
| | | else
|
| | | {
|
| | | m_TaskState.SetSprite("LocalMapTaskState_0");
|
| | | }
|
| | |
|
| | | m_TaskState.SetNativeSize();
|
| | | PlayerTaskDatas.Event_TaskResponse -= OnTaskStateChange;
|
| | | PlayerTaskDatas.Event_TaskResponse += OnTaskStateChange;
|
| | | break;
|
| | | case TagType.WayPoint:
|
| | | break;
|
| | | case TagType.Boss:
|
| | | break;
|
| | | case TagType.Elite:
|
| | | case TagType.Monster:
|
| | | var config = Config.Instance.Get<NPCConfig>(npcId);
|
| | | m_NpcName.text = config.charName;
|
| | | m_NpcName.colorType = _colorType;
|
| | | break;
|
| | | case TagType.Crystal:
|
| | | OnCrystalStateChange(npcId);
|
| | | m_Moveto.RemoveAllListeners();
|
| | | m_Moveto.AddListener(MoveTo);
|
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent;
|
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
| | | fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
|
| | | fairyLeagueModel.UpdateWarCrystalEvent += OnCrystalStateChange;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | public void Display(int _npcId, TextColType _colorType, Vector3 _position)
|
| | | {
|
| | | worldPosition = _position;
|
| | | npcId = _npcId;
|
| | |
|
| | | switch (m_TagType)
|
| | | {
|
| | | case TagType.Boss:
|
| | | var config = Config.Instance.Get<NPCConfig>(npcId);
|
| | | 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);
|
| | | m_Moveto.RemoveAllListeners();
|
| | | m_Moveto.AddListener(MoveTo);
|
| | | break;
|
| | | default:
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | public void Display(int _index)
|
| | | {
|
| | | index = _index;
|
| | | switch (m_TagType)
|
| | | {
|
| | | case TagType.FairyLeagueBuff:
|
| | | m_Moveto.RemoveAllListeners();
|
| | | m_Moveto.AddListener(MoveTo);
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | public void Dispose()
|
| | | {
|
| | | PlayerTaskDatas.Event_TaskResponse -= OnTaskStateChange;
|
| | | fairyLeagueModel.UpdateWarCrystalEvent -= OnCrystalStateChange;
|
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent;
|
| | | }
|
| | |
|
| | | private void MoveTo()
|
| | | {
|
| | | switch (m_TagType)
|
| | | {
|
| | | case TagType.FairyLeagueBuff:
|
| | | {
|
| | | var _help = fairyLeagueModel.fairyLeagueHelp;
|
| | | Vector2 _buffPos = fairyLeagueModel.crystalPosList[index];
|
| | | var _hero = PlayerDatas.Instance.hero;
|
| | | if (_hero != null)
|
| | | {
|
| | | _hero.MoveToPosition(new Vector3(_buffPos.x, _hero.Pos.y, _buffPos.y));
|
| | | }
|
| | | }
|
| | | break;
|
| | | default:
|
| | | {
|
| | | var model = ModelCenter.Instance.GetModel<MapModel>();
|
| | | WindowCenter.Instance.Close<WorldMapWin>();
|
| | | WindowCenter.Instance.Close<LocalMapWin>();
|
| | | WindowCenter.Instance.Open<MainInterfaceWin>();
|
| | | MapTransferUtility.Instance.MoveToNPC(npcId);
|
| | | model.selectedLocalMapEventPoint = -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 PlayerDataRefreshInfoEvent(PlayerDataRefresh _type)
|
| | | {
|
| | | if (_type == PlayerDataRefresh.Faction)
|
| | | {
|
| | | OnCrystalStateChange();
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnCrystalStateChange(int _npcId)
|
| | | {
|
| | | if (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;
|
| | | }
|
| | | m_TaskState.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueCrystal" : "RedCrystal");
|
| | | m_Moveto.image.SetSprite((FairyCampType)_camp == FairyCampType.Blue ? "BlueBottom" : "RedBottom");
|
| | | }
|
| | |
|
| | | public enum TagType
|
| | | {
|
| | | Boss = 1,
|
| | | Elite = 2,
|
| | | Monster = 3,
|
| | | Function = 4,
|
| | | WayPoint = 5,
|
| | | Crystal = 6,
|
| | | FairyLeagueBuff = 7,
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | 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 _npcBehaviour)
|
| | | {
|
| | | var pattern = _npcBehaviour.tagType;
|
| | | GameObjectPoolManager.GameObjectPool pool;
|
| | | if (pools.TryGetValue((int)pattern, out pool))
|
| | | {
|
| | | _npcBehaviour.enabled = false;
|
| | | pool.Release(_npcBehaviour.gameObject);
|
| | | }
|
| | | }
|
| | |
|
| | | public static void Clear()
|
| | | {
|
| | | foreach (var key in pools.Keys)
|
| | | {
|
| | | var pool = pools[key];
|
| | | if (pool != null)
|
| | | {
|
| | | pool.Clear();
|
| | | }
|
| | | }
|
| | | pools.Clear();
|
| | | }
|
| | | }
|
| | |
|
| | | } |