邮件暂存2

main
LuoFang 2023-12-11 18:56:57 +08:00
parent ec0d4fde72
commit 29d07ce35d
12 changed files with 723 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4b098ec5468d2cd49beee37647c85f29
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,76 @@
using Framework;
using Gameplay;
using Gameplay.Net;
using PhxhSDK;
using System.Collections.Generic;
public class MailSystem : Singlenton<MailSystem>, IInitable
{
public List<SingleMail> DataList;
public Dictionary<ulong, SingleMail> DataDic;
public bool isHaveAll;
public void Init()
{
DataList = new List<SingleMail>();
DataDic = new Dictionary<ulong, SingleMail>();
isHaveAll = false;
}
public void Release()
{
DataList = new List<SingleMail>();
DataDic = new Dictionary<ulong, SingleMail>();
}
public void RemoveMail(ulong id)
{
SingleMail mail = null;
if (DataDic.TryGetValue(id, out mail))
{
DataDic.Remove(id);
DataList.Remove(mail);
}
else
{
DebugUtil.LogError("移除id为{0}的邮件失败",id);
}
}
public void AddMail(Mail mail)
{
SingleMail info2;
if (DataDic.TryGetValue(mail.Id, out info2))
{
DataDic[mail.Id].Refresh(mail);
for (int i = 0; i < DataList.Count; i++)
{
if (DataList[i].Id== mail.Id)
{
DataList[i].Refresh(mail);
return;
}
}
}
else
{
SingleMail newInfo = new SingleMail(mail);
DataList.Add(newInfo);
DataDic[mail.Id] = newInfo;
MailSystem.Instance.isHaveAll=true;
}
}
public void SetStatus(ulong id,uint status)
{
DataDic[id].SetStatus(status);
for (int i = 0; i < DataList.Count; i++)
{
if (DataList[i].Status==status)
{
DataList[i].SetStatus(status);
return;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae20a8275c672af4a879f8af2c61ab9f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using Cysharp.Threading.Tasks;
using PhxhSDK;
using static Gameplay.MusicCubeManager;
using UnityEngine;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
using Gameplay.Net;
public static class MailSystemTools
{
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f48a7713994f61b41b6fae52697edc0e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,39 @@
using cfg;
using cfg.ActorCfg;
using Framework;
using Gameplay.Net;
using NLDPB;
namespace Gameplay
{
public class SingleMail:Mail
{
DataMail cfg;
public DataMail Cfg => cfg;
public SingleMail(Mail mail)
{
Id = mail.Id;
Refresh(mail);
}
public void Refresh(Mail mail)
{
cfg = TableManager.Instance.Tables.MailCfg.GetOrDefault((int)mail.MailID);
SendTime = mail.SendTime;
Status = mail.Status;
MailID = mail.MailID;
Title = mail.Title;
Body = mail.Body;
if (mail.MailData != null)
{
MailData = mail.MailData;
}
}
public void SetStatus(uint stu)
{
Status = stu;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33d4b45a19e43a84ebba03adafd87c76
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,400 @@
using Framework;
using Gameplay;
using Gameplay.Common;
using Gameplay.Net;
using NLDPB;
using PhxhSDK;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
public class UI_EmailController : UIWindow
{
//UI GameObj
///Auto Gen Start///
public Image Image_EmailBG;
public Button Button_Close;
public TMP_Text Text_Title;
public TMP_Text Text_NoEmail;
public Image Image_EmailLogoS;
public TMP_Text Text_NotRead;
public Image Image_ChooseRect;
public Image Image_Triangle;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_NoReadRect;
public Image Image_RedPot;
public Image Image_StuffLogo;
public Image Image_YesReadRect;
public Button Button_GetAll;
public TMP_Text Text_GetAll;
public Button Button_DeleteAll;
public TMP_Text Text_DeleteAll;
public TMP_Text Text_EmailMax;
public Image Image_Red;
public Image Image_Green02;
public TMP_Text Text_EmailMainTitle;
public TMP_Text Text_SendName;
public TMP_Text Text_Time;
public Image Image_MusicLogo;
public Image Image_SeperateLine;
public TMP_Text Text_MainText;
public Image Image_StuffBG;
public Button Button_Get;
public TMP_Text Text_Get;
public Image Image_Stuff01;
public TMP_Text Text_StuffNum;
public Image Image_Stuff02;
public Image Image_Stuff03;
private GameObject mCurrentScrollViewContentObj = null;
///Auto Gen End///
public List<SingleMail> AllMail;
PhxhScrollView _mCurrentScrollView = null;
Dictionary<GameObject, SingleMail> mMailDic = new Dictionary<GameObject, SingleMail>();
SingleMail mNowMail = null;
const int OneDaySecond = 86400;
const int OneHourSec = 3600;
// Use this for initialization
public override void OnAwake()
{
AllMail = new List<SingleMail>();
//bind UI GameObj
UI_EmailBinder.GetComponents(this);
mCurrentScrollViewContentObj = FindObj("Image_EmailBG/Left/ScrollView/Viewport/Content");
_mCurrentScrollView = GetComponent<PhxhScrollView>("Image_EmailBG/Left/ScrollView");
BindButton(Button_GetAll,OnGetAllBtnClick);
BindButton(Button_DeleteAll, OnDeleteAllClick);
BindButton(Button_GetAll, OnGetBtnClick);
BindButton(Button_Close, OnCloseClick);
}
private void OnCloseClick()
{
CloseWindow();
}
void RegistEvent()
{
EventManager.Instance.Register(EventManager.EventName.ClaimMailGoods, (Action<ItemList>)OnClaimMailGoods);
}
private async void OnClaimMailGoods(ItemList list)
{
await UIManager.Instance.OpenWindow(UINameConst.UIGiftCodeAwards, list);
}
void UnRegisterEvent()
{
EventManager.Instance.Unregister(EventManager.EventName.ClaimMailGoods, (Action<ItemList>)OnClaimMailGoods);
}
private void OnGetBtnClick()
{
if(mNowMail.Status==2)
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("mail_lingQued"));
return;
}
NetHelper.CliamMail(mNowMail.Id);
}
private void OnDeleteAllClick()
{
List<SingleMail> delMailList = new List<SingleMail>();
for (int i = 0; i < AllMail.Count; i++)
{
if (AllMail[i].Status==2)
{
delMailList.Add(AllMail[i]);
}
}
for (int i = 0; i < delMailList.Count; i++)
{
DeleteMail(delMailList[i]);
}
RefreshScrollview();
}
private void OnGetAllBtnClick()
{
if(IsHaveClaim())
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("mail_allGetTip"));
return;
}
NetHelper.CliamMail(0);
}
bool IsHaveClaim()
{
bool isHaveClaim = false;
for (int i = 0; i < AllMail.Count; i++)
{
if ((AllMail[i].Status != 2) && (AllMail[i].MailData.Items.Count != 0))
{
isHaveClaim = true;
}
}
return isHaveClaim;
}
//invoke when open window
protected override void OnOpenWindow()
{
NetHelper.RequestMailList(false);
GetStorageData();
SetScrollview();
RefreshRight();
RefreshMailCount();
RefreshNotReadCount();
RefreshMaterial();
RegistEvent();
}
private void RefreshRight()
{
FindObj("Image_EmailBG/Right").gameObject.SetActive(AllMail.Count != 0);
Text_NoEmail.gameObject.SetActive(AllMail.Count == 0);
DateTime sendTime = CommonUtils.ParseTime(mNowMail.SendTime);
Text_EmailMainTitle.text = CommonUtils.GetLocalizeText(mNowMail.Cfg.TitleLo);
Text_SendName.text = CommonUtils.GetLocalizeText(mNowMail.Cfg.SenderLo);
Text_Time.text = string.Format(CommonUtils. GetLocalizeText("Date_year_month_day"), sendTime.Year, sendTime.Month, sendTime.Day)+" "+sendTime.ToString("HH:mm");
Text_MainText.text = CommonUtils.GetLocalizeText(mNowMail.Cfg.BodyLo);
}
private void RefreshMailCount()
{
Text_EmailMax.text = string.Format(CommonUtils.GetLocalizeText("mail_mailCount"),AllMail.Count,GLConfig.Inst.data.MaxMailCount);
}
private void RefreshNotReadCount()
{
int j = 0;
for (int i = 0; i < AllMail.Count; i++)
{
if (AllMail[i].Status == 0)
{
j++;
}
}
if (j == 0)
{
Text_NotRead.text = "";
}
else
{
Text_NotRead.text = CommonUtils.GetLocalizeText("mail_notReadedCount", j);
}
}
private void SetScrollview()
{
if(AllMail.Count==0)
{
return;
}
_mCurrentScrollView.SetUpdateFunc(RefreshItem);
_mCurrentScrollView.SetItemCountFunc(GetCountFunc);
_mCurrentScrollView.UpdateData(false);
_mCurrentScrollView.SetButton(SetScrollviewItemButton);
}
private void SetScrollviewItemButton(GameObject itme)
{
BindButton<GameObject>(CommonUtils.GetGameObject(itme, "ClickBtn"), OnMailClick, itme);
}
private void RefreshScrollview()
{
_mCurrentScrollView.UpdateData(true);
}
private void OnMailClick(GameObject item)
{
GameObject lastObj = null;
SingleMail lastMail = mNowMail;
foreach(var val in mMailDic)
{
if (val.Value==mNowMail)
{
lastObj = val.Key;
}
}
SingleMail mail = mMailDic[item];
if (mail.Status==0)
{
mail.SetStatus(1);
}
MailSystem.GetSingleton().SetStatus(mail.Id,1);
mNowMail = mail;
RefreshRight();
RefreshSingleItem(lastObj,lastMail);
RefreshSingleItem(item, mNowMail);
}
private int GetCountFunc()
{
return AllMail.Count;
}
private void RefreshItem(int index, RectTransform item)
{
item.gameObject.SetActive(true);
mMailDic[item.gameObject] = AllMail[index];
RefreshSingleItem(item.gameObject, AllMail[index]);
}
private void RefreshMaterial()
{
for (int i = 0; i < 3; i++)
{
GameObject itemParent = FindObj(string.Format("Image_EmailBG/Right/UI_Materals/{0}", (i + 1).ToString()));
CommonUtils.DestoryAllChildGameObject(CommonUtils.GetGameObject(itemParent, "item"));
if (i < mNowMail.MailData.Items.Count)
{
itemParent.SetActive(true);
ItemObj itemObj = new ItemObj((int)mNowMail.MailData.Items[i].Id, CommonUtils.GetGameObject(itemParent, "item"));
}
else
{
itemParent.SetActive(false);
}
}
}
private void RefreshSingleItem(GameObject item,SingleMail mail)
{
TimeSpan overTime = CommonUtils.ParseTime(mail.SendTime).AddDays(GLConfig.Inst.data.MailDays) - CommonUtils.NowTime();
string dateStr = "";
if (overTime.TotalSeconds >= OneDaySecond)
{
dateStr = string.Format(CommonUtils.GetLocalizeText("mail_validTime_day"), overTime.Days);
}
else if (overTime.TotalSeconds >= OneHourSec)
{
dateStr = string.Format(CommonUtils.GetLocalizeText("mail_validTime_hour"), overTime.Hours);
}
else
{
dateStr = string.Format(CommonUtils.GetLocalizeText("mail_validTime_minute"));
}
GameObject chooseObj = CommonUtils.GetGameObject(item, "Image_ChooseRect");
GameObject noReadObj = CommonUtils.GetGameObject(item, "Image_NoReadRect");
GameObject yesReadObj = CommonUtils.GetGameObject(item, "Image_YesReadRect");
if(mNowMail.Id==mail.Id)
{
CommonUtils.SetActive(chooseObj, true);
CommonUtils.SetActive(noReadObj, false);
CommonUtils.SetActive(yesReadObj, false);
CommonUtils.GetComponent<TMP_Text>(chooseObj, "Text_EmailTitle").text = mail.Title;
CommonUtils.GetComponent<TMP_Text>(chooseObj, "Text_Addresor").text = CommonUtils.GetLocalizeText("mail_sender")+CommonUtils.GetLocalizeText(mail.Cfg.Sender);
CommonUtils.GetComponent<TMP_Text>(chooseObj, "Text_Date").text = dateStr;
}
else if(mail.Status==2)//已读
{
CommonUtils.SetActive(chooseObj, false);
CommonUtils.SetActive(noReadObj, true);
CommonUtils.SetActive(yesReadObj, false);
CommonUtils.GetComponent<TMP_Text>(yesReadObj, "Text_EmailTitle").text = mail.Title;
CommonUtils.GetComponent<TMP_Text>(yesReadObj, "Text_Addresor").text = CommonUtils.GetLocalizeText("mail_sender") + CommonUtils.GetLocalizeText(mail.Cfg.Sender);
CommonUtils.GetComponent<TMP_Text>(yesReadObj, "Text_Date").text = dateStr;
}
else
{
CommonUtils.SetActive(chooseObj, false);
CommonUtils.SetActive(noReadObj, false);
CommonUtils.SetActive(yesReadObj, true);
CommonUtils.GetComponent<TMP_Text>(noReadObj, "Text_EmailTitle").text = mail.Title;
CommonUtils.GetComponent<TMP_Text>(noReadObj, "Text_Addresor").text = CommonUtils.GetLocalizeText("mail_sender") + CommonUtils.GetLocalizeText(mail.Cfg.Sender);
CommonUtils.GetComponent<TMP_Text>(noReadObj, "Text_Date").text = dateStr;
}
}
void GetStorageData()
{
AllMail.Clear();
AllMail.AddRange(MailSystem.Instance.DataList);
if(IfListEmpty())
{
ShowWaiting();
}else
{
mNowMail = AllMail[0];
}
}
private void ShowWaiting()
{
}
bool IfListEmpty()
{
return AllMail.Count == 0;
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
//invoke when close window
protected override void OnCloseWindow()
{
UnRegisterEvent();
}
private void Update()
{
for (int i = 0; i < AllMail.Count; i++)
{
TimeSpan overTime = CommonUtils.ParseTime(AllMail[i].SendTime).AddDays(GLConfig.Inst.data.MailDays) - CommonUtils.NowTime();
if(overTime.TotalSeconds==(OneDaySecond-1)||overTime.TotalSeconds==(OneHourSec-1))
{
RefreshScrollview();
}else if(overTime.TotalSeconds<=0)
{
DeleteMail(AllMail[i]);
}
}
}
void DeleteMail(SingleMail mail)
{
NetHelper.DeleteMail(mail.Id);
AllMail.Remove(mail);
MailSystem.GetSingleton().RemoveMail(mail.Id);
RefreshScrollview();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60b0dc814e72acc4da8aeb9495f5da41
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,126 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using Framework;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
public class UI_EmailBinder
{
public static void GetComponents(UI_EmailController window)
{
window.Image_EmailBG = window.GetComponent<Image>("Image_EmailBG");
window.Button_Close = window.GetComponent<Button>("Image_EmailBG/Top/Button_Close");
window.Text_Title = window.GetComponent<TMP_Text>("Image_EmailBG/Top/Text_Title");
window.Text_NoEmail = window.GetComponent<TMP_Text>("Image_EmailBG/Top/Text_NoEmail");
window.Image_EmailLogoS = window.GetComponent<Image>("Image_EmailBG/Top/Image_EmailLogoS");
window.Text_NotRead = window.GetComponent<TMP_Text>("Image_EmailBG/Top/Image_EmailLogoS/Text_NotRead");
window.Button_GetAll = window.GetComponent<Button>("Image_EmailBG/Left/Button_GetAll");
window.Text_GetAll = window.GetComponent<TMP_Text>("Image_EmailBG/Left/Button_GetAll/Text_GetAll");
window.Button_DeleteAll = window.GetComponent<Button>("Image_EmailBG/Left/Button_DeleteAll");
window.Text_DeleteAll = window.GetComponent<TMP_Text>("Image_EmailBG/Left/Button_DeleteAll/Text_DeleteAll");
window.Text_EmailMax = window.GetComponent<TMP_Text>("Image_EmailBG/Left/Text_EmailMax");
window.Image_Red = window.GetComponent<Image>("Image_EmailBG/Right/UI_Materals/1/Image_Red");
window.Image_Green02 = window.GetComponent<Image>("Image_EmailBG/Right/UI_Materals/1/Image_Green02");
window.Image_Red = window.GetComponent<Image>("Image_EmailBG/Right/UI_Materals/2/Image_Red");
window.Image_Green02 = window.GetComponent<Image>("Image_EmailBG/Right/UI_Materals/2/Image_Green02");
window.Image_Red = window.GetComponent<Image>("Image_EmailBG/Right/UI_Materals/3/Image_Red");
window.Image_Green02 = window.GetComponent<Image>("Image_EmailBG/Right/UI_Materals/3/Image_Green02");
window.Text_EmailMainTitle = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Text_EmailMainTitle");
window.Text_SendName = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Text_SendName");
window.Text_Time = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Text_Time");
window.Image_MusicLogo = window.GetComponent<Image>("Image_EmailBG/Right/Image_MusicLogo");
window.Image_SeperateLine = window.GetComponent<Image>("Image_EmailBG/Right/Image_MusicLogo/Image_SeperateLine");
window.Text_MainText = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Text_MainText");
window.Image_StuffBG = window.GetComponent<Image>("Image_EmailBG/Right/Image_StuffBG");
window.Button_Get = window.GetComponent<Button>("Image_EmailBG/Right/Image_StuffBG/Button_Get");
window.Text_Get = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Image_StuffBG/Button_Get/Text_Get");
window.Image_Stuff01 = window.GetComponent<Image>("Image_EmailBG/Right/Image_StuffBG/Image_Stuff01");
window.Text_StuffNum = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Image_StuffBG/Image_Stuff01/Text_StuffNum");
window.Image_Stuff02 = window.GetComponent<Image>("Image_EmailBG/Right/Image_StuffBG/Image_Stuff02");
window.Text_StuffNum = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Image_StuffBG/Image_Stuff02/Text_StuffNum");
window.Image_Stuff03 = window.GetComponent<Image>("Image_EmailBG/Right/Image_StuffBG/Image_Stuff03");
window.Text_StuffNum = window.GetComponent<TMP_Text>("Image_EmailBG/Right/Image_StuffBG/Image_Stuff03/Text_StuffNum");
}
/****** ******
public Image Image_EmailBG;
public Button Button_Close;
public TMP_Text Text_Title;
public TMP_Text Text_NoEmail;
public Image Image_EmailLogoS;
public TMP_Text Text_NotRead;
public Image Image_ChooseRect;
public Image Image_Triangle;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_NoReadRect;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_RedPot;
public Image Image_StuffLogo;
public Image Image_YesReadRect;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_ChooseRect;
public Image Image_Triangle;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_NoReadRect;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_RedPot;
public Image Image_StuffLogo;
public Image Image_YesReadRect;
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_YesReadRect (1);
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Image Image_YesReadRect (2);
public TMP_Text Text_EmailTitle;
public TMP_Text Text_Addresor;
public TMP_Text Text_Date;
public Button Button_GetAll;
public TMP_Text Text_GetAll;
public Button Button_DeleteAll;
public TMP_Text Text_DeleteAll;
public TMP_Text Text_EmailMax;
public Image Image_Red;
public Image Image_Green02;
public Image Image_Red;
public Image Image_Green02;
public Image Image_Red;
public Image Image_Green02;
public TMP_Text Text_EmailMainTitle;
public TMP_Text Text_SendName;
public TMP_Text Text_Time;
public Image Image_MusicLogo;
public Image Image_SeperateLine;
public TMP_Text Text_MainText;
public Image Image_StuffBG;
public Button Button_Get;
public TMP_Text Text_Get;
public Image Image_Stuff01;
public TMP_Text Text_StuffNum;
public Image Image_Stuff02;
public TMP_Text Text_StuffNum;
public Image Image_Stuff03;
public TMP_Text Text_StuffNum;
****** End ******/
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46280367bb31e29419a8cd2855b106f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 170833bb50db352458cbce2eeb2f2158
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: