Browse Source

邮件系统

zhengweijie 1 day ago
parent
commit
a68542483a

+ 2 - 2
Assets/Scripts/Business/Runtime/Data/Items/ItemService.cs

@@ -35,7 +35,7 @@ namespace FL.Data
         /// <param name="count"></param>
         /// <param name="count"></param>
         /// <param name="kind"></param>
         /// <param name="kind"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public IItemBase GetItemBase(int id, long count, int kind)
+        public IItemBase GetItemBase(int id, long count, int kind, bool isGet = false)
         {
         {
             if (kind == 1)
             if (kind == 1)
             {
             {
@@ -55,7 +55,7 @@ namespace FL.Data
                 else
                 else
                 {
                 {
                     var item = new ItemBase();
                     var item = new ItemBase();
-                    item.Init(id, count);
+                    item.Init(id, count, isGet);
                     return item;
                     return item;
                 }
                 }
             }
             }

+ 1 - 1
Assets/Scripts/Business/Runtime/Data/Mail/MailData.cs

@@ -12,7 +12,7 @@ namespace FL.Data
     public class MailData : DataSingleton<MailData>
     public class MailData : DataSingleton<MailData>
     {
     {
         
         
-        public List<MailInfo> mailInfo = null;
+        public Dictionary<string, MailInfo> mailInfo = new Dictionary<string, MailInfo>();
         
         
     }
     }
 }
 }

+ 1 - 0
Assets/Scripts/Business/Runtime/Define/StringDefine.cs

@@ -61,5 +61,6 @@ namespace FL
         public static string UnlockMountSpecialAttr = "{0}阶{1}星解锁";
         public static string UnlockMountSpecialAttr = "{0}阶{1}星解锁";
         public static string TotalTrainLevel = "驯养总等级:{0}";
         public static string TotalTrainLevel = "驯养总等级:{0}";
         public static string TrainSuccessRate = "驯养成功率:{0}";
         public static string TrainSuccessRate = "驯养成功率:{0}";
+        public static string MailCountLabel = "邮件数量:{0}/{1}";
     }
     }
 }
 }

+ 2 - 3
Assets/Scripts/Business/Runtime/Event/EventDefine.cs

@@ -275,9 +275,8 @@
         EpigraphChangeSelect,
         EpigraphChangeSelect,
         #endregion
         #endregion
         #region 邮件3900-3999
         #region 邮件3900-3999
-        OpenSingleMail = 3900,
-        UpMailList = 3901,
-        OpenMailUI = 3902,
+        UpMailList = 3900,
+        OpenMailUI,
         #endregion
         #endregion
 
 
         #region 坐骑Mount 4000-4099
         #region 坐骑Mount 4000-4099

+ 2 - 0
Assets/Scripts/Business/Runtime/FGUI/Common/ItemBase/CommonItemBaseCtrl.cs

@@ -77,6 +77,7 @@ namespace FL.FGUI
             _data = item;
             _data = item;
             VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality);
             VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality);
             VM.ItemIcon.icon = item.Icon;
             VM.ItemIcon.icon = item.Icon;
+            VM.IsGetImg.visible = false;
             if (item is ItemBase itemBase)
             if (item is ItemBase itemBase)
             {
             {
                 VM.LvLabel.visible = false;
                 VM.LvLabel.visible = false;
@@ -89,6 +90,7 @@ namespace FL.FGUI
                 {
                 {
                     VM.CountLabel.visible = false;
                     VM.CountLabel.visible = false;
                 }
                 }
+                VM.IsGetImg.visible = itemBase.IsGet == true;
             }
             }
             else if (item is EquipItemBase equipItemBase)
             else if (item is EquipItemBase equipItemBase)
             {
             {

+ 2 - 0
Assets/Scripts/Business/Runtime/FGUI/Common/ItemBase/CommonItemBaseVM.Gen.cs

@@ -22,6 +22,7 @@ namespace FL.FGUI
         public GLoader ItemIcon { get; private set; }
         public GLoader ItemIcon { get; private set; }
         public GTextField CountLabel { get; private set; }
         public GTextField CountLabel { get; private set; }
         public GTextField LvLabel { get; private set; }
         public GTextField LvLabel { get; private set; }
+        public GImage IsGetImg { get; private set; }
         public GButton ItemBtn { get; private set; }
         public GButton ItemBtn { get; private set; }
 
 
         protected override void BindComponents(GComponent panel, IUIViewAdapter adapter)
         protected override void BindComponents(GComponent panel, IUIViewAdapter adapter)
@@ -30,6 +31,7 @@ namespace FL.FGUI
             ItemIcon = panel.GetChild("ItemIcon") as GLoader;
             ItemIcon = panel.GetChild("ItemIcon") as GLoader;
             CountLabel = panel.GetChild("CountLabel") as GTextField;
             CountLabel = panel.GetChild("CountLabel") as GTextField;
             LvLabel = panel.GetChild("LvLabel") as GTextField;
             LvLabel = panel.GetChild("LvLabel") as GTextField;
+            IsGetImg = panel.GetChild("IsGetImg") as GImage;
             ItemBtn = panel.GetChild("ItemBtn") as GButton;
             ItemBtn = panel.GetChild("ItemBtn") as GButton;
 
 
         }
         }

+ 5 - 2
Assets/Scripts/Business/Runtime/FGUI/Common/ItemBase/ItemBase.cs

@@ -19,12 +19,15 @@ namespace FL.Data.Items
 
 
         public long Count { get; private set; }
         public long Count { get; private set; }
 
 
+        public bool IsGet { get; private set; }
 
 
-        public void Init(int id, long count)
+
+        public void Init(int id, long count, bool isGet = false)
         {
         {
             _table = ItemTableRepo.Get(id);
             _table = ItemTableRepo.Get(id);
             Count = count;
             Count = count;
-            if(_table == null)
+            IsGet = isGet;
+            if (_table == null)
             {
             {
                 Log.Error($"道具表不存在,id:{id}");
                 Log.Error($"道具表不存在,id:{id}");
             }
             }

+ 28 - 26
Assets/Scripts/Business/Runtime/FGUI/Mail/MailPanel/MailMailPanelCtrl.cs

@@ -8,11 +8,11 @@ using FairyGUI;
 using FL.Data;
 using FL.Data;
 using FL.Data.Items;
 using FL.Data.Items;
 using FL.Network;
 using FL.Network;
+using Opencoding.Shared.Utils;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using XGame.Database;
 using XGame.Database;
 using XGame.Framework.UI;
 using XGame.Framework.UI;
-using static UnityEditor.Progress;
 
 
 namespace FL.FGUI
 namespace FL.FGUI
 {
 {
@@ -23,8 +23,8 @@ namespace FL.FGUI
     public partial class MailMailPanelCtrl : UIController<MailMailPanelVM>
     public partial class MailMailPanelCtrl : UIController<MailMailPanelVM>
     {
     {
 
 
-        private List<MailInfo> _mailList;
-        private List<ItemBase> _mailRwdList;
+        private List<MailInfo> _mailList = new List<MailInfo>();
+        private List<IItemBase> _mailRwdList;
         private bool _isOpenMail;// 是否打开单封邮件
         private bool _isOpenMail;// 是否打开单封邮件
         private string _mailId;// 当前打开的邮件id
         private string _mailId;// 当前打开的邮件id
 
 
@@ -49,8 +49,8 @@ namespace FL.FGUI
             VM.ReadBtn.onClick.Add(OnClickReadBtn);
             VM.ReadBtn.onClick.Add(OnClickReadBtn);
             VM.GetBtn.onClick.Add(OnClickGetBtn);
             VM.GetBtn.onClick.Add(OnClickGetBtn);
             VM.DeleteBtn.onClick.Add(OnClickDeleteBtn);
             VM.DeleteBtn.onClick.Add(OnClickDeleteBtn);
-            Context.AddListener(EventDefine.OpenSingleMail, OpenSingleMail);
             Context.AddListener(EventDefine.UpMailList, UpMailList);
             Context.AddListener(EventDefine.UpMailList, UpMailList);
+            VM.MailList.ItemClickEvent += OnClcikMailListItem;
 
 
         }
         }
         private void RemoveUIListenres()
         private void RemoveUIListenres()
@@ -62,28 +62,28 @@ namespace FL.FGUI
             VM.ReadBtn.onClick.Remove(OnClickReadBtn);
             VM.ReadBtn.onClick.Remove(OnClickReadBtn);
             VM.GetBtn.onClick.Remove(OnClickGetBtn);
             VM.GetBtn.onClick.Remove(OnClickGetBtn);
             VM.DeleteBtn.onClick.Remove(OnClickDeleteBtn);
             VM.DeleteBtn.onClick.Remove(OnClickDeleteBtn);
-            Context.RemoveListener(EventDefine.OpenSingleMail, OpenSingleMail);
             Context.RemoveListener(EventDefine.UpMailList, UpMailList);
             Context.RemoveListener(EventDefine.UpMailList, UpMailList);
+            VM.MailList.ItemClickEvent -= OnClcikMailListItem;
 
 
         }
         }
 
 
         private void Init()
         private void Init()
         {
         {
             if (_mailList == null) _mailList = new List<MailInfo>();
             if (_mailList == null) _mailList = new List<MailInfo>();
-            if (_mailRwdList == null) _mailRwdList = new List<ItemBase>();
+            if (_mailRwdList == null) _mailRwdList = new List<IItemBase>();
         }
         }
 
 
         private void ShowUI()
         private void ShowUI()
         {
         {
             bool canGet = false;
             bool canGet = false;
             bool canRead = false;
             bool canRead = false;
-            List<MailInfo> dataList = new List<MailInfo>();
+            _mailList.Clear();
             MailInfo mailInfo = null;
             MailInfo mailInfo = null;
-            for (int i = 0; i < MailData.Instance.mailInfo.Count; i++)
+            foreach (var mail in MailData.Instance.mailInfo)
             {
             {
-                if (MailData.Instance.mailInfo[i].rts <= 0)
+                if (mail.Value.rts <= 0)
                 {
                 {
-                    if (MailData.Instance.mailInfo[i].items.Count > 0)
+                    if (mail.Value.items.Count > 0)
                     {
                     {
                         canGet = true;
                         canGet = true;
                     }
                     }
@@ -92,14 +92,14 @@ namespace FL.FGUI
                         canRead = true;
                         canRead = true;
                     }
                     }
                 }
                 }
-                if (_isOpenMail && _mailId == MailData.Instance.mailInfo[i].id)
+                if (_isOpenMail && _mailId == mail.Value.id)
                 {
                 {
-                    mailInfo = MailData.Instance.mailInfo[i];
+                    mailInfo = mail.Value;
                 }
                 }
                 long nowTime = Context.Time.GetNowTime() / 1000;
                 long nowTime = Context.Time.GetNowTime() / 1000;
-                if (MailData.Instance.mailInfo[i].ets >= nowTime)
+                if (mail.Value.ets >= nowTime)
                 {
                 {
-                    dataList.Add(MailData.Instance.mailInfo[i]);
+                    _mailList.Add(mail.Value);
                 }
                 }
             }
             }
             VM.AllReadBtn.visible = !_isOpenMail && canRead;// 一键已读
             VM.AllReadBtn.visible = !_isOpenMail && canRead;// 一键已读
@@ -119,33 +119,29 @@ namespace FL.FGUI
                 VM.GetBtn.visible = _isOpenMail && singleCanGet;// 领取
                 VM.GetBtn.visible = _isOpenMail && singleCanGet;// 领取
                 VM.DeleteBtn.visible = _isOpenMail && !singleCanGet && !singleCanRead;// 删除
                 VM.DeleteBtn.visible = _isOpenMail && !singleCanGet && !singleCanRead;// 删除
                 VM.TitleLabel.text = mailInfo.title;
                 VM.TitleLabel.text = mailInfo.title;
-                DateTimeOffset dateTime = DateTimeOffset.FromUnixTimeSeconds(mailInfo.ets);
-                string yearMonthDay = dateTime.ToString("yyyy-MM-dd hh:mm");
-                VM.TimeLabel.text = yearMonthDay;
+                VM.TimeLabel.text = mailInfo.ets.ToTimeYMDHM();
                 VM.ContentLabel.text = mailInfo.content;
                 VM.ContentLabel.text = mailInfo.content;
                 VM.ItemGrp.visible = hasItem;
                 VM.ItemGrp.visible = hasItem;
                 if (hasItem)
                 if (hasItem)
                 {
                 {
                     _mailRwdList.Clear();
                     _mailRwdList.Clear();
-                    for (global::System.Int32 i = 0; i < mailInfo.items.Count; i++)
+                    for (int i = 0; i < mailInfo.items.Count; i++)
                     {
                     {
-                        ItemTable itemInfo = ItemTableRepo.Get(mailInfo.items[i].id);
-                        ItemBase _item = new ItemBase();
-                        _item.Init(itemInfo.Id, mailInfo.items[i].count);
+                        IItemBase _item = ItemService.Instance.GetItemBase(mailInfo.items[i].id, mailInfo.items[i].count, mailInfo.items[i].kind, mailInfo.rts > 0);
                         _mailRwdList.Add(_item);
                         _mailRwdList.Add(_item);
                     }
                     }
                     ShowItemsUI(_mailRwdList);
                     ShowItemsUI(_mailRwdList);
                 }
                 }
             }
             }
 
 
-            SetMailList(dataList);
+            SetMailList(_mailList);
 
 
         }
         }
         // 打开单封邮件
         // 打开单封邮件
-        private void OpenSingleMail(int eventId, object args)
+        private void OpenSingleMail(string mailId)
         {
         {
             _isOpenMail = true;
             _isOpenMail = true;
-            _mailId = args.ToString();
+            _mailId = mailId;
             ShowUI();
             ShowUI();
         }
         }
         //刷新邮件列表
         //刷新邮件列表
@@ -163,13 +159,19 @@ namespace FL.FGUI
         // 邮件数量
         // 邮件数量
         private void UpMailCount(int num)
         private void UpMailCount(int num)
         {
         {
-            VM.MailCountLabel.text = $"邮件数量:{num}/{KeyValue.mailMax}";
+            VM.MailCountLabel.text = string.Format(StringDefine.MailCountLabel, num, KeyValue.mailMax);
         }
         }
         //单封邮件内的奖励
         //单封邮件内的奖励
-        private void ShowItemsUI(List<ItemBase> dataList)
+        private void ShowItemsUI(List<IItemBase> dataList)
         {
         {
             VM.ItemList.BindDatas(dataList);
             VM.ItemList.BindDatas(dataList);
         }
         }
+        //点击邮件列表
+        private void OnClcikMailListItem(int index)
+        {
+            string mailId = _mailList[index].id;
+            OpenSingleMail(mailId);
+        }
         //一键已读
         //一键已读
         private void OnClickAllReadBtn(EventContext context)
         private void OnClickAllReadBtn(EventContext context)
         {
         {

+ 7 - 19
Assets/Scripts/Business/Runtime/FGUI/Mail/MailPanelItem/MailMailPanelItemCtrl.cs

@@ -4,15 +4,13 @@
 /// 该脚本由模板创建
 /// 该脚本由模板创建
 /// created by cb 2024
 /// created by cb 2024
 
 
-using FairyGUI;
+using FL.Data;
 using FL.Data.Items;
 using FL.Data.Items;
 using FL.Network;
 using FL.Network;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using XGame.Database;
 using XGame.Database;
-using XGame.Framework.Time;
 using XGame.Framework.UI;
 using XGame.Framework.UI;
-using static UnityEditor.Progress;
 using Item = FL.Data.Items.ItemBase;
 using Item = FL.Data.Items.ItemBase;
 
 
 namespace FL.FGUI
 namespace FL.FGUI
@@ -25,7 +23,7 @@ namespace FL.FGUI
     {
     {
         private MailInfo _mailInfo;
         private MailInfo _mailInfo;
         private string _mailId;
         private string _mailId;
-        private List<ItemBase> _itemDataList;
+        private List<IItemBase> _itemDataList;
         protected override void OnEnable(object intent)
         protected override void OnEnable(object intent)
         {
         {
             AddUIListenres();
             AddUIListenres();
@@ -37,46 +35,36 @@ namespace FL.FGUI
         #region UI事件
         #region UI事件
         private void AddUIListenres()
         private void AddUIListenres()
         {
         {
-            VM.PanelEvent.Add(OnClickNode);
 
 
         }
         }
         private void RemoveUIListenres()
         private void RemoveUIListenres()
         {
         {
-            VM.PanelEvent.Remove(OnClickNode);
         }
         }
         public void OnRefresh(int index, MailInfo mailInfo)
         public void OnRefresh(int index, MailInfo mailInfo)
         {
         {
-            if (_itemDataList == null) _itemDataList = new List<Item>();
+            if (_itemDataList == null) _itemDataList = new List<IItemBase>();
             _mailInfo = mailInfo;
             _mailInfo = mailInfo;
             _mailId = mailInfo.id;
             _mailId = mailInfo.id;
             VM.IsGet.selectedIndex = _mailInfo.rts > 0 ? 1 : 0;
             VM.IsGet.selectedIndex = _mailInfo.rts > 0 ? 1 : 0;
             VM.HasItem.selectedIndex = _mailInfo.items.Count > 0 ? 1 : 0;
             VM.HasItem.selectedIndex = _mailInfo.items.Count > 0 ? 1 : 0;
             VM.TitleLabel.text = _mailInfo.title;
             VM.TitleLabel.text = _mailInfo.title;
-            DateTimeOffset dateTime = DateTimeOffset.FromUnixTimeSeconds(_mailInfo.ets);
-            string yearMonthDay = dateTime.ToString("yyyy-MM-dd hh:mm");
-            VM.TimeLabel.text = yearMonthDay;
+            VM.TimeLabel.text = mailInfo.ets.ToTimeYMDHM(); ;
             VM.ContentLabel.text = _mailInfo.items.Count > 0 ? "" : _mailInfo.content;
             VM.ContentLabel.text = _mailInfo.items.Count > 0 ? "" : _mailInfo.content;
             if (_mailInfo.items.Count > 0)
             if (_mailInfo.items.Count > 0)
             {
             {
                 _itemDataList.Clear();
                 _itemDataList.Clear();
-                for (global::System.Int32 i = 0; i < _mailInfo.items.Count; i++)
+                for (int i = 0; i < _mailInfo.items.Count; i++)
                 {
                 {
-                    ItemTable itemInfo = ItemTableRepo.Get(_mailInfo.items[i].id);
-                    ItemBase _item = new ItemBase();
-                    _item.Init(itemInfo.Id, _mailInfo.items[i].count);
+                    IItemBase _item = ItemService.Instance.GetItemBase(mailInfo.items[i].id, mailInfo.items[i].count, mailInfo.items[i].kind);
                     _itemDataList.Add(_item);
                     _itemDataList.Add(_item);
                 }
                 }
                 ShowItemsUI(_itemDataList);
                 ShowItemsUI(_itemDataList);
             }
             }
         }
         }
-        private void ShowItemsUI(List<ItemBase> dataList)
+        private void ShowItemsUI(List<IItemBase> dataList)
         {
         {
             VM.ItemList.BindDatas(dataList);
             VM.ItemList.BindDatas(dataList);
         }
         }
-        private void OnClickNode()
-        {
-            EventSingle.Instance.Notify(EventDefine.OpenSingleMail, _mailId);
-        }
 
 
         #endregion
         #endregion
     }
     }

+ 2 - 20
Assets/Scripts/Business/Runtime/Network/Controllers/MailListPushCtrl.cs

@@ -9,27 +9,9 @@ namespace FL.Network
         {
         {
             for (int i = 0; i < message.mail_list.Count; i++)
             for (int i = 0; i < message.mail_list.Count; i++)
             {
             {
-                if (MailData.Instance.mailInfo == null)
-                {
-                    MailData.Instance.mailInfo = message.mail_list;
-                    break;
-                }
-                bool hasMail = false;
-                for (global::System.Int32 j = 0; j < MailData.Instance.mailInfo.Count; j++)
-                {
-                    if (message.mail_list[i].id == MailData.Instance.mailInfo[j].id)
-                    {
-                        MailData.Instance.mailInfo[j] = message.mail_list[i];
-                        hasMail = true;
-                        break;
-                    }
-                }
-                if (!hasMail)
-                {
-                    MailData.Instance.mailInfo.Add(message.mail_list[i]);
-                }
+                //int mailId = message.mail_list[i].id;
+                MailData.Instance.mailInfo[message.mail_list[i].id] = message.mail_list[i];
             }
             }
-            //MailData.Instance.mailInfo = message.mail_list;
         }
         }
     }
     }
 }
 }

+ 13 - 1
Assets/Scripts/Business/Runtime/Utils/StringUtils.cs

@@ -1,4 +1,5 @@
-using System;
+using FL.Network;
+using System;
 
 
 namespace FL
 namespace FL
 {
 {
@@ -40,5 +41,16 @@ namespace FL
             }
             }
             return number.ToString();
             return number.ToString();
         }
         }
+        /// <summary>
+        /// 时间戳转换成 xxxx-xx-xx xx:xx格式
+        /// </summary>
+        /// <param name="milliseconds"></param>
+        /// <returns></returns>
+        public static string ToTimeYMDHM(this long milliseconds)
+        {
+            DateTimeOffset dateTime = DateTimeOffset.FromUnixTimeSeconds(milliseconds);
+            string yearMonthDay = dateTime.ToString("yyyy-MM-dd hh:mm");
+            return yearMonthDay;
+        }
     }
     }
 }
 }

+ 1 - 0
fl-fgui-project/assets/Common/ItemBase.xml

@@ -5,6 +5,7 @@
     <loader id="n10_n1qe" name="ItemIcon" xy="11,11" pivot="0.5,0.5" size="128,128" touchable="false" url="ui://gt6q23qwq0v63z" align="center" vAlign="middle" autoSize="true" clearOnPublish="true"/>
     <loader id="n10_n1qe" name="ItemIcon" xy="11,11" pivot="0.5,0.5" size="128,128" touchable="false" url="ui://gt6q23qwq0v63z" align="center" vAlign="middle" autoSize="true" clearOnPublish="true"/>
     <text id="n2_b4qr" name="CountLabel" xy="103,103" pivot="1,0.5" size="34,36" fontSize="26" color="#ffffff" align="right" vAlign="middle" leading="0" autoClearText="true" text="88"/>
     <text id="n2_b4qr" name="CountLabel" xy="103,103" pivot="1,0.5" size="34,36" fontSize="26" color="#ffffff" align="right" vAlign="middle" leading="0" autoClearText="true" text="88"/>
     <text id="n14_fr8z" name="LvLabel" xy="15,130" pivot="0,0.5" anchor="true" size="52,36" font="font_dengjishuzi" fontSize="26" color="#ffffff" vAlign="middle" leading="0" autoClearText="true" text="Lv.1"/>
     <text id="n14_fr8z" name="LvLabel" xy="15,130" pivot="0,0.5" anchor="true" size="52,36" font="font_dengjishuzi" fontSize="26" color="#ffffff" vAlign="middle" leading="0" autoClearText="true" text="Lv.1"/>
+    <image id="n15_or70" name="IsGetImg" src="apdef" fileName="images/imgTick.png" xy="74,74" pivot="0.5,0.5" anchor="true" scale="2.5,2.5"/>
     <component id="n13_negq" name="ItemBtn" src="negq2e" fileName="Components/EmptyBtn.xml" xy="7,7" size="136,136"/>
     <component id="n13_negq" name="ItemBtn" src="negq2e" fileName="Components/EmptyBtn.xml" xy="7,7" size="136,136"/>
   </displayList>
   </displayList>
   <scriptData gencodeme3q0="1" genuitypeme3q0="2"/>
   <scriptData gencodeme3q0="1" genuitypeme3q0="2"/>