using System.Collections; using System.Collections.Generic; using UnityEngine; using UI.Mail; using FairyGUI; using ET; namespace GFGGame { public class MailView : BaseWindow { private UI_MailUI _ui; private MailDataManager mailDataMgr; private const int _maxMailCount = 300; private const int _retainDay = 30;//邮件保存时间 private const int _showCount = 5;//列表展示数量 private int _firstChildIndex = 0;//列表显示内容得一个项的显示对象索引 public bool _canShowContent = false;//获取内容数据返回前不可查看 public List mailInfos = new List(); public override void Dispose() { base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_MailUI.PACKAGE_NAME; _ui = UI_MailUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_list.itemRenderer = RenderListItem; _ui.m_list.SetVirtual(); _ui.m_btnGet.onClick.Add(OnClickBtnGet); _ui.m_btnDelete.onClick.Add(OnClickBtnDelete); EventAgent.AddEventListener(ConstMessage.MAIL_REFRESH, RefreshList); EventAgent.AddEventListener(ConstMessage.MAIL_REWARD, RefreshList); EventAgent.AddEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal); EventAgent.AddEventListener(ConstMessage.MAIL_DELETE, UpdateNormal); EventAgent.AddEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal); EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal); mailDataMgr = MailDataManager.Instance; } protected override void OnShown() { base.OnShown(); _firstChildIndex = 0; UpdateNormal(); } private void UpdateNormal() { _ui.m_list.numItems = mailDataMgr.TotolCount; _ui.m_txtTips.visible = mailDataMgr.TotolCount == 0 ? true : false; _ui.m_txtCount.text = string.Format("当前邮件:{0}/{1}", StringUtil.GetColorText(mailDataMgr.TotolCount.ToString(), mailDataMgr.TotolCount >= _maxMailCount ? "#B19977" : "#E27D78"), _maxMailCount); _ui.m_txtMaxCount.text = string.Format("最高可储存{0}封邮箱,请及时查看", _maxMailCount); RefreshMailInfo(0, true); } private void RenderListItem(int index, GObject obj) { UI_ListItem item = UI_ListItem.Proxy(obj); if (index + 1 > mailInfos.Count) return; MailInfo data = mailInfos[index]; item.m_c1.selectedIndex = mailDataMgr.GetMailState(data); item.m_txtTitle.text = data.title; string str = TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, ((int)data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY)); item.m_txtTime.text = string.Format("剩余时间:{0}", str); if (item.m_btnLook.data == null) { item.m_btnLook.onClick.Add(OnClickBtnLook); } item.m_btnLook.data = index; } private async void OnClickBtnLook(EventContext context) { int index = (int)(context.sender as GObject).data; bool result = await MailSProxy.ReqMailContent(mailInfos[index].mailId); if (result) { ViewManager.Show(mailInfos[index].mailId); } } private async void RefreshMailInfo(int index, bool needSort) { if (mailDataMgr.TotolCount == 0) return; if (needSort) { _ui.m_list.ScrollToView(0); } bool result = await MailSProxy.ReqMailList(index, mailDataMgr.TotolCount, needSort); if (result) { mailInfos = mailDataMgr.GetMailInfos(index, mailDataMgr.TotolCount); RefreshList(); _canShowContent = true; } } private void RefreshList() { _ui.m_list.RefreshVirtualList(); } private void OnClickBtnGet() { MailSProxy.ReqAllMailRewards().Coroutine(); } private void OnClickBtnDelete() { Alert.Show("是否删除所有已读文件?").SetLeftButton(true).SetRightButton(true, "确认", (object data) => { SendDeleteAll(); }); } private void SendDeleteAll() { MailSProxy.ReqDeleteAllMails().Coroutine(); } protected override void OnHide() { base.OnHide(); } } }