备份CatanBuilding瘦身独立工程
This commit is contained in:
106
Assets/Scripts/UI/Shop/LackOfTicketPopupPanel.cs
Normal file
106
Assets/Scripts/UI/Shop/LackOfTicketPopupPanel.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class LackOfTicketPopupPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RewardItemNew _rewardShown;
|
||||
[SerializeField] private Button btnBuy, btnMask, btnDiscount;
|
||||
[SerializeField] private TMP_Text textPrice, textPriceOrigin, textPriceDiscount, textDiscount;
|
||||
[SerializeField] private GameObject discountTag;
|
||||
private Tables _tables;
|
||||
private TbWheelLevel _tableWheelLevel;
|
||||
private FishingEventData _fishingEventData;
|
||||
private PlayerItemData _playerItemData;
|
||||
private int _wheelLvl, _diamondCost;
|
||||
private ItemData _reward;
|
||||
private const int LackOfTicketPurchaseCount = -2;
|
||||
private TbWheelInit _tableWheelInit;
|
||||
private int PurchaseCount
|
||||
{
|
||||
get => _fishingEventData.WheelLevelCount[LackOfTicketPurchaseCount];
|
||||
set => _fishingEventData.WheelLevelCount[LackOfTicketPurchaseCount] = value;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
btnMask.onClick.AddListener(OnClickContinue);
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
_tableWheelLevel = _tables.TbWheelLevel;
|
||||
_tableWheelInit = _tables.TbWheelInit;
|
||||
_fishingEventData = GContext.container.Resolve<FishingEventData>();
|
||||
_wheelLvl = _fishingEventData.wheelLevel.Level;
|
||||
_reward = new ItemData(1004, _tableWheelLevel[_wheelLvl].BuyCount);
|
||||
SetupPurchaseConfig();
|
||||
_playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
_rewardShown.SetData(_reward);
|
||||
btnBuy.onClick.AddListener(OnClickBuy);
|
||||
btnDiscount.onClick.AddListener(OnClickBuy);
|
||||
}
|
||||
|
||||
private void SetupPurchaseConfig()
|
||||
{
|
||||
_diamondCost = _tableWheelLevel[_wheelLvl].Price;
|
||||
var discountList = _tableWheelInit.DataList[0].Discount;
|
||||
if (PurchaseCount >= discountList.Count)
|
||||
{
|
||||
btnBuy.gameObject.SetActive(true);
|
||||
btnDiscount.gameObject.SetActive(false);
|
||||
discountTag.SetActive(false);
|
||||
textPrice.text = ConvertTools.GetNumberString(_diamondCost);
|
||||
}
|
||||
else
|
||||
{
|
||||
btnBuy.gameObject.SetActive(false);
|
||||
btnDiscount.gameObject.SetActive(true);
|
||||
discountTag.SetActive(true);
|
||||
textDiscount.text = ConvertTools.GetNumberString3(discountList[PurchaseCount]);
|
||||
textPriceOrigin.text = ConvertTools.GetNumberString(_diamondCost);
|
||||
_diamondCost = (int) (_diamondCost * discountList[PurchaseCount]);
|
||||
int r = _diamondCost % 5;
|
||||
_diamondCost -= r;
|
||||
if (r >= 3)
|
||||
_diamondCost += 5;
|
||||
textPriceDiscount.text = ConvertTools.GetNumberString(_diamondCost);
|
||||
}
|
||||
}
|
||||
private void OnClickBuy()
|
||||
{
|
||||
int diamondCount = (int)_playerItemData.GetItemCount(1005);
|
||||
if (diamondCount < _diamondCost)
|
||||
{
|
||||
UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerItemData.AddItem(_reward);
|
||||
_playerItemData.AddItemCount(1005, -_diamondCost);
|
||||
GContext.Publish(new ShowData(_reward));
|
||||
GContext.Publish(new ShowData());
|
||||
PurchaseCount++;
|
||||
_fishingEventData.UpdateTurnTableData();
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("resource_shop"))
|
||||
{
|
||||
e.AddContent("cost_diamond_count", _diamondCost)
|
||||
.AddContent("change_type", 5)
|
||||
.AddContent("change_num", _reward.count)
|
||||
.AddContent("item_id", "1004")
|
||||
.AddContent("change_count", 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
GContext.Publish(new ResAddEvent(1004));
|
||||
UIManager.Instance.DestroyUI(UITypes.LackOfTicketPopupPanel);
|
||||
}
|
||||
}
|
||||
private void OnClickContinue()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.LackOfTicketPopupPanel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user