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.
112 lines
3.4 KiB
112 lines
3.4 KiB
using UnityEngine;
|
|
using TMPro;
|
|
using IVDataFormat;
|
|
|
|
public class IVPpItemsUseTo : MonoBehaviour
|
|
{
|
|
protected TextMeshProUGUI txtTitle;
|
|
protected TextMeshProUGUI txtMsg;
|
|
protected TextMeshProUGUI txtBtnYes;
|
|
protected TextMeshProUGUI txtBtnNo;
|
|
|
|
protected GoodsItem goodsItemTo;
|
|
protected GoodsItem[] goodsItemUses;
|
|
protected TextMeshProUGUI[] txtItemUses;
|
|
|
|
protected ButtonIV btnYes;
|
|
|
|
protected System.Action actionBtnYes;
|
|
protected System.Action actionBtnNo;
|
|
|
|
|
|
|
|
public bool IsOpen()
|
|
{
|
|
return gameObject.activeSelf;
|
|
}
|
|
|
|
public virtual void Init()
|
|
{
|
|
txtTitle = transform.Find("txtTitle").GetComponent<TextMeshProUGUI>();
|
|
txtMsg = transform.Find("txtMsg").GetComponent<TextMeshProUGUI>();
|
|
btnYes = transform.Find("btnYes").GetComponent<ButtonIV>();
|
|
txtBtnYes = btnYes.transform.Find("txt").GetComponent<TextMeshProUGUI>();
|
|
txtBtnNo = transform.Find("btnNo").Find("txt").GetComponent<TextMeshProUGUI>();
|
|
|
|
goodsItemTo = transform.Find("GoodsItemTo").GetComponent<GoodsItem>();
|
|
goodsItemUses = transform.Find("uses").GetComponentsInChildren<GoodsItem>(true);
|
|
txtItemUses = new TextMeshProUGUI[goodsItemUses.Length];
|
|
for (int i = 0; i < goodsItemUses.Length; i++)
|
|
{
|
|
txtItemUses[i] = goodsItemUses[i].transform.Find("txtUse").GetComponent<TextMeshProUGUI>();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void Open(nGoods[] goodsuses, nGoods goodsto, System.Action actionyes, System.Action actionno = null, string strtitle = null, string strmsg = null, string stryes = null, string strno = null)
|
|
{
|
|
if (string.IsNullOrEmpty(strtitle))
|
|
strtitle = LocalizationText.GetText(Global.STR_USE);
|
|
if (string.IsNullOrEmpty(stryes))
|
|
stryes = LocalizationText.GetText(Global.STR_USE);
|
|
if (string.IsNullOrEmpty(strno))
|
|
strno = LocalizationText.GetText(Global.STR_CANCEL);
|
|
|
|
txtTitle.text = strtitle;
|
|
txtMsg.text = strmsg;
|
|
txtBtnYes.text = stryes;
|
|
txtBtnNo.text = strno;
|
|
|
|
for (int i = 0; i < goodsItemUses.Length; i++)
|
|
{
|
|
if (i >= goodsuses.Length)
|
|
{
|
|
goodsItemUses[i].gameObject.SetActive(false);
|
|
continue;
|
|
}
|
|
goodsItemUses[i].gameObject.SetActive(true);
|
|
goodsItemUses[i].SetData(goodsuses[i]);
|
|
}
|
|
goodsItemTo.SetData(goodsto);
|
|
|
|
actionBtnYes = actionyes;
|
|
actionBtnNo = actionno;
|
|
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void SetCount(int[] icnthaves, int[] icntneeds)
|
|
{
|
|
bool bavail = true;
|
|
for (int i = 0; i < txtItemUses.Length; i++)
|
|
{
|
|
if (i >= icnthaves.Length)
|
|
break;
|
|
txtItemUses[i].text = FormatString.TextCntPerRed(icnthaves[i], icntneeds[i]);
|
|
if (icnthaves[i] < icntneeds[i])
|
|
bavail = false;
|
|
}
|
|
btnYes.interactable = bavail;
|
|
}
|
|
|
|
|
|
public void BtnYesPressed()
|
|
{
|
|
SoundMgr.PlaySfx(SoundName.BtnPress);
|
|
GameUIMgr.SOnClosePopup();
|
|
gameObject.SetActive(false);
|
|
if (actionBtnYes != null)
|
|
actionBtnYes.Invoke();
|
|
}
|
|
|
|
public void BtnNoPressed()
|
|
{
|
|
SoundMgr.PlaySfx(SoundName.BtnPress);
|
|
GameUIMgr.SOnClosePopup();
|
|
gameObject.SetActive(false);
|
|
if (actionBtnNo != null)
|
|
actionBtnNo.Invoke();
|
|
}
|
|
|
|
}
|