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 ObjectIndicator[] 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(); txtMsg = transform.Find("txtMsg").GetComponent(); btnYes = transform.Find("btnYes").GetComponent(); txtBtnYes = btnYes.transform.Find("txt").GetComponent(); txtBtnNo = transform.Find("btnNo").Find("txt").GetComponent(); goodsItemTo = transform.Find("GoodsItemTo").GetComponent(); #if false goodsItemUses = transform.Find("uses").GetComponentsInChildren(true); #else goodsItemUses = transform.Find("uses").GetComponentsInChildren(true); #endif txtItemUses = new TextMeshProUGUI[goodsItemUses.Length]; for (int i = 0; i < goodsItemUses.Length; i++) { txtItemUses[i] = goodsItemUses[i].transform.Find("txtUse").GetComponent(); } } 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); ObjectIndicatorSetter.SetWith(goodsItemUses[i], goodsuses[i]); //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.Instance.PlaySfx(SoundName.BtnPress); GameUIMgr.SOnClosePopup(); gameObject.SetActive(false); if (actionBtnYes != null) actionBtnYes.Invoke(); } public void BtnNoPressed() { SoundMgr.Instance.PlaySfx(SoundName.BtnPress); GameUIMgr.SOnClosePopup(); gameObject.SetActive(false); if (actionBtnNo != null) actionBtnNo.Invoke(); } }