using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace GFGGame { public class MailInfo { public long mailId;//邮件id public string title;//邮件标题 public long timeSec;//邮件时间戳,单位秒 public string content = "";//邮件内容 public List rewards; public int state;//邮件状态 0未读, 1已读未领取,2已读已领取 public bool hasItem;//是否有奖励 } public class MailDataManager : SingletonBase { public int PageCount = 30;//每次请求数量 public int CurPage = 0;//每次请求数量 private int _totolCount = 0; public int TotolCount//邮件总数 { get { return _totolCount; } set { _totolCount = value; } } private int _unreadCount = 0; public int UnreadCount////未读邮件数量 { get { return _unreadCount; } set { if (_unreadCount != value) { _unreadCount = value; EventAgent.DispatchEvent(ConstMessage.RED_CHANGE); } } } private int _startIndex = 0; public int StartIndex//起始索引,从0开始 { get { return _startIndex; } set { _startIndex = value; } } public Dictionary _mailInfoDic = new Dictionary(); public Dictionary MailInfoDic { get { return _mailInfoDic; } } private Dictionary> _mailIdsDic = new Dictionary>(); public List mailInfos = new List(); public void RefreshMailInfoDic(bool sort) { if (sort) { _mailInfoDic.Clear(); _mailIdsDic.Clear(); } } public void UpdateMainInfoDic(long mailId, MailInfo mailInfo) { if (!_mailInfoDic.ContainsKey(mailId)) { _mailInfoDic.Add(mailId, mailInfo); } else { _mailInfoDic[mailId] = mailInfo; } } public void UpdateMailIdList(int page, long mailId) { if (!_mailIdsDic.ContainsKey(page)) { _mailIdsDic.Add(page, new List()); } _mailIdsDic[page].Add(mailId); } public void UpdateMailContent(long mailId, int state, string content = "", List rewards = null) { _mailInfoDic[mailId].state = state; if (content != "") _mailInfoDic[mailId].content = content; if (rewards != null) _mailInfoDic[mailId].rewards = rewards; UnreadCount = UnreadCount - 1; } public long GetMailIdByIndex(int index) { int page = index / PageCount; int pageIndex = index % PageCount; if (_mailIdsDic.ContainsKey(page) && _mailIdsDic[page].Count > pageIndex) { return _mailIdsDic[page][pageIndex]; } return -1; } public List GetMailIdByPage(int page) { if (_mailIdsDic.ContainsKey(page)) { return _mailIdsDic[page]; } return null; } /// /// 根据邮件Id获取邮件信息 /// /// /// public MailInfo GetMailInfoById(long mailId) { if (_mailInfoDic.ContainsKey(mailId)) { return _mailInfoDic[mailId]; } return null; } //0未读,1无奖已读,2有奖未领,3有奖已领 public int GetMailState(MailInfo data) { if (data.hasItem == false) { if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 0; if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 1; if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 1; } else { if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 2; if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 2; if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 3; } return 0; } } }