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