68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using GameCore;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
|
|
public class LackOfCommonItemPopupPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private RewardItemNew reward;
|
|
[SerializeField] private Button btnBuy, btnMask;
|
|
[SerializeField] private Image iconCurrency;
|
|
[SerializeField] private TMP_Text textCurrencyCount, textTitle;
|
|
private PlayerItemData _playerItemData;
|
|
private LackOfCommonItemPopupPanelInfo _data;
|
|
private const string TitleDefaultKey = "UI_TurntableInfoPopupPanel_19";
|
|
private Item _reward;
|
|
|
|
public void Init(LackOfCommonItemPopupPanelInfo info)
|
|
{
|
|
reward.SetData(info.reward);
|
|
_reward = GContext.container.Resolve<Tables>().TbItem[info.reward.id];
|
|
var currencyIconUrl = GContext.container.Resolve<Tables>().TbItem[info.CurrencyId];
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(iconCurrency, currencyIconUrl.Icon);
|
|
textCurrencyCount.text = info.Cost.ToString();
|
|
if (info.TitleKey != "")
|
|
textTitle.text = LocalizationMgr.GetText(info.TitleKey);
|
|
else
|
|
textTitle.text = LocalizationMgr.GetFormatTextValue(TitleDefaultKey, LocalizationMgr.GetFormatTextValue(_reward.Name_l10n_key));
|
|
btnBuy.onClick.AddListener(OnClickBuy);
|
|
btnMask.onClick.AddListener(OnClickContinue);
|
|
_playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
_data = info;
|
|
}
|
|
|
|
private void OnClickBuy()
|
|
{
|
|
var currencyCount = (int)_playerItemData.GetItemCount(_data.CurrencyId);
|
|
if (currencyCount < _data.Cost)
|
|
{
|
|
_ = UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
|
|
}
|
|
else
|
|
{
|
|
_playerItemData.AddItem(_data.reward);
|
|
_playerItemData.AddItemCount(_data.CurrencyId, -_data.Cost);
|
|
GContext.Publish(new ShowData(_data.reward));
|
|
GContext.Publish(new ShowData());
|
|
GContext.Publish(new ResAddEvent(1004));
|
|
UIManager.Instance.DestroyUI(UITypes.LackOfCommonItemPopupPanel);
|
|
}
|
|
}
|
|
|
|
private void OnClickContinue()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.LackOfCommonItemPopupPanel);
|
|
}
|
|
}
|
|
|
|
public class LackOfCommonItemPopupPanelInfo
|
|
{
|
|
public ItemData reward;
|
|
public int CurrencyId;
|
|
public int Cost;
|
|
public string TitleKey = "";
|
|
}
|