| using vnxbqy.UI;  | 
| using System;  | 
| using System.Collections;  | 
| using System.Collections.Generic;  | 
| using System.Text;  | 
| using UnityEngine;  | 
| using UnityEngine.UI;  | 
| public class ChatTip : MonoBehaviour  | 
| {  | 
|     private static ChatTip _inst = null;  | 
|   | 
|     public static ChatTip Inst  | 
|     {  | 
|         get { return _inst; }  | 
|     }  | 
|   | 
|     private void Awake()  | 
|     {  | 
|         _inst = this;  | 
|         InitCom();  | 
|     }  | 
|   | 
|     private GameObject chatPrefab;  | 
|     private GameObject chatContent;  | 
|     private GameObject chatMask;  | 
|     private GameObject chatMaskRay;  | 
|     private GameObject chatUpMaskRay;  | 
|     private GameObject chatUp;  | 
|   | 
|     private Button chatUpBtn;  | 
|     private Image chatUpImg;  | 
|     private bool isChatUp = false;  | 
|   | 
|     [SerializeField] Vector2 m_ChatLowSize = Vector2.zero;  | 
|     [SerializeField] Vector2 m_ChatHighSize = Vector2.zero;  | 
|   | 
|     public bool IsChatUp  | 
|     {  | 
|         get  | 
|         {  | 
|             return isChatUp;  | 
|         }  | 
|     }  | 
|   | 
|     public static event Action OnChatUpEvent;  | 
|   | 
|     private Image chatBg;  | 
|     private ScrollerController chatUpCtrl;  | 
|     private RichText destText;  | 
|     private List<ChatData> chatUpDataList;  | 
|   | 
|     private List<GameObject> chatItems = new List<GameObject>(ChatCtrl.CHAT_TIP_CNT);  | 
|   | 
|     static StringBuilder sb = new StringBuilder();  | 
|   | 
|     public Vector2 chatLowSize { get { return m_ChatLowSize; } }  | 
|     public Vector2 chatHighSize { get { return m_ChatHighSize; } }  | 
|   | 
|     void InitCom()  | 
|     {  | 
|         chatBg = this.GetComponent<Image>("Image");  | 
|   | 
|         chatContent = transform.Find("ChatMask/ChatContent").gameObject;  | 
|         chatPrefab = chatContent.transform.Find("ChatText").gameObject;  | 
|         chatMask = transform.Find("ChatMask").gameObject;  | 
|         chatMaskRay = chatMask.transform.Find("Ray").gameObject;  | 
|         UIEventTrigger.Get(chatMaskRay).OnNoParamsClick = OnChatClick;  | 
|   | 
|         chatUpBtn = this.GetComponent<Button>("Image/Btn_UP");  | 
|         chatUpImg = chatUpBtn.GetComponent<Image>();  | 
|         chatUpBtn.onClick.AddListener(OnChatUpBtn);  | 
|   | 
|         chatUp = transform.Find("ChatUp").gameObject;  | 
|         chatUpMaskRay = chatUp.transform.Find("Scroller/Ray").gameObject;  | 
|         UIEventTrigger.Get(chatUpMaskRay).OnNoParamsClick = OnChatClick;  | 
|         chatUpCtrl = chatUp.transform.Find("Controll").GetComponent<ScrollerController>();  | 
|         chatUpCtrl.lockType = EnhanceLockType.KeepVertical;  | 
|         destText = chatUp.transform.Find("ChatCell/ChatText").GetComponent<RichText>();  | 
|         chatUpCtrl.OnRefreshCell += OnRefreshChatUpCell;  | 
|         chatUpCtrl.OnGetDynamicSize += OnGetDynamicSize;  | 
|     }  | 
|   | 
|     private bool OnGetDynamicSize(ScrollerDataType type, int index, out float height)  | 
|     {  | 
|         destText.SetExtenalData(chatUpDataList[index].infoList);  | 
|         destText.text = StringUtility.Contact(SetChatExtraInfo(chatUpDataList[index]),  | 
|             chatUpDataList[index].content);  | 
|         height = destText.preferredHeight;  | 
|         return true;  | 
|     }  | 
|   | 
|     private void OnRefreshChatUpCell(ScrollerDataType type, CellView cell)  | 
|     {  | 
|         int index = cell.index;  | 
|         if (chatUpDataList != null && index < chatUpDataList.Count)  | 
|         {  | 
|             RichText text = cell.transform.Find("ChatText").GetComponent<RichText>();  | 
|             ChatData data = chatUpDataList[index];  | 
|             if (chatUpDataList[index].infoList != null)  | 
|             {  | 
|                 text.SetExtenalData(chatUpDataList[index].infoList);  | 
|             }  | 
|             text.text = StringUtility.Contact(SetChatExtraInfo(chatUpDataList[index]),  | 
|                 chatUpDataList[index].content);  | 
|             text.OnClick = () =>  | 
|             {  | 
|                 OnChatDataClick(data);  | 
|             };  | 
|         }  | 
|     }  | 
|   | 
|     private void OnChatUpBtn()  | 
|     {  | 
|         if (!isChatUp)  | 
|         {  | 
|             isChatUp = true;  | 
|             chatBg.rectTransform.sizeDelta = m_ChatHighSize.Equals(Vector2.zero) ? new Vector2(470, 205) : m_ChatHighSize;  | 
|             chatMask.SetActive(false);  | 
|             chatUp.SetActive(true);  | 
|             OnInitUpChat();  | 
|             chatUpImg.transform.localScale = chatUpImg.transform.localScale.SetY(-1);  | 
|             chatUpCtrl.mScrollRect.verticalNormalizedPosition = 0;  | 
|         }  | 
|         else  | 
|         {  | 
|             isChatUp = false;  | 
|             chatBg.rectTransform.sizeDelta = m_ChatLowSize.Equals(Vector2.zero) ? new Vector2(470, 79) : m_ChatLowSize;  | 
|             chatUpImg.transform.localScale = chatUpImg.transform.localScale.SetY(1);  | 
|             chatUp.SetActive(false);  | 
|             chatMask.SetActive(true);  | 
|             OnRefreshAllChat();  | 
|         }  | 
|   | 
|         if (OnChatUpEvent != null)  | 
|         {  | 
|             OnChatUpEvent();  | 
|         }  | 
|     }  | 
|   | 
|     private void OnInitUpChat()  | 
|     {  | 
|         chatUpDataList = ChatCtrl.Inst.GetChatUpInfo();  | 
|         chatUpCtrl.Refresh();  | 
|         if (chatUpDataList != null && chatUpDataList.Count > 0)  | 
|         {  | 
|             for (int i = 0; i < chatUpDataList.Count; i++)  | 
|             {  | 
|                 chatUpCtrl.AddCell(ScrollerDataType.Header, i);  | 
|             }  | 
|         }  | 
|         chatUpCtrl.Restart();  | 
|     }  | 
|   | 
|     private void OnChatClick()  | 
|     {  | 
|         if (WindowCenter.Instance.IsOpen<ChatWin>())  | 
|         {  | 
|             return;  | 
|         }  | 
|         ChatCtrl.Inst.presentChatType = ChatInfoType.World;  | 
|         var mapId = ModelCenter.Instance.GetModel<DungeonModel>().GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);  | 
|         if (mapId == 31230)  | 
|         {  | 
|             ChatCtrl.Inst.presentChatType = ChatInfoType.Fairy;  | 
|         }  | 
|         WindowCenter.Instance.Open<ChatWin>();  | 
|     }  | 
|   | 
|     private void OnEnable()  | 
|     {  | 
|         ChatCtrl.OnRefreshChat += OnRefreshChatTip;  | 
|         OnRefreshAllChat();  | 
|         isChatUp = true;  | 
|         OnChatUpBtn();  | 
|     }  | 
|   | 
|     private void OnRefreshAllChat()  | 
|     {  | 
|         List<ChatData> list = ChatCtrl.Inst.GetChatInfo();  | 
|         for (int i = 0; i < list.Count; i++)  | 
|         {  | 
|             GameObject prefab = null;  | 
|             if (i >= chatItems.Count)  | 
|             {  | 
|                 prefab = Instantiate(chatPrefab) as GameObject;  | 
|                 prefab.transform.SetParent(chatContent.transform);  | 
|                 prefab.transform.localScale = Vector3.one;  | 
|                 Vector3 pos = prefab.transform.localPosition;  | 
|                 prefab.transform.localPosition = pos.SetZ(0);  | 
|                 prefab.SetActive(true);  | 
|                 chatItems.Add(prefab);  | 
|             }  | 
|             else  | 
|             {  | 
|                 prefab = chatItems[i];  | 
|                 prefab.SetActive(true);  | 
|             }  | 
|             SetChatItemData(prefab, list[i]);  | 
|         }  | 
|         for (int i = chatItems.Count - 1; i >= list.Count; i--)  | 
|         {  | 
|             if (chatItems[i].activeSelf)  | 
|             {  | 
|                 chatItems[i].SetActive(false);  | 
|             }  | 
|         }  | 
|     }  | 
|   | 
|     void OnChatDataClick(ChatData data)  | 
|     {  | 
|         if (WindowCenter.Instance.IsOpen<ChatWin>())  | 
|         {  | 
|             return;  | 
|         }  | 
|         ChatCtrl.Inst.presentChatType = data.type;  | 
|         var mapId = ModelCenter.Instance.GetModel<DungeonModel>().GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);  | 
|         if (mapId == 31230)  | 
|         {  | 
|             ChatCtrl.Inst.presentChatType = ChatInfoType.Fairy;  | 
|         }  | 
|         if (ChatCtrl.Inst.presentChatType == ChatInfoType.CrossServer  | 
|             && !FuncOpen.Instance.IsFuncOpen(162))  | 
|         {  | 
|             ChatCtrl.Inst.presentChatType = ChatInfoType.World;  | 
|         }  | 
|         WindowCenter.Instance.Open<ChatWin>();  | 
|     }  | 
|   | 
|     void OnRefreshChatTip(ChatInfoType type)  | 
|     {  | 
|         if (isChatUp)  | 
|         {  | 
|             OnInitUpChat();  | 
|         }  | 
|         else  | 
|         {  | 
|             OnRefreshAllChat();  | 
|         }  | 
|     }  | 
|   | 
|     void SetChatItemData(GameObject prefab, ChatData data)  | 
|     {  | 
|         RichText text = prefab.GetComponent<RichText>();  | 
|         if (data.infoList != null)  | 
|         {  | 
|             text.SetExtenalData(data.infoList);  | 
|         }  | 
|         text.text = StringUtility.Contact(SetChatExtraInfo(data), data.content);  | 
|         text.OnClick = () =>  | 
|         {  | 
|             OnChatDataClick(data);  | 
|         };  | 
|     }  | 
|   | 
|     string SetChatExtraInfo(ChatData data)  | 
|     {  | 
|         sb.Length = 0;  | 
|         string vipLv = string.Empty;  | 
|         string chatIcon = string.Empty;  | 
|         string chatName = string.Empty;  | 
|         var chatUserData = (data as ChatUeseData);  | 
|         switch (data.type)  | 
|         {  | 
|             case ChatInfoType.World:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_World";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";//StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.Area:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_Area";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";// StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.CrossServer:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_CrossServer";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";// StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.Team:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_Team";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";// StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.Fairy:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_Fairy";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";// StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.Trumpet:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_Trumpet";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";// StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.default1:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_default1";  | 
|                     chatName = chatUserData.name;  | 
|                     if (chatUserData.vipLv > 0)  | 
|                     {  | 
|                         vipLv = "VIP";// StringUtility.Contact("V", chatUserData.vipLv);  | 
|                     }  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.Invite:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_Invite";  | 
|                     break;  | 
|                 }  | 
|             case ChatInfoType.System:  | 
|                 {  | 
|                     chatIcon = "ChatIcon_System";  | 
|                     break;  | 
|                 }  | 
|         }  | 
|         if (!string.IsNullOrEmpty(chatIcon))  | 
|         {  | 
|             sb.Append(string.Format("<Img chat={0}/> ", chatIcon));  | 
|         }  | 
|         if (!string.IsNullOrEmpty(vipLv))  | 
|         {  | 
|             sb.Append(string.Format("<color=#f8983b>{0}</color> ", vipLv));  | 
|         }  | 
|         if (!string.IsNullOrEmpty(chatName))  | 
|         {  | 
|             sb.Append(string.Format("<color=#109d06>{0}</color>: ", chatName));  | 
|         }  | 
|         return sb.ToString();  | 
|     }  | 
|   | 
|     private void OnDisable()  | 
|     {  | 
|         ChatCtrl.OnRefreshChat -= OnRefreshChatTip;  | 
|     }  | 
|   | 
|     private void OnDestroy()  | 
|     {  | 
|         _inst = null;  | 
|     }  | 
|   | 
|     public bool IsOpen  | 
|     {  | 
|         get  | 
|         {  | 
|             return gameObject.activeInHierarchy;  | 
|         }  | 
|     }  | 
| }  |