MailView.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UI.Mail;
  5. using FairyGUI;
  6. using ET;
  7. namespace GFGGame
  8. {
  9. public class MailView : BaseWindow
  10. {
  11. private UI_MailUI _ui;
  12. private MailDataManager mailDataMgr;
  13. private const int _maxMailCount = 300;
  14. private const int _retainDay = 30;//邮件保存时间
  15. // private const int _showCount = 5;//??????????
  16. private int _firstPage = 0;//当前页面
  17. private int _endPage = 0;//当前页面
  18. public bool _canShowContent = false;//获取内容数据返回前不可查看
  19. public List<MailInfo> mailInfos;//= new List<MailInfo>();
  20. public override void Dispose()
  21. {
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_MailUI.PACKAGE_NAME;
  33. _ui = UI_MailUI.Create();
  34. this.viewCom = _ui.target;
  35. this.viewCom.Center();
  36. this.modal = true;
  37. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  38. _ui.m_list.itemRenderer = RenderListItem;
  39. _ui.m_list.SetVirtual();
  40. _ui.m_list.scrollPane.onScrollEnd.Add(() =>
  41. {
  42. RefreshMailInfo(false);
  43. });
  44. // _ui.target.onTouchEnd.Add(() =>
  45. // {
  46. // RefreshMailInfo(false);
  47. // });
  48. _ui.m_btnGet.onClick.Add(OnClickBtnGet);
  49. _ui.m_btnDelete.onClick.Add(OnClickBtnDelete);
  50. mailDataMgr = MailDataManager.Instance;
  51. }
  52. protected override void AddEventListener()
  53. {
  54. base.AddEventListener();
  55. EventAgent.AddEventListener(ConstMessage.MAIL_REFRESH, RefreshList);
  56. EventAgent.AddEventListener(ConstMessage.MAIL_REWARD, RefreshList);
  57. EventAgent.AddEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal);
  58. EventAgent.AddEventListener(ConstMessage.MAIL_DELETE, UpdateNormal);
  59. EventAgent.AddEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal);
  60. EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  61. }
  62. protected override void OnShown()
  63. {
  64. base.OnShown();
  65. mailDataMgr.CurPage = 0;
  66. UpdateNormal();
  67. }
  68. private void UpdateNormal()
  69. {
  70. _ui.m_list.numItems = mailDataMgr.TotolCount;
  71. _ui.m_txtTips.visible = mailDataMgr.TotolCount == 0 ? true : false;
  72. _ui.m_txtCount.text = string.Format("当前邮件:{0}/{1}", StringUtil.GetColorText(mailDataMgr.TotolCount.ToString(), mailDataMgr.TotolCount >= _maxMailCount ? "#B19977" : "#E27D78"), _maxMailCount);
  73. _ui.m_txtMaxCount.text = string.Format("最高可储存{0}封邮箱,请及时查看", _maxMailCount);
  74. RefreshMailInfo(true);
  75. }
  76. private void RenderListItem(int index, GObject obj)
  77. {
  78. // _endPage = index / mailDataMgr.PageCount;
  79. // ET.Log.Debug("_endPage:" + _endPage + " index:" + index + " PageCount:" + mailDataMgr.PageCount);
  80. UI_ListItem item = UI_ListItem.Proxy(obj);
  81. long mailId = mailDataMgr.GetMailIdByIndex(index);
  82. // item.m_btnLook.data = mailId;
  83. if (mailId < 0)
  84. {
  85. item.m_txtTitle.text = "请稍后...";
  86. item.m_txtTime.text = "";
  87. return;
  88. }
  89. // long mailId = mailDataMgr.MailIds[index];
  90. MailInfo data = mailDataMgr.GetMailInfoById(mailId);
  91. item.m_c1.selectedIndex = mailDataMgr.GetMailState(data);
  92. item.m_txtTitle.text = data.title;
  93. long endTime = (data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY * 1000);
  94. string str = TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  95. item.m_txtTime.text = string.Format("剩余时间:{0}", str);
  96. if (item.m_btnLook.data == null)
  97. {
  98. item.m_btnLook.onClick.Add(OnClickBtnLook);
  99. }
  100. item.m_btnLook.data = mailId;
  101. UI_ListItem.ProxyEnd();
  102. }
  103. private async void OnClickBtnLook(EventContext context)
  104. {
  105. // int index = (int)(context.sender as GObject).data;
  106. long mailId = (long)(context.sender as GObject).data;
  107. bool result = await MailSProxy.ReqMailContent(mailId);
  108. if (result)
  109. {
  110. ViewManager.Show<MailContentView>(mailId);
  111. }
  112. }
  113. private async void RefreshMailInfo(bool needSort)
  114. {
  115. if (mailDataMgr.TotolCount == 0) return;
  116. if (needSort)
  117. {
  118. _ui.m_list.ScrollToView(0);
  119. MailDataManager.Instance.RefreshMailInfoDic(needSort);
  120. }
  121. _firstPage = _ui.m_list.ChildIndexToItemIndex(0) / mailDataMgr.PageCount;
  122. _endPage = _ui.m_list.ChildIndexToItemIndex(_ui.m_list.numChildren - 1) / mailDataMgr.PageCount;
  123. ET.Log.Debug("_firstPage:" + _firstPage + " _endPage:" + _endPage);
  124. if (mailDataMgr.GetMailIdByPage(_firstPage) != null && mailDataMgr.GetMailIdByPage(_endPage) != null)
  125. {
  126. RefreshList();
  127. return;
  128. }
  129. if (mailDataMgr.GetMailIdByPage(_firstPage) == null)
  130. {
  131. bool result = await MailSProxy.ReqMailList(_firstPage * mailDataMgr.PageCount, mailDataMgr.PageCount, needSort, _firstPage);
  132. if (result)
  133. {
  134. RefreshList();
  135. }
  136. }
  137. if (_endPage == _firstPage) return;
  138. if (mailDataMgr.GetMailIdByPage(_endPage) == null)
  139. {
  140. bool result = await MailSProxy.ReqMailList(_endPage * mailDataMgr.PageCount, mailDataMgr.PageCount, needSort, _endPage);
  141. if (result)
  142. {
  143. RefreshList();
  144. }
  145. }
  146. }
  147. private void RefreshList()
  148. {
  149. // mailInfos = mailDataMgr.GetMailInfos();
  150. _ui.m_list.RefreshVirtualList();
  151. }
  152. private void OnClickBtnGet()
  153. {
  154. MailSProxy.ReqAllMailRewards().Coroutine();
  155. }
  156. private void OnClickBtnDelete()
  157. {
  158. if (mailDataMgr.TotolCount == 0)
  159. {
  160. PromptController.Instance.ShowFloatTextPrompt("暂无邮件可删除");
  161. return;
  162. }
  163. AlertUI.Show("是否删除所有已读文件?").SetLeftButton(true).SetRightButton(true, "确认", (object data) =>
  164. {
  165. SendDeleteAll();
  166. });
  167. }
  168. private void SendDeleteAll()
  169. {
  170. MailSProxy.ReqDeleteAllMails().Coroutine();
  171. }
  172. protected override void OnHide()
  173. {
  174. base.OnHide();
  175. }
  176. protected override void RemoveEventListener()
  177. {
  178. base.RemoveEventListener();
  179. EventAgent.RemoveEventListener(ConstMessage.MAIL_REFRESH, RefreshList);
  180. EventAgent.RemoveEventListener(ConstMessage.MAIL_REWARD, RefreshList);
  181. EventAgent.RemoveEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal);
  182. EventAgent.RemoveEventListener(ConstMessage.MAIL_DELETE, UpdateNormal);
  183. EventAgent.RemoveEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal);
  184. EventAgent.RemoveEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  185. }
  186. }
  187. }