Files
MinFt/Client/Assets/Scripts/UI/Shop/GiftPopupPanel_2.cs
2026-04-27 12:07:32 +08:00

108 lines
3.3 KiB
C#

using asap.core;
using cfg;
using game;
using GameCore;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UniRx;
public class GiftPopupPanel_2 : MonoBehaviour
{
//public Button btn_mask;
public Button btn_close;
public TMP_Text text_time;
List<GiftPopupItem> giftPopupItems = new List<GiftPopupItem>();
GiftPopupItem curData;
private void Awake()
{
//btn_mask = transform.Find("mask").GetComponent<Button>();
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
text_time = transform.Find("root/text_time").GetComponent<TMP_Text>();
giftPopupItems.Capacity = 3;
for (int i = 1; i < 4; i++)
{
giftPopupItems.Add(transform.Find($"root/Content/gift{i}/Item").GetComponent<GiftPopupItem>());
}
GContext.OnEvent<RewardPanelClose>().Subscribe(_ => SetData()).AddTo(this);
}
protected void Start()
{
//btn_mask.onClick.AddListener(OnClickClose);
btn_close.onClick.AddListener(OnClickClose);
SetEndTime();
SetData();
}
void OnBuySuccess()
{
//GContext.container.Resolve<PlayerShopData>().AddOpenChainGifIndex();
curData.SetReceived();
//await Awaiters.Seconds(0.5f);
//SetData();
}
private void SetData()
{
List<int> items = new List<int>();
PlayerShopData playerShopData = GContext.container.Resolve<PlayerShopData>();
int curIndex = playerShopData.ChainPackData.index;
int vipLevel = playerShopData.ChainPackData.lastID;
EventPackManager chainGiftPack = playerShopData.chainPackM;
if (chainGiftPack == null)
{
OnClickClose();
return;
}
List<int> packIDs = chainGiftPack.VIPPackList[vipLevel];
int startIndex = curIndex;
if (curIndex > packIDs.Count - 3)
{
startIndex = packIDs.Count - 3;
}
else
{
for (int i = 0; i < 3; i++)
{
giftPopupItems[i].PlayMove(i);
}
}
int isDone = 1;
for (int i = 0; i < 3; i++)
{
if (startIndex + i == curIndex)
{
isDone = 1;
curData = giftPopupItems[i];
}
else if (startIndex + i < curIndex)
{
isDone = 0;
}
else
{
isDone = 2;
}
giftPopupItems[i].SetData(OnBuySuccess, packIDs[startIndex + i], isDone, startIndex + i, i);
}
}
void SetEndTime()
{
DateTime endTime = GContext.container.Resolve<PlayerShopData>().GetChainEndTime();
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
double seconds = now.TotalSeconds;
this.AttachTimer((float)seconds,
() => { OnClickClose(); },
(elapsed) =>
{
now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
}, useRealTime: true);
}
void OnClickClose()
{
UIManager.Instance.DestroyUI(gameObject.name);
//GContext.container.Resolve<IFaceUIService>().ShowFaceUI();
}
}