using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System.Linq;
|
using vnxbqy.UI;
|
|
public enum MailState
|
{
|
Read,
|
NoRead,
|
Delete,
|
Receive,
|
}
|
|
namespace vnxbqy.UI
|
{
|
public class MailWin : Window
|
{
|
|
#region 成员变量
|
[SerializeField]
|
private Text _senderMessagerText;
|
[SerializeField]
|
private Text _titleMessageText;
|
[SerializeField]
|
private Text _theTotalTitleText;
|
[SerializeField]
|
private GameObject _buddyBlueAG;
|
[SerializeField]
|
private GameObject _buddyBlueBG;
|
[SerializeField]
|
private GameObject _buddyBlueCG;
|
[SerializeField]
|
private GameObject _buddyBlueDG;
|
[SerializeField]
|
private GameObject _buddyBlueEG;
|
[SerializeField]
|
private GameObject _goldBox;
|
[SerializeField]
|
private Text _goldText;
|
[SerializeField]
|
private GameObject _drillBox;
|
[SerializeField]
|
private Text _drillBoxeText;
|
[SerializeField]
|
private GameObject _fairyJadeBox;
|
[SerializeField]
|
private Text _fairyJadeBoxText;
|
[SerializeField]
|
private Toggle _allSelectToggle;
|
[SerializeField]
|
private Button _receiveBtn;
|
[SerializeField]
|
private Button _deleteBtn;
|
[SerializeField]
|
private ScrollerController _mailCellCtrl;
|
[SerializeField] TextEx noMailTip;
|
[SerializeField] Text mailCnt;
|
[SerializeField] Image gotGiftImg;
|
#endregion
|
|
private MailState _mailState = MailState.NoRead;
|
private List<MailInfo> _chooseMailList;
|
public Dictionary<string, MailInfo> _isChooseMailDict = new Dictionary<string, MailInfo>();
|
private List<GameObject> _reciveItemParent = new List<GameObject>();
|
private List<MailInfo> mailModellist;
|
private MailInfo _currentMailInfo;
|
private int curMail = 0;
|
|
|
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
_senderMessagerText.text = "";
|
_titleMessageText.text = "";
|
_theTotalTitleText.text = "";
|
_reciveItemParent.Add(_buddyBlueAG);
|
_reciveItemParent.Add(_buddyBlueBG);
|
_reciveItemParent.Add(_buddyBlueCG);
|
_reciveItemParent.Add(_buddyBlueDG);
|
_reciveItemParent.Add(_buddyBlueEG);
|
_mailCellCtrl.OnRefreshCell += RefreshMailCell;
|
_allSelectToggle.isOn = false;
|
_allSelectToggle.onValueChanged.AddListener(
|
(bool isOn) =>
|
{
|
OnAllSelectToggle(isOn);
|
}
|
);
|
}
|
|
protected override void OnPreOpen()
|
{
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
MailAllModel.Instance.GetNewMailEvent -= GetNewMail;
|
MailAllModel.Instance.CallBackReceiveEvent -= OnGetReceiveResult;
|
MailAllModel.Instance.DeleteMailEvent -= OnGetDeleteResult;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
curMail = 0;
|
CreateMailCell();
|
MailAllModel.Instance.GetNewMailEvent += GetNewMail;
|
MailAllModel.Instance.CallBackReceiveEvent += OnGetReceiveResult;
|
MailAllModel.Instance.DeleteMailEvent += OnGetDeleteResult;
|
}
|
|
private void CreateMailCell()
|
{
|
mailModellist = MailAllModel.Instance.GetTimeOrderMaillist();
|
if (mailModellist == null)
|
return;
|
|
noMailTip.SetActive(mailModellist.Count == 0);
|
_mailCellCtrl.Refresh();
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
_mailCellCtrl.AddCell(ScrollerDataType.Header, mailCount);
|
}
|
_mailCellCtrl.Restart();
|
|
if (mailModellist.Count < 1)
|
{
|
ResetUI();
|
}
|
|
mailCnt.text = mailModellist.Count + "/" + MailAllModel.Instance.totalMailCnt;
|
}
|
|
private void GetNewMail()
|
{
|
mailModellist = MailAllModel.Instance.GetTimeOrderMaillist();
|
curMail += MailAllModel.Instance.addMailCnt;
|
noMailTip.SetActive(mailModellist.Count == 0);
|
|
_mailCellCtrl.Refresh();
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
_mailCellCtrl.AddCell(ScrollerDataType.Header, mailCount);
|
}
|
_mailCellCtrl.Restart();
|
|
|
if (curMail >= mailModellist.Count)
|
{
|
ResetUI();
|
}
|
|
mailCnt.text = mailModellist.Count + "/" + MailAllModel.Instance.totalMailCnt;
|
}
|
|
private void ResetUI()
|
{
|
_theTotalTitleText.text = "";
|
_titleMessageText.text = "";
|
_senderMessagerText.text = "";
|
_goldBox.SetActive(false);
|
_drillBox.SetActive(false);
|
_fairyJadeBox.SetActive(false);
|
int giftCount = 0;
|
for (giftCount = 0; giftCount < _reciveItemParent.Count; giftCount++)
|
{
|
_reciveItemParent[giftCount].SetActive(false);
|
}
|
_deleteBtn.interactable = false;
|
_receiveBtn.interactable = false;
|
noMailTip.SetActive(true);
|
gotGiftImg.SetActive(false);
|
}
|
|
|
|
private void RefreshMailCell(ScrollerDataType type, CellView cell)
|
{
|
MailCell mailCell = cell.GetComponent<MailCell>();
|
MailInfo info = mailModellist[cell.index];
|
MailAllModel.Instance.GetReciveMailContent(info);
|
mailCell.cellToggel.group = _mailCellCtrl.GetComponent<ToggleGroup>();
|
mailCell.chooseToggle.onValueChanged.RemoveAllListeners();
|
mailCell.cellToggel.onValueChanged.RemoveAllListeners();
|
|
mailCell.cellToggel.isOn = false;
|
mailCell.noticeText.text = MailAllModel.Instance.mailTitleStr;
|
mailCell.dateText.text = info.CreateTime;
|
if (info.IsRead == 0)
|
{
|
mailCell.noReadIcon.SetActive(true);
|
mailCell.readIcon.SetActive(false);
|
}
|
else
|
{
|
mailCell.noReadIcon.SetActive(false);
|
mailCell.readIcon.SetActive(true);
|
}
|
|
if ((info.Count > 0 || info.Gold > 0 || info.GoldPaper > 0
|
|| info.Silver > 0) && info.IsRead != 3)
|
mailCell.giftIcon.SetActive(true);
|
else
|
mailCell.giftIcon.SetActive(false);
|
|
mailCell.chooseToggle.isOn = info.isChoose;
|
if (curMail == cell.index)
|
{
|
mailCell.cellToggel.isOn = true;
|
OnClickMailCell(true, info, cell);
|
}
|
|
|
mailCell.chooseToggle.onValueChanged.AddListener((bool isOn) => { OnClickChooseToggle(isOn, info); });
|
mailCell.cellToggel.onValueChanged.AddListener((bool isOn) => { OnClickMailCell(isOn, info, cell); });
|
}
|
|
public void OnAllSelectToggle(bool isOn)
|
{
|
if (isOn)
|
{
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
mailModellist[mailCount].isChoose = true;
|
if (mailModellist[mailCount].Count > 0 || mailModellist[mailCount].Gold > 0
|
|| mailModellist[mailCount].GoldPaper > 0
|
|| mailModellist[mailCount].Silver > 0)
|
{
|
ChangeRightBtnUI(mailModellist[mailCount]);
|
}
|
}
|
|
}
|
else
|
{
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
mailModellist[mailCount].isChoose = false;
|
}
|
}
|
CreateMailCell();
|
}
|
|
private Dictionary<string, MailInfo> chooseMailDict = new Dictionary<string, MailInfo>();
|
private void OnClickChooseToggle(bool isOn, MailInfo info)
|
{
|
info.isChoose = isOn;
|
if (isOn)
|
{
|
if (!chooseMailDict.ContainsKey(info.GUID))
|
{
|
chooseMailDict.Add(info.GUID, info);
|
}
|
else
|
{
|
chooseMailDict[info.GUID] = info;
|
}
|
}
|
else
|
{
|
if (chooseMailDict.ContainsKey(info.GUID))
|
{
|
chooseMailDict.Remove(info.GUID);
|
}
|
}
|
|
foreach (var value in chooseMailDict.Values)
|
{
|
if (value.Count > 0 || value.Gold > 0
|
|| value.GoldPaper > 0
|
|| value.Silver > 0)
|
{
|
ChangeRightBtnUI(value);
|
return;
|
}
|
}
|
|
ChangeRightBtnUI(_currentMailInfo);
|
}
|
|
private void OnClickMailCell(bool isOn, MailInfo info, CellView cell)
|
{
|
if (isOn)
|
{
|
_deleteBtn.interactable = true;
|
_deleteBtn.RemoveAllListeners();
|
_deleteBtn.onClick.AddListener(OnClickDeleteBtn);
|
|
gotGiftImg.SetActive(info.IsRead == 3);
|
|
curMail = cell.index;
|
_currentMailInfo = info;
|
MailAllModel.Instance.GetReciveMailContent(info);
|
_senderMessagerText.text = MailAllModel.Instance.mailSendPersonStr;
|
_titleMessageText.text = MailAllModel.Instance.mailTitleStr;
|
_theTotalTitleText.text = MailAllModel.Instance.mailContentstr;
|
Image noReadIcon = cell.transform.Find("NoReadIcon").GetComponent<Image>();
|
Image readIcon = cell.transform.Find("ReadIcon").GetComponent<Image>();
|
|
#region 刷新右边Ui信息
|
int giftCount = 0;
|
for (giftCount = 0; giftCount < _reciveItemParent.Count; giftCount++)
|
{
|
ItemCell itemCell = _reciveItemParent[giftCount].transform.Find("ItemCell").GetComponent<ItemCell>();
|
if (info.Count > 0 || info.Gold > 0 || info.GoldPaper > 0 || info.Silver > 0)
|
{
|
_deleteBtn.interactable = info.IsRead == 3;
|
_reciveItemParent[giftCount].SetActive(true);
|
_goldBox.SetActive(true);
|
_drillBox.SetActive(true);
|
_fairyJadeBox.SetActive(true);
|
if (giftCount < info.Count)
|
{
|
itemCell.SetActive(true);
|
MailItemModel itemModel = info.Items[giftCount];
|
var userDataDict = ConfigParse.Analysis(itemModel.UserData);
|
ItemCellModel cellModel = new ItemCellModel((int)itemModel.ItemID, false, (ulong)itemModel.Count,
|
"", PackType.Deleted, false, userDataDict);
|
itemCell.Init(cellModel);
|
itemCell.button.onClick.RemoveAllListeners();
|
itemCell.button.onClick.AddListener(() =>
|
{
|
if (itemModel.IsBind == 1 &&
|
ItemLogicUtility.Instance.IsRealmEquip((int)itemModel.ItemID))
|
{
|
ItemTipUtility.Show(new ItemTipUtility.ItemViewInfo()
|
{
|
itemId = (int)itemModel.ItemID,
|
isAuctionEquip = true,
|
score = ItemLogicUtility.Instance.GetEquipScore((int)itemModel.ItemID, userDataDict, true),
|
legendProperty = ItemTipUtility.GetLegendProperty((int)itemModel.ItemID, userDataDict),
|
});
|
}
|
else
|
{
|
ItemTipUtility.Show((int)itemModel.ItemID);
|
}
|
}
|
);
|
}
|
else
|
{
|
itemCell.SetActive(false);
|
}
|
_goldText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(info.Silver).ToString();
|
_drillBoxeText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(info.GoldPaper).ToString();
|
_fairyJadeBoxText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(info.Gold).ToString();
|
|
}
|
else
|
{
|
_reciveItemParent[giftCount].SetActive(false);
|
_goldBox.SetActive(false);
|
_drillBox.SetActive(false);
|
_fairyJadeBox.SetActive(false);
|
}
|
|
}
|
#endregion
|
|
if (info.IsRead == 0)
|
{
|
noReadIcon.SetActive(false);
|
readIcon.SetActive(true);
|
info.IsRead = 1;
|
MailAllModel.Instance.SendReadMailQuest(info.GUID);
|
}
|
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
if (mailModellist[mailCount].isChoose)
|
{
|
if (mailModellist[mailCount].Count > 0 || mailModellist[mailCount].Gold > 0
|
|| mailModellist[mailCount].GoldPaper > 0
|
|| mailModellist[mailCount].Silver > 0)
|
{
|
ChangeRightBtnUI(mailModellist[mailCount]);
|
return;
|
}
|
}
|
}
|
ChangeRightBtnUI(info);
|
}
|
}
|
|
public void ChangeRightBtnUI(MailInfo info)
|
{
|
if ((info.Count > 0 || info.Gold > 0 || info.GoldPaper > 0
|
|| info.Silver > 0) && info.IsRead != 3)
|
{
|
_receiveBtn.interactable = true;
|
_receiveBtn.onClick.RemoveAllListeners();
|
_receiveBtn.onClick.AddListener(
|
delegate
|
{
|
OnClickReceiveBtn();
|
}
|
);
|
}
|
|
else
|
{
|
_receiveBtn.onClick.RemoveAllListeners();
|
_receiveBtn.interactable = false;
|
}
|
|
}
|
|
public void OnClickReceiveBtn()
|
{
|
#region 得到领取的邮件
|
_isChooseMailDict.Clear();
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
if (mailModellist[mailCount].isChoose)
|
{
|
if (!_isChooseMailDict.ContainsKey(mailModellist[mailCount].GUID))
|
{
|
_isChooseMailDict.Add(mailModellist[mailCount].GUID, mailModellist[mailCount]);
|
}
|
}
|
}
|
if (_currentMailInfo != null)
|
{
|
if (!_isChooseMailDict.ContainsKey(_currentMailInfo.GUID))
|
{
|
_isChooseMailDict.Add(_currentMailInfo.GUID, _currentMailInfo);
|
}
|
}
|
|
#endregion
|
|
_chooseMailList = _isChooseMailDict.Values.ToList();
|
DebugEx.Log("OnClickReceiveBtn" + _chooseMailList.Count);
|
if (_chooseMailList.Count > 0)
|
{
|
ReceiveAllChooseMail(0, _chooseMailList[0]);
|
}
|
|
}
|
|
public void OnClickDeleteBtn()
|
{
|
#region 得到删除的邮件
|
|
_isChooseMailDict.Clear();
|
int mailCount = 0;
|
for (mailCount = 0; mailCount < mailModellist.Count; mailCount++)
|
{
|
if (mailModellist[mailCount].isChoose)
|
{
|
if (!_isChooseMailDict.ContainsKey(mailModellist[mailCount].GUID))
|
{
|
_isChooseMailDict.Add(mailModellist[mailCount].GUID, mailModellist[mailCount]);
|
}
|
}
|
}
|
|
if (_currentMailInfo != null)
|
{
|
if (!_isChooseMailDict.ContainsKey(_currentMailInfo.GUID))
|
{
|
_isChooseMailDict.Add(_currentMailInfo.GUID, _currentMailInfo);
|
}
|
}
|
|
#endregion
|
|
_chooseMailList = _isChooseMailDict.Values.ToList();
|
|
if (_chooseMailList.Count > 0)
|
{
|
DeleteAllChooseMail(0, _chooseMailList[0]);
|
}
|
|
}
|
|
|
//使用递归发送请求
|
public void DeleteAllChooseMail(int index, MailInfo deleteCell)
|
{
|
|
DebugEx.Log(index + "比较" + _chooseMailList.Count);
|
_mailState = MailState.Delete;
|
if (index >= _chooseMailList.Count)
|
{
|
_allSelectToggle.isOn = false;
|
OnAllSelectToggle(false);
|
return;
|
}
|
|
if (deleteCell.IsRead == 0 || ((deleteCell.Count > 0 || (int)deleteCell.Gold > 0 || (int)deleteCell.GoldPaper > 0
|
|| (int)deleteCell.Silver > 0) && deleteCell.IsRead != 3))
|
{
|
index += 1;
|
if (index < _chooseMailList.Count)
|
{
|
DebugEx.Log("递归" + index);
|
DeleteAllChooseMail(index, _chooseMailList[index]);
|
}
|
else
|
{
|
DeleteAllChooseMail(index, null);
|
}
|
return;
|
}
|
|
|
MailAllModel.Instance.SendAskDelete(deleteCell.GUID);
|
index += 1;
|
if (index < _chooseMailList.Count)
|
{
|
DebugEx.Log("递归" + index);
|
DeleteAllChooseMail(index, _chooseMailList[index]);
|
}
|
else
|
{
|
DeleteAllChooseMail(index, null);
|
}
|
|
}
|
|
private int _nextReceiveIndex = 0;
|
private int preReceiveIndex = 0;
|
public void ReceiveAllChooseMail(int index, MailInfo receiveCell)
|
{
|
_mailState = MailState.Receive;
|
preReceiveIndex = index;
|
if ((receiveCell.Count > 0 || receiveCell.Gold > 0
|
|| receiveCell.GoldPaper > 0 || receiveCell.Silver > 0) && receiveCell.IsRead != 3)
|
{
|
DebugEx.Log("领取邮件:" + index);
|
MailAllModel.Instance.SendAskReceive(receiveCell.GUID);
|
}
|
|
index += 1;
|
if (index >= _chooseMailList.Count)
|
{
|
_allSelectToggle.isOn = false;
|
OnAllSelectToggle(false);
|
return;
|
}
|
_nextReceiveIndex = index;
|
if (receiveCell.Count <= 0 && receiveCell.Gold <= 0
|
&& receiveCell.GoldPaper <= 0 && receiveCell.Silver <= 0)
|
{
|
ReceiveAllChooseMail(_nextReceiveIndex, _chooseMailList[_nextReceiveIndex]);
|
}
|
|
}
|
|
//由于服务端删除邮件可能有冷却时间所以造成返回的次数不准确
|
public void OnGetReceiveResult(string guId, int result)
|
{
|
DebugEx.Log("OnGetReceiveResult" + result);
|
if (result == 1)
|
{
|
if (_mailState == MailState.Receive)
|
{
|
if (preReceiveIndex != _nextReceiveIndex)
|
{
|
if (_chooseMailList != null && _chooseMailList.Count > _nextReceiveIndex)
|
{
|
ReceiveAllChooseMail(_nextReceiveIndex, _chooseMailList[_nextReceiveIndex]);
|
}
|
}
|
}
|
|
}
|
else
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("Mail103"));
|
}
|
}
|
|
public void OnGetDeleteResult()
|
{
|
curMail = 0;
|
CreateMailCell();
|
}
|
|
|
}
|
}
|