using TMPro; using UnityEngine; using UnityEngine.UI; namespace DDD { public class ItemSlotUi : MonoBehaviour, IInventorySlotUi { [SerializeField] private Button _button; [SerializeField] private Image _icon; [SerializeField] private TextMeshProUGUI _countText; [SerializeField] private Image _markImage; public ItemViewModel Model { get; private set; } private const string CheckNoSpriteKey = "CheckNo"; private const string CheckYesSpriteKey = "CheckYes"; private const string EmptyDrinkSpriteKey = "EmptyDrink"; private const string EmptyFoodSpriteKey = "EmptyFood"; public void Initialize(ItemViewModel model, RecipeType recipeType = RecipeType.None) { // TODO : 오늘의 메뉴에서 텍스트 출력 없애기 Model = model; _button.onClick.RemoveAllListeners(); _button.onClick.AddListener(() => { RestaurantEvents.ItemSlotSelectedEvent.Model = Model; EventBus.Broadcast(RestaurantEvents.ItemSlotSelectedEvent); }); if (Model != null) { _icon.sprite = model.ItemSprite; _countText.text = model.Count.ToString(); EnableCountText(); _button.interactable = true; } else { if (recipeType == RecipeType.FoodRecipe) { SetEmptyFood(); } else if (recipeType == RecipeType.DrinkRecipe) { SetEmptyDrink(); } _countText.gameObject.SetActive(false); _button.interactable = false; } } public bool CanCraft() { return Model.Count > 0; } public void EnableCountText() { _countText.gameObject.SetActive(true); _markImage.gameObject.SetActive(false); } public void EnableMarkImage() { // TODO : 추후에 현재 등록된 요리도구와 매칭되는지 체크 //_markImage.sprite = registered ? _checkSprite : _xSprite; _countText.gameObject.SetActive(false); _markImage.gameObject.SetActive(true); } public void SetEmptyFood() { _icon.sprite = DataManager.Instance.GetSprite(EmptyFoodSpriteKey); _markImage.gameObject.SetActive(false); _button.interactable = false; } public void SetEmptyDrink() { _icon.sprite = DataManager.Instance.GetSprite(EmptyDrinkSpriteKey); _markImage.gameObject.SetActive(false); _button.interactable = false; } public void SetActive(bool value) => gameObject.SetActive(value); } }