MailView.cs 8.2 KB

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