|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using UI.Mail;
|
|
|
using FairyGUI;
|
|
|
+using ET;
|
|
|
|
|
|
namespace GFGGame
|
|
|
{
|
|
@@ -12,7 +13,11 @@ namespace GFGGame
|
|
|
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 override void Dispose()
|
|
|
{
|
|
|
base.Dispose();
|
|
@@ -29,12 +34,19 @@ namespace GFGGame
|
|
|
viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
|
|
|
|
|
|
_ui.m_list.itemRenderer = RenderListItem;
|
|
|
+ _ui.m_list.scrollPane.onScrollEnd.Add(OnListScrollEnd);
|
|
|
+ _ui.m_list.scrollPane.onScroll.Add(OnListScroll);
|
|
|
_ui.m_list.SetVirtual();
|
|
|
|
|
|
_ui.m_btnGet.onClick.Add(OnClickBtnGet);
|
|
|
_ui.m_btnDelete.onClick.Add(OnClickBtnDelete);
|
|
|
+ EventAgent.AddEventListener(ConstMessage.MAIL_REFRESH, () =>
|
|
|
+ {
|
|
|
+ _ui.m_list.RefreshVirtualList();
|
|
|
+ });
|
|
|
+
|
|
|
+ EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
|
|
|
|
|
|
- MailDataManager.Instance.GMSetList(20);
|
|
|
mailDataMgr = MailDataManager.Instance;
|
|
|
}
|
|
|
|
|
@@ -42,58 +54,96 @@ namespace GFGGame
|
|
|
{
|
|
|
base.OnShown();
|
|
|
|
|
|
- EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
|
|
|
-
|
|
|
+ _firstChildIndex = 0;
|
|
|
UpdateNormal();
|
|
|
-
|
|
|
}
|
|
|
private void UpdateNormal()
|
|
|
{
|
|
|
- int count = mailDataMgr.mailListData.Count;
|
|
|
- _ui.m_list.numItems = count;
|
|
|
- _ui.m_txtTips.visible = count == 0 ? true : false;
|
|
|
- _ui.m_txtCount.text = string.Format("当前邮件:{0}/{1}", StringUtil.GetColorText(count.ToString(), count >= _maxMailCount ? "#B19977" : "#E27D78"), _maxMailCount);
|
|
|
+ _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)
|
|
|
{
|
|
|
+ int childIndex = _ui.m_list.ItemIndexToChildIndex(index);
|
|
|
UI_ListItem item = UI_ListItem.Proxy(obj);
|
|
|
- MailData data = mailDataMgr.mailListData[index];
|
|
|
+ if (mailDataMgr.mailInfos.Count == 0) return;
|
|
|
+ MailInfo data = mailDataMgr.mailInfos[childIndex];
|
|
|
item.m_c1.selectedIndex = mailDataMgr.GetMailState(data);
|
|
|
- item.m_txtDiscribe.text = string.Format("{0}...", data.content.Length > 10 ? data.content.Substring(0, 10) : data.content);
|
|
|
- item.m_txtTime.text = string.Format("剩余时间:{0}天", data.remainingTime);
|
|
|
- item.m_btnLook.onClick.Clear();
|
|
|
- item.m_btnLook.onClick.Add(OnClickBtnLook);
|
|
|
- item.m_btnLook.data = index;
|
|
|
+ item.m_txtTitle.text = data.title;// string.Format("{0}...", data.content.Length > 10 ? data.content.Substring(0, 10) : data.content);
|
|
|
+ string str = TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, ((int)data.timeSec + _retainDay * TimeUtil.SECOND_PER_DAY));
|
|
|
+ item.m_txtTime.text = string.Format("剩余时间:{0}", str);
|
|
|
+ if (item.target.data == null)
|
|
|
+ {
|
|
|
+ item.m_btnLook.onClick.Add(OnClickBtnLook);
|
|
|
+ }
|
|
|
+ item.target.data = index;
|
|
|
+
|
|
|
+ }
|
|
|
+ private async void OnClickBtnLook(EventContext context)
|
|
|
+ {
|
|
|
+ if (!_canShowContent) return;
|
|
|
+ int index = (int)(context.data as GObject).data;
|
|
|
+ int childIndex = (int)_ui.m_list.ItemIndexToChildIndex(index);
|
|
|
+ bool result = await MailSProxy.ReqMailContent(mailDataMgr.mailInfos[childIndex].mailId);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ ViewManager.Show<MailContentView>(childIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ private void OnListScroll()
|
|
|
+ {
|
|
|
+ _canShowContent = false;
|
|
|
}
|
|
|
- private void OnClickBtnLook(EventContext context)
|
|
|
+ private void OnListScrollEnd()
|
|
|
{
|
|
|
- GButton btn = context.sender as GButton;
|
|
|
- int data = (int)btn.data;
|
|
|
- ViewManager.Show<MailContentView>(data);
|
|
|
+ _firstChildIndex = (int)_ui.m_list.GetChildAt(0).data;
|
|
|
+ RefreshMailInfo(_firstChildIndex, false);
|
|
|
}
|
|
|
- private void OnClickBtnGet()
|
|
|
+
|
|
|
+ private async void RefreshMailInfo(int index, bool needSort)
|
|
|
{
|
|
|
- mailDataMgr.GetAllRewards();
|
|
|
- _ui.m_list.scrollPane.ScrollTop();
|
|
|
+ bool result = await MailSProxy.ReqMailList(index, _showCount, needSort);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ _ui.m_list.RefreshVirtualList();
|
|
|
+ _canShowContent = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void OnClickBtnGet()
|
|
|
+ {
|
|
|
+ bool result = await MailSProxy.ReqAllMailRewards();
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ RefreshMailInfo(_firstChildIndex, false);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void OnClickBtnDelete()
|
|
|
{
|
|
|
Alert.Show("是否删除所有已读文件?").SetLeftButton(true).SetRightButton(true, "确认", (object data) =>
|
|
|
{
|
|
|
- mailDataMgr.DeleteAllMail();
|
|
|
- _ui.m_list.scrollPane.ScrollTop();
|
|
|
+ SendDeleteAll();
|
|
|
});
|
|
|
-
|
|
|
+ }
|
|
|
+ private async void SendDeleteAll()
|
|
|
+ {
|
|
|
+ bool result = await MailSProxy.ReqDeleteAllMails();
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ _ui.m_list.ScrollToView(0);
|
|
|
+ RefreshMailInfo(0, true);
|
|
|
+ }
|
|
|
}
|
|
|
protected override void OnHide()
|
|
|
{
|
|
|
base.OnHide();
|
|
|
- EventAgent.RemoveEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|