131 lines
4.8 KiB
C#
131 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UI.PackPanel
|
|
{
|
|
public class GeneralEventNormalAndFreePackPanel:BasePanel
|
|
{
|
|
private GeneralEventNormalPackCell[] _packCells;
|
|
private TMP_Text _textTime;
|
|
private Button _btnClose;
|
|
private Tables Tables=>GContext.container.Resolve<Tables>();
|
|
|
|
private void Awake()
|
|
{
|
|
_textTime = gameObject.FindChildGameObject("text_time").GetComponent<TextMeshProUGUI>();
|
|
_packCells = gameObject.GetComponentsInChildren<GeneralEventNormalPackCell>();
|
|
_btnClose = gameObject.FindChildGameObject("btn_close").GetComponent<Button>();
|
|
_btnClose.onClick.AddListener(OnClickClose);
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
_btnClose.onClick.RemoveListener(OnClickClose);
|
|
}
|
|
|
|
private void UpdateEventTime()
|
|
{
|
|
if (!_textTime) return;
|
|
_textTime.text = ConvertTools.ConvertTime2(_remainingTime);
|
|
}
|
|
|
|
private TimeSpan _remainingTime;
|
|
public void ShowUI(EventPackManager packManager, int eventID,bool isClaimedFreePack,TimeSpan remainingTime,Action onClickFree,float? inflationRate)
|
|
{
|
|
_remainingTime = remainingTime;
|
|
UpdateEventTime();
|
|
Observable.Interval(TimeSpan.FromSeconds(1f))
|
|
.Subscribe(_ => UpdateEventTime())
|
|
.AddTo(this);
|
|
|
|
var packIDs = packManager.GetPackIDsByCurrentVipLevel();
|
|
if (packIDs.Count != 3)
|
|
{
|
|
Debug.LogError($"配置错误 packIDs.Count not 3 packManager id {packManager.ID} ");
|
|
return;
|
|
}
|
|
var playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
for (int i = 0; i < _packCells.Length; i++)
|
|
{
|
|
var cell=_packCells[i];
|
|
if (i >= packIDs.Count)
|
|
{
|
|
cell.gameObject.SetActive(false);
|
|
continue;
|
|
}
|
|
|
|
var pack=Tables.TbPack.GetOrDefault(packIDs[i]);
|
|
if (pack == null)
|
|
{
|
|
Debug.LogError($" pack is null id {packIDs[i]}");
|
|
continue;
|
|
}
|
|
var iapItem = Tables.TbIAPItemList?.GetOrDefault(pack.IAPID);
|
|
var sKUDetailDataEvent = new SKUDetailDataEvent(iapItem);
|
|
GContext.Publish(sKUDetailDataEvent);
|
|
var itemDatas=playerItemData.GetItemDataByDropIdLureInflation(inflationRate, pack.DropID);
|
|
if (iapItem == null)
|
|
cell.Init(sKUDetailDataEvent.price, itemDatas, () => OnClickFreeBuyBtn(itemDatas, onClickFree, isClaimedFreePack),isGary:isClaimedFreePack);
|
|
else
|
|
cell.Init(sKUDetailDataEvent.price, itemDatas,
|
|
() => OnClickBuyBtn(pack.DropID, eventID, iapItem, itemDatas));
|
|
cell.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private async void OnClickBuyBtn(int dropId,int eventId, IAPItemList iAPItemList,List<ItemData> itemDatas)
|
|
{
|
|
try
|
|
{
|
|
await OnClickBuy(dropId, eventId,iAPItemList,itemDatas);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void OnClickFreeBuyBtn(List<ItemData> itemDataGift, Action onClick, bool isClaimedFreePack)
|
|
{
|
|
if (isClaimedFreePack) return;
|
|
if (itemDataGift == null || itemDataGift.Count == 0) return;
|
|
|
|
var playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
var newItemData = itemDataGift.Where(x => x.id != 3002).ToList();
|
|
GContext.Publish(new ShowData(newItemData, RewardType.Normal));
|
|
playerItemData.AddItem(itemDataGift, null);
|
|
|
|
GContext.Publish(new EventTicketUpdate());
|
|
GContext.Publish(new ShowData());
|
|
onClick?.Invoke();
|
|
OnClickClose();
|
|
}
|
|
private async Task OnClickBuy(int dropId,int eventId, IAPItemList iAPItemList, List<ItemData> itemDatas)
|
|
{
|
|
bool res = await GContext.container.Resolve<PlayerShopData>().OnBuy(dropId,
|
|
new ShopBuyTypeData { type = ShopBuyType.None, ID = eventId }, iAPItemList,
|
|
itemDatas);
|
|
if (res)
|
|
{
|
|
GContext.Publish(new EventTicketUpdate());
|
|
OnClickClose();
|
|
}
|
|
}
|
|
|
|
private void OnClickClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(this.gameObject.name);
|
|
}
|
|
}
|
|
} |