MailView.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. string str = TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, ((int)data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY));
  94. item.m_txtTime.text = string.Format("剩余时间:{0}", str);
  95. if (item.m_btnLook.data == null)
  96. {
  97. item.m_btnLook.onClick.Add(OnClickBtnLook);
  98. }
  99. item.m_btnLook.data = mailId;
  100. UI_ListItem.ProxyEnd();
  101. }
  102. private async void OnClickBtnLook(EventContext context)
  103. {
  104. // int index = (int)(context.sender as GObject).data;
  105. long mailId = (long)(context.sender as GObject).data;
  106. bool result = await MailSProxy.ReqMailContent(mailId);
  107. if (result)
  108. {
  109. ViewManager.Show<MailContentView>(mailId);
  110. }
  111. }
  112. private async void RefreshMailInfo(bool needSort)
  113. {
  114. if (mailDataMgr.TotolCount == 0) return;
  115. if (needSort)
  116. {
  117. _ui.m_list.ScrollToView(0);
  118. MailDataManager.Instance.RefreshMailInfoDic(needSort);
  119. }
  120. _firstPage = _ui.m_list.ChildIndexToItemIndex(0) / mailDataMgr.PageCount;
  121. _endPage = _ui.m_list.ChildIndexToItemIndex(_ui.m_list.numChildren - 1) / mailDataMgr.PageCount;
  122. ET.Log.Debug("_firstPage:" + _firstPage + " _endPage:" + _endPage);
  123. if (mailDataMgr.GetMailIdByPage(_firstPage) != null && mailDataMgr.GetMailIdByPage(_endPage) != null)
  124. {
  125. RefreshList();
  126. return;
  127. }
  128. if (mailDataMgr.GetMailIdByPage(_firstPage) == null)
  129. {
  130. bool result = await MailSProxy.ReqMailList(_firstPage * mailDataMgr.PageCount, mailDataMgr.PageCount, needSort, _firstPage);
  131. if (result)
  132. {
  133. RefreshList();
  134. }
  135. }
  136. if (_endPage == _firstPage) return;
  137. if (mailDataMgr.GetMailIdByPage(_endPage) == null)
  138. {
  139. bool result = await MailSProxy.ReqMailList(_endPage * mailDataMgr.PageCount, mailDataMgr.PageCount, needSort, _endPage);
  140. if (result)
  141. {
  142. RefreshList();
  143. }
  144. }
  145. }
  146. private void RefreshList()
  147. {
  148. // mailInfos = mailDataMgr.GetMailInfos();
  149. _ui.m_list.RefreshVirtualList();
  150. }
  151. private void OnClickBtnGet()
  152. {
  153. MailSProxy.ReqAllMailRewards().Coroutine();
  154. }
  155. private void OnClickBtnDelete()
  156. {
  157. if (mailDataMgr.TotolCount == 0)
  158. {
  159. PromptController.Instance.ShowFloatTextPrompt("暂无邮件可删除");
  160. return;
  161. }
  162. Alert.Show("是否删除所有已读文件?").SetLeftButton(true).SetRightButton(true, "确认", (object data) =>
  163. {
  164. SendDeleteAll();
  165. });
  166. }
  167. private void SendDeleteAll()
  168. {
  169. MailSProxy.ReqDeleteAllMails().Coroutine();
  170. }
  171. protected override void OnHide()
  172. {
  173. base.OnHide();
  174. }
  175. protected override void RemoveEventListener()
  176. {
  177. base.RemoveEventListener();
  178. EventAgent.RemoveEventListener(ConstMessage.MAIL_REFRESH, RefreshList);
  179. EventAgent.RemoveEventListener(ConstMessage.MAIL_REWARD, RefreshList);
  180. EventAgent.RemoveEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal);
  181. EventAgent.RemoveEventListener(ConstMessage.MAIL_DELETE, UpdateNormal);
  182. EventAgent.RemoveEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal);
  183. EventAgent.RemoveEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  184. }
  185. }
  186. }