MailView.cs 7.3 KB

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