备份CatanBuilding瘦身独立工程
This commit is contained in:
78
Assets/Scripts/EventCan/GeneralEventNormalPackPanel.cs
Normal file
78
Assets/Scripts/EventCan/GeneralEventNormalPackPanel.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
using UniRx;
|
||||
|
||||
public class GeneralEventNormalPackPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TMP_Text textTimer, textPriceLeft, textPriceRight, textCountLeft, textCountRight, textDiscount;
|
||||
[SerializeField] private Button btnClose, btnBuyLeft, btnBuyRight;
|
||||
private IAPItemList _iapLeft, _iapRight;
|
||||
private PlayerItemData _playerItemData;
|
||||
private DateTime _expireTime;
|
||||
private TimeSpan RemainingTime => _expireTime - ZZTimeHelper.UtcNow();
|
||||
private int _eventId;
|
||||
private Pack _packLeft, _packRight;
|
||||
|
||||
public void Init(GeneralEventNormalPackInfo info)
|
||||
{
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
_eventId = info.EventId;
|
||||
_packLeft = info.PackLeft;
|
||||
_packRight = info.PackRight;
|
||||
_expireTime = info.ExpireTime;
|
||||
_playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
textTimer.text = ConvertTools.ConvertTime2(RemainingTime);
|
||||
Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ =>
|
||||
{
|
||||
textTimer.text = ConvertTools.ConvertTime2(RemainingTime);
|
||||
if (RemainingTime.TotalSeconds <= 0) OnClickClose();
|
||||
}).AddTo(this);
|
||||
_playerItemData.ResolveIapId(_packLeft.IAPID, out _iapLeft, textPriceLeft);
|
||||
_playerItemData.ResolveIapId(_packRight.IAPID, out _iapRight, textPriceRight);
|
||||
btnBuyLeft.onClick.AddListener(() => _ = OnClickBuy(_packLeft.DropID, _iapLeft));
|
||||
btnBuyRight.onClick.AddListener(() => _ = OnClickBuy(_packRight.DropID, _iapRight));
|
||||
textCountLeft.text =
|
||||
((int)_playerItemData.GetItemDataByDropId(_packLeft.DropID)[0].count).ToString();
|
||||
textCountRight.text =
|
||||
((int)_playerItemData.GetItemDataByDropId(_packRight.DropID)[0].count).ToString();
|
||||
textDiscount.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_2", GetDiscountNumber());
|
||||
}
|
||||
|
||||
private int GetDiscountNumber()
|
||||
{
|
||||
float discount = _packRight.Rebate * 100;
|
||||
return (int)discount;
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task OnClickBuy(int dropId, IAPItemList iapItemList)
|
||||
{
|
||||
if (RemainingTime.TotalSeconds <= 0)
|
||||
return;
|
||||
bool res = await GContext.container.Resolve<PlayerShopData>().OnBuy(dropId,
|
||||
new ShopBuyTypeData { type = ShopBuyType.EventPack, ID = _eventId }, iapItemList,
|
||||
_playerItemData.GetItemDataByDropId(dropId));
|
||||
if (res)
|
||||
{
|
||||
GContext.Publish(new EventTicketUpdate());
|
||||
OnClickClose();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClickClose()
|
||||
{
|
||||
// RedPointManager.Instance.SetRedPointState(EventShootingRangeData.PackRedPointId, false);
|
||||
UIManager.Instance.DestroyUI(gameObject.name);
|
||||
}
|
||||
}
|
||||
public class GeneralEventNormalPackInfo
|
||||
{
|
||||
public int EventId;
|
||||
public Pack PackLeft, PackRight;
|
||||
public DateTime ExpireTime;
|
||||
}
|
||||
Reference in New Issue
Block a user