You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.7 KiB

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using IVDataFormat;
public class EscrExchangePanel : MonoBehaviour
{
TextMeshProUGUI txtTitle;
TextMeshProUGUI txtBuyCount;
TextMeshProUGUI txtGoodsCount;
TextMeshProUGUI txtPrice;
ButtonIV btnBuy;
Image imgGoods;
GameObject soldOut;
TextMeshProUGUI txtSoldOut;
int itemID;
nRewardLimit Goods;
public void Init()
{
imgGoods = transform.Find("explainImg").GetComponent<Image>();
txtTitle = transform.Find("txtGoodTitle").GetComponent<TextMeshProUGUI>();
txtBuyCount = transform.Find("txtChangeCount").GetComponent<TextMeshProUGUI>();
txtGoodsCount = transform.Find("txtCount").GetComponent<TextMeshProUGUI>();
btnBuy = transform.Find("btnBuy").GetComponent<ButtonIV>();
txtPrice = btnBuy.transform.Find("txtCount").GetComponent<TextMeshProUGUI>();
soldOut = transform.Find("soldOut").gameObject;
txtSoldOut = soldOut.transform.Find("txtGoodTitle").GetComponent<TextMeshProUGUI>();
}
public void SetData(int itemid, nRewardLimit goods)
{
Init();
itemID = itemid;
Goods = goods;
imgGoods.sprite = AddressableMgr.GetIcon(goods.rewardType, goods.rewardId);
txtTitle.text = FormatString.GetGoodsName(goods.rewardType, goods.rewardId);
txtGoodsCount.text = goods.rewardCount.ToString();
txtPrice.text = goods.price.ToString();
int nowLeft = 0;
for(int i = 0; i < DataHandler.GetPlayEventTrade().rewards.Length; i++)
{
if(itemid == DataHandler.GetPlayEventTrade().rewards[i].sid - 1)
{
nowLeft = goods.limitCnt - DataHandler.GetPlayEventTrade().rewards[i].buyCnt;
}
}
txtBuyCount.text = FormatString.StringFormat(LocalizationText.GetText("event_exchange_count"), Mathf.Max(nowLeft, 0), goods.limitCnt);
if(nowLeft <= 0)
{
btnBuy.interactable = false;
soldOut.SetActive(true);
txtSoldOut.text = LocalizationText.GetText("event_shop_soldout");
txtPrice.color = new Color(1f, 1f, 1f);
}
else if (goods.price > DataHandler.GetPlayEventTrade().item)
{
btnBuy.interactable = false;
txtPrice.color = new Color(255f / 255f, 114f / 255f, 114f / 255f, 1f);
}
else
{
btnBuy.interactable = true;
soldOut.SetActive(false);
txtPrice.color = new Color(1f, 1f, 1f);
}
}
public void PressButton()
{
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
EventMgr.TradeRewardSetting(itemID, Goods);
}
}