MailView.cs 8.2 KB

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