MailView.cs 7.4 KB

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