备份CatanBuilding瘦身独立工程
This commit is contained in:
144
Assets/Scripts/UI/Shop/GiftPopupItem.cs
Normal file
144
Assets/Scripts/UI/Shop/GiftPopupItem.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GiftPopupItem : MonoBehaviour
|
||||
{
|
||||
Tables _tables;
|
||||
Transform rewardRoot;
|
||||
List<RewardItemNew> items = new List<RewardItemNew>();
|
||||
public List<ItemData> itemData;
|
||||
public Pack pack;
|
||||
public IAPItemList iAPItemList;
|
||||
public int dataIndex;
|
||||
Button btn_buy;
|
||||
TMP_Text text_buy;
|
||||
GameObject done;
|
||||
GameObject arrow;
|
||||
Action OnBuySuccess;
|
||||
GameObject lockGo;
|
||||
RectTransform rectTransform;
|
||||
int isDone;
|
||||
GameObject bg1;
|
||||
GameObject bg2;
|
||||
GameObject light1;
|
||||
GameObject light2;
|
||||
private void Awake()
|
||||
{
|
||||
rewardRoot = transform.Find("reward");
|
||||
int count = rewardRoot.childCount;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
items.Add(rewardRoot.GetChild(i).GetComponent<RewardItemNew>());
|
||||
}
|
||||
btn_buy = transform.Find("btn_buy/btn_green").GetComponent<Button>();
|
||||
text_buy = transform.Find("btn_buy/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
done = transform.Find("done").gameObject;
|
||||
arrow = transform.Find("arrow").gameObject;
|
||||
lockGo = transform.Find("btn_buy/btn_green/lock").gameObject;
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
bg1 = transform.Find("bg1").gameObject;
|
||||
bg2 = transform.Find("bg2").gameObject;
|
||||
light1 = transform.Find("light1").gameObject;
|
||||
light2 = transform.Find("light2").gameObject;
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
btn_buy.onClick.AddListener(OnBuy);
|
||||
}
|
||||
public void SetData(Action action, int packId, int isDone, int dataIndex, int index)
|
||||
{
|
||||
this.dataIndex = dataIndex;
|
||||
arrow.SetActive(index > 0);
|
||||
done.SetActive(isDone == 0);
|
||||
btn_buy.gameObject.SetActive(isDone != 0);
|
||||
this.isDone = isDone;
|
||||
lockGo.SetActive(isDone == 2);
|
||||
pack = _tables.TbPack.GetOrDefault(packId);
|
||||
iAPItemList = _tables.TbIAPItemList.GetOrDefault(pack.IAPID);
|
||||
itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(pack.DropID);
|
||||
|
||||
int itemCount = itemData.Count;
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i].gameObject.SetActive(i < itemCount);
|
||||
if (i < itemCount)
|
||||
{
|
||||
items[i].SetData(itemData[i]);
|
||||
items[i].SetReceived(isDone == 0);
|
||||
}
|
||||
}
|
||||
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iAPItemList);
|
||||
GContext.Publish(sKUDetailDataEvent);
|
||||
text_buy.text = sKUDetailDataEvent.price;
|
||||
this.OnBuySuccess = action;
|
||||
bool isOne = dataIndex % 2 == 0;
|
||||
bg1.SetActive(isOne && isDone != 1);
|
||||
bg2.SetActive(!isOne && isDone != 1);
|
||||
light1.SetActive(isOne && isDone == 1);
|
||||
light2.SetActive(!isOne && isDone == 1);
|
||||
}
|
||||
public void SetReceived()
|
||||
{
|
||||
int itemCount = itemData.Count;
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
items[i].SetReceived(true);
|
||||
}
|
||||
}
|
||||
public void PlayMove(int index)
|
||||
{
|
||||
rectTransform.DOKill();
|
||||
rectTransform.anchoredPosition = Vector3.down * rectTransform.rect.height;
|
||||
rectTransform.DOAnchorPosY(0, 0.5f).SetEase(Ease.Linear);
|
||||
//await Awaiters.Seconds(0.5f);
|
||||
//if (index == 0)
|
||||
//{
|
||||
// arrow.SetActive(false);
|
||||
//}
|
||||
}
|
||||
async void OnBuy()
|
||||
{
|
||||
if (isDone == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (isDone == 2)
|
||||
{
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_30"));
|
||||
}
|
||||
if (GContext.container.Resolve<PlayerShopData>().ChainPackData.index == dataIndex)
|
||||
{
|
||||
btn_buy.onClick.RemoveAllListeners();
|
||||
if (iAPItemList == null)
|
||||
{
|
||||
GContext.Publish(new ShowData(itemData, RewardType.Normal));
|
||||
GContext.container.Resolve<PlayerItemData>().AddItem(itemData);
|
||||
GContext.Publish(new ShowData());
|
||||
GContext.container.Resolve<PlayerShopData>().AddOpenChainGifIndex();
|
||||
OnBuySuccess?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
|
||||
shopBuyTypeData.type = ShopBuyType.EventPack;
|
||||
shopBuyTypeData.ID = GContext.container.Resolve<PlayerShopData>().ChainPackData.ID;
|
||||
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(pack.DropID, shopBuyTypeData, iAPItemList, itemData, RewardType.Normal);
|
||||
if (Result)
|
||||
{
|
||||
OnBuySuccess?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
btn_buy.onClick.AddListener(OnBuy);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user