using asap.core; using cfg; using GameCore; using System; using System.Collections.Generic; using TMPro; using UnityEngine; public class GiftPopupPanel_Energy : GiftPopupPanel { protected virtual int Type => 1; protected TriggerPackManager packManager; protected TriggerPackBuyData curTriggerPackState; List triggerPackDic; int allCount = 0; TMP_Text txt_packName; protected override void Awake() { base.Awake(); Transform text_title = transform.Find("root/text_title"); txt_packName = text_title?.GetComponent(); } protected override void Start() { triggerPackDic = GContext.container.Resolve().GetTriggerPackList(Type); if (triggerPackDic.Count <= 0) { OnClickClose(); return; } base.Start(); btn_close.onClick.AddListener(OnClickClose); SetTriggerPackTimer(); } void Init() { allCount = triggerPackDic.Count; if (allCount <= 0) { OnClickClose(); return; } SetData(); } protected virtual void SetPack() { int vipLevel = curTriggerPackState.vipLevel; int buyCount = GContext.container.Resolve().GetShopPackBuyCount(curTriggerPackState.lastID); List VIPPackList = packManager.VIPPackList[vipLevel]; if (buyCount > VIPPackList.Count) { buyCount = VIPPackList.Count; } else if (buyCount <= 0) { buyCount = 1; } pack = _tables.TbPack.GetOrDefault(VIPPackList[buyCount - 1]); } public void SetData() { curTriggerPackState = triggerPackDic[0]; int id = curTriggerPackState.ID; packManager = _tables.TbTriggerPackManager.GetOrDefault(id); SetPack(); iAPItemList = _tables.TbIAPItemList.GetOrDefault(pack.IAPID); itemDatas = GContext.container.Resolve().GetItemDataByDropIdAndTypeLureInflation(null, pack.DropID); SetShowData(); SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iAPItemList); GContext.Publish(sKUDetailDataEvent); text_buy.text = sKUDetailDataEvent.price; tag_more.SetActive(pack.Rebate > 0.01); text_best.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_2", (pack.Rebate * 100).ToString("F0")); //Remaining.gameObject.SetActive(false); TimeSpan now = GContext.container.Resolve().GetCurTriggerPackEndTime(curTriggerPackState); if (now.TotalSeconds < 0) { triggerPackDic.Remove(curTriggerPackState); Init(); } text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds); if (txt_packName != null) { txt_packName.text = LocalizationMgr.GetText(pack.Title_l10n_key); } } protected override ShopBuyTypeData GetShopBuyTypeData() { ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData(); shopBuyTypeData.type = ShopBuyType.TriggerPack; shopBuyTypeData.ID = packManager.ID; return shopBuyTypeData; } protected override void OnSuccess() { GContext.container.Resolve().AddTriggerPackCount(packManager.ID); triggerPackDic.Remove(curTriggerPackState); Init(); } protected override void OnBuySuccess() { //GContext.container.Resolve().AddTriggerPackCount(packManager.ID); triggerPackDic.Remove(curTriggerPackState); Init(); } public async void SetTriggerPackTimer() { Init(); DateTime dateTime = ZZTimeHelper.UtcNow().UtcNowOffset(); DateTime dateTime1 = dateTime.AddDays(1).Date; while (this != null && dateTime.Ticks < dateTime1.Ticks) { TimeSpan now = GContext.container.Resolve().GetCurTriggerPackEndTime(curTriggerPackState); if (now.TotalSeconds < 0) { triggerPackDic.Remove(curTriggerPackState); Init(); } text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds); await System.Threading.Tasks.Task.Delay(1000); dateTime.AddSeconds(1); } if (this != null && dateTime.Ticks >= dateTime1.Ticks) { SetTriggerPackTimer(); } } protected virtual void OnClickClose() { GContext.Publish(new GiftPopupPanelEnergyEvent { isClose = true }); } }