123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Data;
- using FL.Data.Items;
- using FL.Network;
- using System.Collections.Generic;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- public struct IMailRwdItem
- {
- public IItemBase Item;
- public bool IsGet;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class MailMailPanelCtrl : UIController<MailMailPanelVM>
- {
- private List<MailInfo> _mailList = new List<MailInfo>();
- private List<IMailRwdItem> _mailRwdList;
- private bool _isOpenMail;// 是否打开单封邮件
- private string _mailId;// 当前打开的邮件id
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- Init();
- _isOpenMail = false;
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.AllReadBtn.onClick.Add(OnClickAllReadBtn);
- VM.DeleteReadBtn.onClick.Add(OnClickDeleteReadBtn);
- VM.BackMainBtn.onClick.Add(OnClickBackMainBtn);
- VM.AllGetBtn.onClick.Add(OnClickAllGetBtn);
- VM.ReadBtn.onClick.Add(OnClickReadBtn);
- VM.GetBtn.onClick.Add(OnClickGetBtn);
- VM.DeleteBtn.onClick.Add(OnClickDeleteBtn);
- Context.AddListener(EventDefine.UpMailList, UpMailList);
- VM.MailList.ItemClickEvent += OnClcikMailListItem;
- }
- private void RemoveUIListenres()
- {
- VM.AllReadBtn.onClick.Remove(OnClickAllReadBtn);
- VM.DeleteReadBtn.onClick.Remove(OnClickDeleteReadBtn);
- VM.BackMainBtn.onClick.Remove(OnClickBackMainBtn);
- VM.AllGetBtn.onClick.Remove(OnClickAllGetBtn);
- VM.ReadBtn.onClick.Remove(OnClickReadBtn);
- VM.GetBtn.onClick.Remove(OnClickGetBtn);
- VM.DeleteBtn.onClick.Remove(OnClickDeleteBtn);
- Context.RemoveListener(EventDefine.UpMailList, UpMailList);
- VM.MailList.ItemClickEvent -= OnClcikMailListItem;
- }
- private void Init()
- {
- if (_mailList == null) _mailList = new List<MailInfo>();
- if (_mailRwdList == null) _mailRwdList = new List<IMailRwdItem>();
- }
- private void ShowUI()
- {
- bool canGet = false;
- bool canRead = false;
- _mailList.Clear();
- MailInfo mailInfo = null;
- foreach (var mail in MailData.Instance.mailInfo)
- {
- if (mail.Value.rts <= 0)
- {
- if (mail.Value.items.Count > 0)
- {
- canGet = true;
- }
- else
- {
- canRead = true;
- }
- }
- if (_isOpenMail && _mailId == mail.Value.id)
- {
- mailInfo = mail.Value;
- }
- long nowTime = Context.Time.GetNowTime() / 1000;
- if (mail.Value.ets >= nowTime)
- {
- _mailList.Add(mail.Value);
- }
- }
- VM.AllReadBtn.visible = !_isOpenMail && canRead;// 一键已读
- VM.DeleteReadBtn.visible = !_isOpenMail && !canRead;// 删除已读
- VM.AllGetBtn.visible = !_isOpenMail;// 全部领取
- VM.AllGetBtn.enabled = canGet;// 全部领取
- VM.MailDetailsGrp.visible = _isOpenMail && mailInfo != null;// 是否打开单封邮件
- VM.MailList.visible = !VM.MailDetailsGrp.visible;// 邮件列表隐藏
- if (_isOpenMail && mailInfo != null)
- {
- VM.BackMainBtn.visible = _isOpenMail;// 返回邮件列表
- bool hasItem = mailInfo.items.Count > 0;
- bool singleCanGet = mailInfo.rts <= 0 && hasItem;
- bool singleCanRead = mailInfo.rts <= 0 && !hasItem;
- VM.ReadBtn.visible = _isOpenMail && singleCanRead;// 已读
- VM.GetBtn.visible = _isOpenMail && singleCanGet;// 领取
- VM.DeleteBtn.visible = _isOpenMail && !singleCanGet && !singleCanRead;// 删除
- VM.TitleLabel.text = mailInfo.title;
- VM.TimeLabel.text = mailInfo.ets.ToTimeYMDHM();
- VM.ContentLabel.text = mailInfo.content;
- VM.ItemGrp.visible = hasItem;
- if (hasItem)
- {
- _mailRwdList.Clear();
- for (int i = 0; i < mailInfo.items.Count; i++)
- {
- IMailRwdItem mailRwdItem = new IMailRwdItem()
- {
- Item = ItemService.Instance.GetItemBase(mailInfo.items[i].id, mailInfo.items[i].count, mailInfo.items[i].kind),
- IsGet = mailInfo.rts > 0,
- };
- _mailRwdList.Add(mailRwdItem);
- }
- ShowItemsUI(_mailRwdList);
- }
- }
- SetMailList(_mailList);
- }
- // 打开单封邮件
- private void OpenSingleMail(string mailId)
- {
- _isOpenMail = true;
- _mailId = mailId;
- ShowUI();
- }
- //刷新邮件列表
- private void UpMailList(int eventId, object args)
- {
- ShowUI();
- }
- //刷新邮件列表
- private void SetMailList(List<MailInfo> dataList)
- {
- VM.MailList.BindDatas(dataList);
- UpMailCount(dataList.Count);
- VM.EmptyLabel.visible = dataList.Count == 0;
- }
- // 邮件数量
- private void UpMailCount(int num)
- {
- VM.MailCountLabel.text = string.Format(StringDefine.MailCountLabel, num, KeyValue.mailMax);
- }
- //单封邮件内的奖励
- private void ShowItemsUI(List<IMailRwdItem> dataList)
- {
- VM.ItemList.BindDatas(dataList);
- }
- //点击邮件列表
- private void OnClcikMailListItem(int index)
- {
- string mailId = _mailList[index].id;
- OpenSingleMail(mailId);
- }
- //一键已读
- private void OnClickAllReadBtn(EventContext context)
- {
- MailService.Instance.RequestMailReadAll();
- }
- //删除已读
- private void OnClickDeleteReadBtn(EventContext context)
- {
- MailService.Instance.RequestMailDelAll();
- }
- //返回
- private void OnClickBackMainBtn(EventContext context)
- {
- _isOpenMail = false;
- ShowUI();
- }
- //一键领取
- private void OnClickAllGetBtn(EventContext context)
- {
- MailService.Instance.RequestMailRwdAll();
- }
- //已读
- private void OnClickReadBtn(EventContext context)
- {
- MailService.Instance.RequestMailRwd(_mailId);
- }
- //领取
- private void OnClickGetBtn(EventContext context)
- {
- MailService.Instance.RequestMailRwd(_mailId);
- }
- //删除
- private void OnClickDeleteBtn(EventContext context)
- {
- _isOpenMail = false;
- VM.MailDetailsGrp.visible = false;
- VM.MailList.visible = true;
- MailService.Instance.RequestMailDel(_mailId);
- }
- #endregion
- }
- }
|