MailView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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(() => { RefreshMailInfo(false); });
  47. // _ui.target.onTouchEnd.Add(() =>
  48. // {
  49. // RefreshMailInfo(false);
  50. // });
  51. _ui.m_btnGet.onClick.Add(OnClickBtnGet);
  52. _ui.m_btnDelete.onClick.Add(OnClickBtnDelete);
  53. mailDataMgr = MailDataManager.Instance;
  54. AddEffect();
  55. }
  56. protected override void AddEventListener()
  57. {
  58. base.AddEventListener();
  59. EventAgent.AddEventListener(ConstMessage.MAIL_REFRESH, RefreshList);
  60. EventAgent.AddEventListener(ConstMessage.MAIL_REWARD, RefreshList);
  61. EventAgent.AddEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal);
  62. EventAgent.AddEventListener(ConstMessage.MAIL_DELETE, UpdateNormal);
  63. EventAgent.AddEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal);
  64. EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  65. }
  66. protected override void OnShown()
  67. {
  68. base.OnShown();
  69. mailDataMgr.CurPage = 0;
  70. UpdateNormal();
  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}",
  77. StringUtil.GetColorText(mailDataMgr.TotolCount.ToString(),
  78. mailDataMgr.TotolCount >= _maxMailCount ? "#B19977" : "#E27D78"), _maxMailCount);
  79. _ui.m_txtMaxCount.text = string.Format("最高可储存{0}封邮箱,请及时查看", _maxMailCount);
  80. RefreshMailInfo(true);
  81. }
  82. private void RenderListItem(int index, GObject obj)
  83. {
  84. // _endPage = index / mailDataMgr.PageCount;
  85. // ET.Log.Debug("_endPage:" + _endPage + " index:" + index + " PageCount:" + mailDataMgr.PageCount);
  86. UI_ListItem item = UI_ListItem.Proxy(obj);
  87. long mailId = mailDataMgr.GetMailIdByIndex(index);
  88. // item.m_btnLook.data = mailId;
  89. if (mailId < 0)
  90. {
  91. item.m_txtTitle.text = "请稍后...";
  92. item.m_txtTime.text = "";
  93. return;
  94. }
  95. // long mailId = mailDataMgr.MailIds[index];
  96. MailInfo data = mailDataMgr.GetMailInfoById(mailId);
  97. item.m_c1.selectedIndex = mailDataMgr.GetMailState(data);
  98. item.m_txtTitle.text = data.title;
  99. long endTime = (data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY * 1000);
  100. string str = TimeUtil.FormattingTimeDetail(TimeHelper.ServerNow(), endTime);
  101. item.m_txtTime.text = string.Format("剩余时间:{0}", str);
  102. if (item.m_bg.data == null)
  103. {
  104. item.m_bg.onClick.Add(OnClickBtnLook);
  105. }
  106. item.m_bg.data = mailId;
  107. UI_ListItem.ProxyEnd();
  108. }
  109. private async void OnClickBtnLook(EventContext context)
  110. {
  111. // int index = (int)(context.sender as GObject).data;
  112. long mailId = (long)(context.sender as GObject).data;
  113. bool result = await MailSProxy.ReqMailContent(mailId);
  114. if (result)
  115. {
  116. ViewManager.Show<MailContentView>(mailId);
  117. }
  118. }
  119. private async void RefreshMailInfo(bool needSort)
  120. {
  121. if (mailDataMgr.TotolCount == 0) return;
  122. if (needSort)
  123. {
  124. _ui.m_list.ScrollToView(0);
  125. MailDataManager.Instance.RefreshMailInfoDic(needSort);
  126. }
  127. _firstPage = _ui.m_list.ChildIndexToItemIndex(0) / mailDataMgr.PageCount;
  128. _endPage = _ui.m_list.ChildIndexToItemIndex(_ui.m_list.numChildren - 1) / mailDataMgr.PageCount;
  129. ET.Log.Debug("_firstPage:" + _firstPage + " _endPage:" + _endPage);
  130. if (mailDataMgr.GetMailIdByPage(_firstPage) != null && mailDataMgr.GetMailIdByPage(_endPage) != null)
  131. {
  132. RefreshList();
  133. return;
  134. }
  135. if (mailDataMgr.GetMailIdByPage(_firstPage) == null)
  136. {
  137. bool result = await MailSProxy.ReqMailList(_firstPage * mailDataMgr.PageCount, mailDataMgr.PageCount,
  138. 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,
  148. 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)
  172. .SetRightButton(true, "确认", (object data) => { SendDeleteAll(); });
  173. }
  174. private void SendDeleteAll()
  175. {
  176. MailSProxy.ReqDeleteAllMails().Coroutine();
  177. }
  178. protected override void OnHide()
  179. {
  180. base.OnHide();
  181. }
  182. protected override void RemoveEventListener()
  183. {
  184. base.RemoveEventListener();
  185. EventAgent.RemoveEventListener(ConstMessage.MAIL_REFRESH, RefreshList);
  186. EventAgent.RemoveEventListener(ConstMessage.MAIL_REWARD, RefreshList);
  187. EventAgent.RemoveEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal);
  188. EventAgent.RemoveEventListener(ConstMessage.MAIL_DELETE, UpdateNormal);
  189. EventAgent.RemoveEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal);
  190. EventAgent.RemoveEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  191. }
  192. private void AddEffect()
  193. {
  194. //邊框左上角特效
  195. EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up",
  196. onComplete: (effect) =>
  197. {
  198. if (effect != null)
  199. {
  200. _effectUI1 = effect;
  201. }
  202. });
  203. //邊框右下角特效
  204. EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down",
  205. onComplete: (effect) =>
  206. {
  207. if (effect != null)
  208. {
  209. _effectUI2 = effect;
  210. }
  211. });
  212. }
  213. }
  214. }