158 lines
5.0 KiB
C#
158 lines
5.0 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
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<TriggerPackBuyData> triggerPackDic;
|
|
int index = 0;
|
|
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<TMP_Text>();
|
|
}
|
|
protected override void Start()
|
|
{
|
|
triggerPackDic = GContext.container.Resolve<TriggerPackData>().GetTriggerPackList(Type);
|
|
if (triggerPackDic.Count <= 0)
|
|
{
|
|
OnClickClose();
|
|
return;
|
|
}
|
|
triggerPackDic.Sort((a, b) => b.time.CompareTo(a.time));
|
|
index = 0;
|
|
if (curRedirectID > 0)
|
|
{
|
|
for (int i = 0; i < triggerPackDic.Count; i++)
|
|
{
|
|
if (triggerPackDic[i].ID == curRedirectID)
|
|
{
|
|
index = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
base.Start();
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
SetTriggerPackTimer();
|
|
}
|
|
void Init()
|
|
{
|
|
allCount = triggerPackDic.Count;
|
|
if (allCount <= 0)
|
|
{
|
|
OnClickClose();
|
|
return;
|
|
}
|
|
if (index >= allCount)
|
|
{
|
|
index = 0;
|
|
}
|
|
|
|
SetData();
|
|
}
|
|
protected virtual void SetPack()
|
|
{
|
|
int vipLevel = curTriggerPackState.vipLevel;
|
|
int buyCount = GContext.container.Resolve<PlayerShopData>().GetShopPackBuyCount(curTriggerPackState.lastID);
|
|
List<int> 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[index];
|
|
int id = curTriggerPackState.ID;
|
|
packManager = _tables.TbTriggerPackManager.GetOrDefault(id);
|
|
SetPack();
|
|
iAPItemList = _tables.TbIAPItemList.GetOrDefault(pack.IAPID);
|
|
itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(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<TriggerPackData>().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<TriggerPackData>().AddTriggerPackCount(packManager.ID);
|
|
triggerPackDic.Remove(curTriggerPackState);
|
|
Init();
|
|
}
|
|
protected override void OnBuySuccess()
|
|
{
|
|
//GContext.container.Resolve<TriggerPackData>().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<TriggerPackData>().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 });
|
|
}
|
|
}
|