MailView.cs 4.7 KB

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