141 lines
4.5 KiB
C#
141 lines
4.5 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BattlePassActivePopupPanel : BasePanel
|
|
{
|
|
#region Field
|
|
[SerializeField]
|
|
private Button
|
|
btn_buyNormal,
|
|
btn_buySpecial,
|
|
btn_close;
|
|
|
|
[SerializeField]
|
|
private TMP_Text
|
|
txt_title,
|
|
txt_normalCost,
|
|
txt_specialCost;
|
|
|
|
[SerializeField]
|
|
RewardItemNew
|
|
rewardItem;
|
|
[SerializeField]
|
|
Transform
|
|
tran_vipBar,
|
|
tran_nomralBar;
|
|
|
|
BattlePassDataProvider _dataProvider;
|
|
#endregion
|
|
|
|
|
|
#region Func
|
|
private void Awake()
|
|
{
|
|
_dataProvider = GContext.container.Resolve<BattlePassDataProvider>();
|
|
}
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
var dic_iAPItemList = GContext.container.Resolve<Tables>().TbIAPItemList.DataMap;
|
|
var curPassMain = _dataProvider.curPassMain;
|
|
|
|
SKUDetailDataEvent ssde = new SKUDetailDataEvent(dic_iAPItemList[_dataProvider.curPassMain.PrimeIAPID]);
|
|
GContext.Publish(ssde);
|
|
txt_normalCost.text = ssde.price;
|
|
ssde = new SKUDetailDataEvent(dic_iAPItemList[_dataProvider.curPassMain.DeluxeIAPID]);
|
|
GContext.Publish(ssde);
|
|
txt_specialCost.text = ssde.price;
|
|
txt_title.text = LocalizationMgr.GetText("UI_BattlePassPanel_6");
|
|
|
|
rewardItem.gameObject.SetActive(false);
|
|
var dropID = _dataProvider.curPassMain.PrimeReward;
|
|
var itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdLureInflation(null, dropID);
|
|
for (int i = 1; i < itemDatas.Count; i++)
|
|
{
|
|
Instantiate(rewardItem, tran_nomralBar).SetData(itemDatas[i]);
|
|
}
|
|
dropID = _dataProvider.curPassMain.DeluxeReward;
|
|
itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdLureInflation(null, dropID);
|
|
for (int i = 1; i < itemDatas.Count; i++)
|
|
{
|
|
Instantiate(rewardItem, tran_vipBar).SetData(itemDatas[i]);
|
|
}
|
|
|
|
btn_close.OnClickAsObservable().Subscribe(_ => Close()).AddTo(disposables);
|
|
btn_buyNormal.OnClickAsObservable().Subscribe(_ => OnBuy(0)).AddTo(disposables);
|
|
btn_buySpecial.OnClickAsObservable().Subscribe(_ => OnBuy(1)).AddTo(disposables);
|
|
}
|
|
|
|
protected void Close()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.BattlePassActivePopupPanel);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="scope">0:Normal 1:Special</param>
|
|
async void OnBuy(int scope)
|
|
{
|
|
var iAPItemID = scope == 0 ? _dataProvider.curPassMain.PrimeIAPID : scope == 1 ? _dataProvider.curPassMain.DeluxeIAPID : -1;
|
|
var iAPItemList = GContext.container.Resolve<Tables>().TbIAPItemList.GetOrDefault(iAPItemID);
|
|
var dropID = scope == 0 ? _dataProvider.curPassMain.PrimeReward : scope == 1 ? _dataProvider.curPassMain.DeluxeReward : -1;
|
|
var itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdLureInflation(null, dropID);
|
|
ChangeSource changeSource = new ChangeSource(_dataProvider.Data.BattlePassRecord.ID, "BattlePass", "BattlePass_Normal28Day", "PurchaseReward");
|
|
for (int i = 0; i < itemDatas.Count; i++)
|
|
{
|
|
var itemData = itemDatas[i];
|
|
itemData.changeSource = changeSource;
|
|
}
|
|
var startLevel = _dataProvider.GetBPCurLevel;
|
|
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
|
|
shopBuyTypeData.type = ShopBuyType.None;
|
|
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(dropID, shopBuyTypeData, iAPItemList, itemDatas);
|
|
if (Result)
|
|
{
|
|
#if AGG
|
|
using ( var e = GEvent.GameEvent("bp_active") )
|
|
{
|
|
e.AddContent("bp_level", startLevel)
|
|
.AddContent("active_type", scope+1);
|
|
}
|
|
#endif
|
|
OnBuySuccess(scope);
|
|
}
|
|
}
|
|
|
|
/*async*/
|
|
void OnBuySuccess(int scope)
|
|
{
|
|
|
|
GContext.Publish(new BpVipUnlock());
|
|
if (scope == 1)
|
|
GContext.Publish(new BpGetExp());
|
|
Close();
|
|
//await WaitForRewardPanel();
|
|
}
|
|
|
|
private async System.Threading.Tasks.Task WaitForRewardPanel()
|
|
{
|
|
var count = 0;
|
|
var rewardInfo = new RewardPopupData();
|
|
while (count++ < 5)
|
|
{
|
|
GContext.Publish(rewardInfo);
|
|
if (rewardInfo.isShow)
|
|
{
|
|
await rewardInfo.tcs.Task;
|
|
break;
|
|
}
|
|
await new WaitForSeconds(0.2f);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|