LeagueChatView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using ET;
  2. using FairyGUI;
  3. using UI.CommonGame;
  4. using UI.League;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. //联盟聊天
  9. public class LeagueChatView : BaseWindow
  10. {
  11. private UI_LeagueChatUI _ui;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. packageName = UI_LeagueChatUI.PACKAGE_NAME;
  25. _ui = UI_LeagueChatUI.Create();
  26. this.viewCom = _ui.target;
  27. isfullScreen = true;
  28. isReturnView = true;
  29. _ui.m_loaBg.onClick.Add(Hide);
  30. _ui.m_list.itemRenderer = RenderListItem;
  31. _ui.m_list.itemProvider = GetListChatItemResource;
  32. _ui.m_list.SetVirtual();
  33. _ui.m_btnSend.target.onClick.Add(OnBtnSendClick);
  34. }
  35. protected override void AddEventListener()
  36. {
  37. base.AddEventListener();
  38. EventAgent.AddEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. UpdateChatList();
  44. }
  45. protected override void OnHide()
  46. {
  47. base.OnHide();
  48. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  49. }
  50. protected override void RemoveEventListener()
  51. {
  52. base.RemoveEventListener();
  53. EventAgent.RemoveEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);
  54. }
  55. private void UpdateChatList()
  56. {
  57. _ui.m_list.numItems = ChatDataManager.Instance.GetChatDatas(ChatType.League).Count;
  58. _ui.m_list.scrollPane.ScrollBottom(true);
  59. }
  60. private string GetListChatItemResource(int index)
  61. {
  62. if (ChatDataManager.Instance.GetChatDatas(ChatType.League)[index].RoleInfo.roleId == RoleDataManager.roleId)
  63. return "ui://League/ListChatItemMine";
  64. else
  65. return "ui://League/ListChatItem";
  66. }
  67. private void RenderListItem(int index, GObject obj)
  68. {
  69. ChatData chatData = ChatDataManager.Instance.ChatDatas[ChatType.League][index];
  70. OtherRoleInfoData roleInfo = chatData.RoleInfo;
  71. UI_ListChatItem item = UI_ListChatItem.Proxy(obj);
  72. RoleInfoManager.Instance.UpdateHeadWithLv(item.m_comHead, roleInfo.headId, roleInfo.headBorderId, roleInfo.roleLv);
  73. item.m_txtName.text = roleInfo.roleName;
  74. string content = "";
  75. for (int i = 0; i < chatData.Content.Length; i++)
  76. {
  77. string str = i == 12 * (i + 1) ? chatData.Content[i] + "/n" : chatData.Content[i].ToString();
  78. content += str;
  79. }
  80. item.m_txtChatContent.text = chatData.Content;
  81. UI_ListChatItem.ProxyEnd();
  82. }
  83. private async void OnBtnSendClick()
  84. {
  85. if (_ui.m_btnSend.m_c1.selectedIndex == 1)
  86. {
  87. PromptController.Instance.ShowFloatTextPrompt("消息发送频繁");
  88. return;
  89. }
  90. if (string.IsNullOrEmpty(_ui.m_txtChat.text))
  91. {
  92. PromptController.Instance.ShowFloatTextPrompt("还没有输入想发送的内容哦");
  93. return;
  94. }
  95. bool result = await ChatSProxy.ReqSendChatMsg(ChatType.League, _ui.m_txtChat.text);
  96. if (result)
  97. {
  98. _ui.m_txtChat.text = "";
  99. UpdateChatList();
  100. int num = GlobalCfgArray.globalCfg.chatTime;
  101. _ui.m_btnSend.m_timeStr.text = num.ToString();
  102. _ui.m_btnSend.m_c1.selectedIndex = 1;
  103. Timers.inst.Add(1, 10, (param) =>
  104. {
  105. num--;
  106. _ui.m_btnSend.m_timeStr.text = num.ToString();
  107. if (num == 0)
  108. {
  109. _ui.m_btnSend.m_c1.selectedIndex = 0;
  110. }
  111. });
  112. }
  113. }
  114. }
  115. }