MailView.cs 8.2 KB

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