MailView.cs 6.7 KB

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