备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
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 = "";
|
||||
}
|
||||
Reference in New Issue
Block a user