MailView.cs 8.5 KB

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