Files
ft/Client/Assets/Scripts/UI/PackPanel/GeneralEventNormalPackCell.cs
2026-06-29 21:18:33 +08:00

72 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using asap.core;
using cfg;
using GameCore;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace UI.PackPanel
{
public class GeneralEventNormalPackCell:MonoBehaviour
{
[SerializeField] private RewardItemNew[] itemList;
[SerializeField] private Button btnPurchase,btnGary;
[SerializeField] private TMP_Text textPrice, textPriceOrigin, textDiscount;
private void Awake()
{
FindUI();
}
private void Reset()
{
FindUI();
}
private void FindUI()
{
itemList=GetComponentsInChildren<RewardItemNew>();
btnPurchase=gameObject.FindChildGameObject("btn_purchase").GetComponentInChildren<Button>();
textPrice=gameObject.FindChildGameObject("p_text").GetComponent<TMP_Text>();
textPrice.text=string.Empty;
btnGary=gameObject.FindChildGameObject("btn_gray")?.GetComponentInChildren<Button>();
textPriceOrigin=gameObject.FindChildGameObject("text_old")?.GetComponent<TMP_Text>();
textDiscount=gameObject.FindChildGameObject("text_num")?.GetComponent<TMP_Text>();
if(textPriceOrigin)
textPriceOrigin.text=string.Empty;
if(textDiscount)
textDiscount.text=string.Empty;
}
private void OnDestroy()
{
btnPurchase.onClick.RemoveAllListeners();
if(btnGary)
btnGary.onClick.RemoveAllListeners();
}
public void Init(string priceStr,List<ItemData> items, Action onClickPurchase ,float rebate=0,string originPrice="",Action onClickGary=null,bool isGary=false)
{
btnPurchase.onClick.RemoveAllListeners();
btnPurchase.onClick.AddListener(() => onClickPurchase?.Invoke());
btnPurchase.transform.parent.gameObject.SetActive(!isGary);
if (btnGary)
{
btnGary.onClick.RemoveAllListeners();
btnGary.onClick.AddListener(() => onClickGary?.Invoke());
btnGary.transform.parent.gameObject.SetActive(isGary);
}
textPrice.text = priceStr;
itemList.SetData(items);
if (textPriceOrigin&&!string.IsNullOrEmpty(originPrice))
textPriceOrigin.text = originPrice;
if(textDiscount&&rebate>0)
textDiscount.text = ConvertTools.GetDiscountStringActual(rebate);
}
}
}