备份CatanBuilding瘦身独立工程
This commit is contained in:
147
Assets/Scripts/UI/Shop/GiftPopupPanel_3.cs
Normal file
147
Assets/Scripts/UI/Shop/GiftPopupPanel_3.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GiftPopupPanel_3 : GiftPopupPanel
|
||||
{
|
||||
string Type = "WheelPack";
|
||||
GameObject Advert;
|
||||
Button btn_advert;
|
||||
GameObject soldout;
|
||||
|
||||
WheelPack wheelPack;
|
||||
FishingEventData _fishingEventData;
|
||||
IDisposable ads;
|
||||
|
||||
private AdvertPopupType _curOpenAdType = AdvertPopupType.None;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
soldout = transform.Find("root/soldout").gameObject;
|
||||
Advert = transform.Find("root/advert").gameObject;
|
||||
btn_advert = transform.Find("root/advert/btn_advert").GetComponent<Button>();
|
||||
}
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
wheelPack = _tables.TbWheelPack[1];
|
||||
_fishingEventData = GContext.container.Resolve<FishingEventData>();
|
||||
SetAdvertState();
|
||||
btn_advert.onClick.AddListener(OnWatchClick);
|
||||
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
SetData();
|
||||
}
|
||||
|
||||
public void SetData()
|
||||
{
|
||||
int vipLevel = GContext.container.Resolve<TriggerPackData>().GetVIPLevel(Type);
|
||||
int buyCount = GContext.container.Resolve<PlayerShopData>().GetShopPackBuyCount(Type);
|
||||
var PackList = wheelPack.PackList[vipLevel];
|
||||
if (buyCount >= PackList.Count)
|
||||
{
|
||||
buyCount = PackList.Count - 1;
|
||||
}
|
||||
pack = _tables.TbPack.GetOrDefault(wheelPack.PackList[vipLevel][buyCount]);
|
||||
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.0001);
|
||||
text_best.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_2", pack.Rebate * 100);
|
||||
SetState();
|
||||
}
|
||||
|
||||
protected override ShopBuyTypeData GetShopBuyTypeData()
|
||||
{
|
||||
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
|
||||
shopBuyTypeData.type = ShopBuyType.ShopPackDailyBuy;
|
||||
shopBuyTypeData.key = Type;
|
||||
shopBuyTypeData.endDay = ZZTimeHelper.UtcNow().UtcNowOffset().Day;
|
||||
return shopBuyTypeData;
|
||||
}
|
||||
protected override void OnSuccess()
|
||||
{
|
||||
GContext.container.Resolve<PlayerShopData>().AddShopPackDailyBuyCount(Type);
|
||||
//GContext.container.Resolve<PlayerShopData>().AddShopPackDailyBuyCount(pack.ID, 1);
|
||||
GContext.container.Resolve<TriggerPackData>().SetVIPLevel(Type, wheelPack.VIPBonusForNextType);
|
||||
//SetState();
|
||||
OnClickClose();
|
||||
}
|
||||
protected override void OnBuySuccess()
|
||||
{
|
||||
//GContext.container.Resolve<PlayerShopData>().AddShopPackDailyBuyCount(Type);
|
||||
//GContext.container.Resolve<PlayerShopData>().AddShopPackDailyBuyCount(pack.ID, 1);
|
||||
GContext.container.Resolve<TriggerPackData>().SetVIPLevel(Type, wheelPack.VIPBonusForNextType);
|
||||
//SetState();
|
||||
OnClickClose();
|
||||
}
|
||||
void SetState()
|
||||
{
|
||||
int remainder = wheelPack.MaxPurchaseCount - GContext.container.Resolve<PlayerShopData>().GetShopPackBuyCount(Type);
|
||||
if (remainder <= 0)
|
||||
{
|
||||
remainder = 0;
|
||||
}
|
||||
Remaining.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_1", remainder, wheelPack.MaxPurchaseCount);
|
||||
soldout.SetActive(remainder <= 0);
|
||||
btn_buy.gameObject.SetActive(remainder > 0);
|
||||
}
|
||||
protected void OnClickClose()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.GiftPopupPanel_3);
|
||||
}
|
||||
|
||||
private void OnWatchClick()
|
||||
{
|
||||
btn_advert.enabled = false;
|
||||
AdsDispose();
|
||||
ads = GContext.OnEvent<AdsResult>().Subscribe(SetResult);
|
||||
_curOpenAdType = AdvertPopupType.Turntable;
|
||||
GContext.container.Resolve<IAdsService>().ShowRewarded(AdvertPopupType.Turntable);
|
||||
}
|
||||
void SetResult(AdsResult adsResult)
|
||||
{
|
||||
if (adsResult.Result == 0 && adsResult.Type == _curOpenAdType)
|
||||
{
|
||||
OnSucceed();
|
||||
}
|
||||
AdsDispose();
|
||||
btn_advert.enabled = true;
|
||||
}
|
||||
void AdsDispose()
|
||||
{
|
||||
if (ads != null)
|
||||
{
|
||||
_curOpenAdType = AdvertPopupType.None;
|
||||
ads.Dispose();
|
||||
ads = null;
|
||||
}
|
||||
}
|
||||
|
||||
void OnSucceed()
|
||||
{
|
||||
GContext.container.Resolve<PlayerShopData>().AddAdvertCount(_fishingEventData.wheelInit.ID);
|
||||
GContext.container.Resolve<PlayerItemData>().AddItemByDrop(1000001);
|
||||
GContext.Publish(new ShowData());
|
||||
SetAdvertState();
|
||||
}
|
||||
void SetAdvertState()
|
||||
{
|
||||
int count = GContext.container.Resolve<PlayerShopData>().GetAdvertCount(_fishingEventData.wheelInit.ID);
|
||||
int WheelIAADailyCount = _tables.TbGlobalConfig.WheelIAADailyCount;
|
||||
Advert.SetActive(count < WheelIAADailyCount);
|
||||
}
|
||||
protected void OnDestroy()
|
||||
{
|
||||
AdsDispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user