101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishingMailPopupPanel : MonoBehaviour
|
|
{
|
|
Button btn_close;
|
|
Button btn_mask;
|
|
Button btn_delete;
|
|
Button btn_receive;
|
|
GameObject itemPrefab;
|
|
[SerializeField]
|
|
GameObject empty;
|
|
Transform content;
|
|
List<MailSlot> items=new();
|
|
IInGameMailService _mailService;
|
|
|
|
private void Awake()
|
|
{
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
btn_mask = transform.Find("mask").GetComponent<Button>();
|
|
btn_delete = transform.Find("root/btn_delete/btn_green").GetComponent<Button>();
|
|
btn_receive = transform.Find("root/btn_read/btn_green").GetComponent<Button>();
|
|
itemPrefab = transform.Find("root/ScrollView/Viewport/Content/Item1").gameObject;
|
|
content = transform.Find("root/ScrollView/Viewport/Content");
|
|
_mailService=GContext.container.Resolve<IInGameMailService>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_mask.onClick.AddListener(OnClickClose);
|
|
btn_delete.onClick.AddListener(OnClickDelete);
|
|
btn_receive.onClick.AddListener(OnClickReceive);
|
|
itemPrefab.SetActive(false);
|
|
SetData();
|
|
}
|
|
|
|
void SetData()
|
|
{
|
|
if(items != null)
|
|
{
|
|
foreach (var item in items)
|
|
{
|
|
Destroy(item.gameObject);
|
|
}
|
|
items.Clear();
|
|
}
|
|
|
|
var unreadCount = 0;
|
|
var mails = _mailService.GetAllMail();
|
|
|
|
foreach (var mail in mails)
|
|
{
|
|
var mailItem=Instantiate(itemPrefab, content).GetComponent<MailSlot>();
|
|
mailItem.SetData(mail,SetData);
|
|
items.Add(mailItem);
|
|
if(!mail.IsRead || !mail.HasReward)
|
|
unreadCount++;
|
|
}
|
|
|
|
RedPointManager.Instance.SetRedPointState(RedPointName.Unread_Mail, unreadCount > 0, unreadCount);
|
|
|
|
btn_delete.interactable = (mails != null && mails.Count > unreadCount);
|
|
|
|
empty.SetActive(mails == null || mails.Count == 0);
|
|
}
|
|
|
|
private async void OnClickReceive()
|
|
{
|
|
UIManager.ShowWaitingBlock("FishingMailPopupPanel::OnClickReceive");
|
|
await _mailService.FetchMail();
|
|
UIManager.HideWaitingBlock("FishingMailPopupPanel::OnClickReceive");
|
|
SetData();
|
|
}
|
|
|
|
private async void OnClickDelete()
|
|
{
|
|
UIManager.ShowWaitingBlock("FishingMailPopupPanel::OnClickDelete");
|
|
var success = await _mailService.DelMail();
|
|
UIManager.HideWaitingBlock("FishingMailPopupPanel::OnClickDelete");
|
|
if (!success)
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_ErrCode_1"));
|
|
}
|
|
else
|
|
{
|
|
SetData();
|
|
}
|
|
}
|
|
|
|
void OnClickClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishingMailPopupPanel);
|
|
}
|
|
}
|