MailView.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. public bool _canShowContent = false;//获取内容数据返回前不可查看
  17. public List<MailInfo> mailInfos = new List<MailInfo>();
  18. public override void Dispose()
  19. {
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_MailUI.PACKAGE_NAME;
  26. _ui = UI_MailUI.Create();
  27. this.viewCom = _ui.target;
  28. this.viewCom.Center();
  29. this.modal = true;
  30. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  31. _ui.m_list.itemRenderer = RenderListItem;
  32. _ui.m_list.SetVirtual();
  33. _ui.m_btnGet.onClick.Add(OnClickBtnGet);
  34. _ui.m_btnDelete.onClick.Add(OnClickBtnDelete);
  35. EventAgent.AddEventListener(ConstMessage.MAIL_REFRESH, RefreshList);
  36. EventAgent.AddEventListener(ConstMessage.MAIL_REWARD, RefreshList);
  37. EventAgent.AddEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal);
  38. EventAgent.AddEventListener(ConstMessage.MAIL_DELETE, UpdateNormal);
  39. EventAgent.AddEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal);
  40. EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  41. mailDataMgr = MailDataManager.Instance;
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. UpdateNormal();
  47. }
  48. private void UpdateNormal()
  49. {
  50. _ui.m_list.numItems = mailDataMgr.TotolCount;
  51. _ui.m_txtTips.visible = mailDataMgr.TotolCount == 0 ? true : false;
  52. _ui.m_txtCount.text = string.Format("当前邮件:{0}/{1}", StringUtil.GetColorText(mailDataMgr.TotolCount.ToString(), mailDataMgr.TotolCount >= _maxMailCount ? "#B19977" : "#E27D78"), _maxMailCount);
  53. _ui.m_txtMaxCount.text = string.Format("最高可储存{0}封邮箱,请及时查看", _maxMailCount);
  54. RefreshMailInfo(0, true);
  55. }
  56. private void RenderListItem(int index, GObject obj)
  57. {
  58. UI_ListItem item = UI_ListItem.Proxy(obj);
  59. if (index + 1 > mailInfos.Count) return;
  60. MailInfo data = mailInfos[index];
  61. item.m_c1.selectedIndex = mailDataMgr.GetMailState(data);
  62. item.m_txtTitle.text = data.title;
  63. string str = TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, ((int)data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY));
  64. item.m_txtTime.text = string.Format("剩余时间:{0}", str);
  65. if (item.m_btnLook.data == null)
  66. {
  67. item.m_btnLook.onClick.Add(OnClickBtnLook);
  68. }
  69. item.m_btnLook.data = index;
  70. }
  71. private async void OnClickBtnLook(EventContext context)
  72. {
  73. int index = (int)(context.sender as GObject).data;
  74. bool result = await MailSProxy.ReqMailContent(mailInfos[index].mailId);
  75. if (result)
  76. {
  77. ViewManager.Show<MailContentView>(mailInfos[index].mailId);
  78. }
  79. }
  80. private async void RefreshMailInfo(int index, bool needSort)
  81. {
  82. if (mailDataMgr.TotolCount == 0) return;
  83. if (needSort)
  84. {
  85. _ui.m_list.ScrollToView(0);
  86. }
  87. bool result = await MailSProxy.ReqMailList(index, mailDataMgr.TotolCount, needSort);
  88. if (result)
  89. {
  90. mailInfos = mailDataMgr.GetMailInfos(index, mailDataMgr.TotolCount);
  91. RefreshList();
  92. _canShowContent = true;
  93. }
  94. }
  95. private void RefreshList()
  96. {
  97. _ui.m_list.RefreshVirtualList();
  98. }
  99. private void OnClickBtnGet()
  100. {
  101. MailSProxy.ReqAllMailRewards().Coroutine();
  102. }
  103. private void OnClickBtnDelete()
  104. {
  105. Alert.Show("是否删除所有已读文件?").SetLeftButton(true).SetRightButton(true, "确认", (object data) =>
  106. {
  107. SendDeleteAll();
  108. });
  109. }
  110. private void SendDeleteAll()
  111. {
  112. MailSProxy.ReqDeleteAllMails().Coroutine();
  113. }
  114. protected override void OnHide()
  115. {
  116. base.OnHide();
  117. }
  118. }
  119. }