MailDataManager.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class MailInfo
  9. {
  10. public long mailId;//邮件id
  11. public string title;//邮件标题
  12. public long timeSec;//邮件时间戳,单位毫秒
  13. public string content = "";//邮件内容
  14. public List<ItemData> rewards;
  15. public int state;//邮件状态 0未读, 1已读未领取,2已读已领取
  16. public bool hasItem;//是否有奖励
  17. }
  18. public class MailDataManager : SingletonBase<MailDataManager>
  19. {
  20. public int PageCount = 30;//每次请求数量
  21. public int CurPage = 0;//每次请求数量
  22. private int _totolCount = 0;
  23. public int TotolCount//邮件总数
  24. {
  25. get { return _totolCount; }
  26. set
  27. {
  28. _totolCount = value;
  29. }
  30. }
  31. private int _unreadCount = 0;
  32. public int UnreadCount////未读邮件数量
  33. {
  34. get { return _unreadCount; }
  35. set
  36. {
  37. if (_unreadCount != value)
  38. {
  39. _unreadCount = value;
  40. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  41. }
  42. }
  43. }
  44. private int _startIndex = 0;
  45. public int StartIndex//起始索引,从0开始
  46. {
  47. get { return _startIndex; }
  48. set { _startIndex = value; }
  49. }
  50. public Dictionary<long, MailInfo> _mailInfoDic = new Dictionary<long, MailInfo>();
  51. public Dictionary<long, MailInfo> MailInfoDic
  52. {
  53. get
  54. {
  55. return _mailInfoDic;
  56. }
  57. }
  58. private Dictionary<int, List<long>> _mailIdsDic = new Dictionary<int, List<long>>();
  59. public List<MailInfo> mailInfos = new List<MailInfo>();
  60. public void RefreshMailInfoDic(bool sort)
  61. {
  62. if (sort)
  63. {
  64. _mailInfoDic.Clear();
  65. _mailIdsDic.Clear();
  66. }
  67. }
  68. public void UpdateMainInfoDic(long mailId, MailInfo mailInfo)
  69. {
  70. if (!_mailInfoDic.ContainsKey(mailId))
  71. {
  72. _mailInfoDic.Add(mailId, mailInfo);
  73. }
  74. else
  75. {
  76. _mailInfoDic[mailId] = mailInfo;
  77. }
  78. }
  79. public void UpdateMailIdList(int page, long mailId)
  80. {
  81. if (!_mailIdsDic.ContainsKey(page))
  82. {
  83. _mailIdsDic.Add(page, new List<long>());
  84. }
  85. _mailIdsDic[page].Add(mailId);
  86. }
  87. public void UpdateMailContent(long mailId, int state, string content = "", List<ItemData> rewards = null)
  88. {
  89. _mailInfoDic[mailId].state = state;
  90. if (content != "") _mailInfoDic[mailId].content = content;
  91. if (rewards != null) _mailInfoDic[mailId].rewards = rewards;
  92. UnreadCount = UnreadCount - 1;
  93. }
  94. public long GetMailIdByIndex(int index)
  95. {
  96. int page = index / PageCount;
  97. int pageIndex = index % PageCount;
  98. if (_mailIdsDic.ContainsKey(page) && _mailIdsDic[page].Count > pageIndex)
  99. {
  100. return _mailIdsDic[page][pageIndex];
  101. }
  102. return -1;
  103. }
  104. public List<long> GetMailIdByPage(int page)
  105. {
  106. if (_mailIdsDic.ContainsKey(page))
  107. {
  108. return _mailIdsDic[page];
  109. }
  110. return null;
  111. }
  112. /// <summary>
  113. /// 根据邮件Id获取邮件信息
  114. /// </summary>
  115. /// <param name="mailId"></param>
  116. /// <returns></returns>
  117. public MailInfo GetMailInfoById(long mailId)
  118. {
  119. if (_mailInfoDic.ContainsKey(mailId))
  120. {
  121. return _mailInfoDic[mailId];
  122. }
  123. return null;
  124. }
  125. //0未读,1无奖已读,2有奖未领,3有奖已领
  126. public int GetMailState(MailInfo data)
  127. {
  128. if (data.hasItem == false)
  129. {
  130. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 0;
  131. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 1;
  132. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 1;
  133. }
  134. else
  135. {
  136. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 2;
  137. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 2;
  138. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 3;
  139. }
  140. return 0;
  141. }
  142. }
  143. }