using System; using BlueWater.Items; using TMPro; using UnityEngine; using UnityEngine.UI; namespace BlueWater.Uis { [Serializable] public class BrewingIngredientSlotUi : MonoBehaviour { [SerializeField] private Image _image; [SerializeField] private TMP_Text _quantity; [SerializeField] private Color _enoughColor = Color.black; [SerializeField] private Color _notEnoughColor = Color.red; private string _ingredientIdx; private int _inventoryQuantity; private int _needQuantity; private bool _isEnough; /// /// 양조장에서 레시피를 선택했을 때, 재료를 설정하는 함수 /// /// 재료의 Idx /// 재료 요구량 public void SetIngredient(string ingredientIdx, int quantity) { _ingredientIdx = ingredientIdx; _needQuantity = quantity; var ingredientItemData = ItemManager.Instance.GetItemDataByIdx(_ingredientIdx); _image.sprite = ingredientItemData.Sprite; _inventoryQuantity = DataManager.Instance.Inventory.GetItemByIdx(_ingredientIdx).Quantity; SetQuantity(); } /// /// 재료 수량 변경하는 함수 /// 여러개를 제작하는 경우 multiply값을 조정 /// /// 제조하는 개수 public void SetQuantity(int multiply = 1) { var finalNeedQuantity = _needQuantity * multiply; _quantity.text = $"{_inventoryQuantity}/{finalNeedQuantity}"; _isEnough = _inventoryQuantity >= finalNeedQuantity; _quantity.color = _isEnough ? _enoughColor : _notEnoughColor; } /// /// 현재 인벤토리의 재료로 만들 수 있는 최대 개수 반환 함수 /// /// public int GetMaxQuantity() { if (_needQuantity == 0) return 1; return _inventoryQuantity / _needQuantity; } public bool GetIsEnough() => _isEnough; } }