Files
back_cantanBuilding/Assets/Scripts/UI/Buff/FishingBuffInfoPopupPanel.cs
2026-05-26 16:15:54 +08:00

87 lines
2.9 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System;
using UnityEngine;
using UnityEngine.UI;
public class FishingBuffInfoPopupPanel : MonoBehaviour
{
Timer buff_timer;
BuffInfoPopup buffInfoPopup;
Button btn_close;
private void Start()
{
btn_close = transform.Find("btn_close").GetComponent<Button>();
btn_close.onClick.AddListener(Close);
}
public void InitPanel(FishBuff buff)
{
Transform root = transform.Find("root");
for (int i = 0; i < root.childCount; i++)
{
GameObject gameObj = root.GetChild(i).gameObject;
gameObj.SetActive(gameObj.name == buff.RemarkNode);
if (gameObj.name == buff.RemarkNode)
{
buffInfoPopup = gameObj.GetComponent<BuffInfoPopup>();
}
}
if (buffInfoPopup != null)
{
buffInfoPopup.InitPanel(buff);
buff_timer?.Cancel();
buffInfoPopup.SetBuffTime(LocalizationMgr.GetFormatTextValue("UI_COMMON_min", buff.CountDown / 60));
}
}
public void InitPanel(FishBuffTimeData buffTimeData)
{
FishBuff buff = GContext.container.Resolve<Tables>().TbFishBuff.GetOrDefault(buffTimeData.buffID);
Transform root = transform.Find("root");
for (int i = 0; i < root.childCount; i++)
{
GameObject gameObj = root.GetChild(i).gameObject;
gameObj.SetActive(gameObj.name == buff.RemarkNode);
if (gameObj.name == buff.RemarkNode)
{
buffInfoPopup = gameObj.GetComponent<BuffInfoPopup>();
}
}
if (buffInfoPopup != null)
{
buffInfoPopup.InitPanel(buff);
var buffTime = buffTimeData.buffEndTime - ZZTimeHelper.UtcNow().UtcNowOffset();
buff_timer?.Cancel();
double seconds = buffTime.TotalSeconds;
TimeSpan now = buffTimeData.buffEndTime - ZZTimeHelper.UtcNow().UtcNowOffset();
buffInfoPopup.SetBuffTime(ConvertTools.ConvertTime2(now));
buff_timer = this.AttachTimer((float)seconds,
() => { Close(); },
(elapsed) =>
{
if (buffTimeData.isEnd)
{
Close();
return;
}
now = buffTimeData.buffEndTime - ZZTimeHelper.UtcNow().UtcNowOffset();
if (now.TotalSeconds <= 0)
{
Close();
return;
}
buffInfoPopup.SetBuffTime(ConvertTools.ConvertTime2(now));
}, useRealTime: true);
}
}
void Close()
{
UIManager.Instance.DestroyUI(UITypes.FishingBuffInfoPopupPanel);
}
private void OnDestroy()
{
buff_timer?.Cancel();
buff_timer = null;
}
}