备份CatanBuilding瘦身独立工程
This commit is contained in:
114
Assets/Scripts/UI/Mail/FishingMailInfoPopupPanel.cs
Normal file
114
Assets/Scripts/UI/Mail/FishingMailInfoPopupPanel.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FishingMailInfoPopupPanel : MonoBehaviour
|
||||
{
|
||||
Button btn_close;
|
||||
Button btn_mask;
|
||||
TMP_Text text_title;
|
||||
TMP_Text text_content;
|
||||
TMP_Text text_end;
|
||||
RewardItemNew[] rewardSlot;
|
||||
Button btn_receive;
|
||||
Button btn_delete;
|
||||
GameMail _mail;
|
||||
|
||||
IInGameMailService _mailService;
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform mailBody;
|
||||
[SerializeField]
|
||||
private RectTransform rewardRect;
|
||||
|
||||
private PlayerItemData _playerItemData;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
||||
btn_mask = transform.Find("mask").GetComponent<Button>();
|
||||
text_title = transform.Find("root/text_title").GetComponent<TMP_Text>();
|
||||
text_content = transform.Find("root/ScrollView/Viewport/Content/text_content").GetComponent<TMP_Text>();
|
||||
text_end = transform.Find("root/ScrollView/Viewport/Content/text_end").GetComponent<TMP_Text>();
|
||||
rewardSlot = transform.Find("root/reward").GetComponentsInChildren<RewardItemNew>();
|
||||
btn_receive = transform.Find("root/btn_receive/btn_green").GetComponent<Button>();
|
||||
btn_delete = transform.Find("root/btn_delete/btn_green").GetComponent<Button>();
|
||||
_mailService=GContext.container.Resolve<IInGameMailService>();
|
||||
_playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
btn_mask.onClick.AddListener(OnClickClose);
|
||||
btn_receive.onClick.AddListener(OnClickReceive);
|
||||
btn_delete.onClick.AddListener(OnClickDelete);
|
||||
}
|
||||
|
||||
private Action refreshMailList;
|
||||
public void SetData(GameMail mail, Action refreshMailList)
|
||||
{
|
||||
this.refreshMailList = refreshMailList;
|
||||
_mail = mail;
|
||||
text_title.text = _mail.Title;
|
||||
text_content.text = _mail.Content;
|
||||
text_end.text = _mail.From;
|
||||
for ( int i = 0; i < rewardSlot.Length; i++ )
|
||||
{
|
||||
rewardSlot[i].gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (mail.HasDrops)
|
||||
{
|
||||
// var rewardItems = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(mail.DropIds[0]);
|
||||
var rewardItems = _playerItemData.GetItemDataByDropList(mail.DropIds.ToList());
|
||||
for ( int i = 0; i < rewardSlot.Length; i++ )
|
||||
{
|
||||
if ( i < rewardItems.Count )
|
||||
{
|
||||
rewardSlot[i].SetData(rewardItems[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var mailBodySize = new Vector2(mailBody.rect.width, mailBody.rect.height + rewardRect.rect.height);
|
||||
mailBody.sizeDelta = mailBodySize;
|
||||
rewardRect.gameObject.SetActive(false);
|
||||
}
|
||||
SetState();
|
||||
}
|
||||
|
||||
private void SetState()
|
||||
{
|
||||
btn_delete.transform.parent.gameObject.SetActive(_mail.HasReward);
|
||||
btn_receive.transform.parent.gameObject.SetActive(!_mail.HasReward);
|
||||
}
|
||||
|
||||
private async void OnClickDelete()
|
||||
{
|
||||
if (await _mailService.DelMail(_mail))
|
||||
{
|
||||
OnClickClose();
|
||||
}
|
||||
}
|
||||
private async void OnClickReceive()
|
||||
{
|
||||
UIManager.ShowWaitingBlock("FishingMailInfoPopupPanel::OnClickReceive");
|
||||
if (await _mailService.TakeReward(_mail))
|
||||
{
|
||||
SetState();
|
||||
}
|
||||
UIManager.HideWaitingBlock("FishingMailInfoPopupPanel::OnClickReceive");
|
||||
}
|
||||
|
||||
void OnClickClose()
|
||||
{
|
||||
refreshMailList?.Invoke();
|
||||
UIManager.Instance.DestroyUI(UITypes.FishingMailInfoPopupPanel);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Mail/FishingMailInfoPopupPanel.cs.meta
Normal file
11
Assets/Scripts/UI/Mail/FishingMailInfoPopupPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f5aec7ee9ab0054187b5ebf92468099
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
100
Assets/Scripts/UI/Mail/FishingMailPopupPanel.cs
Normal file
100
Assets/Scripts/UI/Mail/FishingMailPopupPanel.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Mail/FishingMailPopupPanel.cs.meta
Normal file
11
Assets/Scripts/UI/Mail/FishingMailPopupPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f7cea6046fe3774f9c7f856c219e78f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
155
Assets/Scripts/UI/Mail/MailSlot.cs
Normal file
155
Assets/Scripts/UI/Mail/MailSlot.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MailSlot : MonoBehaviour
|
||||
{
|
||||
public TMP_Text
|
||||
text_name,
|
||||
text_info,
|
||||
text_expireTime,
|
||||
text_time;
|
||||
|
||||
Head btn_head;
|
||||
|
||||
GameObject
|
||||
go_normal,
|
||||
go_normalDone,
|
||||
go_reward,
|
||||
go_rewardDone,
|
||||
go_bg,
|
||||
go_bg_done;
|
||||
|
||||
Button btn;
|
||||
GameMail data;
|
||||
|
||||
private static TimeSpan _MaxExpireTime = TimeSpan.FromDays(400);
|
||||
private static TimeSpan _CountDownTime = TimeSpan.FromDays(1);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
text_name = transform.Find("info/text_name").GetComponent<TMP_Text>();
|
||||
text_info = transform.Find("info/text_info").GetComponent<TMP_Text>();
|
||||
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
||||
text_expireTime= transform.Find("text_overdue").GetComponent<TMP_Text>();
|
||||
btn_head = transform.Find("btn_head").GetComponent<Head>();
|
||||
go_normal = transform.Find("icon_mail").gameObject;
|
||||
go_normalDone = transform.Find("icon_mail_done").gameObject;
|
||||
go_reward = transform.Find("icon_gift").gameObject;
|
||||
go_rewardDone = transform.Find("icon_gift_done").gameObject;
|
||||
go_bg = transform.Find("bg").gameObject;
|
||||
go_bg_done = transform.Find("bg_done").gameObject;
|
||||
btn=transform.transform.Find("btn").GetComponent<Button>();
|
||||
btn_head.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btn.OnClickAsObservable().Subscribe(_ => OnClick()).AddTo(this);
|
||||
}
|
||||
|
||||
async void OnClick()
|
||||
{
|
||||
bool canOpen = false;
|
||||
|
||||
if(!data.IsRead)
|
||||
{
|
||||
UIManager.ShowWaitingBlock("MailSlot::OnClick");
|
||||
var mailService = GContext.container.Resolve<IInGameMailService>();
|
||||
if (await mailService.MarkRead(data))
|
||||
{
|
||||
SetState();
|
||||
canOpen = true;
|
||||
}
|
||||
UIManager.HideWaitingBlock("MailSlot::OnClick");
|
||||
}
|
||||
else
|
||||
{
|
||||
canOpen = true;
|
||||
}
|
||||
|
||||
if(canOpen)
|
||||
{
|
||||
var mailInfoPanel = await UIManager.Instance.ShowUI(UITypes.FishingMailInfoPopupPanel);
|
||||
mailInfoPanel.GetComponent<FishingMailInfoPopupPanel>().SetData(data, refreshMailList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Action refreshMailList;
|
||||
public void SetData(GameMail data, Action refreshMailList)
|
||||
{
|
||||
this.refreshMailList = refreshMailList;
|
||||
this.data = data;
|
||||
gameObject.SetActive(true);
|
||||
text_name.text = data.Title;
|
||||
SetState();
|
||||
SetTimer();
|
||||
}
|
||||
|
||||
private void SetTimer()
|
||||
{
|
||||
var utcNowOffset = ZZTimeHelper.UtcNow();
|
||||
text_time.text = LocalizationMgr.GetFormatTextValue("UI_FishingMailPopupPanel_6", ConvertTools.ConvertTime3(utcNowOffset - data.SendTime));
|
||||
|
||||
var expireTime = data.ExpireTime - utcNowOffset;
|
||||
if (expireTime > _MaxExpireTime)
|
||||
text_expireTime.text = string.Empty;
|
||||
else
|
||||
text_expireTime.text = LocalizationMgr.GetFormatTextValue("UI_FishingMailPopupPanel_5", ConvertTools.ConvertTime3(expireTime));
|
||||
|
||||
if(expireTime > _CountDownTime)
|
||||
{
|
||||
|
||||
Observable.Interval(TimeSpan.FromSeconds(1))
|
||||
.TakeWhile( _=>data.ExpireTime>= utcNowOffset)
|
||||
.Subscribe(_ => {
|
||||
text_time.text = LocalizationMgr.GetFormatTextValue("UI_FishingMailPopupPanel_6", ConvertTools.ConvertTime3(utcNowOffset - data.SendTime));
|
||||
text_expireTime.text = LocalizationMgr.GetFormatTextValue("UI_FishingMailPopupPanel_5", ConvertTools.ConvertTime3(data.ExpireTime - utcNowOffset));
|
||||
},
|
||||
_=>{
|
||||
gameObject.SetActive(false);
|
||||
}).AddTo(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SetState()
|
||||
{
|
||||
if (data.IsDeleted)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
if (data.HasDrops)
|
||||
{
|
||||
go_normal.SetActive(false);
|
||||
go_normalDone.SetActive(false);
|
||||
|
||||
go_reward.SetActive(!data.HasReward);
|
||||
go_rewardDone.SetActive(data.HasReward);
|
||||
|
||||
go_bg.SetActive(!data.HasReward);
|
||||
go_bg_done.SetActive(data.HasReward);
|
||||
}
|
||||
else
|
||||
{
|
||||
go_reward.SetActive(false);
|
||||
go_rewardDone.SetActive(false);
|
||||
|
||||
go_normal.SetActive(!data.IsRead);
|
||||
go_normalDone.SetActive(data.IsRead);
|
||||
|
||||
go_bg.SetActive(!data.IsRead);
|
||||
go_bg_done.SetActive(data.IsRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/Mail/MailSlot.cs.meta
Normal file
11
Assets/Scripts/UI/Mail/MailSlot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8eded8edd6d44d74985b1cf541aa6d28
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user