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.target.onClick.Add(OnBtnSendClick); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList); } protected override void OnShown() { base.OnShown(); ChatDataManager.Instance.NewChatInfo = false; EventAgent.DispatchEvent(ConstMessage.OPEN_CHAT_MESSAGE); 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; item.m_txtChatContent.text = chatData.Content; UI_ListChatItem.ProxyEnd(); } private async void OnBtnSendClick() { if (_ui.m_btnSend.m_c1.selectedIndex == 1) { PromptController.Instance.ShowFloatTextPrompt("消息发送频繁"); return; } 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(); int num = GlobalCfgArray.globalCfg.chatTime; _ui.m_btnSend.m_timeStr.text = num.ToString(); _ui.m_btnSend.m_c1.selectedIndex = 1; Timers.inst.Add(1, 10, (param) => { num--; _ui.m_btnSend.m_timeStr.text = num.ToString(); if (num == 0) { _ui.m_btnSend.m_c1.selectedIndex = 0; } }); } } } }