LeagueChatView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. _ui.m_loaBg.onClick.Add(Hide);
  29. _ui.m_list.itemRenderer = RenderListItem;
  30. _ui.m_list.itemProvider = GetListChatItemResource;
  31. _ui.m_list.SetVirtual();
  32. _ui.m_btnSend.target.onClick.Add(OnBtnSendClick);
  33. }
  34. protected override void AddEventListener()
  35. {
  36. base.AddEventListener();
  37. EventAgent.AddEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. UpdateChatList();
  43. }
  44. protected override void OnHide()
  45. {
  46. base.OnHide();
  47. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  48. }
  49. protected override void RemoveEventListener()
  50. {
  51. base.RemoveEventListener();
  52. EventAgent.RemoveEventListener(ConstMessage.NOTICE_CHAT_MESSAGE, UpdateChatList);
  53. }
  54. private void UpdateChatList()
  55. {
  56. _ui.m_list.numItems = ChatDataManager.Instance.GetChatDatas(ChatType.League).Count;
  57. _ui.m_list.scrollPane.ScrollBottom(true);
  58. }
  59. private string GetListChatItemResource(int index)
  60. {
  61. if (ChatDataManager.Instance.GetChatDatas(ChatType.League)[index].RoleInfo.roleId == RoleDataManager.roleId)
  62. return "ui://League/ListChatItemMine";
  63. else
  64. return "ui://League/ListChatItem";
  65. }
  66. private void RenderListItem(int index, GObject obj)
  67. {
  68. ChatData chatData = ChatDataManager.Instance.ChatDatas[ChatType.League][index];
  69. OtherRoleInfoData roleInfo = chatData.RoleInfo;
  70. UI_ListChatItem item = UI_ListChatItem.Proxy(obj);
  71. RoleInfoManager.Instance.UpdateHeadWithLv(item.m_comHead, roleInfo.headId, roleInfo.headBorderId, roleInfo.roleLv);
  72. item.m_txtName.text = roleInfo.roleName;
  73. item.m_txtChatContent.text = chatData.Content;
  74. UI_ListChatItem.ProxyEnd();
  75. }
  76. private async void OnBtnSendClick()
  77. {
  78. if (_ui.m_btnSend.m_c1.selectedIndex == 1)
  79. {
  80. PromptController.Instance.ShowFloatTextPrompt("消息发送频繁");
  81. return;
  82. }
  83. if (string.IsNullOrEmpty(_ui.m_txtChat.text))
  84. {
  85. PromptController.Instance.ShowFloatTextPrompt("还没有输入想发送的内容哦");
  86. return;
  87. }
  88. bool result = await ChatSProxy.ReqSendChatMsg(ChatType.League, _ui.m_txtChat.text);
  89. if (result)
  90. {
  91. _ui.m_txtChat.text = "";
  92. UpdateChatList();
  93. int num = GlobalCfgArray.globalCfg.chatTime;
  94. _ui.m_btnSend.m_timeStr.text = num.ToString();
  95. _ui.m_btnSend.m_c1.selectedIndex = 1;
  96. Timers.inst.Add(1, 10, (param) =>
  97. {
  98. num--;
  99. _ui.m_btnSend.m_timeStr.text = num.ToString();
  100. if (num == 0)
  101. {
  102. _ui.m_btnSend.m_c1.selectedIndex = 0;
  103. }
  104. });
  105. }
  106. }
  107. }
  108. }