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 _firstPage = 0;//当前页面 private int _endPage = 0;//当前页面 public bool _canShowContent = false;//获取内容数据返回前不可查看 public List mailInfos;//= new List(); private EffectUI _effectUI1; private EffectUI _effectUI2; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; if (_ui != null) { _ui.Dispose(); _ui = null; } 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_list.scrollPane.onScrollEnd.Add(() => { RefreshMailInfo(false); }); // _ui.target.onTouchEnd.Add(() => // { // RefreshMailInfo(false); // }); _ui.m_btnGet.onClick.Add(OnClickBtnGet); _ui.m_btnDelete.onClick.Add(OnClickBtnDelete); mailDataMgr = MailDataManager.Instance; AddEffect(); } protected override void AddEventListener() { base.AddEventListener(); 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); } protected override void OnShown() { base.OnShown(); mailDataMgr.CurPage = 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(true); } private void RenderListItem(int index, GObject obj) { // _endPage = index / mailDataMgr.PageCount; // ET.Log.Debug("_endPage:" + _endPage + " index:" + index + " PageCount:" + mailDataMgr.PageCount); UI_ListItem item = UI_ListItem.Proxy(obj); long mailId = mailDataMgr.GetMailIdByIndex(index); // item.m_btnLook.data = mailId; if (mailId < 0) { item.m_txtTitle.text = "请稍后..."; item.m_txtTime.text = ""; return; } // long mailId = mailDataMgr.MailIds[index]; MailInfo data = mailDataMgr.GetMailInfoById(mailId); item.m_c1.selectedIndex = mailDataMgr.GetMailState(data); item.m_txtTitle.text = data.title; long endTime = (data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY * 1000); string str = TimeUtil.FormattingTimeDetail(TimeHelper.ServerNow(), endTime); item.m_txtTime.text = string.Format("剩余时间:{0}", str); if (item.m_bg.data == null) { item.m_bg.onClick.Add(OnClickBtnLook); } item.m_bg.data = mailId; UI_ListItem.ProxyEnd(); } private async void OnClickBtnLook(EventContext context) { // int index = (int)(context.sender as GObject).data; long mailId = (long)(context.sender as GObject).data; bool result = await MailSProxy.ReqMailContent(mailId); if (result) { ViewManager.Show(mailId); } } private async void RefreshMailInfo(bool needSort) { if (mailDataMgr.TotolCount == 0) return; if (needSort) { _ui.m_list.ScrollToView(0); MailDataManager.Instance.RefreshMailInfoDic(needSort); } _firstPage = _ui.m_list.ChildIndexToItemIndex(0) / mailDataMgr.PageCount; _endPage = _ui.m_list.ChildIndexToItemIndex(_ui.m_list.numChildren - 1) / mailDataMgr.PageCount; ET.Log.Debug("_firstPage:" + _firstPage + " _endPage:" + _endPage); if (mailDataMgr.GetMailIdByPage(_firstPage) != null && mailDataMgr.GetMailIdByPage(_endPage) != null) { RefreshList(); return; } if (mailDataMgr.GetMailIdByPage(_firstPage) == null) { bool result = await MailSProxy.ReqMailList(_firstPage * mailDataMgr.PageCount, mailDataMgr.PageCount, needSort, _firstPage); if (result) { RefreshList(); } } if (_endPage == _firstPage) return; if (mailDataMgr.GetMailIdByPage(_endPage) == null) { bool result = await MailSProxy.ReqMailList(_endPage * mailDataMgr.PageCount, mailDataMgr.PageCount, needSort, _endPage); if (result) { RefreshList(); } } } private void RefreshList() { // mailInfos = mailDataMgr.GetMailInfos(); _ui.m_list.RefreshVirtualList(); } private void OnClickBtnGet() { MailSProxy.ReqAllMailRewards().Coroutine(); } private void OnClickBtnDelete() { if (mailDataMgr.TotolCount == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无邮件可删除"); return; } AlertUI.Show("是否删除所有已读文件?").SetLeftButton(true).SetRightButton(true, "确认", (object data) => { SendDeleteAll(); }); } private void SendDeleteAll() { MailSProxy.ReqDeleteAllMails().Coroutine(); } protected override void OnHide() { base.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.MAIL_REFRESH, RefreshList); EventAgent.RemoveEventListener(ConstMessage.MAIL_REWARD, RefreshList); EventAgent.RemoveEventListener(ConstMessage.MAIL_ALLREWARD, UpdateNormal); EventAgent.RemoveEventListener(ConstMessage.MAIL_DELETE, UpdateNormal); EventAgent.RemoveEventListener(ConstMessage.MAIL_AllDELETE, UpdateNormal); EventAgent.RemoveEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal); } private void AddEffect() { //邊框左上角特效 _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up"); //邊框右下角特效 _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down"); } } }