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

89 lines
3.6 KiB
C#

using asap.core;
using cfg;
using GameCore;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UniRx;
using System;
using game;
public class GiftRodSelectionPopupPanel : BasePanel
{
#region UI
private Button _btnBuy, _btnClose, _btnSelect;
private TMP_Text _textTimer, _textPrice, _textRemain;
private GiftRewardAttached _rewards;
#endregion
#region config
private Tables _tables;
private RodSelectionPackData _rspd;
#endregion
private IAPItemList _iap;
private void Awake()
{
#region UI
_btnBuy = transform.Find("root/btn_buy/btn_green").GetComponent<Button>();
_btnClose = transform.Find("root/btn_close").GetComponent<Button>();
_btnSelect = transform.Find("root/reward_4/gift1/btn_selection").GetComponent<Button>();
_textTimer = transform.Find("root/text_time").GetComponent<TMP_Text>();
_textPrice = transform.Find("root/btn_buy/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
_rewards = transform.Find("root/reward_4").GetComponent<GiftRewardAttached>();
_textRemain = transform.Find("root/text_remaining").GetComponent<TMP_Text>();
#endregion
#region config
_tables = GContext.container.Resolve<Tables>();
_rspd = GContext.container.Resolve<RodSelectionPackData>();
#endregion
}
protected override void Start()
{
_btnClose.onClick.AddListener(() => UIManager.Instance.DestroyUI(UITypes.GiftRodSelectionPopupPanel));
_textTimer.text = ConvertTools.ConvertTime2(_rspd.RemainingTime);
Observable.Interval(TimeSpan.FromSeconds(1.0f))
.Subscribe(_ => { _textTimer.text = ConvertTools.ConvertTime2(_rspd.RemainingTime); })
.AddTo(this);
GContext.OnEvent<GiftRodSelectEvent>()
.Subscribe(e => { _rewards.SetData(_rspd.RewardList); })
.AddTo(this);
GContext.Publish(new GiftRodSelectEvent(_rspd.RodID));
//_rewards.SetData(_rspd.RewardList);
_textRemain.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_1",
_rspd.MaxPurchaseCount - _rspd.PurchaseCount, _rspd.MaxPurchaseCount);
//_textRemain.text = $"Remaining: {_rspd.MaxPurchaseCount - _rspd.PurchaseCount}/{_rspd.MaxPurchaseCount}";
_iap = _tables.TbIAPItemList.GetOrDefault(_rspd.IAPID);
//Debug.Log($"_iap: {_iap}");
SKUDetailDataEvent sdde = new SKUDetailDataEvent(_iap);
GContext.Publish(sdde);
_textPrice.text = sdde.price;
_btnBuy.onClick.AddListener(async () => await OnClickBuy());
_btnSelect.onClick.AddListener(async () => await OpenSelectPanel());
}
private async System.Threading.Tasks.Task OnClickBuy()
{
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
shopBuyTypeData.type = ShopBuyType.EventPack;
shopBuyTypeData.ID = _rspd.CurrentEventID;
bool res = await GContext.container.Resolve<PlayerShopData>().OnBuy(_rspd.DropID, shopBuyTypeData, _iap, _rspd.RewardList);
if (res)
{
//_rspd.AddPurchase();
UIManager.Instance.DestroyUI(UITypes.GiftRodSelectionPopupPanel);
}
}
private async System.Threading.Tasks.Task OpenSelectPanel()
{
GameObject selectPanel = await UIManager.Instance.ShowUI(UITypes.GiftRodSelectePopupPanel);
//selectPanel.GetComponent<GiftRodSelectePopupPanel>()
// .OnGameObjectDestroy += () => _rewards.SetData(_rspd.RewardList);
}
}
public struct GiftRodSelectEvent
{
public int RodID;
public GiftRodSelectEvent(int id)
{
RodID = id;
}
}