Browse Source

邮件单次请求数量

zhaoyang 3 years ago
parent
commit
bae95a0a7f

+ 1 - 1
FGUIProject/assets/Mail/components/ListItem.xml

@@ -6,7 +6,7 @@
     <loader id="n4_ehs9" name="loaIcon" xy="35,32" size="84,84" url="ui://y44a413eehs95" autoSize="true">
       <gearIcon controller="c1" pages="1,2,3" values="ui://y44a413eehs96|ui://y44a413eehs97|ui://y44a413eehs90" default="ui://y44a413eehs95"/>
     </loader>
-    <text id="n5_ehs9" name="txtTitle" xy="184,18" size="423,52" fontSize="38" color="#9b7853" autoSize="none" autoClearText="true" text="周日奖励周日奖励周报...."/>
+    <text id="n5_ehs9" name="txtTitle" xy="184,18" size="423,52" fontSize="38" color="#9b7853" autoSize="none" autoClearText="true" text="请稍后..."/>
     <text id="n6_ehs9" name="txtTime" xy="184,95" size="189,39" fontSize="28" color="#c19f7b" autoClearText="true" text="剩余时间:5天"/>
     <component id="n8_ehs9" name="btnLook" src="ehs9e" fileName="components/Button1.xml" xy="669,41"/>
   </displayList>

+ 33 - 10
GameClient/Assets/Game/HotUpdate/Data/MailDataManager.cs

@@ -17,12 +17,17 @@ namespace GFGGame
     }
     public class MailDataManager : SingletonBase<MailDataManager>
     {
+        public int PageCount = 30;//每次请求数量
+        public int CurPage = 0;//每次请求数量
 
         private int _totolCount = 0;
         public int TotolCount//邮件总数
         {
             get { return _totolCount; }
-            set { _totolCount = value; }
+            set
+            {
+                _totolCount = value;
+            }
         }
 
         private int _unreadCount = 0;
@@ -32,8 +37,6 @@ namespace GFGGame
             set { _unreadCount = value; }
         }
 
-        public const int Count = 20;//每次请求个数
-
         private int _startIndex = 0;
         public int StartIndex//起始索引,从0开始
         {
@@ -49,12 +52,14 @@ namespace GFGGame
             }
         }
 
+        private Dictionary<int, List<long>> _mailIdsDic = new Dictionary<int, List<long>>();
         public List<MailInfo> mailInfos = new List<MailInfo>();
         public void RefreshMailInfoDic(bool sort)
         {
             if (sort)
             {
                 _mailInfoDic.Clear();
+                _mailIdsDic.Clear();
             }
         }
 
@@ -69,6 +74,16 @@ namespace GFGGame
                 _mailInfoDic[mailId] = mailInfo;
             }
         }
+        public void UpdateMailIdList(int page, long mailId)
+        {
+
+            if (!_mailIdsDic.ContainsKey(page))
+            {
+                _mailIdsDic.Add(page, new List<long>());
+            }
+            _mailIdsDic[page].Add(mailId);
+        }
+
         public void UpdateMailContent(long mailId, int state, string content = "", List<ItemData> rewards = null)
         {
             _mailInfoDic[mailId].state = state;
@@ -77,16 +92,24 @@ namespace GFGGame
         }
 
 
-        public List<MailInfo> GetMailInfos(int index, int count)
+        public long GetMailIdByIndex(int index)
         {
-            List<MailInfo> mailInfos = new List<MailInfo>();
-            for (int i = 0; i < count; i++)
+            int page = index / PageCount;
+            int pageIndex = index % PageCount;
+            if (_mailIdsDic.ContainsKey(page) && _mailIdsDic[page].Count > pageIndex)
             {
-                if (index + i + 1 > _mailInfoDic.Count) break;
-                MailInfo mailInfo = _mailInfoDic.ElementAt(index + i).Value;
-                mailInfos.Add(mailInfo);
+                return _mailIdsDic[page][pageIndex];
             }
-            return mailInfos;
+            return -1;
+        }
+        public List<long> GetMailIdByPage(int page)
+        {
+
+            if (_mailIdsDic.ContainsKey(page))
+            {
+                return _mailIdsDic[page];
+            }
+            return null;
         }
 
 

+ 2 - 2
GameClient/Assets/Game/HotUpdate/ServerProxy/MailSProxy.cs

@@ -38,7 +38,7 @@ namespace GFGGame
             return false;
         }
 
-        public static async ETTask<bool> ReqMailList(int index, int count, bool sort)
+        public static async ETTask<bool> ReqMailList(int index, int count, bool sort, int page)
         {
             Mail2C_GetMailList response = null;
             response = (Mail2C_GetMailList)await MessageHelper.SendToServer(new C2Mail_GetMailList() { StartIndex = index, Count = count, NeedSort = sort });
@@ -46,7 +46,6 @@ namespace GFGGame
             {
                 if (response.Error == ErrorCode.ERR_Success)
                 {
-                    MailDataManager.Instance.RefreshMailInfoDic(sort);
                     List<MailInfo> mailInfos = new List<MailInfo>();
                     for (int i = 0; i < response.mailList.Count; i++)
                     {
@@ -58,6 +57,7 @@ namespace GFGGame
                         mailInfo.hasItem = response.mailList[i].HasItem;
                         // mailInfos.Add(mailInfo);
                         MailDataManager.Instance.UpdateMainInfoDic(mailInfo.mailId, mailInfo);
+                        MailDataManager.Instance.UpdateMailIdList(page, mailInfo.mailId);
                     }
                     // MailDataManager.Instance.UpdateMailInfoList(mailInfos);
 

+ 63 - 16
GameClient/Assets/Game/HotUpdate/Views/Mail/MailView.cs

@@ -14,10 +14,13 @@ namespace GFGGame
         private MailDataManager mailDataMgr;
         private const int _maxMailCount = 300;
         private const int _retainDay = 30;//邮件保存时间
-        private const int _showCount = 5;//列表展示数量
+                                          // private const int _showCount = 5;//?б???????
+
+        private int _firstPage = 0;//当前页面
+        private int _endPage = 0;//当前页面
 
         public bool _canShowContent = false;//获取内容数据返回前不可查看
-        public List<MailInfo> mailInfos = new List<MailInfo>();
+        public List<MailInfo> mailInfos;//= new List<MailInfo>();
 
         public override void Dispose()
         {
@@ -36,6 +39,14 @@ namespace GFGGame
 
             _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);
@@ -54,7 +65,7 @@ namespace GFGGame
         protected override void OnShown()
         {
             base.OnShown();
-
+            mailDataMgr.CurPage = 0;
             UpdateNormal();
         }
         private void UpdateNormal()
@@ -63,14 +74,27 @@ namespace GFGGame
             _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);
+            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);
-            if (index + 1 > mailInfos.Count) return;
-            MailInfo data = mailInfos[index];
+
+            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;
@@ -80,38 +104,61 @@ namespace GFGGame
             {
                 item.m_btnLook.onClick.Add(OnClickBtnLook);
             }
-            item.m_btnLook.data = index;
+            item.m_btnLook.data = mailId;
 
+            UI_ListItem.ProxyEnd();
         }
         private async void OnClickBtnLook(EventContext context)
         {
-            int index = (int)(context.sender as GObject).data;
-
-            bool result = await MailSProxy.ReqMailContent(mailInfos[index].mailId);
+            // 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<MailContentView>(mailInfos[index].mailId);
+                ViewManager.Show<MailContentView>(mailId);
             }
         }
 
 
-        private async void RefreshMailInfo(int index, bool needSort)
+        private async void RefreshMailInfo(bool needSort)
         {
             if (mailDataMgr.TotolCount == 0) return;
             if (needSort)
             {
                 _ui.m_list.ScrollToView(0);
+                MailDataManager.Instance.RefreshMailInfoDic(needSort);
             }
-            bool result = await MailSProxy.ReqMailList(index, mailDataMgr.TotolCount, needSort);
-            if (result)
+            _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)
             {
-                mailInfos = mailDataMgr.GetMailInfos(index, mailDataMgr.TotolCount);
                 RefreshList();
-                _canShowContent = true;
+                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();
 
         }