| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | using ET;using FairyGUI;using UI.CommonGame;using UI.League;using UnityEngine;namespace GFGGame{    //联盟聊天    public class LeagueChatView : BaseWindow    {        private UI_LeagueChatUI _ui;        public override void Dispose()        {            if (_ui != null)            {                _ui.Dispose();                _ui = null;            }            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_LeagueChatUI.PACKAGE_NAME;            _ui = UI_LeagueChatUI.Create();            this.viewCom = _ui.target;            isfullScreen = true;            _ui.m_loaBg.onClick.Add(Hide);            _ui.m_list.itemRenderer = RenderListItem;            _ui.m_list.itemProvider = GetListChatItemResource;            _ui.m_list.SetVirtual();            _ui.m_btnSend.onClick.Add(OnBtnSendClick);        }        protected override void AddEventListener()        {            base.AddEventListener();            EventAgent.AddEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);        }        protected override void OnShown()        {            base.OnShown();            UpdateChatList();        }        protected override void OnHide()        {            base.OnHide();            if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);        }        protected override void RemoveEventListener()        {            base.RemoveEventListener();            EventAgent.RemoveEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);        }        private void UpdateChatList()        {            _ui.m_list.numItems = ChatDataManager.Instance.GetChatDatas(ChatType.League).Count;            _ui.m_list.scrollPane.ScrollBottom(true);        }        private string GetListChatItemResource(int index)        {            if (ChatDataManager.Instance.GetChatDatas(ChatType.League)[index].RoleInfo.roleId == RoleDataManager.roleId)                return "ui://League/ListChatItemMine";            else                return "ui://League/ListChatItem";        }        private void RenderListItem(int index, GObject obj)        {            ChatData chatData = ChatDataManager.Instance.ChatDatas[ChatType.League][index];            OtherRoleInfoData roleInfo = chatData.RoleInfo;            UI_ListChatItem item = UI_ListChatItem.Proxy(obj);            RoleInfoManager.Instance.UpdateHeadWithLv(item.m_comHead, roleInfo.headId, roleInfo.headBorderId, roleInfo.roleLv);            item.m_txtName.text = roleInfo.roleName;            string content = "";            for (int i = 0; i < chatData.Content.Length; i++)            {                string str = i == 12 * (i + 1) ? chatData.Content[i] + "/n" : chatData.Content[i].ToString();                content += str;            }            item.m_txtChatContent.text = chatData.Content;            UI_ListChatItem.ProxyEnd();        }        private async void OnBtnSendClick()        {            if (string.IsNullOrEmpty(_ui.m_txtChat.text))            {                PromptController.Instance.ShowFloatTextPrompt("还没有输入想发送的内容哦");                return;            }            bool result = await ChatSProxy.ReqSendChatMsg(ChatType.League, _ui.m_txtChat.text);            if (result)            {                _ui.m_txtChat.text = "";                UpdateChatList();            }        }    }}
 |