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

103 lines
5.0 KiB
C#

using System;
using TMPro;
using UniRx;
using UnityEngine.UI;
using cfg;
using asap.core;
using GameCore;
using UnityEngine;
using game;
using System.Collections.Generic;
public class GiftPiggyBankPopupPanel : BasePanel
{
private TMP_Text _textTimer, _textPrice, _textPriceGray,
_textBubbleFull, _textBubbleNormal, _textBarEnd, _textBarMid;
private Image _progressBar;
private Tables _tables;
private Button _btnBuy, _btnClose, _btnInfo, _btnBuyGray;
private GameObject _bubbleNormal, _bubbleFull, _textContentNormal, _textContentFull, _tagFull, text_info;
private PiggyBankPackData _pbpd;
private IAPItemList _iap;
private void Awake()
{
#region UI
_textTimer = transform.Find("root/text_time").GetComponent<TMP_Text>();
_progressBar = transform.Find("root/bg_bar/bar").GetComponent<Image>();
_btnBuy = transform.Find("root/btn_buy/btn_green").GetComponent<Button>();
_btnBuyGray = transform.Find("root/btn_buy_gray/btn_green").GetComponent<Button>();
_textPrice = transform.Find("root/btn_buy/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
_textPriceGray = transform.Find("root/btn_buy_gray/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
_btnClose = transform.Find("root/btn_close").GetComponent<Button>();
_btnInfo = transform.Find("root/btn_questionmark").GetComponent<Button>();
_tagFull = transform.Find("root/tag_full").gameObject;
text_info = transform.Find("root/text_info").gameObject;
_bubbleNormal = transform.Find("root/bubble_normal").gameObject;
_bubbleFull = transform.Find("root/bubble_full").gameObject;
_textBubbleNormal = transform.Find("root/bubble_normal/resin1/text_num").GetComponent<TMP_Text>();
_textBubbleFull = transform.Find("root/bubble_full/resin1/text_num").GetComponent<TMP_Text>();
_textContentNormal = transform.Find("root/text_content1").gameObject;
_textContentFull = transform.Find("root/text_content2").gameObject;
_textBarMid = transform.Find("root/bg_bar/reward2/text_num").GetComponent<TMP_Text>();
_textBarEnd = transform.Find("root/bg_bar/reward3/text_num").GetComponent<TMP_Text>();
#endregion
#region config
_tables = GContext.container.Resolve<Tables>();
_pbpd = GContext.container.Resolve<PiggyBankPackData>();
#endregion
}
protected override void Start()
{
_pbpd.DoNeedUpdate = false;
_textTimer.text = ConvertTools.ConvertTime2(_pbpd.RemainingTime);
Observable.Interval(TimeSpan.FromSeconds(1.0f))
.Subscribe(_ => { _textTimer.text = ConvertTools.ConvertTime2(_pbpd.RemainingTime); })
.AddTo(this);
_btnClose.onClick.AddListener(() => UIManager.Instance.DestroyUI(UITypes.GiftPiggyBankPopupPanel));
_btnInfo.onClick.AddListener(
async () => await UIManager.Instance.ShowUI(UITypes.GiftPiggyBankInfoPopupPanel));
_btnBuy.onClick.AddListener(async () => { await OnClickBuy(); });
_btnBuyGray.onClick.AddListener(() =>
{ ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_ToastPanel_72", _pbpd.CanBuyCount)); });
_textBubbleNormal.text = _pbpd.Progress.ToString();
_textBubbleFull.text = _pbpd.Progress.ToString();
bool isCanBuy = _pbpd.Progress >= _pbpd.CanBuyCount;
_bubbleNormal.SetActive(!isCanBuy);
_bubbleFull.SetActive(isCanBuy);
_tagFull.SetActive(_pbpd.IsFull);
_textContentNormal.SetActive(!_pbpd.IsFull);
_textContentFull.SetActive(_pbpd.IsFull);
text_info.SetActive(isCanBuy);
_btnBuy.gameObject.SetActive(isCanBuy);
_btnBuyGray.gameObject.SetActive(!isCanBuy);
int IAPID = _tables.TbSpecialPack[_tables.TbEventPackManager[_pbpd.RedirectID].VIPPackList[_pbpd.VIPLvlWhenEventActivated][0]].IAPID[0];
_iap = _tables.TbIAPItemList.GetOrDefault(IAPID);
//Debug.Log($"iap: {_iap}");
SKUDetailDataEvent sdde = new SKUDetailDataEvent(_iap);
GContext.Publish(sdde);
_textPrice.text = sdde.price;
_textPriceGray.text = sdde.price;
_textBarMid.text = _pbpd.CanBuyCount.ToString();
_textBarEnd.text = _pbpd.Target.ToString();
_progressBar.fillAmount = (float)_pbpd.Progress / (float)_pbpd.Target;
oldPanelName = panelName;
base.Start();
}
private async System.Threading.Tasks.Task OnClickBuy()
{
List<ItemData> itemDatas = GContext.container.Resolve<PlayerItemData>()
.GetItemDataByDropId(_pbpd.RewardDropID);
itemDatas[0].count = _pbpd.Progress;
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
shopBuyTypeData.type = ShopBuyType.EventPack;
shopBuyTypeData.ID = _pbpd.CurrentEventID;
bool res = await GContext.container.Resolve<PlayerShopData>()
.OnBuy(_pbpd.RewardDropID,shopBuyTypeData, _iap, itemDatas);
if (res)
{
//_pbpd.AddPurchase();
UIManager.Instance.DestroyUI(UITypes.GiftPiggyBankPopupPanel);
}
}
}